X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fo1%2Fves%2FJsonHelper.cpp;h=595222c99edb91b4f4daa1c3cb79b743e569acdf;hb=f1f733a2f14d22b8725e121fa0f5e70a7febc9af;hp=5eeb39f26f683695562294a388959698a1c1d1e2;hpb=093afd2e854d73d697233396fb9c74ed67bdd615;p=o-du%2Fl2.git diff --git a/src/o1/ves/JsonHelper.cpp b/src/o1/ves/JsonHelper.cpp index 5eeb39f26..595222c99 100644 --- a/src/o1/ves/JsonHelper.cpp +++ b/src/o1/ves/JsonHelper.cpp @@ -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 **********************************************************************/