Cell down alarm notification [Issue-Id: ODUHIGH-430]
[o-du/l2.git] / src / o1 / ves / JsonHelper.cpp
index 5eeb39f..595222c 100644 (file)
@@ -94,6 +94,29 @@ cJSON* JsonHelper::addNodeToObject(cJSON * parent, \
 }
 
 
+/*******************************************************************
+ *
+ * @brief wraps cJSON_AddNumberToObject cJSON library function
+ *
+ * @details
+ *
+ *    Function : addNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_AddNumberToObject cJSON library function
+ *
+ * @params[in] cJSON * parent, const char * nodeName, bool value
+ * @return pointer to cJSON object     - success
+ *         NULL                        - failure
+ *
+ * ****************************************************************/
+
+cJSON* JsonHelper::addNodeToObject(cJSON * parent, \
+                                          const char * nodeName, bool value)
+{
+   return cJSON_AddBoolToObject(parent, nodeName, (bool) value);
+}
+
 /*******************************************************************
  *
  * @brief wraps cJSON_AddItemToObject cJSON library function
@@ -117,6 +140,7 @@ cJSON_bool JsonHelper::addJsonNodeToObject(cJSON * parent, \
    return cJSON_AddItemToObject(parent, nodeName, node);
 }
 
+
 /*******************************************************************
  *
  * @brief wraps cJSON_Delete cJSON library function
@@ -223,15 +247,15 @@ const char *JsonHelper::getError()
  *
  * ****************************************************************/
 
-char* JsonHelper::getValue(cJSON *json, const char *node)
+string JsonHelper::getValue(cJSON *json, const char *node)
 {
    cJSON *object;
-   char * value = NULL;
+   string value = "";
    object = cJSON_GetObjectItem(json, node);
    if(object)
    {
       value = object->valuestring;
-      O1_LOG("O1 VES : [ %s] : [%s]\n",node, value );
+      O1_LOG("O1 VES : [ %s] : [%s]\n",node, value.c_str() );
    }
    else
       O1_LOG("O1 VES : node [ %s] not found\n",node);
@@ -283,18 +307,30 @@ cJSON* JsonHelper::read(const char * fileName)
    std::fstream fs(fileName, std::ios::in | std::ios::binary);
 
    if (!fs) {
-       O1_LOG("O1 VES : json can NOT open file %s\n", fileName);
-        return NULL;
+      O1_LOG("\nO1 JsonHelper : Cannot open file %s", fileName);
+      return NULL;
    }
 
    std::stringstream iss;
 
    iss << fs.rdbuf();
 
-    cJSON *json = cJSON_Parse(iss.str().c_str());
-    return json;
+   cJSON *json = cJSON_Parse(iss.str().c_str());
+   return json;
+}
+
+cJSON* JsonHelper::createArray() 
+{
+   return cJSON_CreateArray();
 }
 
+cJSON_bool JsonHelper::addJsonNodeToArray(cJSON * array, cJSON* node)
+{
+   return cJSON_AddItemToArray(array, node);
+}
+
+
+
 /**********************************************************************
   End of file
  **********************************************************************/