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