#define IC_DBUS_SIGNAL_MONITORING "MONITORING"
#define IC_DBUS_SIGNAL_CACHING "CACHING"
-#define IC_INTERFACE_DEFAULT "oic.if.baseline"
-#define IC_INTERFACE_LINK "oic.if.ll"
-#define IC_INTERFACE_BATCH "oic.if.b"
-#define IC_INTERFACE_GROUP "oic.mi.grp"
-#define IC_INTERFACE_READONLY "oic.if.r"
-
#define IC_FEATURE_OIC "http://tizen.org/feature/iot.oic"
#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__ */
<method name="registerResource">
<arg type="s" name="uri_path" direction="in"/>
<arg type="as" name="resource_types" direction="in"/>
- <arg type="i" name="ifaces" direction="in"/>
+ <arg type="as" name="ifaces" direction="in"/>
<arg type="i" name="properties" direction="in"/>
<arg type="b" name="is_lite" direction="in"/>
<arg type="x" name="signal_number" direction="out"/>
</method>
<method name="bindInterface">
<arg type="x" name="resource" direction="in"/>
- <arg type="i" name="iface" direction="in"/>
+ <arg type="s" name="iface" direction="in"/>
<arg type="i" name="ret" direction="out"/>
</method>
<method name="bindType">
</method>
<method name="put">
<arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
- <arg type="(siasa{sv}av)" name="repr" direction="in"/>
+ <arg type="(sasasa{sv}av)" name="repr" direction="in"/>
<arg type="a(ss)" name="query" direction="in"/>
<arg type="(a(qs)vi)" name="ret" direction="out"/>
</method>
<method name="post">
<arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
- <arg type="(siasa{sv}av)" name="repr" direction="in"/>
+ <arg type="(sasasa{sv}av)" name="repr" direction="in"/>
<arg type="a(ss)" name="query" direction="in"/>
<arg type="(a(qs)vi)" name="ret" direction="out"/>
</method>
}
-int ic_utils_convert_interface_flag(iotcon_interface_e src, char **dest)
-{
- switch (src) {
- case IOTCON_INTERFACE_DEFAULT:
- *dest = IC_INTERFACE_DEFAULT;
- break;
- case IOTCON_INTERFACE_LINK:
- *dest = IC_INTERFACE_LINK;
- break;
- case IOTCON_INTERFACE_BATCH:
- *dest = IC_INTERFACE_BATCH;
- break;
- case IOTCON_INTERFACE_GROUP:
- *dest = IC_INTERFACE_GROUP;
- break;
- case IOTCON_INTERFACE_READONLY:
- *dest = IC_INTERFACE_READONLY;
- break;
- case IOTCON_INTERFACE_NONE:
- default:
- ERR("Invalid interface(%d)", src);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- return IOTCON_ERROR_NONE;
-}
-
-
-int ic_utils_convert_interface_string(const char *src, iotcon_interface_e *dest)
-{
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (IC_STR_EQUAL == strcmp(IC_INTERFACE_DEFAULT, src)) {
- *dest = IOTCON_INTERFACE_DEFAULT;
- } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_LINK, src)) {
- *dest = IOTCON_INTERFACE_LINK;
- } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_BATCH, src)) {
- *dest = IOTCON_INTERFACE_BATCH;
- } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_GROUP, src)) {
- *dest = IOTCON_INTERFACE_GROUP;
- } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_READONLY, src)) {
- *dest = IOTCON_INTERFACE_READONLY;
- } else {
- ERR("Invalid Interface(%s)", src);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
void ic_utils_gvariant_array_free(GVariant **value)
{
int i;
if (_ic_oic_feature_supported < 0) {
bool feature_supported = false;
system_info_get_platform_bool(IC_FEATURE_OIC, &feature_supported);
- _ic_oic_feature_supported = feature_supported? 1: 0;
+ _ic_oic_feature_supported = feature_supported ? 1 : 0;
}
return _ic_oic_feature_supported;
#else
#define IC_STR_EQUAL 0
#define IC_STR_NULL "(NULL)"
-#define IC_INTERFACE_MAX (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | \
- IOTCON_INTERFACE_BATCH | IOTCON_INTERFACE_GROUP | IOTCON_INTERFACE_READONLY)
-
char* ic_utils_strdup(const char *src);
const char* ic_utils_dbus_encode_str(const char *src);
char* ic_utils_dbus_decode_str(char *src);
-int ic_utils_convert_interface_flag(iotcon_interface_e src, char **dest);
-int ic_utils_convert_interface_string(const char *src, iotcon_interface_e *dest);
void ic_utils_gvariant_array_free(GVariant **value);
bool ic_utils_check_oic_feature_supported();
GDBusMethodInvocation *invocation,
const gchar *uri_path,
const gchar* const *resource_types,
- gint ifaces,
+ const gchar* const *ifaces,
gint properties,
gboolean is_lite)
{
static gboolean _dbus_handle_bind_interface(icDbus *object,
- GDBusMethodInvocation *invocation, gint64 resource, gint iface)
+ GDBusMethodInvocation *invocation, gint64 resource, const gchar *iface)
{
int ret;
}
OCResourceHandle icd_ioty_register_resource(const char *uri_path,
- const char * const *res_types, int ifaces, int properties)
+ const char* const *res_types, const char* const *res_ifaces, int properties)
{
FN_CALL;
int i;
OCStackResult ret;
OCResourceHandle handle;
- const char *res_iface = NULL;
-
- if (IOTCON_INTERFACE_DEFAULT & ifaces) {
- res_iface = IC_INTERFACE_DEFAULT;
- ifaces ^= IOTCON_INTERFACE_DEFAULT;
- } else if (IOTCON_INTERFACE_LINK & ifaces) {
- res_iface = IC_INTERFACE_LINK;
- ifaces ^= IOTCON_INTERFACE_LINK;
- } else if (IOTCON_INTERFACE_BATCH & ifaces) {
- res_iface = IC_INTERFACE_BATCH;
- ifaces ^= IOTCON_INTERFACE_BATCH;
- } else if (IOTCON_INTERFACE_GROUP & ifaces) {
- res_iface = IC_INTERFACE_GROUP;
- ifaces ^= IOTCON_INTERFACE_GROUP;
- } else if (IOTCON_INTERFACE_READONLY & ifaces) {
- res_iface = IC_INTERFACE_READONLY;
- ifaces ^= IOTCON_INTERFACE_READONLY;
- } else {
- ERR("Invalid interface type(%d)", ifaces);
- return NULL;
- }
properties = _ioty_properties_to_oic_properties(properties);
icd_ioty_csdk_lock();
- ret = OCCreateResource(&handle, res_types[0], res_iface, uri_path,
+ ret = OCCreateResource(&handle, res_types[0], res_ifaces[0], uri_path,
icd_ioty_ocprocess_req_handler, NULL, properties);
icd_ioty_csdk_unlock();
if (OC_STACK_OK != ret) {
for (i = 1; res_types[i]; i++)
icd_ioty_bind_type(handle, res_types[i]);
- if (IOTCON_INTERFACE_DEFAULT & ifaces)
- icd_ioty_bind_interface(handle, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_INTERFACE_LINK & ifaces)
- icd_ioty_bind_interface(handle, IOTCON_INTERFACE_LINK);
- if (IOTCON_INTERFACE_BATCH & ifaces)
- icd_ioty_bind_interface(handle, IOTCON_INTERFACE_BATCH);
- if (IOTCON_INTERFACE_GROUP & ifaces)
- icd_ioty_bind_interface(handle, IOTCON_INTERFACE_GROUP);
- if (IOTCON_INTERFACE_READONLY & ifaces)
- icd_ioty_bind_interface(handle, IOTCON_INTERFACE_READONLY);
+ for (i = 1; res_ifaces[i]; i++)
+ icd_ioty_bind_interface(handle, res_ifaces[i]);
return handle;
}
}
-int icd_ioty_bind_interface(OCResourceHandle handle, iotcon_interface_e iface)
+int icd_ioty_bind_interface(OCResourceHandle handle, const char *resource_interface)
{
- int ret;
- OCStackResult result;
- char *resource_interface;
-
- ret = ic_utils_convert_interface_flag(iface, &resource_interface);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("ic_utils_convert_interface_flag(%d) Fail(%d)", iface, ret);
- return ret;
- }
+ OCStackResult ret;
icd_ioty_csdk_lock();
- result = OCBindResourceInterfaceToResource(handle, resource_interface);
+ ret = OCBindResourceInterfaceToResource(handle, resource_interface);
icd_ioty_csdk_unlock();
- if (OC_STACK_OK != result) {
- ERR("OCBindResourceInterfaceToResource() Fail(%d)", result);
- return icd_ioty_convert_error(result);
+ if (OC_STACK_OK != ret) {
+ ERR("OCBindResourceInterfaceToResource() Fail(%d)", ret);
+ return icd_ioty_convert_error(ret);
}
return IOTCON_ERROR_NONE;
void icd_ioty_deinit(GThread *thread);
OCResourceHandle icd_ioty_register_resource(const char *uri_path,
- const char* const* res_types, int ifaces, int properties);
+ const char* const *res_types, const char* const *res_ifaces, int properties);
int icd_ioty_unregister_resource(OCResourceHandle handle);
-int icd_ioty_bind_interface(OCResourceHandle handle, iotcon_interface_e iface);
+int icd_ioty_bind_interface(OCResourceHandle handle, const char *resource_interface);
int icd_ioty_bind_type(OCResourceHandle handle, const char *resource_type);
GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr)
{
int port = 0;
- int ifaces;
GVariant **value;
OCStringLL *node;
- iotcon_interface_e iface;
GVariantBuilder types;
+ GVariantBuilder ifaces;
OCRandomUuidResult random_res;
OCDiscoveryPayload *discovered;
struct OCResourcePayload *resource;
- int i, properties, ret, res_count;
+ int i, properties, res_count;
char device_id[UUID_STRING_SIZE] = {0};
discovered = (OCDiscoveryPayload*)payload;
}
/* Resource Interfaces */
- ifaces = 0;
+ g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
node = resource->interfaces;
if (NULL == node) {
ERR("resource interfaces is NULL");
g_variant_builder_clear(&types);
continue;
}
- for (; node; node = node->next) {
- ret = ic_utils_convert_interface_string(node->value, &iface);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("ic_utils_convert_interface_string() Fail(%d)", ret);
- g_variant_builder_clear(&types);
- continue;
- }
- ifaces |= iface;
+ while (node) {
+ g_variant_builder_add(&ifaces, "s", node->value);
+ node = node->next;
}
/* Resource Properties */
/* TODO
* Check "resource->secure" and "resource->bitmap" */
- value[i] = g_variant_new("(ssiasibsi)", resource->uri, device_id, ifaces, &types,
+ value[i] = g_variant_new("(ssasasibsi)", resource->uri, device_id, &ifaces, &types,
properties, resource->secure, dev_addr->addr, port);
DBG("found resource[%d] : %s", i, g_variant_print(value[i], FALSE));
}
gboolean is_parent)
{
OCStringLL *node;
- int ret, ifaces = 0;
GVariant *child, *value;
OCRepPayload *child_node;
- iotcon_interface_e iface;
GVariantBuilder *repr_gvar;
- GVariantBuilder children, types_builder;
+ GVariantBuilder children, types_builder, ifaces_builder;
RETV_IF(NULL == repr, NULL);
}
/* Resource Interfaces */
+ g_variant_builder_init(&ifaces_builder, G_VARIANT_TYPE("as"));
+
node = repr->interfaces;
while (node) {
- ret = ic_utils_convert_interface_string(node->value, &iface);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("ic_utils_convert_interface_string() Fail(%d)", ret);
- g_variant_builder_clear(&types_builder);
- return NULL;
- }
- ifaces |= iface;
-
+ g_variant_builder_add(&ifaces_builder, "s", node->value);
node = node->next;
}
child_node = child_node->next;
}
- value = g_variant_new("(siasa{sv}av)", ic_utils_dbus_encode_str(repr->uri), ifaces,
- &types_builder, repr_gvar, &children);
+ value = g_variant_new("(sasasa{sv}av)", ic_utils_dbus_encode_str(repr->uri),
+ &ifaces_builder, &types_builder, repr_gvar, &children);
return value;
}
GVariant* icd_payload_representation_empty_gvariant(void)
{
GVariant *value;
- GVariantBuilder types, repr, children;
+ GVariantBuilder ifaces, types, repr, children;
+ g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
g_variant_builder_init(&repr, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
- value = g_variant_new("(siasa{sv}av)", IC_STR_NULL, 0, &types, &repr, &children);
+ value = g_variant_new("(sasasa{sv}av)", IC_STR_NULL, &ifaces, &types, &repr, &children);
return value;
}
OCRepPayload* icd_payload_representation_from_gvariant(GVariant *var)
{
+ int ret;
GVariant *child;
- int ret, i, ifaces = 0;
OCRepPayload *repr, *cur;
- char *uri_path, *iface_str, *resource_type;
- GVariantIter *resource_types, *repr_gvar, *children;
+ char *uri_path, *resource_iface, *resource_type;
+ GVariantIter *resource_types, *resource_ifaces, *repr_gvar, *children;
repr = OCRepPayloadCreate();
- g_variant_get(var, "(&siasa{sv}av)", &uri_path, &ifaces, &resource_types, &repr_gvar,
- &children);
+ g_variant_get(var, "(&sasasa{sv}av)", &uri_path, &resource_ifaces, &resource_types,
+ &repr_gvar, &children);
if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
OCRepPayloadSetUri(repr, uri_path);
- for (i = 1; i <= IC_INTERFACE_MAX; i = i << 1) {
- if (IOTCON_INTERFACE_NONE == (ifaces & i)) /* this interface not exist */
- continue;
+ while (g_variant_iter_loop(resource_ifaces, "s", &resource_iface))
+ OCRepPayloadAddInterface(repr, resource_iface);
- ret = ic_utils_convert_interface_flag((ifaces & i), &iface_str);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("ic_utils_convert_interface_flag(%d) Fail(%d)", i, ret);
- OCRepPayloadDestroy(repr);
- return NULL;
- }
- OCRepPayloadAddInterface(repr, iface_str);
- }
while (g_variant_iter_loop(resource_types, "s", &resource_type))
OCRepPayloadAddResourceType(repr, resource_type);
...
{
int ret;
- int interfaces = IOTCON_INTERFACE_DEFAULT;
int properties = (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE);
const char *uri_path = "/door/1";
const char *type = "org.tizen.door";
iotcon_resource_types_h resource_types;
+ iotcon_resource_interfaces_h resource_ifaces;
iotcon_resource_h resource = NULL;
ret = iotcon_resource_types_create(&resource_types);
return;
}
+ ret = iotcon_resource_interfaces_create(&resource_ifaces);
+ if (IOTCON_ERROR_NONE != ret)
+ iotcon_resource_types_destroy(resource_types);
+ return;
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
ret = iotcon_resource_create(uri_path, resource_types,
- interfaces, properties, _request_handler, NULL, &resource);
+ resource_ifaces, properties, _request_handler, NULL, &resource);
if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
return;
}
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
}
* @endcode
void *user_data)
{
int ret;
- int resource_interfaces;
char *resource_uri_path;
char *resource_host;
char *device_id;
iotcon_query_h query;
iotcon_resource_types_h resource_types;
+ iotcon_resource_interfaces_h resource_interfaces;
iotcon_remote_resource_h resource_clone = NULL;
if (IOTCON_ERROR_NONE != result)
...
{
int ret;
- int interfaces = IOTCON_INTERFACE_DEFAULT;
int properties = (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE);
const char *uri_path = "/door/1";
const char *type = "org.tizen.door";
iotcon_resource_types_h resource_types;
+ iotcon_resource_interfaces_h resource_ifaces;
ret = iotcon_resource_types_create(&resource_types);
if (IOTCON_ERROR_NONE != ret)
return;
}
+ ret = iotcon_resource_interfaces_create(&resource_ifaces);
+ if (IOTCON_ERROR_NONE != ret)
+ iotcon_resource_types_destroy(resource_types);
+ return;
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
ret = iotcon_resource_create(uri_path, resource_types,
- interfaces, properties, _request_handler, NULL, &_door_handle);
+ resource_ifaces, properties, _request_handler, NULL, &_door_handle);
if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
return;
}
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
}
...
#include "icl.h"
#include "icl-resource.h"
#include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
#include "icl-options.h"
#include "icl-query.h"
#include "icl-request.h"
#include "icl-observation.h"
#include "icl-dbus-type.h"
+const char** icl_dbus_resource_interfaces_to_array(iotcon_resource_interfaces_h ifaces)
+{
+ int i = 0;
+ GList *node = ifaces->iface_list;
+ int len = g_list_length(node);
+
+ if (0 == len) {
+ ERR("Empty Resource Interface List");
+ return NULL;
+ }
+
+ const char **array = calloc(len + 1, sizeof(char*));
+ if (NULL == array) {
+ ERR("calloc() Fail(%d)", errno);
+ return NULL;
+ }
+
+ for (node = ifaces->iface_list; node; node = node->next, i++)
+ array[i] = node->data;
+ array[i] = NULL;
+
+ return array;
+}
+
+
const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
{
int i = 0;
GList *node = types->type_list;
int len = g_list_length(node);
+ if (0 == len) {
+ ERR("Empty Resource Type List");
+ return NULL;
+ }
+
const char **array = calloc(len + 1, sizeof(char*));
if (NULL == array) {
ERR("calloc() Fail(%d)", errno);
#include "icl-device.h"
#include "icl-resource-types.h"
+const char** icl_dbus_resource_interfaces_to_array(iotcon_resource_interfaces_h types);
const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types);
GVariant* icl_dbus_representation_to_gvariant(struct icl_representation_s *repr);
GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response);
ERR("calloc() Fail(%d)", errno);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- response->iface = IOTCON_INTERFACE_DEFAULT;
+ response->iface = strdup(IOTCON_INTERFACE_DEFAULT);
response->result = response_result;
response->oic_request_h = oic_request_h;
response->oic_resource_h = oic_resource_h;
return;
}
- g_variant_get(repr_gvar, "(siasa{sv}av)", NULL, NULL, NULL, &state_iter,
+ g_variant_get(repr_gvar, "(sasasa{sv}av)", NULL, NULL, NULL, &state_iter,
NULL);
ret = iotcon_state_create(&recv_state);
void *user_data,
iotcon_lite_resource_h *resource_handle)
{
- int ret, iface;
+ int ret;
unsigned int sub_id;
- const gchar **types;
+ const gchar **types, **ifaces;
GError *error = NULL;
iotcon_lite_resource_h resource;
int64_t signal_number;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- iface = IOTCON_INTERFACE_DEFAULT;
+ ifaces = calloc(2, sizeof(char*));
+ if (NULL == ifaces) {
+ ERR("calloc() Fail(%d)", errno);
+ free(resource);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ ifaces[0] = IOTCON_INTERFACE_DEFAULT;
+ ifaces[1] = NULL;
types = icl_dbus_resource_types_to_array(res_types);
if (NULL == types) {
ERR("icl_dbus_resource_types_to_array() Fail");
+ free(ifaces);
free(resource);
return IOTCON_ERROR_INVALID_PARAMETER;
}
- ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, types, iface,
+ ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, types, ifaces,
properties, true, &signal_number, &(resource->handle), NULL, &error);
if (error) {
ERR("ic_dbus_call_register_resource_sync() Fail(%s)", error->message);
ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
free(types);
+ free(ifaces);
free(resource);
return ret;
}
free(types);
+ free(ifaces);
if (0 == resource->handle) {
ERR("iotcon-daemon Fail");
#include "icl-list.h"
#include "icl-value.h"
#include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
#include "icl-response.h"
#include "icl-payload.h"
static GVariant* _icl_representation_empty_gvariant(void)
{
GVariant *value;
- GVariantBuilder types, repr, children;
+ GVariantBuilder types, ifaces, repr, children;
+ g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
g_variant_builder_init(&repr, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
- value = g_variant_new("(siasa{sv}av)", IC_STR_NULL, 0, &types, &repr, &children);
+ value = g_variant_new("(sasasa{sv}av)", IC_STR_NULL, &ifaces, &types, &repr, &children);
return value;
}
GVariant* icl_representation_to_gvariant(iotcon_representation_h repr)
{
GList *node;
- int ifaces = 0;
const char *uri_path;
GVariant *value, *child;
iotcon_state_h state;
GVariantBuilder *repr_gvar = NULL;
- GVariantBuilder children, resource_types;
+ GVariantBuilder children, resource_types, resource_ifaces;
if (NULL == repr)
return _icl_representation_empty_gvariant();
/* Resource Types & Interfaces */
g_variant_builder_init(&resource_types, G_VARIANT_TYPE("as"));
+ g_variant_builder_init(&resource_ifaces, G_VARIANT_TYPE("as"));
if (ICL_VISIBILITY_PROP & repr->visibility) {
if (repr->res_types) {
g_variant_builder_add(&resource_types, "s", node->data);
}
- ifaces = repr->interfaces;
+ if (repr->interfaces) {
+ for (node = repr->interfaces->iface_list; node; node = node->next)
+ g_variant_builder_add(&resource_ifaces, "s", node->data);
+ }
}
/* Representation */
g_variant_builder_add(&children, "v", child);
}
- value = g_variant_new("(siasa{sv}av)", uri_path, ifaces, &resource_types,
+ value = g_variant_new("(sasasa{sv}av)", uri_path, &resource_ifaces, &resource_types,
repr_gvar, &children);
return value;
GVariant *child;
iotcon_representation_h repr;
iotcon_state_h state;
- char *uri_path, *resource_type;
- GVariantIter *children, *repr_gvar, *resource_types;
+ char *uri_path, *resource_type, *resource_iface;
+ GVariantIter *children, *repr_gvar, *resource_types, *resource_ifaces;
ret = iotcon_representation_create(&repr);
if (IOTCON_ERROR_NONE != ret) {
return NULL;
}
- g_variant_get(var, "(&siasa{sv}av)", &uri_path, &repr->interfaces,
- &resource_types, &repr_gvar, &children);
+ g_variant_get(var, "(&sasasa{sv}av)", &uri_path, &resource_ifaces, &resource_types,
+ &repr_gvar, &children);
/* uri path */
if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
ret = iotcon_resource_types_create(&repr->res_types);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_create() Fail(%d)", ret);
+ g_variant_iter_free(resource_ifaces);
g_variant_iter_free(resource_types);
g_variant_iter_free(children);
iotcon_state_destroy(state);
}
g_variant_iter_free(resource_types);
+ /* resource ifaces */
+ if (g_variant_iter_n_children(resource_ifaces)) {
+ ret = iotcon_resource_interfaces_create(&repr->interfaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+ g_variant_iter_free(resource_ifaces);
+ g_variant_iter_free(children);
+ iotcon_state_destroy(state);
+ iotcon_representation_destroy(repr);
+ return NULL;
+ }
+
+ while (g_variant_iter_loop(resource_ifaces, "s", &resource_iface))
+ iotcon_resource_interfaces_add(repr->interfaces, resource_iface);
+ }
+ g_variant_iter_free(resource_ifaces);
+
/* attribute */
icl_state_from_gvariant(state, repr_gvar);
return IOTCON_ERROR_NONE;
}
-API int iotcon_query_get_interface(iotcon_query_h query, iotcon_interface_e *iface)
+API int iotcon_query_get_interface(iotcon_query_h query, char **resource_iface)
{
- char *iface_str = NULL;
+ char *iface;
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
- iotcon_query_lookup(query, ICL_QUERY_KEY_INTERFACE, &iface_str);
- if (NULL == iface_str) {
- ERR("iface_str is NULL");
+ iotcon_query_lookup(query, ICL_QUERY_KEY_INTERFACE, &iface);
+ if (NULL == iface) {
+ ERR("iface is NULL");
return IOTCON_ERROR_NO_DATA;
}
- *iface = atoi(iface_str);
+ *resource_iface = iface;
return IOTCON_ERROR_NONE;
}
return IOTCON_ERROR_NONE;
}
-API int iotcon_query_set_interface(iotcon_query_h query, iotcon_interface_e iface)
+API int iotcon_query_set_interface(iotcon_query_h query, const char *resource_iface)
{
int length_old = 0;
int length_new = 0;
char *value = NULL;
- char iface_str[ICL_QUERY_LENGTH_MAX] = {0};
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
if (value)
length_old = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(value) + 2;
- snprintf(iface_str, sizeof(iface_str), "%d", iface);
- length_new = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(iface_str) + 2;
+ if (resource_iface && *resource_iface)
+ length_new = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(resource_iface) + 2;
if (ICL_QUERY_LENGTH_MAX < query->len - length_old + length_new) {
ERR("Length of query is invalid.");
if (value)
iotcon_query_remove(query, ICL_QUERY_KEY_INTERFACE);
- iotcon_query_add(query, ICL_QUERY_KEY_INTERFACE, iface_str);
+ iotcon_query_add(query, ICL_QUERY_KEY_INTERFACE, resource_iface);
return IOTCON_ERROR_NONE;
}
#include "icl-representation.h"
#include "icl-remote-resource.h"
#include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
#include "icl-payload.h"
#define ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL 3600 /* 60 min */
const char *uri_path,
int properties,
iotcon_resource_types_h resource_types,
- int resource_ifs,
+ iotcon_resource_interfaces_h resource_ifaces,
iotcon_remote_resource_h *resource_handle)
{
FN_CALL;
RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resource_types, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == resource_ifaces, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
resource = calloc(1, sizeof(struct icl_remote_resource));
resource->uri_path = ic_utils_strdup(uri_path);
resource->properties = properties;
resource->types = icl_resource_types_ref(resource_types);
- resource->ifaces = resource_ifs;
+ resource->ifaces = icl_resource_interfaces_ref(resource_ifaces);
resource->ref_count = 1;
*resource_handle = resource;
free(resource->uri_path);
free(resource->host_address);
free(resource->device_id);
+ iotcon_resource_interfaces_destroy(resource->ifaces);
iotcon_resource_types_destroy(resource->types);
/* null COULD be allowed */
}
}
- if (src->types) {
- ret = iotcon_resource_types_clone(src->types, &resource->types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_clone() Fail(%d)", ret);
- iotcon_remote_resource_destroy(resource);
- return ret;
- }
+ ret = iotcon_resource_types_clone(src->types, &resource->types);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_clone() Fail(%d)", ret);
+ iotcon_remote_resource_destroy(resource);
+ return ret;
+ }
+
+ ret = iotcon_resource_interfaces_clone(src->ifaces, &resource->ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_clone() Fail(%d)", ret);
+ iotcon_remote_resource_destroy(resource);
+ return ret;
}
- resource->ifaces = src->ifaces;
resource->connectivity_type = src->connectivity_type;
*dest = resource;
}
+/* The content of the resource should not be freed by user. */
API int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource,
- int *ifaces)
+ iotcon_resource_interfaces_h *ifaces)
{
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
{
int ret;
iotcon_remote_resource_h resource;
- GVariantIter *types_iter;
+ GVariantIter *types_iter, *ifaces_iter;
char host_addr[PATH_MAX] = {0};
iotcon_resource_types_h res_types;
- char *uri_path, *device_id, *res_type, *addr;
- int ifaces, properties, is_secure, port;
+ iotcon_resource_interfaces_h ifaces;
+ char *uri_path, *device_id, *res_type, *iface, *addr;
+ int properties, is_secure, port;
- g_variant_get(payload, "(&s&siasib&si)", &uri_path, &device_id, &ifaces, &types_iter,
- &properties, &is_secure, &addr, &port);
+ g_variant_get(payload, "(&s&sasasib&si)", &uri_path, &device_id, &ifaces_iter,
+ &types_iter, &properties, &is_secure, &addr, &port);
switch (connectivity_type) {
case IOTCON_CONNECTIVITY_IPV6:
while (g_variant_iter_loop(types_iter, "s", &res_type))
iotcon_resource_types_add(res_types, res_type);
+ ret = iotcon_resource_interfaces_create(&ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+ iotcon_resource_types_destroy(res_types);
+ return NULL;
+ }
+
+ while (g_variant_iter_loop(ifaces_iter, "s", &iface))
+ iotcon_resource_interfaces_add(ifaces, iface);
+
ret = iotcon_remote_resource_create(host_addr, connectivity_type, uri_path,
properties, res_types, ifaces, &resource);
- if (res_types)
- iotcon_resource_types_destroy(res_types);
+
+ iotcon_resource_interfaces_destroy(ifaces);
+ iotcon_resource_types_destroy(res_types);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_remote_resource_create() Fail");
int properties;
iotcon_options_h header_options;
iotcon_resource_types_h types;
- int ifaces;
+ iotcon_resource_interfaces_h ifaces;
iotcon_connectivity_type_e connectivity_type;
int64_t observe_handle;
unsigned int observe_sub_id;
#include "icl.h"
#include "icl-resource.h"
#include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
#include "icl-response.h"
#include "icl-list.h"
#include "icl-value.h"
/* (GDestroyNotify) : iotcon_representation_h is proper type than gpointer */
g_list_free_full(repr->children, (GDestroyNotify)iotcon_representation_destroy);
+ /* null COULD be allowed */
+ if (repr->interfaces)
+ iotcon_resource_interfaces_destroy(repr->interfaces);
+
/* null COULD be allowed */
if (repr->res_types)
iotcon_resource_types_destroy(repr->res_types);
}
API int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
- int *ifaces)
+ iotcon_resource_interfaces_h *ifaces)
{
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
}
API int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
- int ifaces)
+ iotcon_resource_interfaces_h ifaces)
{
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(ifaces <= IOTCON_INTERFACE_NONE || IC_INTERFACE_MAX < ifaces,
- IOTCON_ERROR_INVALID_PARAMETER);
+ if (ifaces)
+ ifaces = icl_resource_interfaces_ref(ifaces);
+
+ if (repr->interfaces)
+ iotcon_resource_interfaces_destroy(repr->interfaces);
repr->interfaces = ifaces;
FN_CALL;
int ret;
GList *node;
- iotcon_resource_types_h list;
+ iotcon_resource_types_h types;
+ iotcon_resource_interfaces_h ifaces;
iotcon_representation_h cloned_repr, copied_repr;
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
}
}
- if (src->interfaces)
- cloned_repr->interfaces = src->interfaces;
+ if (src->interfaces) {
+ ret = iotcon_resource_interfaces_clone(src->interfaces, &ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_clone() Fail(%d)");
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
+ }
+ cloned_repr->interfaces = ifaces;
+ }
if (src->res_types) {
- ret = iotcon_resource_types_clone(src->res_types, &list);
+ ret = iotcon_resource_types_clone(src->res_types, &types);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_clone() Fail");
iotcon_representation_destroy(cloned_repr);
return ret;
}
- cloned_repr->res_types = list;
+ cloned_repr->res_types = types;
}
if (src->children) {
struct icl_representation_s {
char *uri_path;
int ref_count;
- int interfaces;
int visibility;
GList *children;
iotcon_resource_types_h res_types;
+ iotcon_resource_interfaces_h interfaces;
struct icl_state_s *state;
};
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon-types.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-resource-interfaces.h"
+
+iotcon_resource_interfaces_h icl_resource_interfaces_ref(
+ iotcon_resource_interfaces_h ifaces)
+{
+ RETV_IF(NULL == ifaces, NULL);
+ RETV_IF(ifaces->ref_count <= 0, NULL);
+
+ ifaces->ref_count++;
+
+ return ifaces;
+}
+
+
+API int iotcon_resource_interfaces_create(iotcon_resource_interfaces_h *ret_ifaces)
+{
+ iotcon_resource_interfaces_h ifaces;
+
+ RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == ret_ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ifaces = calloc(1, sizeof(struct icl_resource_ifaces));
+ if (NULL == ifaces) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ ifaces->ref_count = 1;
+
+ *ret_ifaces = ifaces;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API void iotcon_resource_interfaces_destroy(iotcon_resource_interfaces_h ifaces)
+{
+ RET_IF(NULL == ifaces);
+
+ ifaces->ref_count--;
+
+ if (0 == ifaces->ref_count) {
+ g_list_free_full(ifaces->iface_list, free);
+ free(ifaces);
+ }
+}
+
+
+static int _icl_resource_interfaces_strcmp(const void *a, const void *b)
+{
+ return strcmp(a, b);
+}
+
+
+static bool _icl_resource_interfaces_duplicate_check(iotcon_resource_interfaces_h ifaces,
+ const char *iface)
+{
+ GList *node = NULL;
+
+ RETV_IF(NULL == ifaces, false);
+ RETV_IF(NULL == iface, false);
+
+ node = g_list_find_custom(ifaces->iface_list, iface, _icl_resource_interfaces_strcmp);
+ if (NULL == node)
+ return false;
+
+ return true;
+}
+
+
+/* Duplicate strings are not allowed. */
+API int iotcon_resource_interfaces_add(iotcon_resource_interfaces_h ifaces,
+ const char *iface)
+{
+ char *resource_iface;
+
+ RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(1 < ifaces->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
+ "Don't modify it. It is already set.");
+
+ if (true == _icl_resource_interfaces_duplicate_check(ifaces, iface)) {
+ ERR("%s is already contained.", iface);
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+
+ resource_iface = strdup(iface);
+ if (NULL == resource_iface) {
+ ERR("strdup() Fail");
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+
+ ifaces->iface_list = g_list_append(ifaces->iface_list, resource_iface);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_interfaces_remove(iotcon_resource_interfaces_h ifaces,
+ const char *iface)
+{
+ GList *node;
+
+ RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(1 < ifaces->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
+ "Don't modify it. It is already set.");
+
+ node = g_list_find_custom(ifaces->iface_list, iface, _icl_resource_interfaces_strcmp);
+ if (NULL == node) {
+ ERR("g_list_find_custom() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ifaces->iface_list = g_list_delete_link(ifaces->iface_list, node);
+ free(node->data);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_interfaces_foreach(iotcon_resource_interfaces_h ifaces,
+ iotcon_resource_interfaces_foreach_cb cb, void *user_data)
+{
+ GList *node;
+
+ RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ for (node = ifaces->iface_list; node; node = node->next) {
+ if (IOTCON_FUNC_STOP == cb((const char*)node->data, user_data))
+ break;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_interfaces_clone(iotcon_resource_interfaces_h src,
+ iotcon_resource_interfaces_h *dest)
+{
+ GList *node;
+ char *resource_iface;
+ iotcon_resource_interfaces_h resource_ifaces;
+
+ RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+ resource_ifaces = calloc(1, sizeof(struct icl_resource_ifaces));
+ if (NULL == resource_ifaces) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ for (node = src->iface_list; node; node = node->next) {
+ resource_iface = ic_utils_strdup(node->data);
+ if (NULL == resource_iface) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ ERR("ic_utils_strdup() Fail");
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ resource_ifaces->iface_list = g_list_append(resource_ifaces->iface_list,
+ resource_iface);
+ }
+
+ resource_ifaces->ref_count = 1;
+
+ *dest = resource_ifaces;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+/* counting from 0 */
+const char* icl_resource_interfaces_get_nth_data(iotcon_resource_interfaces_h ifaces,
+ int index)
+{
+ return g_list_nth_data(ifaces->iface_list, index);
+}
+
+
+unsigned int icl_resource_interfaces_get_length(iotcon_resource_interfaces_h ifaces)
+{
+ return g_list_length(ifaces->iface_list);
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__
+
+#include <glib.h>
+#include "iotcon-types.h"
+
+struct icl_resource_ifaces {
+ int ref_count;
+ GList *iface_list;
+};
+
+iotcon_resource_interfaces_h icl_resource_interfaces_ref(
+ iotcon_resource_interfaces_h res_ifaces);
+const char* icl_resource_interfaces_get_nth_data(iotcon_resource_interfaces_h res_ifaces,
+ int index);
+unsigned int icl_resource_interfaces_get_length(iotcon_resource_interfaces_h res_ifaces);
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__ */
return IOTCON_ERROR_NO_DATA;
}
- free(found_node->data);
types->type_list = g_list_delete_link(types->type_list, found_node);
+ free(found_node->data);
return IOTCON_ERROR_NONE;
}
#include "icl-request.h"
#include "icl-dbus-type.h"
#include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
#include "icl-resource.h"
#include "icl-payload.h"
return;
}
+ iotcon_resource_interfaces_destroy(resource->ifaces);
iotcon_resource_types_destroy(resource->types);
if (resource->observers)
iotcon_observers_destroy(resource->observers);
/* The length of uri_path should be less than or equal to 36. */
API int iotcon_resource_create(const char *uri_path,
iotcon_resource_types_h res_types,
- int ifaces,
+ iotcon_resource_interfaces_h ifaces,
int properties,
iotcon_request_handler_cb cb,
void *user_data,
{
int ret;
unsigned int sub_id;
- const gchar **types;
+ const gchar **type_array, **iface_array;
GError *error = NULL;
iotcon_resource_h resource;
int64_t signal_number;
RETVM_IF(ICL_URI_PATH_LENGTH_MAX < strlen(uri_path),
IOTCON_ERROR_INVALID_PARAMETER, "Invalid uri_path(%s)", uri_path);
RETV_IF(NULL == res_types, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- types = icl_dbus_resource_types_to_array(res_types);
- if (NULL == types) {
+ type_array = icl_dbus_resource_types_to_array(res_types);
+ if (NULL == type_array) {
ERR("icl_dbus_resource_types_to_array() Fail");
free(resource);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, types, ifaces,
+ iface_array = icl_dbus_resource_interfaces_to_array(ifaces);
+ if (NULL == iface_array) {
+ ERR("icl_dbus_resource_interfaces_to_array() Fail");
+ free(type_array);
+ free(resource);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, type_array, iface_array,
properties, false, &signal_number, &(resource->handle), NULL, &error);
if (error) {
ERR("ic_dbus_call_register_resource_sync() Fail(%s)", error->message);
ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- free(types);
+ free(iface_array);
+ free(type_array);
free(resource);
return ret;
}
- free(types);
+ free(iface_array);
+ free(type_array);
if (0 == resource->handle) {
ERR("iotcon-daemon Fail");
resource->cb = cb;
resource->user_data = user_data;
- resource->types = icl_resource_types_ref(res_types);
resource->uri_path = ic_utils_strdup(uri_path);
- resource->ifaces = ifaces;
+ resource->types = icl_resource_types_ref(res_types);
+ resource->ifaces = icl_resource_interfaces_ref(ifaces);
resource->properties = properties;
snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
_icl_request_handler);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
- iotcon_resource_types_destroy(res_types);
+ iotcon_resource_interfaces_destroy(resource->ifaces);
+ iotcon_resource_types_destroy(resource->types);
free(resource->uri_path);
free(resource);
return IOTCON_ERROR_DBUS;
if (0 == resource->handle) { /* iotcon dbus disconnected */
WARN("Invalid Resource handle");
+ iotcon_resource_interfaces_destroy(resource->ifaces);
iotcon_resource_types_destroy(resource->types);
if (resource->observers)
iotcon_observers_destroy(resource->observers);
}
-API int iotcon_resource_bind_interface(iotcon_resource_h resource,
- iotcon_interface_e iface)
+API int iotcon_resource_bind_interface(iotcon_resource_h resource, const char *iface)
{
FN_CALL;
int ret;
GError *error = NULL;
+ iotcon_resource_interfaces_h resource_ifaces;
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
if (0 == resource->sub_id) {
ERR("Invalid Resource handle");
return IOTCON_ERROR_INVALID_PARAMETER;
}
- if (resource->ifaces & iface) {
- ERR("iface(%d) is already contained.", iface);
- return IOTCON_ERROR_INVALID_PARAMETER;
+ ret = iotcon_resource_interfaces_clone(resource->ifaces, &resource_ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_clone() Fail(%d)", ret);
+ return ret;
+ }
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, iface);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ return ret;
}
ic_dbus_call_bind_interface_sync(icl_dbus_get_object(), resource->handle,
ERR("ic_dbus_call_bind_interface_sync() Fail(%s)", error->message);
ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
+ iotcon_resource_interfaces_destroy(resource_ifaces);
return ret;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon-daemon Fail(%d)", ret);
+ iotcon_resource_interfaces_destroy(resource_ifaces);
return icl_dbus_convert_daemon_error(ret);
}
- resource->ifaces |= iface;
+
+ iotcon_resource_interfaces_destroy(resource->ifaces);
+ resource->ifaces = resource_ifaces;
return ret;
}
}
-API int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces)
+API int iotcon_resource_get_interfaces(iotcon_resource_h resource,
+ iotcon_resource_interfaces_h *ifaces)
{
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
#define ICL_URI_PATH_LENGTH_MAX 36
struct icl_notify_msg {
- iotcon_interface_e iface;
+ char *iface;
iotcon_representation_h repr;
};
char *uri_path;
int properties;
iotcon_resource_types_h types;
- int ifaces;
+ iotcon_resource_interfaces_h ifaces;
iotcon_request_handler_cb cb;
void *user_data;
unsigned int sub_id;
iotcon_representation_destroy(resp->repr);
if (resp->header_options)
iotcon_options_destroy(resp->header_options);
+ if (resp->iface)
+ free(resp->iface);
free(resp);
}
}
-API int iotcon_response_set_representation(iotcon_response_h resp,
- iotcon_interface_e iface, iotcon_representation_h repr)
+API int iotcon_response_set_representation(iotcon_response_h resp, const char *iface,
+ iotcon_representation_h repr)
{
RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
- resp->iface = iface;
+ free(resp->iface);
+ resp->iface = strdup(iface);
if (repr)
repr = icl_representation_ref(repr);
static bool _icl_response_representation_child_cb(iotcon_representation_h child,
void *user_data)
{
- int iface = GPOINTER_TO_INT(user_data);
+ char *iface = user_data;
- switch (iface) {
- case IOTCON_INTERFACE_BATCH:
+ if (IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_BATCH, iface))
child->visibility = ICL_VISIBILITY_REPR;
- break;
- case IOTCON_INTERFACE_NONE:
- case IOTCON_INTERFACE_DEFAULT:
- case IOTCON_INTERFACE_LINK:
- case IOTCON_INTERFACE_GROUP:
+ else
child->visibility = ICL_VISIBILITY_PROP;
- break;
- case IOTCON_INTERFACE_READONLY:
- default:
- WARN("Invalid interface type(%d)", iface);
- child->visibility = ICL_VISIBILITY_PROP;
- break;
- }
return IOTCON_FUNC_CONTINUE;
}
iotcon_representation_h first = resp->repr;
- DBG("interface type of response : %d", resp->iface);
+ DBG("interface type of response : %s", resp->iface);
- switch (resp->iface) {
- case IOTCON_INTERFACE_NONE:
- case IOTCON_INTERFACE_DEFAULT:
- case IOTCON_INTERFACE_GROUP:
- first->visibility = ICL_VISIBILITY_REPR;
- break;
- case IOTCON_INTERFACE_LINK:
- case IOTCON_INTERFACE_BATCH:
+ if (IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_LINK, resp->iface)
+ || IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_BATCH, resp->iface))
first->visibility = ICL_VISIBILITY_NONE;
- break;
- case IOTCON_INTERFACE_READONLY:
- default:
- WARN("Invalid interface type(%d)", resp->iface);
+ else
first->visibility = ICL_VISIBILITY_REPR;
- break;
- }
ret = iotcon_representation_foreach_children(first,
- _icl_response_representation_child_cb, GINT_TO_POINTER(resp->iface));
+ _icl_response_representation_child_cb, resp->iface);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_representation_foreach_children() Fail(%d)", ret);
return ret;
struct icl_resource_response {
iotcon_options_h header_options;
- iotcon_interface_e iface;
+ char *iface;
int result;
iotcon_representation_h repr;
int64_t oic_request_h;
*/
#define IOTCON_FUNC_CONTINUE true
+/**
+ * @brief Default Interface
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_DEFAULT "oic.if.baseline"
+
+/**
+ * @brief List Links Interface which is used to list the references to other resources contained in a resource
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_LINK "oic.if.ll"
+
+/**
+ * @brief Batch Interface which is used to manipulate (GET, PUT, POST, DELETE) on other resource contained in a resource
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_BATCH "oic.if.b"
+
+/**
+ * @brief Group Interface which is used to manipulate (GET, PUT, POST) a group of remote resources
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_GROUP "oic.mi.grp"
+
+/**
+ * @brief Read-Only Interface which is used to limit the methods that can be applied to a resource to GET only
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_READONLY "oic.if.r"
+
/**
* @brief Enumeration for type of observation.
*
IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER = 1 /**< Indicates observation request for all notifications including stale notifications */
} iotcon_observe_policy_e;
-/**
- * @brief Enumeration for type of interfaces which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_INTERFACE_NONE = 0, /**< Indicates interface not specified or uninitialized */
- IOTCON_INTERFACE_DEFAULT = (1 << 0), /**< Indicates interface for default */
- IOTCON_INTERFACE_LINK = (1 << 1), /**< Indicates interface which is used to list the references to other resources contained in a resource */
- IOTCON_INTERFACE_BATCH = (1 << 2), /**< Indicates interface which is used to manipulate (GET, PUT, POST, DELETE) on other resources contained in a resource */
- IOTCON_INTERFACE_GROUP = (1 << 3), /**< Indicates interface which is used to manipulate (GET, PUT, POST) a group of remote resources */
- IOTCON_INTERFACE_READONLY = (1 << 4), /**< Indicates interface which is used to limit the methods that can be applied to a resource to GET only */
-} iotcon_interface_e;
-
/**
* @brief Enumeration for of connectivities which can be held in a resource.
*
/**
* @brief Gets resource interface from the query.
- * @details @a iface could be one of #iotcon_interface_e.
*
* @since_tizen 3.0
*
+ * @remarks @a resource_iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ * @remarks @a resource_iface must not be released using free().
+ *
* @param[in] query The handle of the query
- * @param[out] iface Found interface from query
+ * @param[out] resource_iface Found resource interface from query
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @see iotcon_query_remove()
* @see iotcon_query_set_interface()
*/
-int iotcon_query_get_interface(iotcon_query_h query, iotcon_interface_e *iface);
+int iotcon_query_get_interface(iotcon_query_h query, char **resource_iface);
/**
* @brief Sets the resource type into the query.
int iotcon_query_set_resource_type(iotcon_query_h query, const char *resource_type);
/**
- * @brief Sets the interface into the query.
+ * @brief Sets the resource interface into the query.
*
* @since_tizen 3.0
*
+ * @remarks @a resource_iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
* @param[in] query The handle of the query
- * @param[in] iface The interface to add into the query
+ * @param[in] resource_iface The resource interface to add into the query
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @see iotcon_query_lookup()
* @see iotcon_query_get_interface()
*/
-int iotcon_query_set_interface(iotcon_query_h query, iotcon_interface_e iface);
+int iotcon_query_set_interface(iotcon_query_h query, const char *resource_iface);
/**
* @brief Adds a new key and correspoding value into the query.
* If not, you should discover the resource object manually.\n
* The @a properties can contain multiple properties like
* IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.\n
- * The @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
*
* @since_tizen 3.0
*
* @param[in] connectivity_type The connectivity type
* @param[in] uri_path The URI path of the resource
* @param[in] properties The properties of the resource\n Set of #iotcon_resource_property_e
- * @param[in] resource_types The resource type of the resource. For example, "core.light"
- * @param[in] resource_ifaces The resource interfaces (whether it is collection etc)\n
- * Set of #iotcon_interface_e
+ * @param[in] resource_types The resource types of the resource. For example, "core.light"
+ * @param[in] resource_ifaces The resource interfaces of the resource.
* @param[out] remote_resource Generated resource handle
*
* @return 0 on success, otherwise a negative error value.
const char *uri_path,
int properties,
iotcon_resource_types_h resource_types,
- int resource_ifaces,
+ iotcon_resource_interfaces_h resource_ifaces,
iotcon_remote_resource_h *remote_resource);
/**
/**
* @brief Gets resource interfaces of the remote resource
- * @details @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
*
* @since_tizen 3.0
*
+ * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
+ *
* @param[in] resource The handle of the remote resource
- * @param[out] ifaces The resource interfaces of the remote resource\n Set of #iotcon_interface_e
+ * @param[out] ifaces The resource interfaces of the remote resource
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @see iotcon_remote_resource_get_properties()
* @see iotcon_remote_resource_set_options()
*/
-int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource, int *ifaces);
+int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource,
+ iotcon_resource_interfaces_h *ifaces);
/**
* @brief Checks whether the remote resource is observable or not.
* @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_OVERVIEW Overview
* The Iotcon Representation API provides data type of resp_repr handling.\n
* A resp_repr is a payload of a request or a response.\n
- * It has uri_path, interface, list of resource types and its attributes.\n
+ * It has uri_path, list of resource interfaces, list of resource types and its attributes.\n
* Attributes have capabilties to store and retrieve integer, boolean, double, string,
* byte string, list, null, resp_repr.\n
* A list is a container that includes number of datas of same type.\n
iotcon_resource_types_h *types);
/**
- * @brief Sets interfaces to the representation.
- * @details If you set new interfaces, current interfaces value will be replaced with @a ifaces.\n
- * @a ifaces can be consist of multiple interface like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
+ * @brief Sets list of resource interfaces to the representation.
*
* @since_tizen 3.0
*
+ * @remarks Stored list is replaced with @a ifaces. If @a ifaces is NULL, stored list is set
+ * by NULL.
+ *
* @param[in] repr The representation handle
- * @param[in] ifaces The interfaces to set\n Set of #iotcon_interface_e
+ * @param[in] ifaces The list of resource interfaces
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
- int ifaces);
+ iotcon_resource_interfaces_h ifaces);
/**
- * @brief Gets resource interfaces from the representation.
- * @details @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
+ * @brief Gets list of resource interfaces from the representation.
*
* @since_tizen 3.0
*
+ * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
+ *
* @param[in] repr The representation handle
- * @param[out] ifaces The interfaces to get\n Set of #iotcon_interface_e
+ * @param[out] ifaces The list of resource interfaces to get
*
- * @return Interfaces to get. Interfaces may contain multiple interfaces.
- * @retval #IOTCON_INTERFACE_NONE Not set
- * @retval Bitwise OR value which consists of iotcon_interface_e items
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
- int *ifaces);
+ iotcon_resource_interfaces_h *ifaces);
/**
* @brief Sets a new state handle into the representation.
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__
+#define __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__
+
+#include <iotcon-types.h>
+
+/**
+ * @file iotcon-resource-interfaces.h
+ */
+
+/**
+ * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
+ * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE Resource Interfaces
+ *
+ * @brief Iotcon Resource Interfaces provides API to manage resource interfaces.
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_HEADER Required Header
+ * \#include <iotcon.h>
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_OVERVIEW Overview
+ * The iotcon resource interfaces API provides methods for managing handle and add, remove resource interfaces.
+ * A resource interface indicates a class or category of resources.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+ void *user_data)
+{
+ // handle request
+ ...
+}
+
+static void _create_light_resource()
+{
+ int ret;
+ iotcon_resource_h resource = NULL;
+ iotcon_resource_interfaces_h resource_ifaces = NULL;
+ iotcon_resource_interfaces_h resource_types = NULL;
+
+ ret = iotcon_resource_types_create(&resource_types);
+ if (IOTCON_ERROR_NONE != ret)
+ return;
+
+ ret = iotcon_resource_types_add(resource_types, "org.tizen.light");
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
+ ret = iotcon_resource_interfaces_create(&resource_ifaces);
+ if (IOTCON_ERROR_NONE != ret)
+ iotcon_resource_types_destroy(resource_types);
+ return;
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
+ ret = iotcon_resource_create("/light/1", resource_types, resource_ifaces,
+ IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, _request_handler, NULL, &resource);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+}
+ * @endcode
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ * - http://tizen.org/feature/iot.oic\n
+ *
+ * It is recommended to design feature related codes in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * 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.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ * @{
+ */
+
+/**
+ * @brief Creates a new resource interfaces handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks You must destroy @a ifaces by calling iotcon_resource_interfaces_destroy()
+ * if @a ifaces is no longer needed.
+ *
+ * @param[out] ifaces A newly allocated list of resource ifaces handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_remove()
+ * @see iotcon_resource_interfaces_clone()
+ */
+int iotcon_resource_interfaces_create(iotcon_resource_interfaces_h *ifaces);
+
+/**
+ * @brief Destroys a resource ifaces handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] ifaces The handle of the resource ifaces
+ *
+ * @return void
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_remove()
+ * @see iotcon_resource_interfaces_clone()
+ */
+void iotcon_resource_interfaces_destroy(iotcon_resource_interfaces_h ifaces);
+
+/**
+ * @brief Inserts a resource iface into the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
+ * @param[in] ifaces The handle of the resource ifaces
+ * @param[in] iface The string data to insert into the resource ifaces
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_remove()
+ * @see iotcon_resource_interfaces_clone()
+ */
+int iotcon_resource_interfaces_add(iotcon_resource_interfaces_h ifaces,
+ const char *iface);
+
+/**
+ * @brief Delete a resource iface form the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
+ * @param[in] ifaces The handle of the resource ifaces
+ * @param[in] iface The string data to delete from the resource ifaces
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_clone()
+ */
+int iotcon_resource_interfaces_remove(iotcon_resource_interfaces_h ifaces,
+ const char *iface);
+
+/**
+ * @brief Specifies the iface of function passed to iotcon_resource_interfaces_foreach()
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
+ * @param[in] iface The value of the resource ifaces
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @return 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.
+ *
+ * @pre iotcon_resource_interfaces_foreach() will invoke this callback function.
+ *
+ * @see iotcon_resource_interfaces_foreach()
+ */
+typedef bool (*iotcon_resource_interfaces_foreach_cb)(const char *iface, void *user_data);
+
+/**
+ * @brief Gets all of the resource ifaces of the list by invoking the callback function.
+ * @details iotcon_resource_interfaces_foreach_cb() will be called for each iface.\n
+ * If iotcon_resource_interfaces_foreach_cb() returns false, iteration will be stop.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] ifaces The handle of resource ifaces
+ * @param[in] cb The callback function to get data
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @post iotcon_resource_interfaces_foreach() will be called for each iface.
+ *
+ * @see iotcon_resource_interfaces_foreach_cb()
+ */
+int iotcon_resource_interfaces_foreach(iotcon_resource_interfaces_h ifaces,
+ iotcon_resource_interfaces_foreach_cb cb, void *user_data);
+
+/**
+ * @brief Clones the resource ifaces handle.
+ * @details Makes a deep copy of a source list of resource ifaces.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks You must @a destroy dest by calling iotcon_resource_interfaces_destroy()
+ * if @a dest is no longer needed.
+ *
+ * @param[in] src The origin handle of the resource ifaces
+ * @param[out] dest Clone of a source list of resource ifaces
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_remove()
+ */
+int iotcon_resource_interfaces_clone(iotcon_resource_interfaces_h src,
+ iotcon_resource_interfaces_h *dest);
+
+/**
+ * @}
+ */
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__ */
{
int ret;
iotcon_resource_h resource = NULL;
- iotcon_resource_types_h resource_types = NULL;
+ iotcon_resource_interfaces_h resource_ifaces = NULL;
+ iotcon_resource_interfaces_h resource_types = NULL;
ret = iotcon_resource_types_create(&resource_types);
if (IOTCON_ERROR_NONE != ret)
return;
}
- ret = iotcon_resource_create("/light/1", resource_types, IOTCON_INTERFACE_DEFAULT,
+ ret = iotcon_resource_interfaces_create(&resource_ifaces);
+ if (IOTCON_ERROR_NONE != ret)
+ iotcon_resource_types_destroy(resource_types);
+ return;
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
+ ret = iotcon_resource_create("/light/1", resource_types, resource_ifaces,
IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, _request_handler, NULL, &resource);
if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
return;
}
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
}
* @endcode
static void _create_resource()
{
int ret;
- int ifaces;
int properties;
- iotcon_resource_types_h resource_types = NULL;
+ iotcon_resource_interfaces_h resource_ifaces = NULL;
+ iotcon_resource_interfaces_h resource_types = NULL;
iotcon_resource_h resource_door = NULL;
// 1. create room resource
- ifaces = IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH;
properties = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE;
ret = iotcon_resource_types_create(&resource_types);
return;
}
- ret = iotcon_resource_create("/room/1", resource_types, ifaces,
+ ret = iotcon_resource_interfaces_create(&resource_ifaces);
+ if (IOTCON_ERROR_NONE != ret)
+ iotcon_resource_types_destroy(resource_types);
+ return;
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_LINK);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_BATCH);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ return;
+ }
+
+ ret = iotcon_resource_create("/room/1", resource_types, resource_ifaces,
properties, _room_request_handler, NULL, &_resource_room);
if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
return;
}
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
// 2. create door resource
- ifaces = IOTCON_INTERFACE_DEFAULT;
properties = IOTCON_RESOURCE_OBSERVABLE;
ret = iotcon_resource_types_create(&resource_types);
return;
}
- ret = iotcon_resource_create("/door/1", resource_types, ifaces,
+ ret = iotcon_resource_interfaces_create(&resource_ifaces);
+ if (IOTCON_ERROR_NONE != ret)
+ iotcon_resource_types_destroy(resource_types);
+ iotcon_resource_destroy(_resource_room);
+ return;
+
+ ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
+ iotcon_resource_types_destroy(resource_types);
+ iotcon_resource_destroy(_resource_room);
+ return;
+ }
+
+ ret = iotcon_resource_create("/door/1", resource_types, resource_ifaces,
properties, _door_request_handler, NULL, &resource_door);
if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
iotcon_resource_destroy(_resource_room);
_resource_room = NULL;
return;
}
+ iotcon_resource_interfaces_destroy(resource_ifaces);
iotcon_resource_types_destroy(resource_types);
// 3. bind door resouce to room resource
* @a uri_path format would be relative URI path like '/a/light'\n
* @a res_types is a list of resource types. Create a iotcon_resource_types_h handle and
* add types string to it.\n
- * @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.\n
+ * @a ifaces is a list of resource interfaces. Create a iotcon_resource_interfaces_h handle and
+ * add interfaces string to it.\n
* @a properties also can contain multiple properties like
* IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.\n
* iotcon_request_handler_cb() will be called when receive CRUD request to the registered
*
* @param[in] uri_path The URI path of the resource
* @param[in] res_types The list of type of the resource
- * @param[in] ifaces The interfaces of the resource\n Set of #iotcon_interface_e
+ * @param[in] ifaces The list of interface of the resource
* @param[in] properties The properties of the resource\n Set of #iotcon_resource_property_e
* @param[in] cb The request handler callback function
* @param[in] user_data The user data to pass to the callback function
*/
int iotcon_resource_create(const char *uri_path,
iotcon_resource_types_h res_types,
- int ifaces,
+ iotcon_resource_interfaces_h ifaces,
int properties,
iotcon_request_handler_cb cb,
void *user_data,
/**
* @brief Binds an interface to the resource
*
- * @details The @a iface could be one of #iotcon_interface_e.
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/network.get
* @privilege %http://tizen.org/privilege/d2d.datasharing
*
- * @remarks Sets only one interface to @a iface. If not, @a iface will be ignored.
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
*
* @param[in] resource The handle of the resource
* @param[in] iface The interface to be bound to the resource
* @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_resource_bind_interface(iotcon_resource_h resource, iotcon_interface_e iface);
+int iotcon_resource_bind_interface(iotcon_resource_h resource, const char *iface);
/**
* @brief Binds a type to the resource
/**
* @brief Gets the interfaces of the resource
- * @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
*
* @since_tizen 3.0
*
+ * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
+ *
* @param[in] resource The handle of the resource
- * @param[out] ifaces The interfaces of the resource\n Set of #iotcon_interface_e
+ * @param[out] ifaces The interfaces of the resource
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @see iotcon_resource_get_types()
* @see iotcon_resource_get_properties()
*/
-int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces);
+int iotcon_resource_get_interfaces(iotcon_resource_h resource,
+ iotcon_resource_interfaces_h *ifaces);
/**
* @brief Gets the properties in the resource
{
int ret;
int types;
- iotcon_interface_e iface = IOTCON_INTERFACE_DEFAULT;
iotcon_query_h query = NULL;
ret = iotcon_request_get_types(request, &types);
return;
}
- ret = iotcon_response_set_representation(response, iface, repr);
+ ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT, repr);
if (IOTCON_ERROR_NONE != ret) {
iotcon_representation_destroy(repr);
iotcon_response_destroy(response);
*
* @since_tizen 3.0
*
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
* @param[in] resp The handle of the response
* @param[in] iface The interface of the representation
* @param[in] repr The representation of the response
* @see iotcon_response_create()
* @see iotcon_response_destroy()
*/
-int iotcon_response_set_representation(iotcon_response_h resp,
- iotcon_interface_e iface, iotcon_representation_h repr);
+int iotcon_response_set_representation(iotcon_response_h resp, const char *iface,
+ iotcon_representation_h repr);
/**
* @brief Sets header options into the response
*/
typedef struct icl_platform_info* iotcon_platform_info_h;
+/**
+ * @brief The handle of resource interface
+ * @details @a iotcon_resource_interfaces_h is an opaque data structure to have list
+ * of resource interfaces. A resource interface is datatype of string.
+ *
+ * @since_tizen 3.0
+ */
+typedef struct icl_resource_ifaces* iotcon_resource_interfaces_h;
+
/**
* @brief The handle of resource types
* @details @a iotcon_resource_types_h is an opaque data structure to have list
#include <iotcon-options.h>
#include <iotcon-representation.h>
#include <iotcon-resource-types.h>
+#include <iotcon-resource-interfaces.h>
#endif /* __IOT_CONNECTIVITY_MANAGER_TYPES_H__ */
static void _on_response_post(iotcon_remote_resource_h resource,
iotcon_response_h response, void *user_data)
{
+ int ret;
iotcon_state_h recv_state;
char *host, *created_uri_path;
- int ret, ifaces = 0;
iotcon_connectivity_type_e connectivity_type;
iotcon_response_result_e response_result;
iotcon_resource_types_h types = NULL;
+ iotcon_resource_interfaces_h ifaces = NULL;
iotcon_remote_resource_h new_door_resource;
iotcon_representation_h recv_repr = NULL;
iotcon_representation_destroy(send_repr);
}
+static bool _get_res_iface_cb(const char *string, void *user_data)
+{
+ char *resource_uri_path = user_data;
+
+ DBG("[%s] resource interface : %s", resource_uri_path, string);
+
+ return IOTCON_FUNC_CONTINUE;
+}
+
static bool _get_res_type_cb(const char *string, void *user_data)
{
char *resource_uri_path = user_data;
static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
void *user_data)
{
+ int ret;
GList *node;
char *resource_host;
char *resource_uri_path;
char *resource_device_id;
iotcon_presence_h presence_handle;
iotcon_resource_types_h resource_types;
- int ret, resource_interfaces;
+ iotcon_resource_interfaces_h resource_interfaces;
iotcon_connectivity_type_e connectivity_type;
iotcon_remote_resource_h resource_clone = NULL;
free(door_resource_device_id);
return;
}
- if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
- DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_LINK & resource_interfaces)
- DBG("[%s] resource interface : LINK_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_BATCH & resource_interfaces)
- DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_GROUP & resource_interfaces)
- DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_READONLY & resource_interfaces)
- DBG("[%s] resource interface : READONLY_INTERFACE", resource_uri_path);
+
+ ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
+ resource_uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
+ device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+ free(door_resource_device_id);
+ return;
+ }
/* get the resource types */
ret = iotcon_remote_resource_get_types(resource, &resource_types);
bool state;
char *uri_path;
char *type;
- int ifaces;
+ iotcon_resource_interfaces_h ifaces;
int properties;
iotcon_resource_h handle;
iotcon_observers_h observers;
return -1;
}
- door->ifaces = IOTCON_INTERFACE_DEFAULT;
+ ret = iotcon_resource_interfaces_create(&door->ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+ free(door->type);
+ free(door->uri_path);
+ return -1;
+ }
+
+ ret = iotcon_resource_interfaces_add(door->ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ iotcon_resource_interfaces_destroy(door->ifaces);
+ free(door->type);
+ free(door->uri_path);
+ return -1;
+ }
+
door->properties = IOTCON_RESOURCE_DISCOVERABLE;
ret = iotcon_observers_create(&door->observers);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_observers_create() Fail");
+ iotcon_resource_interfaces_destroy(door->ifaces);
free(door->type);
free(door->uri_path);
return -1;
static void _free_door_resource(door_resource_s *door)
{
iotcon_observers_destroy(door->observers);
+ iotcon_resource_interfaces_destroy(door->ifaces);
free(door->type);
free(door->uri_path);
}
INFO("[Door] opened.");
}
-static iotcon_resource_h _create_door_resource(char *uri_path, char *type, int ifaces,
- int properties, void *user_data)
+static iotcon_resource_h _create_door_resource(char *uri_path, char *type,
+ iotcon_resource_interfaces_h ifaces, int properties, void *user_data)
{
int ret;
iotcon_resource_h handle;
}
new_door_handle = _create_door_resource(DOOR_RESOURCE_URI2, door->type,
- IOTCON_INTERFACE_DEFAULT, IOTCON_RESOURCE_NO_PROPERTY, door);
+ door->ifaces, IOTCON_RESOURCE_NO_PROPERTY, door);
if (NULL == new_door_handle) {
ERR("_create_door_resource() Fail");
return -1;
}
/* add resource options */
- my_door.ifaces |= IOTCON_INTERFACE_BATCH;
+ ret = iotcon_resource_interfaces_add(my_door.ifaces, IOTCON_INTERFACE_BATCH);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ _free_door_resource(&my_door);
+ iotcon_disconnect();
+ return -1;
+ }
my_door.properties |= IOTCON_RESOURCE_OBSERVABLE;
/* add presence */
#define DOOR_RESOURCE_TYPE "org.tizen.door"
+static bool _get_res_iface_cb(const char *string, void *user_data)
+{
+ char *resource_uri_path = user_data;
+
+ DBG("[%s] resource interface : %s", resource_uri_path, string);
+
+ return IOTCON_FUNC_CONTINUE;
+}
+
static bool _get_res_type_cb(const char *string, void *user_data)
{
char *resource_uri_path = user_data;
static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
void *user_data)
{
+ int ret;
GList *node;
char *resource_host;
char *resource_uri_path;
char *resource_device_id;
- int ret, resource_interfaces;
+ iotcon_resource_interfaces_h resource_interfaces;
iotcon_resource_types_h resource_types;
iotcon_remote_resource_h cloned_resource;
free(door_resource_device_id);
return;
}
- if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
- DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_LINK & resource_interfaces)
- DBG("[%s] resource interface : LINK_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_BATCH & resource_interfaces)
- DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_GROUP & resource_interfaces)
- DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_READONLY & resource_interfaces)
- DBG("[%s] resource interface : READONLY_INTERFACE", resource_uri_path);
+
+ ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
+ resource_uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
+ device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+ free(door_resource_device_id);
+ return;
+ }
/* get the resource types */
ret = iotcon_remote_resource_get_types(resource, &resource_types);
iotcon_query_destroy(query_params);
}
-static bool _get_res_type_fn(const char *string, void *user_data)
+static bool _get_res_iface_cb(const char *string, void *user_data)
+{
+ char *resource_uri_path = user_data;
+
+ DBG("[%s] resource interface : %s", resource_uri_path, string);
+
+ return IOTCON_FUNC_CONTINUE;
+}
+
+static bool _get_res_type_cb(const char *string, void *user_data)
{
char *resource_uri_path = user_data;
static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
void *user_data)
{
+ int ret;
GList *node;
char *resource_host;
char *resource_uri_path;
char *resource_device_id;
- int ret, resource_interfaces;
+ iotcon_resource_interfaces_h resource_interfaces;
iotcon_resource_types_h resource_types;
iotcon_remote_resource_h cloned_resource;
free(room_resource_device_id);
return;
}
- if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
- DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_LINK & resource_interfaces)
- DBG("[%s] resource interface : LINK_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_BATCH & resource_interfaces)
- DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_GROUP & resource_interfaces)
- DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
- if (IOTCON_INTERFACE_READONLY & resource_interfaces)
- DBG("[%s] resource interface : READONLY_INTERFACE", resource_uri_path);
+
+ ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
+ resource_uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
+ device_id_list = g_list_remove(device_id_list, room_resource_device_id);
+ free(room_resource_device_id);
+ return;
+ }
/* get the resource types */
ret = iotcon_remote_resource_get_types(resource, &resource_types);
free(room_resource_device_id);
return;
}
- ret = iotcon_resource_types_foreach(resource_types, _get_res_type_fn,
+ ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
resource_uri_path);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
int brightness;
char *uri_path;
char *type;
- int ifaces;
+ iotcon_resource_interfaces_h ifaces;
int properties;
iotcon_resource_h handle;
} light_resource_s;
bool state;
char *uri_path;
char *type;
- int ifaces;
+ iotcon_resource_interfaces_h ifaces;
int properties;
iotcon_resource_h handle;
} fan_resource_s;
int today_temp[5];
char *uri_path;
char *type;
- int ifaces;
+ iotcon_resource_interfaces_h ifaces;
int properties;
iotcon_resource_h handle;
light_resource_s *child_light;
static int _set_room_resource(room_resource_s *room)
{
+ int ret;
+
room->name = strdup("Michael's Room");
if (NULL == room->name) {
ERR("strdup() Fail");
return -1;
}
- room->ifaces = IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH;
+ ret = iotcon_resource_interfaces_create(&room->ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+ free(room->type);
+ free(room->uri_path);
+ free(room->name);
+ return -1;
+ }
+
+ ret = iotcon_resource_interfaces_add(room->ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ iotcon_resource_interfaces_destroy(room->ifaces);
+ free(room->type);
+ free(room->uri_path);
+ free(room->name);
+ return -1;
+ }
+
+ ret = iotcon_resource_interfaces_add(room->ifaces, IOTCON_INTERFACE_BATCH);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ iotcon_resource_interfaces_destroy(room->ifaces);
+ free(room->type);
+ free(room->uri_path);
+ free(room->name);
+ return -1;
+ }
+
room->properties = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE;
return 0;
static void _free_room_resource(room_resource_s *room)
{
+ iotcon_resource_interfaces_destroy(room->ifaces);
free(room->type);
free(room->uri_path);
free(room->name);
static int _set_light_resource(light_resource_s *light)
{
+ int ret;
+
light->brightness = 50;
light->uri_path = strdup(LIGHT_RESOURCE_URI);
return -1;
}
- light->ifaces = IOTCON_INTERFACE_DEFAULT;
+ ret = iotcon_resource_interfaces_create(&light->ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+ free(light->type);
+ free(light->uri_path);
+ return -1;
+ }
+
+ ret = iotcon_resource_interfaces_add(light->ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ iotcon_resource_interfaces_destroy(light->ifaces);
+ free(light->type);
+ free(light->uri_path);
+ return -1;
+ }
+
light->properties = IOTCON_RESOURCE_NO_PROPERTY;
return 0;
static void _free_light_resource(light_resource_s *light)
{
+ iotcon_resource_interfaces_destroy(light->ifaces);
free(light->type);
free(light->uri_path);
}
static int _set_fan_resource(fan_resource_s *fan)
{
+ int ret;
+
fan->state = false;
fan->uri_path = strdup(FAN_RESOURCE_URI);
return -1;
}
- fan->ifaces = IOTCON_INTERFACE_DEFAULT;
+ ret = iotcon_resource_interfaces_create(&fan->ifaces);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+ free(fan->type);
+ free(fan->uri_path);
+ return -1;
+ }
+
+ ret = iotcon_resource_interfaces_add(fan->ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ iotcon_resource_interfaces_destroy(fan->ifaces);
+ free(fan->type);
+ free(fan->uri_path);
+ return -1;
+ }
+
fan->properties = IOTCON_RESOURCE_NO_PROPERTY;
return 0;
static void _free_fan_resource(fan_resource_s *fan)
{
+ iotcon_resource_interfaces_destroy(fan->ifaces);
free(fan->type);
free(fan->uri_path);
}
-static iotcon_resource_h _create_resource(char *uri_path, char *type, int ifaces,
- int properties, iotcon_request_handler_cb cb, void *user_data)
+static iotcon_resource_h _create_resource(char *uri_path,
+ char *type,
+ iotcon_resource_interfaces_h ifaces,
+ int properties,
+ iotcon_request_handler_cb cb,
+ void *user_data)
{
int ret;
iotcon_resource_h handle;
}
static int _send_response(iotcon_request_h request, iotcon_representation_h repr,
- iotcon_interface_e iface, iotcon_response_result_e result)
+ const char *iface, iotcon_response_result_e result)
{
int ret;
iotcon_response_h response;
return -1;
}
- ret = _send_response(request, repr, IOTCON_INTERFACE_DEFAULT,
- IOTCON_RESPONSE_OK);
+ ret = _send_response(request, repr, IOTCON_INTERFACE_DEFAULT, IOTCON_RESPONSE_OK);
if (0 != ret) {
ERR("_send_response() Fail(%d)", ret);
iotcon_representation_destroy(repr);
int ret;
iotcon_query_h query;
iotcon_representation_h repr;
- iotcon_interface_e iface = IOTCON_INTERFACE_DEFAULT;
+ char *iface = IOTCON_INTERFACE_DEFAULT;
INFO("GET request - Room");
int ret;
iotcon_request_type_e type;
light_resource_s *light = user_data;
- int iface = IOTCON_INTERFACE_DEFAULT;
+ char *iface = IOTCON_INTERFACE_DEFAULT;
RET_IF(NULL == request);
int ret;
iotcon_request_type_e type;
fan_resource_s *fan = user_data;
- int iface = IOTCON_INTERFACE_DEFAULT;
+ char *iface = IOTCON_INTERFACE_DEFAULT;
RET_IF(NULL == request);
iotcon_request_type_e type;
char *host_address;
room_resource_s *room = user_data;
- int iface = IOTCON_INTERFACE_DEFAULT;
+ char *iface = IOTCON_INTERFACE_DEFAULT;
RET_IF(NULL == request);