|
Tizen Native API
5.5
|
IoTCon Query provides API to manage query.
#include <iotcon.h>
The IoTCon Query API provides methods for managing query of request. Example (Client side) :
#include <iotcon.h> ... static void _request_get(iotcon_remote_resource_h resource) { int ret; iotcon_query_h query = NULL; ret = iotcon_query_create(&query); if (IOTCON_ERROR_NONE != ret) return; ret = iotcon_query_add(query, "key", "value"); if (IOTCON_ERROR_NONE != ret) { iotcon_query_destroy(query); return; } ret = iotcon_remote_resource_get(resource, query, _on_get, NULL); if (IOTCON_ERROR_NONE != ret) { iotcon_query_destroy(query); return; } iotcon_query_destroy(query); }
Example (Server side) :
#include <iotcon.h> ... static bool _query_foreach(const char *key, const char *value, void *user_data) { // handle query return IOTCON_FUNC_CONTINUE; } static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data) { int ret; iotcon_query_h query = NULL; ret = iotcon_request_get_query(request, &query); if (IOTCON_ERROR_NONE != ret) return; if (IOTCON_ERROR_NONE == ret && query) { ret = iotcon_query_foreach(query, _query_foreach, NULL); if (IOTCON_ERROR_NONE != ret) return; } ... }
This API is related with the following features:
Functions | |
| int | iotcon_query_create (iotcon_query_h *query) |
| Creates a new query handle. | |
| int | iotcon_query_destroy (iotcon_query_h query) |
| Destroys a query handle. | |
| int | iotcon_query_get_resource_type (iotcon_query_h query, char **resource_type) |
| Gets resource type from the query. | |
| int | iotcon_query_get_interface (iotcon_query_h query, char **resource_iface) |
| Gets resource interface from the query. | |
| int | iotcon_query_set_resource_type (iotcon_query_h query, const char *resource_type) |
| Sets the resource type into the query. | |
| int | iotcon_query_set_interface (iotcon_query_h query, const char *resource_iface) |
| Sets the resource interface into the query. | |
| int | iotcon_query_add (iotcon_query_h query, const char *key, const char *value) |
| Adds a new key and corresponding value into the query. | |
| int | iotcon_query_remove (iotcon_query_h query, const char *key) |
| Removes the key and its associated value from the query. | |
| int | iotcon_query_lookup (iotcon_query_h query, const char *key, char **data) |
| Looks up data at the given key from the query. | |
| int | iotcon_query_foreach (iotcon_query_h query, iotcon_query_foreach_cb cb, void *user_data) |
| Gets all data of the query by invoking the callback function. | |
Typedefs | |
| typedef bool(* | iotcon_query_foreach_cb )(const char *key, const char *value, void *user_data) |
| Specifies the type of function passed to iotcon_query_foreach(). | |
| typedef bool(* iotcon_query_foreach_cb)(const char *key, const char *value, void *user_data) |
Specifies the type of function passed to iotcon_query_foreach().
| [in] | key | The key of the query |
| [in] | value | The value of the query |
| [in] | user_data | The user data to pass to the function |
true to continue with the next iteration of the loop, otherwise false to break out of the loop IOTCON_FUNC_CONTINUE and IOTCON_FUNC_STOP are more friendly values for the return | int iotcon_query_add | ( | iotcon_query_h | query, |
| const char * | key, | ||
| const char * | value | ||
| ) |
Adds a new key and corresponding value into the query.
| [in] | query | The handle of the query |
| [in] | key | The key of the query to insert |
| [in] | value | The string data to insert into the query |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_OUT_OF_MEMORY | Out of memory |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| int iotcon_query_create | ( | iotcon_query_h * | query | ) |
Creates a new query handle.
| [out] | query | A newly allocated query handle |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_OUT_OF_MEMORY | Out of memory |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| int iotcon_query_destroy | ( | iotcon_query_h | query | ) |
Destroys a query handle.
| [in] | query | The handle of the query |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| int iotcon_query_foreach | ( | iotcon_query_h | query, |
| iotcon_query_foreach_cb | cb, | ||
| void * | user_data | ||
| ) |
Gets all data of the query by invoking the callback function.
iotcon_query_foreach_cb() will be called for each query.
If iotcon_query_foreach_cb() returns false, iteration will be stopped.
| [in] | query | The handle of the query |
| [in] | cb | The callback function to get data |
| [in] | user_data | The user data to be passed to the callback function |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| int iotcon_query_get_interface | ( | iotcon_query_h | query, |
| char ** | resource_iface | ||
| ) |
Gets resource interface from the query.
| [in] | query | The handle of the query |
| [out] | resource_iface | Found resource interface from query |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| IOTCON_ERROR_NO_DATA | No data available |
| int iotcon_query_get_resource_type | ( | iotcon_query_h | query, |
| char ** | resource_type | ||
| ) |
Gets resource type from the query.
| [in] | query | The handle of the query |
| [out] | resource_type | Found resource type from query |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| IOTCON_ERROR_NO_DATA | No data available |
| IOTCON_ERROR_OUT_OF_MEMORY | Out of memory |
| int iotcon_query_lookup | ( | iotcon_query_h | query, |
| const char * | key, | ||
| char ** | data | ||
| ) |
Looks up data at the given key from the query.
| [in] | query | The handle of the query |
| [in] | key | The key of the query to lookup |
| [out] | data | Found data from query |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| int iotcon_query_remove | ( | iotcon_query_h | query, |
| const char * | key | ||
| ) |
Removes the key and its associated value from the query.
| [in] | query | The handle of the query |
| [in] | key | The key of the option to delete |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| int iotcon_query_set_interface | ( | iotcon_query_h | query, |
| const char * | resource_iface | ||
| ) |
Sets the resource interface into the query.
| [in] | query | The handle of the query |
| [in] | resource_iface | The resource interface to add into the query |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_OUT_OF_MEMORY | Out of memory |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
| int iotcon_query_set_resource_type | ( | iotcon_query_h | query, |
| const char * | resource_type | ||
| ) |
Sets the resource type into the query.
| [in] | query | The handle of the query |
| [in] | resource_type | The resource type to set into the query |
0 on success, otherwise a negative error value | IOTCON_ERROR_NONE | Successful |
| IOTCON_ERROR_NOT_SUPPORTED | Not supported |
| IOTCON_ERROR_OUT_OF_MEMORY | Out of memory |
| IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |