2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "rrs_error.h"
25 * @ingroup CAPI_RRS_MODULE
26 * @defgroup CAPI_RRS_SCHEMA_MODULE Schema and data
29 * @brief This file contains the RRS Schema API
30 * @addtogroup CAPI_RRS_SCHEMA_MODULE
32 * @brief This provides APIs related to resource schema and data
41 * @brief Handle of the resource schema.
42 * @details The schema handle can be created or loaded from the schema storage.
45 * @remarks To release the handle use rrs_schema_destroy().
51 * @see rrs_schema_create()
52 * @see rrs_schema_create_from_json()
53 * @see rrs_schema_create_from_simple_json()
54 * @see rrs_schema_data_create_from_json()
55 * @see rrs_schema_load()
56 * @see rrs_schema_load_custom()
58 typedef void *rrs_schema_h;
62 * @brief Handle of the resource schema.
63 * @details The schema handle can be created or loaded from the schema storage.
66 * @remarks To release the handle use rrs_schema_destroy().
72 * @see rrs_schema_create_data()
73 * @see rrs_data_destroy()
75 typedef void *rrs_data_h;
79 * @brief Enumerations of schemas field types, supported by RRS
82 typedef enum _rrs_schema_type_e {
83 RRS_SCHEMA_TYPE_NONE, /**< Indicates no type */
84 RRS_SCHEMA_TYPE_BOOL, /**< Indicates boolean type */
85 RRS_SCHEMA_TYPE_INT, /**< Indicates integer type */
86 RRS_SCHEMA_TYPE_DOUBLE, /**< Indicates floating point type */
87 RRS_SCHEMA_TYPE_STR, /**< Indicates string type */
88 RRS_SCHEMA_TYPE_COMPLEX /**< Indicates complex type */
93 * @brief Enumerations of schema field access types, supported by RRS
96 typedef enum _rrs_schema_access_e {
97 RRS_SCHEMA_ACCESS_NONE = 0, /**< Indicates no access */
98 RRS_SCHEMA_ACCESS_READ = 1, /**< Indicates read only access */
99 RRS_SCHEMA_ACCESS_WRITE = 2, /**< Indicates write only acccess */
100 RRS_SCHEMA_ACCESS_READ_WRITE = 4, /**< Indicates read-write access */
101 RRS_SCHEMA_ACCESS_ALL = 8 /**< Indicates all access */
107 * @brief Called when requesting fields of schema.
108 * @details This callback is invoked while iterating through the list of
109 * fields of the schema.
112 * @remarks @a name must not be released using free().
114 * @param[in] index The current index of the field
115 * @param[in] total The total amount of the fields
116 * @param[in] name The name of the field
117 * @param[in] type The type of the field
118 * @param[in] access The type of the field access, read, write,
120 * @param[in] required The value is required
121 * @param[in] user_data The user data passed from
122 * rrs_schema_foreach_field()
123 * @return @c true to continue with the next iteration of the loop, \n @c
124 * false to break out of the loop
126 * @pre rrs_schema_foreach_field() will invoke this callback.
128 * @see rrs_schema_foreach_field()
130 typedef bool (*rrs_schema_foreach_field_cb) (int index,
133 const RrsSchemaType type,
134 const RrsSchemaAccess access,
136 const rrs_schema_h schema,
141 * @brief Called when requesting fields of data.
142 * @details This callback is invoked while iterating through the list of
143 * fields of the data.
146 * @remarks @a name must not be released using free().
147 * \n @a field must be released using free().
149 * @param[in] index The current index of the field
150 * @param[in] total The total amount of the fields
151 * @param[in] name The name of the field
152 * @param[in] type The type of the field
153 * @param[in] access The type of the field access, read, write,
155 * @param[in] required The value is required
156 * @param[in] v The value the field
157 * @param[in] user_data The user data passed from
158 * rrs_data_foreach_field()
159 * @return @c true to continue with the next iteration of the loop, \n @c
160 * false to break out of the loop
162 * @pre rrs_data_foreach_field() will invoke this callback.
164 * @see rrs_data_foreach_field()
166 typedef bool (*rrs_data_foreach_field_cb) (int index,
169 const RrsSchemaType type,
170 const RrsSchemaAccess access,
177 * @brief Creates an empty resource schema.
178 * @details This function creates an empty resource schema and issues a new
182 * @privilege %http://tizen.org/privilege/healthinfo
184 * @remarks @a schema handle must be released using rrs_schema_destroy().
186 * @param[in] rrs The RRS handle
187 * @param[in] name The schema name
188 * @param[out] schema The handle of the newly created schema
189 * @return 0 on success, otherwise a negative error value
190 * @retval #RRS_ERROR_NONE Successful
191 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
192 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
193 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
195 * @see rrs_schema_destroy()
197 int rrs_schema_create(const char *name, rrs_schema_h *schema);
201 * @brief Creates a resource schema handle from complete Json string.
202 * @details This function creates a resource schema from a complete Json schema
203 * definition and issues a new handle for it.
206 * @privilege %http://tizen.org/privilege/healthinfo
208 * @remarks @a schema handle must be released using rrs_schema_destroy().
210 * @param[in] rrs The RRS handle
211 * @param[in] json_schema The complete OIC-compatible json-formatted
212 * definition of schema
213 * @param[out] schema The handle of the newly created schema
214 * @return 0 on success, otherwise a negative error value
215 * @retval #RRS_ERROR_NONE Successful
216 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
217 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
218 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
220 * @see rrs_schema_destroy()
222 int rrs_schema_create_from_json(const char *json_schema, rrs_schema_h *schema);
226 * @brief Creates a resource schema from simplified json string.
227 * @details This function creates a resource schema from simplified json string
228 * and issues a new handle for it.
231 * @privilege %http://tizen.org/privilege/healthinfo
233 * @remarks @a schema handle must be released using rrs_schema_destroy().
235 * @param[in] rrs The RRS handle
236 * @param[in] schema_name The schema name
237 * @param[in] json_simplified The simplified json-formatted
238 * definition of schema
239 * @param[out] schema The handle of the newly created schema
240 * @return 0 on success, otherwise a negative error value
241 * @retval #RRS_ERROR_NONE Successful
242 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
243 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
244 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
246 * @see rrs_schema_destroy()
248 int rrs_schema_create_from_simple_json(const char *schema_name,
249 const char *json_simplified,
250 rrs_schema_h *schema);
254 * @brief Creates both resource schema and data from simplified json
256 * @details This function creates both resource schema and data from simplified
257 * json-formatted string and issues new handles for results.
260 * @privilege %http://tizen.org/privilege/healthinfo
262 * @remarks @a schema handle must be released using rrs_schema_destroy().
264 * @param[in] rrs The RRS handle
265 * @param[in] schema_name The schema name
266 * @param[in] json_simplified The simplified json-formatted
267 * definition of schema
268 * @param[out] schema The handle of the newly created schema
269 * @param[out] data The handle of the newly created data
270 * @return 0 on success, otherwise a negative error value
271 * @retval #RRS_ERROR_NONE Successful
272 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
273 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
274 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
276 * @see rrs_schema_destroy()
278 int rrs_schema_data_create_from_json(const char *schema_name,
279 const char *json_simplified,
280 rrs_schema_h *schema,
285 * @brief Loads a resource schema by specified schema id.
286 * @details This function loads a resource schema by specified schema id and
287 * issues a new handle for it.
290 * @privilege %http://tizen.org/privilege/healthinfo
292 * @remarks @a schema handle must be released using rrs_schema_destroy().
294 * @param[in] rrs The RRS handle
295 * @param[in] resource_id The predefined resource id
296 * @param[out] schema The handle of the newly created schema
297 * @return 0 on success, otherwise a negative error value
298 * @retval #RRS_ERROR_NONE Successful
299 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
300 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
301 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
303 * @see rrs_schema_destroy()
305 int rrs_schema_load(const rrs_resource_e resource_id,
306 rrs_schema_h *control_schema,
307 rrs_schema_h *event_schema);
311 * @brief Loads a resource schema by specified schema id.
312 * @details This function loads a resource schema by specified schema id and
313 * issues a new handle for it.
316 * @privilege %http://tizen.org/privilege/healthinfo
318 * @remarks @a schema handle must be released using rrs_schema_destroy().
320 * @param[in] rrs The RRS handle
321 * @param[in] resource_id The predefined resource id
322 * @param[out] schema The handle of the newly created schema
323 * @return 0 on success, otherwise a negative error value
324 * @retval #RRS_ERROR_NONE Successful
325 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
326 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
327 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
329 * @see rrs_schema_destroy()
331 int rrs_discovery_schema_load(const rrs_resource_e resource_id,
332 rrs_schema_h *control_schema);
335 * @brief Loads a custom resource schema by schema name.
336 * @details This function loads a custom resource schema by specified schema
337 * name and issues a new handle for it.
340 * @privilege %http://tizen.org/privilege/healthinfo
342 * @remarks @a schema handle must be released using rrs_schema_destroy().
344 * @param[in] rrs The RRS handle
345 * @param[in] schema_name The custom schema name
346 * @param[out] schema The handle of the newly created schema
347 * @return 0 on success, otherwise a negative error value
348 * @retval #RRS_ERROR_NONE Successful
349 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
350 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
351 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
353 * @see rrs_schema_destroy()
355 int rrs_schema_load_custom(const char *schema_name,
356 rrs_schema_h *schema);
360 * @brief Saves a custom resource schema in permanent schema storage.
361 * @details This function saves a custom resource schema in a permanent
362 * system-wide schema storage.
365 * @privilege %http://tizen.org/privilege/healthinfo
367 * @remarks @a schema handle must be released using rrs_schema_destroy().
369 * @param[in] schema The custom schema handle
370 * @return 0 on success, otherwise a negative error value
371 * @retval #RRS_ERROR_NONE Successful
372 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
373 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
374 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
376 * @see rrs_schema_destroy()
378 int rrs_schema_save_to_storage(const rrs_schema_h schema);
382 * @brief Removes a custom resource schema from permanent schema storage.
383 * @details This function removes a custom resource schema from a permanent
384 * system-wide schema storage.
387 * @privilege %http://tizen.org/privilege/healthinfo
389 * @remarks @a schema handle must be released using rrs_schema_destroy().
391 * @param[in] schema_name The custom schema name
392 * @return 0 on success, otherwise a negative error value
393 * @retval #RRS_ERROR_NONE Successful
394 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
395 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
396 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
398 * @see rrs_schema_destroy()
400 int rrs_schema_delete_from_storage(const char *schema_name);
405 * @brief Destroys the schema handle.
406 * @details This function releases the resource schema handle.
409 * @privilege %http://tizen.org/privilege/healthinfo
411 * @param[in] schema The resource schema handle to destroy
412 * @return 0 on success, otherwise a negative error value
413 * @retval #RRS_ERROR_NONE Successful
414 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
415 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
417 * @pre @a schema handle is created with one of create or load functions.
419 * @see rrs_schema_create()
421 int rrs_schema_destroy(rrs_schema_h schema);
425 * @brief Adds new field to the schema.
426 * @details This function adds a new field to the schema.
429 * @param[in] schema The schema handle
430 * @param[in] name The name of the added field
431 * @param[in] type The type of the added field
432 * @param[in] access The type of the field access, read, write,
434 * @param[in] required The value is required
435 * @return 0 on success, otherwise a negative error value
436 * @retval #RRS_ERROR_NONE Successful
437 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
438 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
440 * @pre @a schema handle is created with one of create or load functions.
442 * @see rrs_schema_create()
443 * @see #RrsSchemaType
445 int rrs_schema_add_field(rrs_schema_h schema,
447 const RrsSchemaType type,
448 const RrsSchemaAccess access,
450 const rrs_schema_h complex_schema);
454 * @brief Retrieves all fields in schema.
455 * @details This function retrieves all fields in the schema.
457 * @remarks The fields will be delivered via rrs_schema_foreach_field_cb().
459 * @param[in] schema The schema handle
460 * @param[in] callback The callback function to retrieve fields
461 * @param[in] user_data The user data to be passed to the
463 * @return 0 on success, otherwise a negative error value
464 * @retval #RRS_ERROR_NONE Successful
465 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
466 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
468 * @post This function invokes rrs_schema_foreach_field_cb()
469 * repeatedly to retrieve each field.
471 * @see rrs_schema_foreach_field_cb()
473 int rrs_schema_foreach_field(rrs_schema_h schema,
474 rrs_schema_foreach_field_cb callback,
479 * @brief Creates an instance of structured resource data.
480 * @details This function creates an instance of structured resource data and
481 * issues a new handle for it.
484 * @remarks @a data handle must be released using rrs_data_destroy().
486 * @param[in] schema The handle of schema, defining the data
487 * @param[out] data The handle of newly created data instance
488 * @return 0 on success, otherwise a negative error value
489 * @retval #RRS_ERROR_NONE Successful
490 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
491 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
492 * @retval #RRS_ERROR_PERMISSION_DENIED Permission Denied
494 * @see rrs_data_destroy()
496 int rrs_schema_create_data(const rrs_schema_h schema, rrs_data_h *data);
500 * @brief Destroys the data handle.
501 * @details This function releases the data handle.
504 * @privilege %http://tizen.org/privilege/healthinfo
506 * @param[in] data The data handle to destroy
507 * @return 0 on success, otherwise a negative error value
508 * @retval #RRS_ERROR_NONE Successful
509 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
510 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
512 * @pre @a data handle is created with rrs_schema_create_data() functions.
514 * @see rrs_schema_create_data()
516 int rrs_data_destroy(rrs_data_h data);
520 * @brief Clones the data handle.
521 * @details This function clones the structured data handle @a origin.
524 * @remarks @a cloned must be released using rrs_data_destroy().
526 * @param[in] origin The original data handle
527 * @param[out] cloned A cloned data handle
528 * @return 0 on success, otherwise a negative error data
529 * @retval #RRS_ERROR_NONE Successful
530 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
531 * @retval #RRS_ERROR_OUT_OF_MEMORY Out of memory
533 * @see rrs_data_destroy()
535 int rrs_data_clone(const rrs_data_h origin, rrs_data_h *cloned);
539 * @brief Extracts event data from resource state data.
540 * @details This function extracts the event data from the remote resource state data.
543 int rrs_convert_control_to_event_data(const rrs_data_h control_data, rrs_data_h *event_data);
547 * @brief Set boolean field value.
548 * @details This function set the boolean field value.
551 * @param[in] data The data handle
552 * @param[in] name The name of the field
553 * @param[in] v The value of the field
554 * @return 0 on success, otherwise a negative error value
555 * @retval #RRS_ERROR_NONE Successful
556 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
557 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
559 * @pre @a data handle is created with rrs_schema_create_data() functions.
561 * @see rrs_schema_create_data()
563 int rrs_data_set_bool(rrs_data_h data,
569 * @brief Set integer field value.
570 * @details This function set the integer field value.
573 * @param[in] data The data handle
574 * @param[in] name The name of the field
575 * @param[in] v The value of the field
576 * @return 0 on success, otherwise a negative error value
577 * @retval #RRS_ERROR_NONE Successful
578 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
579 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
581 * @pre @a data handle is created with rrs_schema_create_data() functions.
583 * @see rrs_schema_create_data()
585 int rrs_data_set_int(rrs_data_h data,
591 * @brief Set floating point field value.
592 * @details This function set the floating point field value.
595 * @param[in] data The data handle
596 * @param[in] name The name of the field
597 * @param[in] v The value of the field
598 * @return 0 on success, otherwise a negative error value
599 * @retval #RRS_ERROR_NONE Successful
600 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
601 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
603 * @pre @a data handle is created with rrs_schema_create_data() functions.
605 * @see rrs_schema_create_data()
607 int rrs_data_set_double(rrs_data_h data,
613 * @brief Set string field value.
614 * @details This function set the string field value.
617 * @param[in] data The data handle
618 * @param[in] name The name of the field
619 * @param[in] v The value of the field
620 * @return 0 on success, otherwise a negative error value
621 * @retval #RRS_ERROR_NONE Successful
622 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
623 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
625 * @pre @a data handle is created with rrs_schema_create_data() functions.
627 * @see rrs_schema_create_data()
629 int rrs_data_set_string(rrs_data_h data,
635 * @brief Get boolean field value.
636 * @details This function get the boolean field value.
639 * @param[in] data The data handle
640 * @param[in] name The name of the field
641 * @param[in] v The pointer to bool in which to store the
643 * @return 0 on success, otherwise a negative error value
644 * @retval #RRS_ERROR_NONE Successful
645 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
646 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
648 * @pre @a data handle is created with rrs_schema_create_data() functions.
650 * @see rrs_schema_create_data()
652 int rrs_data_get_bool(const rrs_data_h data,
658 * @brief Get integer field value.
659 * @details This function get the integer field value.
662 * @param[in] data The data handle
663 * @param[in] name The name of the field
664 * @param[in] v The pointer to int in which to store the
666 * @return 0 on success, otherwise a negative error value
667 * @retval #RRS_ERROR_NONE Successful
668 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
669 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
671 * @pre @a data handle is created with rrs_schema_create_data() functions.
673 * @see rrs_schema_create_data()
675 int rrs_data_get_int(const rrs_data_h data,
681 * @brief Get floating point field value.
682 * @details This function get the floating point field value.
685 * @param[in] data The data handle
686 * @param[in] name The name of the field
687 * @param[in] v The pointer to double in which to store the
689 * @return 0 on success, otherwise a negative error value
690 * @retval #RRS_ERROR_NONE Successful
691 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
692 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
694 * @pre @a data handle is created with rrs_schema_create_data() functions.
696 * @see rrs_schema_create_data()
698 int rrs_data_get_double(const rrs_data_h data,
704 * @brief Get string field value.
705 * @details This function get the sting field value.
708 * @remarks Release the value @a v using free.
710 * @param[in] data The data handle
711 * @param[in] name The name of the field
712 * @param[in] v The pointer to char * in which to store the
714 * @return 0 on success, otherwise a negative error value
715 * @retval #RRS_ERROR_NONE Successful
716 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
717 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
719 * @pre @a data handle is created with rrs_schema_create_data() functions.
721 * @see rrs_schema_create_data()
723 int rrs_data_get_string(const rrs_data_h data,
729 * @brief Retrieves all fields of structured data.
730 * @details This function retrieves all fields of the structured data.
733 * @remarks The fields will be delivered via rrs_data_foreach_field_cb().
735 * @param[in] data The data handle
736 * @param[in] callback The callback function to retrieve fields
737 * @param[in] user_data The user data to be passed to the
739 * @return 0 on success, otherwise a negative error value
740 * @retval #RRS_ERROR_NONE Successful
741 * @retval #RRS_ERROR_INVALID_PARAMETER Invalid parameter
742 * @retval #RRS_ERROR_NOT_SUPPORTED Not supported
744 * @post This function invokes rrs_data_foreach_field_cb()
745 * repeatedly to retrieve each field.
747 * @see rrs_data_foreach_field_cb()
749 int rrs_data_foreach_field(const rrs_data_h data,
750 const rrs_schema_h schema,
751 rrs_data_foreach_field_cb callback,
761 #endif /* _SCHEMA_H_ */