VOL-2263: Issues with creating itu-pon-alloc object

- Wait for asynchronous ITU PON Alloc Configuration Completed
  indication before reporting the response to CreateSched/RemoveSched
  from voltha.

Change-Id: I56a06970625e891e197ff9d87e02d73b06070af5
diff --git a/agent/common/Queue.h b/agent/common/Queue.h
index 30fbbda..2e366ce 100644
--- a/agent/common/Queue.h
+++ b/agent/common/Queue.h
@@ -18,17 +18,21 @@
 {
  public:
 
-  std::pair<T, bool> pop(int timeout)
+  // timeout is in milliseconds, wait_granularity in milliseconds
+  std::pair<T, bool> pop(int timeout, int wait_granularity=10)
   {
     std::cv_status status = std::cv_status::no_timeout;
     std::unique_lock<std::mutex> mlock(mutex_);
     static int duration = 0;
+    if (timeout < wait_granularity) {
+        wait_granularity = timeout;
+    }
     while (queue_.empty())
     {
-      status = cond_.wait_for(mlock, std::chrono::seconds(1));
+      status = cond_.wait_for(mlock, std::chrono::milliseconds(wait_granularity));
       if (status == std::cv_status::timeout)
       {
-        duration++;
+        duration+=wait_granularity;
         if (duration > timeout)
         {
           duration = 0;
diff --git a/agent/common/core.h b/agent/common/core.h
index bfb6c9b..4e79d2c 100644
--- a/agent/common/core.h
+++ b/agent/common/core.h
@@ -38,7 +38,7 @@
         BCM_LOG(level, id, "%s" fmt "%s", LIGHT_GREEN, ##__VA_ARGS__, NONE); \
     else \
         BCM_LOG(INFO, id, fmt, ##__VA_ARGS__);
-#define COLLECTION_PERIOD 15
+#define COLLECTION_PERIOD 15 // in seconds
 #define BAL_DYNAMIC_LIST_BUFFER_SIZE (32 * 1024)
 #define MAX_REGID_LENGTH  36
 
@@ -74,6 +74,33 @@
     STATE = 26
 };
 
+enum AllocCfgAction {
+    ALLOC_OBJECT_CREATE,
+    ALLOC_OBJECT_DELETE
+};
+
+enum AllocObjectState {
+    ALLOC_OBJECT_STATE_NOT_CONFIGURED,
+    ALLOC_OBJECT_STATE_INACTIVE,
+    ALLOC_OBJECT_STATE_PROCESSING,
+    ALLOC_OBJECT_STATE_ACTIVE
+};
+
+enum AllocCfgStatus {
+    ALLOC_CFG_STATUS_SUCCESS,
+    ALLOC_CFG_STATUS_FAIL
+};
+
+typedef struct {
+    uint32_t pon_intf_id;
+    uint32_t alloc_id;
+    AllocObjectState state;
+    AllocCfgStatus status;
+} alloc_cfg_complete_result;
+
+// key for map used for tracking ITU PON Alloc Configuration results from BAL
+typedef std::tuple<uint32_t, uint32_t> alloc_cfg_compltd_key;
+
 Status Enable_(int argc, char *argv[]);
 Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
     const char *vendor_id, const char *vendor_specific, uint32_t pir);
diff --git a/agent/common/server.cc b/agent/common/server.cc
index 9e1eb86..1c67137 100644
--- a/agent/common/server.cc
+++ b/agent/common/server.cc
@@ -182,7 +182,7 @@
         state.connect();
 
         while (state.is_connected()) {
-            std::pair<openolt::Indication, bool> ind = oltIndQ.pop(COLLECTION_PERIOD);
+            std::pair<openolt::Indication, bool> ind = oltIndQ.pop(COLLECTION_PERIOD*1000, 1000);
             if (ind.second == false) {
                 /* timeout - do lower priority periodic stuff like stats */
                 stats_collection();