/src/open5gs/lib/sbi/openapi/model/accuracy_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "accuracy_info.h" |
6 | | |
7 | | OpenAPI_accuracy_info_t *OpenAPI_accuracy_info_create( |
8 | | int accuracy_val, |
9 | | bool is_accu_sample_nbr, |
10 | | int accu_sample_nbr, |
11 | | OpenAPI_analytics_accuracy_indication_e ana_accu_ind |
12 | | ) |
13 | 0 | { |
14 | 0 | OpenAPI_accuracy_info_t *accuracy_info_local_var = ogs_malloc(sizeof(OpenAPI_accuracy_info_t)); |
15 | 0 | ogs_assert(accuracy_info_local_var); |
16 | | |
17 | 0 | accuracy_info_local_var->accuracy_val = accuracy_val; |
18 | 0 | accuracy_info_local_var->is_accu_sample_nbr = is_accu_sample_nbr; |
19 | 0 | accuracy_info_local_var->accu_sample_nbr = accu_sample_nbr; |
20 | 0 | accuracy_info_local_var->ana_accu_ind = ana_accu_ind; |
21 | |
|
22 | 0 | return accuracy_info_local_var; |
23 | 0 | } |
24 | | |
25 | | void OpenAPI_accuracy_info_free(OpenAPI_accuracy_info_t *accuracy_info) |
26 | 0 | { |
27 | 0 | OpenAPI_lnode_t *node = NULL; |
28 | |
|
29 | 0 | if (NULL == accuracy_info) { |
30 | 0 | return; |
31 | 0 | } |
32 | 0 | ogs_free(accuracy_info); |
33 | 0 | } |
34 | | |
35 | | cJSON *OpenAPI_accuracy_info_convertToJSON(OpenAPI_accuracy_info_t *accuracy_info) |
36 | 0 | { |
37 | 0 | cJSON *item = NULL; |
38 | 0 | OpenAPI_lnode_t *node = NULL; |
39 | |
|
40 | 0 | if (accuracy_info == NULL) { |
41 | 0 | ogs_error("OpenAPI_accuracy_info_convertToJSON() failed [AccuracyInfo]"); |
42 | 0 | return NULL; |
43 | 0 | } |
44 | | |
45 | 0 | item = cJSON_CreateObject(); |
46 | 0 | if (cJSON_AddNumberToObject(item, "accuracyVal", accuracy_info->accuracy_val) == NULL) { |
47 | 0 | ogs_error("OpenAPI_accuracy_info_convertToJSON() failed [accuracy_val]"); |
48 | 0 | goto end; |
49 | 0 | } |
50 | | |
51 | 0 | if (accuracy_info->is_accu_sample_nbr) { |
52 | 0 | if (cJSON_AddNumberToObject(item, "accuSampleNbr", accuracy_info->accu_sample_nbr) == NULL) { |
53 | 0 | ogs_error("OpenAPI_accuracy_info_convertToJSON() failed [accu_sample_nbr]"); |
54 | 0 | goto end; |
55 | 0 | } |
56 | 0 | } |
57 | | |
58 | 0 | if (accuracy_info->ana_accu_ind != OpenAPI_analytics_accuracy_indication_NULL) { |
59 | 0 | if (cJSON_AddStringToObject(item, "anaAccuInd", OpenAPI_analytics_accuracy_indication_ToString(accuracy_info->ana_accu_ind)) == NULL) { |
60 | 0 | ogs_error("OpenAPI_accuracy_info_convertToJSON() failed [ana_accu_ind]"); |
61 | 0 | goto end; |
62 | 0 | } |
63 | 0 | } |
64 | | |
65 | 0 | end: |
66 | 0 | return item; |
67 | 0 | } |
68 | | |
69 | | OpenAPI_accuracy_info_t *OpenAPI_accuracy_info_parseFromJSON(cJSON *accuracy_infoJSON) |
70 | 0 | { |
71 | 0 | OpenAPI_accuracy_info_t *accuracy_info_local_var = NULL; |
72 | 0 | OpenAPI_lnode_t *node = NULL; |
73 | 0 | cJSON *accuracy_val = NULL; |
74 | 0 | cJSON *accu_sample_nbr = NULL; |
75 | 0 | cJSON *ana_accu_ind = NULL; |
76 | 0 | OpenAPI_analytics_accuracy_indication_e ana_accu_indVariable = 0; |
77 | 0 | accuracy_val = cJSON_GetObjectItemCaseSensitive(accuracy_infoJSON, "accuracyVal"); |
78 | 0 | if (!accuracy_val) { |
79 | 0 | ogs_error("OpenAPI_accuracy_info_parseFromJSON() failed [accuracy_val]"); |
80 | 0 | goto end; |
81 | 0 | } |
82 | 0 | if (!cJSON_IsNumber(accuracy_val)) { |
83 | 0 | ogs_error("OpenAPI_accuracy_info_parseFromJSON() failed [accuracy_val]"); |
84 | 0 | goto end; |
85 | 0 | } |
86 | | |
87 | 0 | accu_sample_nbr = cJSON_GetObjectItemCaseSensitive(accuracy_infoJSON, "accuSampleNbr"); |
88 | 0 | if (accu_sample_nbr) { |
89 | 0 | if (!cJSON_IsNumber(accu_sample_nbr)) { |
90 | 0 | ogs_error("OpenAPI_accuracy_info_parseFromJSON() failed [accu_sample_nbr]"); |
91 | 0 | goto end; |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | 0 | ana_accu_ind = cJSON_GetObjectItemCaseSensitive(accuracy_infoJSON, "anaAccuInd"); |
96 | 0 | if (ana_accu_ind) { |
97 | 0 | if (!cJSON_IsString(ana_accu_ind)) { |
98 | 0 | ogs_error("OpenAPI_accuracy_info_parseFromJSON() failed [ana_accu_ind]"); |
99 | 0 | goto end; |
100 | 0 | } |
101 | 0 | ana_accu_indVariable = OpenAPI_analytics_accuracy_indication_FromString(ana_accu_ind->valuestring); |
102 | 0 | } |
103 | | |
104 | 0 | accuracy_info_local_var = OpenAPI_accuracy_info_create ( |
105 | | |
106 | 0 | accuracy_val->valuedouble, |
107 | 0 | accu_sample_nbr ? true : false, |
108 | 0 | accu_sample_nbr ? accu_sample_nbr->valuedouble : 0, |
109 | 0 | ana_accu_ind ? ana_accu_indVariable : 0 |
110 | 0 | ); |
111 | |
|
112 | 0 | return accuracy_info_local_var; |
113 | 0 | end: |
114 | 0 | return NULL; |
115 | 0 | } |
116 | | |
117 | | OpenAPI_accuracy_info_t *OpenAPI_accuracy_info_copy(OpenAPI_accuracy_info_t *dst, OpenAPI_accuracy_info_t *src) |
118 | 0 | { |
119 | 0 | cJSON *item = NULL; |
120 | 0 | char *content = NULL; |
121 | |
|
122 | 0 | ogs_assert(src); |
123 | 0 | item = OpenAPI_accuracy_info_convertToJSON(src); |
124 | 0 | if (!item) { |
125 | 0 | ogs_error("OpenAPI_accuracy_info_convertToJSON() failed"); |
126 | 0 | return NULL; |
127 | 0 | } |
128 | | |
129 | 0 | content = cJSON_Print(item); |
130 | 0 | cJSON_Delete(item); |
131 | |
|
132 | 0 | if (!content) { |
133 | 0 | ogs_error("cJSON_Print() failed"); |
134 | 0 | return NULL; |
135 | 0 | } |
136 | | |
137 | 0 | item = cJSON_Parse(content); |
138 | 0 | ogs_free(content); |
139 | 0 | if (!item) { |
140 | 0 | ogs_error("cJSON_Parse() failed"); |
141 | 0 | return NULL; |
142 | 0 | } |
143 | | |
144 | 0 | OpenAPI_accuracy_info_free(dst); |
145 | 0 | dst = OpenAPI_accuracy_info_parseFromJSON(item); |
146 | 0 | cJSON_Delete(item); |
147 | |
|
148 | 0 | return dst; |
149 | 0 | } |
150 | | |