Tizen Native API  3.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]keyThe key of the query
[in]valueThe value of the query
[in]user_dataThe user data to pass to the function
Returns:
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
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]queryThe handle of the query
[in]keyThe key of the query to insert
[in]valueThe string data to insert into the query
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_OUT_OF_MEMORYOut of memory
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_query_create()
iotcon_query_destroy()
iotcon_query_remove()
iotcon_query_lookup()

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]queryA newly allocated query handle
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_OUT_OF_MEMORYOut of memory
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_query_destroy()
iotcon_query_add()
iotcon_query_remove()
iotcon_query_lookup()

Destroys a query handle.

Since :
3.0
Parameters:
[in]queryThe handle of the query
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_query_create()
iotcon_query_add()
iotcon_query_remove()
iotcon_query_lookup()
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]queryThe handle of the query
[in]cbThe callback function to get data
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid 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]queryThe handle of the query
[out]resource_ifaceFound resource interface from query
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
IOTCON_ERROR_NO_DATANo data available
See also:
iotcon_query_create()
iotcon_query_destroy()
iotcon_query_add()
iotcon_query_remove()
iotcon_query_set_interface()
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]queryThe handle of the query
[out]resource_typeFound resource type from query
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
IOTCON_ERROR_NO_DATANo data available
IOTCON_ERROR_OUT_OF_MEMORYOut of memory
See also:
iotcon_query_create()
iotcon_query_destroy()
iotcon_query_add()
iotcon_query_remove()
iotcon_query_set_resource_type()
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]queryThe handle of the query
[in]keyThe key of the query to lookup
[out]dataFound data from query
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_query_create()
iotcon_query_destroy()
iotcon_query_add()
iotcon_query_remove()
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]queryThe handle of the query
[in]keyThe key of the option to delete
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_query_create()
iotcon_query_destroy()
iotcon_query_add()
iotcon_query_lookup()
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]queryThe handle of the query
[in]resource_ifaceThe resource interface to add into the query
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_OUT_OF_MEMORYOut of memory
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_query_create()
iotcon_query_destroy()
iotcon_query_add()
iotcon_query_remove()
iotcon_query_lookup()
iotcon_query_get_interface()
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]queryThe handle of the query
[in]resource_typeThe resource type to set into the query
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_OUT_OF_MEMORYOut of memory
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_query_create()
iotcon_query_destroy()
iotcon_query_add()
iotcon_query_remove()
iotcon_query_lookup()
iotcon_query_get_resource_type()