RDK Documentation (Open Sourced RDK Components)
dcajson.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 
21 
22 /**
23  * @defgroup dca
24  * @{
25  **/
26 
27 
28 
29 
30 /**
31  * @defgroup dca
32  * @{
33  * @defgroup src
34  * @{
35  **/
36 
37 // To provide telemetry data in a JSON format
38 
39 #include "dcautils.h"
40 
41 /**
42  * @addtogroup DCA_APIS
43  * @{
44  */
45 
46 
47 /**
48  * @brief This API creates "searchResult" JSON array.
49  *
50  * The search result list contains collection of telemetry marker headers with their value.
51  *
52  * Eg: {"searchResult":[{"MOCA_INFO_pnc_enabled":"1"},{"samv2_boardver_split":" V3.0 ##"},{"RF_ERR_DS_lockfail":"1"},{"RF_ERR_T3_timeout":"2"}]}
53  *
54  * @param[out] root JSON object
55  * @param[in] sr Search result JSON array
56  */
57 void initSearchResultJson(cJSON **root, cJSON **sr)
58 {
59  *root = cJSON_CreateObject();
60  if (NULL != *root) {
61  cJSON_AddItemToObject(*root, "searchResult", *sr = cJSON_CreateArray());
62  }
63 }
64 
65 /**
66  * @brief This API is to append the key/value pair to the SearchResult JSON array .
67  *
68  * @param[in] key marker name
69  * @param[in] value metric count
70  */
71 void addToSearchResult(char *key, char *value)
72 {
73  if (NULL != SEARCH_RESULT_JSON) {
74  cJSON *obj = cJSON_CreateObject();
75  if (NULL != obj) {
76  cJSON_AddStringToObject(obj, key, value);
77  cJSON_AddItemToArray(SEARCH_RESULT_JSON, obj);
78  }
79  }
80 }
81 
82 /**
83  * @brief This API deletes the result JSON object.
84  *
85  * @param[in] root JSON object to be deleted.
86  */
87 void clearSearchResultJson(cJSON **root)
88 {
89  cJSON_Delete(*root);
90 }
91 
92 /**
93  * @brief This API is to print Json result.
94  *
95  * @param[in] root JSON object.
96  *
97  * @return Returns the status of the operation.
98  */
99 void printJson(cJSON *root)
100 {
101  if (NULL != root) {
102  char *out = cJSON_PrintUnformatted(root);
103  if (NULL != out) {
104  printf("%s\n", out);
105  free(out);
106  }
107  }
108 }
109 
110 /** @} */ //END OF GROUP DCA_APIS
111 
112 /** @} */
113 
114 
115 /** @} */
116 /** @} */
addToSearchResult
void addToSearchResult(char *key, char *value)
This API is to append the key/value pair to the SearchResult JSON array .
Definition: dcajson.c:71
printJson
void printJson(cJSON *root)
This API is to print Json result.
Definition: dcajson.c:99
initSearchResultJson
void initSearchResultJson(cJSON **root, cJSON **sr)
This API creates "searchResult" JSON array.
Definition: dcajson.c:57
clearSearchResultJson
void clearSearchResultJson(cJSON **root)
This API deletes the result JSON object.
Definition: dcajson.c:87