Tizen Native API
6.0
|
IoTCon Query provides API to manage query.
Required Header
#include <iotcon.h>
Overview
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; } ... }
Related Features
This API is related with the following features:
- http://tizen.org/feature/iot.ocf
It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.
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 Documentation
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().
- Since :
- 3.0
- Parameters:
-
[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
- Returns:
true
to continue with the next iteration of the loop, otherwisefalse
to break out of the loop IOTCON_FUNC_CONTINUE and IOTCON_FUNC_STOP are more friendly values for the return
- Precondition:
- iotcon_query_foreach() will invoke this callback function.
- See also:
- iotcon_query_foreach()
Function Documentation
int iotcon_query_add | ( | iotcon_query_h | query, |
const char * | key, | ||
const char * | value | ||
) |
Adds a new key and corresponding value into the query.
- Since :
- 3.0
- Remarks:
- The full length of query should be less than or equal to 64.
- Parameters:
-
[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
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Remarks:
- You must destroy query by calling iotcon_query_destroy() if query is no longer needed.
- Parameters:
-
[out] query A newly allocated query handle
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Parameters:
-
[in] query The handle of the query
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Parameters:
-
[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
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- Postcondition:
- iotcon_query_foreach_cb() will be called for each query.
- See also:
- iotcon_query_foreach_cb()
int iotcon_query_get_interface | ( | iotcon_query_h | query, |
char ** | resource_iface | ||
) |
Gets resource interface from the query.
- Since :
- 3.0
- Remarks:
- resource_iface could be a value such as IOTCON_INTERFACE_DEFAULT.
- resource_iface must not be released using free().
- Parameters:
-
[in] query The handle of the query [out] resource_iface Found resource interface from query
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Remarks:
- resource_type must not be released using free(). resource_type must start with a lowercase alphabetic character, followed by a sequence of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.
- Parameters:
-
[in] query The handle of the query [out] resource_type Found resource type from query
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Remarks:
- data must not be released using free().
- Parameters:
-
[in] query The handle of the query [in] key The key of the query to lookup [out] data Found data from query
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Parameters:
-
[in] query The handle of the query [in] key The key of the option to delete
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Remarks:
- resource_iface could be a value such as IOTCON_INTERFACE_DEFAULT.
- Parameters:
-
[in] query The handle of the query [in] resource_iface The resource interface to add into the query
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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.
- Since :
- 3.0
- Parameters:
-
[in] query The handle of the query [in] resource_type The resource type to set into the query
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_OUT_OF_MEMORY Out of memory IOTCON_ERROR_INVALID_PARAMETER Invalid parameter