2 * Copyright (c) 2019 G.camp,
4 * Contact: Jin Seog Bang <seog814@gmail.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #ifndef __ST_THINGS_TYPES_H__
20 #define __ST_THINGS_TYPES_H__
27 * @brief Enumeration for ST Things error code.
30 ST_THINGS_ERROR_NONE = 0, /**< Successful */
31 ST_THINGS_ERROR_INVALID_PARAMETER = -1, /**< Invalid parameter (If parameter is null or empty)*/
32 ST_THINGS_ERROR_OPERATION_FAILED = -2, /**< Operation Failed */
33 ST_THINGS_ERROR_STACK_NOT_INITIALIZED = -3, /**< Stack is not yet initialized*/
34 ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED = -4, /**< Stack is already initialized*/
35 ST_THINGS_ERROR_STACK_NOT_STARTED = -5, /**< Stack is not yet started*/
36 ST_THINGS_ERROR_STACK_RUNNING = -6, /**< Stack is currently running*/
40 * @brief Enumeration for ST Things status.
43 ST_THINGS_STATUS_INIT = 0, /**< Initial state of ST Things */
44 ST_THINGS_STATUS_ES_STARTED, /**< Easy-setup is started */
45 ST_THINGS_STATUS_ES_DONE, /**< Easy-setup is done */
46 ST_THINGS_STATUS_ES_FAILED_ON_OWNERSHIP_TRANSFER, /**< Easy-setup failed due to Ownership-Transfer failure */
47 ST_THINGS_STATUS_CONNECTING_TO_AP, /**< Connecting to target Wi-Fi access point */
48 ST_THINGS_STATUS_CONNECTED_TO_AP, /**< Connected to target Wi-Fi access point */
49 ST_THINGS_STATUS_CONNECTING_TO_AP_FAILED, /**< Failed to connect to target Wi-Fi access point */
50 ST_THINGS_STATUS_REGISTERING_TO_CLOUD, /**< Trying to Sign-up/Sign-in/Publish-Resource(s) to Cloud */
51 ST_THINGS_STATUS_REGISTERED_TO_CLOUD, /**< Publish resource(s) to cloud is complete. Now the Thing is ready to be controlled via Cloud */
52 ST_THINGS_STATUS_REGISTERING_FAILED_ON_SIGN_IN, /**< Failed to sign-in to Cloud */
53 ST_THINGS_STATUS_REGISTERING_FAILED_ON_PUB_RES /**< Failed to publish resources to Cloud */
57 * @brief Structure for Representation.
59 typedef struct _st_things_representation
61 void* payload; /**< Payload of representation */
64 * @brief API for getting the value of string type property with a key.
65 * @remarks This API will return deep-copied string value as out parameter, so application must free it after use.
66 * @param[in] rep Instance of Representation.
67 * @param[in] key Property Name which represents the value.
68 * @param[out] value String value
69 * @return @c true if value exist, otherwise @c false
71 bool (*get_str_value) (struct _st_things_representation* rep, const char* key, char** value);
74 * @brief API for getting the value of boolean type property with a key.
75 * @param[in] rep Instance of Representation.
76 * @param[in] key Property Name which represents the value.
77 * @param[out] value Bool value
78 * @return @c true if value exist, otherwise @c false
80 bool (*get_bool_value) (struct _st_things_representation* rep, const char* key, bool* value);
83 * @brief API for getting the value of integer type property with a key.
84 * @param[in] rep Instance of Representation.
85 * @param[in] key Property Name which represents the value.
86 * @param[out] value Integer value
87 * @return @c true if value exist, otherwise @c false
89 bool (*get_int_value) (struct _st_things_representation* rep, const char* key, int64_t* value);
92 * @brief API for getting the value of double type property with a key.
93 * @param[in] rep Instance of Representation.
94 * @param[in] key Property Name which represents the value.
95 * @param[out] value Double value
96 * @return @c true if value exist, otherwise @c false
98 bool (*get_double_value) (struct _st_things_representation* rep, const char* key, double* value);
101 * @brief API for getting the value of byte array type property with a key.
102 * @remarks This API will return deep-copied byte value as out parameter, so application must free it after use.
103 * @param[in] rep Instance of Representation.
104 * @param[in] key Property Name which represents the value.
105 * @param[out] value Byte value
106 * @param[out] size Size of Byte value
107 * @return @c true if value exist, otherwise @c false
109 bool (*get_byte_value) (struct _st_things_representation* rep, const char* key, uint8_t** value, size_t* size);
112 * @brief API for getting the value of object type property with a key.
113 * @remarks This API will return deep-copied object value as out parameter, so application must free it after use.\n
114 * To free an object, st_things_destroy_representation_inst() in st_things.h should be used.
115 * @param[in] rep Instance of Representation.
116 * @param[in] key Property Name which represents the value.
117 * @param[out] value Object value
118 * @return @c true if value exist, otherwise @c false
120 bool (*get_object_value) (struct _st_things_representation* rep, const char* key, struct _st_things_representation** value);
123 * @brief API for setting the value of string type property with a key.
124 * @remarks This API will deep-copy the string value inside, so application still has an ownership of memory for the string value.
125 * @param[in] rep Instance of Representation.
126 * @param[in] key Property Name which will represent the value.
127 * @param[in] value String value.
128 * @return @c true if setting value is successful, otherwise @c false
130 bool (*set_str_value) (struct _st_things_representation* rep, const char* key, const char* value);
133 * @brief API for setting the value of boolean type property with a key.
134 * @param[in] rep Instance of Representation.
135 * @param[in] key Property Name which will represent the value.
136 * @param[in] value Bool value.
137 * @return @c true if setting value is successful, otherwise @c false
139 bool (*set_bool_value) (struct _st_things_representation* rep, const char* key, bool value);
142 * @brief API for setting the value of integer type property with a key.
143 * @param[in] rep Instance of Representation.
144 * @param[in] key Property Name which will represent the value.
145 * @param[in] value Integer value.
146 * @return @c true if setting value is successful, otherwise @c false
148 bool (*set_int_value) (struct _st_things_representation* rep, const char* key, int64_t value);
151 * @brief API for setting the value of double type property with a key.
152 * @param[in] rep Instance of Representation.
153 * @param[in] key Property Name which will represent the value.
154 * @param[in] value Double value.
155 * @return @c true if setting value is successful, otherwise @c false
157 bool (*set_double_value) (struct _st_things_representation* rep, const char* key, double value);
160 * @brief API for setting the value of byte array type property with a key.
161 * @remarks This API will deep-copy the byte value inside, so application still has an ownership of memory for the byte value.
162 * @param[in] rep Instance of Representation.
163 * @param[in] key Property Name which will represent the value.
164 * @param[in] value Byte value.
165 * @param[in] size Size of Byte value.
166 * @return @c true if setting value is successful, otherwise @c false
168 bool (*set_byte_value) (struct _st_things_representation* rep, const char* key, const uint8_t* value, size_t size);
171 * @brief API for setting the value of object type property with a key.
172 * @remarks This API will deep-copy the object value inside, so application still has an ownership of memory for the object value.
173 * @param[in] rep Instance of Representation.
174 * @param[in] key Property Name which will represent the value.
175 * @param[in] value Object value.
176 * @return @c true if value exist, otherwise @c false
178 bool (*set_object_value) (struct _st_things_representation* rep, const char* key, const struct _st_things_representation* value);
181 * @brief API for getting the value of string array type property with a key.
182 * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
183 * @param[in] rep Instance of Representation.
184 * @param[in] key Property Name which will represent the array type of value.
185 * @param[out] array Reference of the string array to where the value will be copied.
186 * @param[out] length Total number of elements in the array.
187 * @return @c true if value exist, otherwise @c false
189 bool (*get_str_array_value) (struct _st_things_representation* rep, const char* key, char*** array, size_t* length);
192 * @brief API for getting the value of integer array type property with a key.
193 * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
194 * @param[in] rep Instance of Representation.
195 * @param[in] key Property Name which will represent the array type of value.
196 * @param[out] array Reference of the integer array where the value will be copied.
197 * @param[out] length Total number of elements in the array.
198 * @return @c true if value exist, otherwise @c false
200 bool (*get_int_array_value) (struct _st_things_representation* rep, const char* key, int64_t** array, size_t* length);
203 * @brief API for getting the value of double array type property with a key.
204 * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
205 * @param[in] rep Instance of Representation.
206 * @param[in] key Property Name which will represent the array type of value.
207 * @param[out] array Reference of the double array where the value will be copied.
208 * @param[out] length Total number of elements in the array.
209 * @return @c true if value exist, otherwise @c false
211 bool (*get_double_array_value) (struct _st_things_representation* rep, const char* key, double** array, size_t* length);
214 * @brief API for getting the value of object array type property with a key.
215 * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.\n
216 * To free each object in array, st_things_destroy_representation_inst() in st_things.h should be used.
217 * @param[in] rep Instance of Representation.
218 * @param[in] key Property Name which represents the array type of value.
219 * @param[out] array Reference of the object array where the value will be copied.
220 * @param[out] length Total number of elements in the array.
221 * @return @c true if value exist, otherwise @c false
223 bool (*get_object_array_value) (struct _st_things_representation* rep, const char* key, struct _st_things_representation*** array, size_t* length);
226 * @brief API for setting the value of string array type property with a key.
227 * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
228 * @param[in] rep Instance of Representation.
229 * @param[in] key Property Name which represents the value.
230 * @param[in] array String array type value.
231 * @param[in] length Total number of elements in the array.
232 * @return @c true if setting value is successful, otherwise @c false
234 bool (*set_str_array_value) (struct _st_things_representation* rep, const char* key, const char** array, size_t length);
237 * @brief API for setting the value of integer array type property with a key.
238 * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
239 * @param[in] rep Instance of Representation.
240 * @param[in] key Property Name which represents the value.
241 * @param[in] array Integer array type value.
242 * @param[in] length Total number of elements in the array.
243 * @return @c true if setting value is successful, otherwise @c false
245 bool (*set_int_array_value) (struct _st_things_representation* rep, const char* key, const int64_t* array, size_t length);
248 * @brief API for setting the value of double array type property with a key.
249 * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
250 * @param[in] rep Instance of Representation.
251 * @param[in] key Property Name which represents the value.
252 * @param[in] array Double array type value.
253 * @param[in] length Total number of elements in the array.
254 * @return @c true if setting value is successful, otherwise @c false
256 bool (*set_double_array_value) (struct _st_things_representation* rep, const char* key, const double* array, size_t length);
259 * @brief API for setting the value of object array type property with a key.
260 * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
261 * @param[in] rep Instance of Representation.
262 * @param[in] key Property Name which represents the value.
263 * @param[in] array Object array type value.
264 * @param[in] length Total number of elements in the array.
265 * @return @c true if setting value is successful, otherwise @c false
267 bool (*set_object_array_value) (struct _st_things_representation* rep, const char* key, const struct _st_things_representation** array, size_t length);
269 } st_things_representation_s;
272 * @brief Structure for representing the Get Request Message.
274 typedef struct _st_things_get_request_message
276 char* resource_uri; /**< Resource URI */
277 char* query; /**< One or more query parameters of the request message. Ex: key1=value1;key2=value2;... */
278 char* property_key; /**< One or more property key that application needs to set a value for response. Ex: key1;key2;... */
281 * @brief API for getting the value of a specific query from the query parameters of the request.
282 * @param[in] req_msg Instance of get request message.
283 * @param[in] key Name of the query.(ex: key1, key2, etc)
284 * @param[out] value Value of the query.(value1, value2, etc)
285 * @return @c true if query exist, otherwise @c false
287 bool (*get_query_value) (struct _st_things_get_request_message* req_msg, const char* key, char** value);
290 * @brief API for checking whether the request has a specific property key or not.
291 * @param[in] req_msg Instance of get request message.
292 * @param[in] key Name of the property.
293 * @return @c true if the property key exists, otherwise @c false
295 bool (*has_property_key) (struct _st_things_get_request_message* req_msg, const char* key);
297 } st_things_get_request_message_s;
300 * @brief Structure for representing the Set Request Message.
302 typedef struct _st_things_set_request_message
304 char* resource_uri; /**< Resource URI */
305 char* query; /**< One or more query parameters of the request message. Ex: key1=value1?key2=value2?... */
306 struct _st_things_representation* rep; /**< Representation of the set request message */
309 * @brief API for getting the value of a specific query from the query parameters of the request.
310 * @param[in] req_msg Instance of request message.
311 * @param[in] key Name of the query.(ex: key1, key2, etc)
312 * @param[out] value Value of the query.(value1, value2, etc)
313 * @return @c true if query exist, otherwise @c false
315 bool (*get_query_value) (struct _st_things_set_request_message* req_msg, const char* key, char** value);
317 } st_things_set_request_message_s;
319 #endif /* __ST_THINGS_TYPES_H__ */