</method>
<method name="notifyListOfObservers">
<arg type="i" name="resource" direction="in"/>
- <arg type="a(iis)" name="notify_msg" direction="in"/>
+ <arg type="a(is)" name="notify_msg" direction="in"/>
<arg type="ai" name="observers" direction="in"/>
<arg type="i" name="ret" direction="out"/>
</method>
<arg type="i" name="ret" direction="out"/>
</method>
<method name="sendResponse">
- <arg type="(sia(qs)iisii)" name="response" direction="in"/>
+ <arg type="(sia(qs)isii)" name="response" direction="in"/>
<arg type="i" name="ret" direction="out"/>
</method>
<method name="findResource">
#include "icd-dbus.h"
static GDBusConnection *icd_dbus_conn;
-static GList *icd_bus_list; /* global list to care resource handle for each sender bus */
-typedef struct _icd_bus_s {
+static GList *icd_dbus_client_list; /* global list to care resource handle for each sender bus */
+static GMutex icd_dbus_client_list_mutex;
+
+typedef struct _icd_dbus_client_s {
gchar *sender;
GList *hdlist;
-} icd_bus_s;
+} icd_dbus_client_s;
-typedef struct _ic_resource_handle {
+typedef struct _icd_resource_handle {
void *handle;
unsigned int number;
} icd_resource_handle_s;
-static void _icd_dbus_resource_handle_free(int handle)
+
+static void _icd_dbus_client_list_lock()
+{
+ g_mutex_lock(&icd_dbus_client_list_mutex);
+}
+
+
+static void _icd_dbus_client_list_unlock()
{
- icd_bus_s *bus;
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
+}
+
+
+static void _icd_dbus_resource_handle_free(void *handle)
+{
+ icd_dbus_client_s *bus;
GList *cur_bus, *cur_hd;
icd_resource_handle_s *rsrc_handle;
- cur_bus = icd_bus_list;
+ _icd_dbus_client_list_lock();
+ cur_bus = icd_dbus_client_list;
while (cur_bus) {
bus = cur_bus->data;
if (NULL == bus) {
ERR("bus is NULL");
+ _icd_dbus_client_list_unlock();
return;
}
while (cur_hd) {
rsrc_handle = cur_hd->data;
- if (rsrc_handle->handle == GINT_TO_POINTER(handle)) {
- DBG("resource handle(%u, %u) removed from handle list", handle, rsrc_handle->number);
+ if (rsrc_handle->handle == handle) {
+ DBG("resource handle(%u, %u) removed from handle list", handle,
+ rsrc_handle->number);
bus->hdlist = g_list_delete_link(bus->hdlist, cur_hd);
free(rsrc_handle);
+ _icd_dbus_client_list_unlock();
return;
}
cur_hd = cur_hd->next;
cur_bus = cur_bus->next;
}
+ _icd_dbus_client_list_unlock();
return;
}
-int icd_dbus_bus_list_get_info(int handle, unsigned int *sig_num, const gchar **sender)
+int icd_dbus_bus_list_get_info(void *handle, unsigned int *sig_num, gchar **sender)
{
FN_CALL;
- icd_bus_s *bus;
+ icd_dbus_client_s *bus;
GList *cur_bus, *cur_hd;
icd_resource_handle_s *rsrc_handle;
RETV_IF(NULL == sig_num, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == sender, IOTCON_ERROR_INVALID_PARAMETER);
- cur_bus = icd_bus_list;
+ _icd_dbus_client_list_lock();
+ cur_bus = icd_dbus_client_list;
while (cur_bus) {
bus = cur_bus->data;
if (NULL == bus) {
ERR("bus is NULL");
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_NO_DATA;
}
while (cur_hd) {
rsrc_handle = cur_hd->data;
- if (rsrc_handle->handle == GINT_TO_POINTER(handle)) {
- DBG("signal_number(%u) for resource handle(%u) found", rsrc_handle->number, handle);
+ if (rsrc_handle->handle == handle) {
+ DBG("signal_number(%u) for resource handle(%u) found",
+ rsrc_handle->number, handle);
*sig_num = rsrc_handle->number;
- *sender = bus->sender;
+ *sender = ic_utils_strdup(bus->sender);
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_NONE;
}
cur_hd = cur_hd->next;
cur_bus = cur_bus->next;
}
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_NO_DATA;
}
return IOTCON_ERROR_NONE;
}
-void _ic_dbus_cleanup_handle(icd_resource_handle_s *rsrc_handle)
+static void _icd_dbus_cleanup_handle(void *data)
{
int ret;
+ icd_resource_handle_s *rsrc_handle = data;
RET_IF(NULL == rsrc_handle);
RET_IF(NULL == rsrc_handle->handle);
static int _icd_dbus_bus_list_cleanup_handle_list(GList *list)
{
- icd_bus_s *bus;
+ icd_dbus_client_s *bus;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
bus = list->data;
- g_list_free_full(bus->hdlist, (GDestroyNotify)_ic_dbus_cleanup_handle);
+ g_list_free_full(bus->hdlist, _icd_dbus_cleanup_handle);
free(bus->sender);
bus->sender = NULL;
free(bus);
static int _icd_dbus_bus_list_find_sender(const gchar *owner, GList **ret_list)
{
GList *cur;
- icd_bus_s *bus;
+ icd_dbus_client_s *bus;
RETV_IF(NULL == owner, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
- cur = icd_bus_list;
+ cur = icd_dbus_client_list;
while (cur) {
bus = cur->data;
if (NULL == bus) {
g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
if (0 == strlen(new_owner)) {
+ _icd_dbus_client_list_lock();
ret = _icd_dbus_bus_list_find_sender(old_owner, &sender);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icd_dbus_bus_list_find_sender() Fail(%d)", ret);
+ _icd_dbus_client_list_unlock();
return;
}
ret = _icd_dbus_bus_list_cleanup_handle_list(sender);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icd_dbus_bus_list_cleanup_handle_list() Fail(%d)", ret);
+ _icd_dbus_client_list_unlock();
return;
}
- icd_bus_list = g_list_delete_link(icd_bus_list, sender);
+ icd_dbus_client_list = g_list_delete_link(icd_dbus_client_list, sender);
}
+ _icd_dbus_client_list_unlock();
}
}
GList *cur_bus, *cur_hd;
bool sender_exist = false;
icd_resource_handle_s *rsrc_handle;
- icd_bus_s *new_bus = NULL;
- icd_bus_s *bus;
+ icd_dbus_client_s *new_bus = NULL;
+ icd_dbus_client_s *bus;
RETV_IF(NULL == sender, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == handle, IOTCON_ERROR_INVALID_PARAMETER);
- cur_bus = icd_bus_list;
+ _icd_dbus_client_list_lock();
+ cur_bus = icd_dbus_client_list;
while (cur_bus) {
bus = cur_bus->data;
if (NULL == bus) {
ERR("bus is NULL");
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_NO_DATA;
}
if (false == sender_exist) {
DBG("sender(%s) not exist. make new one.", sender);
- new_bus = calloc(1, sizeof(icd_bus_s));
+ new_bus = calloc(1, sizeof(icd_dbus_client_s));
if (NULL == new_bus) {
ERR("calloc(bus) Fail(%d)", errno);
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_OUT_OF_MEMORY;
}
if (NULL == sender_dup) {
ERR("ic_utils_strdup() Fail");
free(new_bus);
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_OUT_OF_MEMORY;
}
while (cur_hd) {
rsrc_handle = cur_hd->data;
- if (rsrc_handle->handle == GINT_TO_POINTER(handle)) {
- ERR("resource handle(%u, %u) already exist", rsrc_handle->handle, rsrc_handle->number);
+ if (rsrc_handle->handle == handle) {
+ ERR("resource handle(%u, %u) already exist", rsrc_handle->handle,
+ rsrc_handle->number);
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_ALREADY;
}
free(new_bus->sender);
free(new_bus);
}
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_OUT_OF_MEMORY;
}
bus->hdlist = g_list_append(bus->hdlist, rsrc_handle);
if (false == sender_exist)
- icd_bus_list = g_list_append(icd_bus_list, bus);
+ icd_dbus_client_list = g_list_append(icd_dbus_client_list, bus);
+ _icd_dbus_client_list_unlock();
return IOTCON_ERROR_NONE;
}
handle = icd_ioty_register_resource(uri_path, resource_types, ifaces, properties);
if (handle) {
sender = g_dbus_method_invocation_get_sender(invocation);
+
ret = _icd_dbus_resource_list_append_handle(sender, handle, signal_number);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icd_dbus_resource_list_append_handle() Fail(%d)", ret);
else
DBG("handle(%u) deregistered", resource);
- _icd_dbus_resource_handle_free(resource);
+ _icd_dbus_resource_handle_free(GINT_TO_POINTER(resource));
ic_dbus_complete_unregister_resource(object, invocation, ret);
{
int ret;
- ret = icd_ioty_notify_list_of_observers(resource, notify_msg, observers);
+ ret = icd_ioty_notify_list_of_observers(GINT_TO_POINTER(resource), notify_msg,
+ observers);
if (IOTCON_ERROR_NONE != ret)
ERR("icd_ioty_notify_list_of_observers() Fail(%d)", ret);
{
int ret;
- ret = icd_ioty_notify_all(resource);
+ ret = icd_ioty_notify_all(GINT_TO_POINTER(resource));
if (IOTCON_ERROR_NONE != ret)
ERR("icd_ioty_notify_all() Fail(%d)", ret);
#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_DBUS_H__
#define __IOT_CONNECTIVITY_MANAGER_DAEMON_DBUS_H__
-int icd_dbus_bus_list_get_info(int handle, unsigned int *sig_num, const gchar **sender);
+#include <glib.h>
+
+int icd_dbus_bus_list_get_info(void *handle, unsigned int *sig_num, gchar **sender);
int icd_dbus_emit_signal(const char *dest, const char *sig_name, GVariant *value);
unsigned int icd_dbus_init();
void icd_dbus_deinit(unsigned int id);
-
#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_DBUS_H__*/
};
+struct icd_req_context {
+ unsigned int signum;
+ char *sender;
+ char *payload;
+ int types;
+ int observer_id;
+ int observe_action;
+ OCRequestHandle request_h;
+ OCResourceHandle resource_h;
+ GVariantBuilder *options;
+ GVariantBuilder *query;
+};
+
+
struct icd_find_context {
unsigned int signum;
char *sender;
GVariantBuilder *options;
};
+
void icd_ioty_ocprocess_stop()
{
icd_ioty_alive = 0;
}
-OCEntityHandlerResult EntityHandlerWrapper(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest *entityHandlerRequest)
+static int _ocprocess_response_signal(const char *dest, const char *signal,
+ unsigned int signum, GVariant *value)
{
- FN_CALL;
+ int ret;
+ char sig_name[IC_DBUS_SIGNAL_LENGTH] = {0};
+
+ ret = snprintf(sig_name, sizeof(sig_name), "%s_%u", signal, signum);
+ if (ret <= 0 || sizeof(sig_name) <= ret) {
+ ERR("snprintf() Fail(%d)", ret);
+ return IOTCON_ERROR_UNKNOWN;
+ }
+
+ ret = icd_dbus_emit_signal(dest, sig_name, value);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icd_dbus_emit_signal() Fail(%d)", ret);
+ return ret;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+static inline GVariantBuilder* _ocprocess_parse_header_options(
+ OCHeaderOption *oic_option, int option_size)
+{
+ int i;
+ GVariantBuilder *options;
+
+ options = g_variant_builder_new(G_VARIANT_TYPE("a(qs)"));
+ for (i = 0; i < option_size; i++) {
+ g_variant_builder_add(options, "(qs)", oic_option[i].optionID,
+ oic_option[i].optionData);
+ }
+
+ return options;
+}
+
+
+static int _worker_req_handler(void *context)
+{
+ int ret;
+ GVariant *value;
+ struct icd_req_context *ctx = context;
+
+ RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_variant_new("(ia(qs)a(ss)iisii)",
+ ctx->types,
+ ctx->options,
+ ctx->query,
+ ctx->observe_action,
+ ctx->observer_id,
+ ctx->payload,
+ GPOINTER_TO_INT(ctx->request_h),
+ GPOINTER_TO_INT(ctx->resource_h));
+
+ ret = _ocprocess_response_signal(ctx->sender, IC_DBUS_SIGNAL_REQUEST_HANDLER,
+ ctx->signum, value);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("_ocprocess_response_signal() Fail(%d)", ret);
+
+ free(ctx->sender);
+ free(ctx->payload);
+ g_variant_builder_unref(ctx->options);
+ g_variant_builder_unref(ctx->query);
+ free(ctx);
+
+ return ret;
+}
+
+
+OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest *request)
+{
+ int ret;
+ unsigned int signal_number;
+ char *query_str, *query_key, *query_value;
+ char *token, *save_ptr1, *save_ptr2;
+ char *sender = NULL;
+ struct icd_req_context *req_ctx;
- DBG("reqJSONPayload : %s", entityHandlerRequest->reqJSONPayload);
+ RETV_IF(NULL == request, OC_EH_ERROR);
+
+ req_ctx = calloc(1, sizeof(struct icd_req_context));
+ if (NULL == req_ctx) {
+ ERR("calloc() Fail(%d)", errno);
+ return OC_EH_ERROR;
+ }
+
+ /* handle */
+ req_ctx->request_h = request->requestHandle;
+ req_ctx->resource_h = request->resource;
+
+ ret = icd_dbus_bus_list_get_info(req_ctx->resource_h, &signal_number, &sender);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icd_dbus_bus_list_get_info() Fail(%d)", ret);
+ free(req_ctx);
+ return OC_EH_ERROR;
+ }
+
+ /* signal number & sender */
+ req_ctx->signum = signal_number;
+ req_ctx->sender = sender;
+
+ /* request type */
+ if (OC_REQUEST_FLAG & flag) {
+ switch (request->method) {
+ case OC_REST_GET:
+ req_ctx->types = IOTCON_REQUEST_GET;
+ req_ctx->payload = strdup(IC_STR_NULL);
+
+ if (OC_OBSERVE_FLAG & flag) {
+ req_ctx->types |= IOTCON_REQUEST_OBSERVE;
+ /* observation info*/
+ req_ctx->observer_id = request->obsInfo.obsId;
+ req_ctx->observe_action = request->obsInfo.action;
+ }
+ break;
+ case OC_REST_PUT:
+ req_ctx->types = IOTCON_REQUEST_PUT;
+ req_ctx->payload = ic_utils_strdup(request->reqJSONPayload);
+ break;
+ case OC_REST_POST:
+ req_ctx->types = IOTCON_REQUEST_POST;
+ req_ctx->payload = ic_utils_strdup(request->reqJSONPayload);
+ break;
+ case OC_REST_DELETE:
+ req_ctx->types = IOTCON_REQUEST_DELETE;
+ req_ctx->payload = strdup(IC_STR_NULL);
+ break;
+ default:
+ free(req_ctx->sender);
+ free(req_ctx);
+ return OC_EH_ERROR;
+ }
+ }
+
+ /* header options */
+ req_ctx->options = _ocprocess_parse_header_options(
+ request->rcvdVendorSpecificHeaderOptions,
+ request->numRcvdVendorSpecificHeaderOptions);
+
+ /* query */
+ req_ctx->query = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
+ query_str = request->query;
+ while ((token = strtok_r(query_str, "&", &save_ptr1))) {
+ while ((query_key = strtok_r(token, "=", &save_ptr2))) {
+ token = NULL;
+ query_value = strtok_r(token, "=", &save_ptr2);
+ if (NULL == query_value)
+ break;
+
+ g_variant_builder_add(req_ctx->query, "(ss)", query_key, query_value);
+ }
+ query_str = NULL;
+ }
+
+ ret = _ocprocess_worker_start(_worker_req_handler, req_ctx);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_ocprocess_worker_start() Fail(%d)", ret);
+ free(req_ctx->sender);
+ free(req_ctx->payload);
+ g_variant_builder_unref(req_ctx->options);
+ g_variant_builder_unref(req_ctx->query);
+ free(req_ctx);
+ return OC_EH_ERROR;
+ }
+
+ /* DO NOT FREE req_ctx. It MUST be freed in the _worker_req_handler func */
return OC_EH_OK;
}
}
-static int _ocprocess_response_signal(const char *dest, const char *signal,
- unsigned int signum, GVariant *value)
-{
- int ret;
- char sig_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- ret = snprintf(sig_name, sizeof(sig_name), "%s_%u", signal, signum);
- if (ret <= 0 || sizeof(sig_name) <= ret) {
- ERR("snprintf() Fail(%d)", ret);
- return IOTCON_ERROR_UNKNOWN;
- }
-
- ret = icd_dbus_emit_signal(dest, sig_name, value);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_dbus_emit_signal() Fail(%d)", ret);
- return ret;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
/*
* returned string SHOULD be released by you
*/
ret = _ocprocess_response_signal(ctx->sender, IC_DBUS_SIGNAL_FOUND_RESOURCE,
ctx->signum, value);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_dbus_emit_signal() Fail(%d)", ret);
+ ERR("_ocprocess_response_signal() Fail(%d)", ret);
return ret;
}
OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *clientResponse)
+ OCClientResponse *resp)
{
int ret;
OCDevAddr *dev_addr;
icd_sig_ctx_s *sig_context = ctx;
RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
- RETV_IF(NULL == clientResponse, OC_STACK_KEEP_TRANSACTION);
- RETV_IF(NULL == clientResponse->resJSONPayload, OC_STACK_KEEP_TRANSACTION);
-
- DBG("JSON Payload : %s", clientResponse->resJSONPayload);
+ RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
+ RETV_IF(NULL == resp->resJSONPayload, OC_STACK_KEEP_TRANSACTION);
find_ctx = calloc(1, sizeof(struct icd_find_context));
if (NULL == find_ctx) {
free(find_ctx);
return OC_STACK_KEEP_TRANSACTION;
}
- memcpy(dev_addr, clientResponse->addr, sizeof(OCDevAddr));
+ memcpy(dev_addr, resp->addr, sizeof(OCDevAddr));
find_ctx->signum = sig_context->signum;
find_ctx->sender = ic_utils_strdup(sig_context->sender);
- find_ctx->payload = ic_utils_strdup(clientResponse->resJSONPayload);
+ find_ctx->payload = ic_utils_strdup(resp->resJSONPayload);
find_ctx->dev_addr = dev_addr;
- find_ctx->conn_type = clientResponse->connType;
+ find_ctx->conn_type = resp->connType;
ret = _ocprocess_worker_start(_worker_find_cb, find_ctx);
if (IOTCON_ERROR_NONE != ret) {
}
-static inline GVariantBuilder* _ocprocess_parse_header_options(OCClientResponse *resp)
-{
- int i;
- GVariantBuilder *options;
-
- RETV_IF(NULL == resp, NULL);
-
- if (0 == resp->numRcvdVendorSpecificHeaderOptions)
- return NULL;
-
- options = g_variant_builder_new(G_VARIANT_TYPE("a(qs)"));
- for (i = 0; i < resp->numRcvdVendorSpecificHeaderOptions; i++) {
- g_variant_builder_add(options, "(qs)",
- resp->rcvdVendorSpecificHeaderOptions[i].optionID,
- resp->rcvdVendorSpecificHeaderOptions[i].optionData);
- }
-
- return options;
-}
-
-
OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
OCClientResponse *resp)
{
result = resp->result;
if (result == OC_STACK_OK) {
res = IOTCON_RESPONSE_RESULT_OK;
- options = _ocprocess_parse_header_options(resp);
+ options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
+ resp->numRcvdVendorSpecificHeaderOptions);
} else {
WARN("resp error(%d)", result);
res = IOTCON_RESPONSE_RESULT_ERROR;
void icd_ioty_ocprocess_stop();
-OCEntityHandlerResult EntityHandlerWrapper(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest *entityHandlerRequest);
-
gpointer icd_ioty_ocprocess_thread(gpointer data);
+OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest *request);
+
OCStackApplicationResult icd_ioty_ocprocess_find_cb(void* ctx, OCDoHandle handle,
- OCClientResponse* clientResponse);
+ OCClientResponse* resp);
OCStackApplicationResult icd_ioty_ocprocess_get_cb(void* ctx, OCDoHandle handle,
- OCClientResponse* clientResponse);
+ OCClientResponse* resp);
#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_THREAD_H__*/
#include "icd-ioty.h"
#include "icd-ioty-ocprocess.h"
-GHashTable *icd_worker_table;
-
-GMutex icd_csdk_mutex;
+static GMutex icd_csdk_mutex;
void icd_ioty_csdk_lock()
{
return thread;
}
+
void icd_ioty_deinit(GThread *thread)
{
OCStackResult result;
}
icd_ioty_csdk_lock();
- ret = OCCreateResource(&handle, res_types[0], resInterface, uri_path, EntityHandlerWrapper,
- properties);
+ ret = OCCreateResource(&handle, res_types[0], resInterface, uri_path,
+ icd_ioty_ocprocess_req_handler, properties);
icd_ioty_csdk_unlock();
if (OC_STACK_OK != ret) {
ERR("OCCreateResource() Fail(%d)", ret);
int icd_ioty_unregister_resource(OCResourceHandle resource_handle)
{
- // TODO : To be implemented
+ OCStackResult ret;
+
+ icd_ioty_csdk_lock();
+ ret = OCDeleteResource(resource_handle);
+ icd_ioty_csdk_unlock();
+ if (OC_STACK_OK != ret) {
+ ERR("OCDeleteResource() Fail(%d)", ret);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
return IOTCON_ERROR_NONE;
}
return ret;
}
+ icd_ioty_csdk_lock();
result = OCBindResourceInterfaceToResource(resourceHandle, resource_interface);
+ icd_ioty_csdk_unlock();
if (OC_STACK_OK != result) {
ERR("OCBindResourceInterfaceToResource() Fail(%d)", result);
return IOTCON_ERROR_IOTIVITY;
{
OCStackResult ret;
+ icd_ioty_csdk_lock();
ret = OCBindResourceTypeToResource(resource_handle, resource_type);
+ icd_ioty_csdk_unlock();
if (OC_STACK_OK != ret) {
ERR("OCBindResourceTypeToResource() Fail(%d)", ret);
return IOTCON_ERROR_IOTIVITY;
int icd_ioty_bind_resource(OCResourceHandle parent, OCResourceHandle child)
{
- // TODO : To be implemented
+ OCStackResult ret;
+
+ icd_ioty_csdk_lock();
+ ret = OCBindResource(parent, child);
+ icd_ioty_csdk_unlock();
+ if (OC_STACK_OK != ret) {
+ ERR("OCBindResource() Fail(%d)", ret);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
return IOTCON_ERROR_NONE;
}
int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child)
{
- // TODO : To be implemented
+ OCStackResult ret;
+
+ icd_ioty_csdk_lock();
+ ret = OCUnBindResource(parent, child);
+ icd_ioty_csdk_unlock();
+ if (OC_STACK_OK != ret) {
+ ERR("OCUnBindResource() Fail(%d)", ret);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
return IOTCON_ERROR_NONE;
}
-int icd_ioty_notify_list_of_observers(int resHandle, GVariant *msg, GVariant *observers)
+int icd_ioty_notify_list_of_observers(void *handle, GVariant *msg, GVariant *observers)
{
- // TODO : To be implemented
+ int i, error_code, obs_length;
+ char *repr_json = NULL;
+ GVariantIter obs_iter, msg_iter;
+ OCStackResult ret;
+
+ g_variant_iter_init(&obs_iter, observers);
+ obs_length = g_variant_iter_n_children(&obs_iter);
+
+ /* Variable-length Array */
+ OCObservationId obs_ids[obs_length];
+
+ for (i = 0; i < obs_length; i++)
+ g_variant_iter_loop(&obs_iter, "i", &obs_ids[i]);
+
+ g_variant_iter_init(&msg_iter, msg);
+ g_variant_iter_loop(&msg_iter, "(i&s)", &error_code, &repr_json);
+ /* TODO : How to use error_code. */
+
+ icd_ioty_csdk_lock();
+ /* TODO : QoS is come from lib. And user can set QoS to client structure. */
+ ret = OCNotifyListOfObservers(handle, obs_ids, obs_length, repr_json, OC_HIGH_QOS);
+ icd_ioty_csdk_unlock();
+
+ if (OC_STACK_NO_OBSERVERS == ret) {
+ WARN("No Observers. Stop Notifying");
+ return IOTCON_ERROR_NONE;
+ } else if (OC_STACK_OK != ret) {
+ ERR("OCNotifyListOfObservers() Fail(%d)", ret);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
return IOTCON_ERROR_NONE;
}
-int icd_ioty_notify_all(int resHandle)
+int icd_ioty_notify_all(void *handle)
{
- // TODO : To be implemented
+ OCStackResult ret;
+
+ icd_ioty_csdk_lock();
+ /* TODO : QoS is come from lib. And user can set QoS to client structure. */
+ ret = OCNotifyAllObservers(handle, OC_HIGH_QOS);
+ icd_ioty_csdk_unlock();
+
+ if (OC_STACK_NO_OBSERVERS == ret) {
+ WARN("No Observers. Stop Notifying");
+ return IOTCON_ERROR_NONE;
+ } else if (OC_STACK_OK != ret) {
+ ERR("OCNotifyAllObservers() Fail(%d)", ret);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+static int _ioty_get_header_options(GVariantIter *src, int src_size,
+ OCHeaderOption dest[], int dest_size)
+{
+ int i = 0;
+ char *option_data;
+ unsigned short option_id;
+
+ RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (dest_size < src_size) {
+ ERR("Exceed Size(%d)", src_size);
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+
+ while (g_variant_iter_loop(src, "(q&s)", &option_id, &option_data)) {
+ dest[i].protocolID = OC_COAP_ID;
+ dest[i].optionID = option_id;
+ dest[i].optionLength = strlen(option_data) + 1;
+ memcpy(dest[i].optionData, option_data, dest[i].optionLength);
+ i++;
+ }
+
return IOTCON_ERROR_NONE;
}
int icd_ioty_send_response(GVariant *resp)
{
- // TODO : To be implemented
+ int result, error_code, options_size;
+ int request_handle, resource_handle;
+ char *new_uri_path, *repr_json;
+ GVariantIter *options;
+ OCStackResult ret;
+ OCEntityHandlerResponse response = {0};
+
+ g_variant_get(resp, "(&sia(qs)i&sii)",
+ &new_uri_path,
+ &error_code,
+ &options,
+ &result,
+ &repr_json,
+ &request_handle,
+ &resource_handle);
+
+ response.requestHandle = GINT_TO_POINTER(request_handle);
+ response.resourceHandle = GINT_TO_POINTER(resource_handle);
+ response.ehResult = (OCEntityHandlerResult)result;
+
+ if (OC_EH_RESOURCE_CREATED == response.ehResult)
+ snprintf(response.resourceUri, sizeof(response.resourceUri), "%s", new_uri_path);
+
+ options_size = g_variant_iter_n_children(options);
+ response.numSendVendorSpecificHeaderOptions = options_size;
+
+ if (0 != options_size) {
+ int ret= _ioty_get_header_options(options,
+ response.numSendVendorSpecificHeaderOptions,
+ response.sendVendorSpecificHeaderOptions,
+ sizeof(response.sendVendorSpecificHeaderOptions)
+ / sizeof(response.sendVendorSpecificHeaderOptions[0]));
+
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("_ioty_get_header_options() Fail(%d)", ret);
+ }
+ g_variant_iter_free(options);
+
+ response.payload = repr_json;
+ response.payloadSize = strlen(response.payload) + 1;
+
+ /* related to block transfer */
+ response.persistentBufferFlag = 0;
+
+ icd_ioty_csdk_lock();
+ ret = OCDoResponse(&response);
+ icd_ioty_csdk_unlock();
+
+ if (OC_STACK_OK != ret) {
+ ERR("OCDoResponse() Fail(%d)", ret);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
return IOTCON_ERROR_NONE;
}
-void _ioty_free_signal_context(void *data)
+static void _ioty_free_signal_context(void *data)
{
icd_sig_ctx_s *context = data;
free(context->sender);
}
-static int _ioty_get_header_options(GVariantIter *src, int src_size,
- OCHeaderOption dest[], int dest_size)
-{
- gsize len;
- char *option_data;
- unsigned short option_id;
-
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (dest_size < src_size) {
- ERR("Exceed Size(%d)", src_size);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- while (g_variant_iter_loop(src, "(q&s)", &option_id, &option_data)) {
- dest[i].protocolID = OC_COAP_ID;
- dest[i].optionID = option_id;
- dest[i].optionLength = strlen(option_data)+1;
- memcpy(dest[i].optionData, option_data, dest[i].optionLength);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
/*
* returned string SHOULD be released by you
*/
char uri_buf[PATH_MAX] = {0};
len = snprintf(uri_buf, sizeof(uri_buf), "%s%s", host, uri_path);
- if (len < 0) {
- ERR("snprintf() Fail");
- return NULL;
- }
/* remove suffix '/' */
if ('/' == uri_buf[strlen(uri_buf) - 1]) {
query_len = snprintf(uri_buf + len, sizeof(uri_buf), "&%s=%s", key, value);
}
- if (0 > query_len) {
- ERR("snprintf() Fail");
- g_variant_iter_free(queryIter);
- return NULL;
- }
-
len += query_len;
}
g_variant_iter_free(queryIter);
int icd_ioty_unbind_resource(void *parent, void *child);
-int icd_ioty_notify_list_of_observers(int resHandle, GVariant *msg, GVariant *observers);
+int icd_ioty_notify_list_of_observers(void *handle, GVariant *msg, GVariant *observers);
-int icd_ioty_notify_all(int resHandle);
+int icd_ioty_notify_all(void *handle);
int icd_ioty_send_response(GVariant *resp);
GVariant *value;
GVariantBuilder *builder;
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(iis)"));
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(is)"));
if (msg) {
+ /* TODO Make repr_json using interface */
repr_json = icl_repr_generate_json(msg->repr, false);
if (NULL == repr_json) {
ERR("icl_repr_generate_json() Fail");
g_variant_builder_unref(builder);
return NULL;
}
- g_variant_builder_add(builder, "(iis)", msg->error_code, msg->iface, repr_json);
+ g_variant_builder_add(builder, "(is)", msg->error_code, repr_json);
}
- value = g_variant_new("a(iis)", builder);
+ value = g_variant_new("a(is)", builder);
free(repr_json);
g_variant_builder_unref(builder);
GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response)
{
+ char *repr_json;
GHashTableIter iter;
GVariantBuilder *options;
gpointer option_id, option_data;
g_variant_builder_add(options, "(qs)", GPOINTER_TO_INT(option_id), option_data);
}
- value = g_variant_new("(sia(qs)iisii)",
+ /* TODO Make repr_json using interface */
+ repr_json = icl_repr_generate_json(response->repr, false);
+ if (NULL == repr_json) {
+ ERR("icl_repr_generate_json() Fail");
+ g_variant_builder_unref(options);
+ return NULL;
+ }
+
+ value = g_variant_new("(sia(qs)isii)",
ic_utils_dbus_encode_str(response->new_uri_path),
response->error_code,
options,
- response->iface,
response->result,
- icl_repr_generate_json(response->repr, false),
+ repr_json,
GPOINTER_TO_INT(response->request_handle),
GPOINTER_TO_INT(response->resource_handle));
{
FN_CALL;
- int index = 0;
GVariantIter *options;
unsigned short option_id;
char *option_data;
GVariantIter *query;
char *key = NULL;
char *value = NULL;
- GVariantIter *repr;
char *repr_json;
- char *repr_uri_path;
int request_handle;
int resource_handle;
struct icl_resource_request request = {0};
icl_cb_container_s *cb_container = user_data;
iotcon_request_handler_cb cb = cb_container->cb;
- g_variant_get(parameters, "(i&sa(qs)a(ss)iiasii)",
+ g_variant_get(parameters, "(ia(qs)a(ss)ii&sii)",
&request.types,
- &request.uri_path,
&options,
&query,
&request.observation_info.action,
&request.observation_info.observer_id,
- &repr,
+ &repr_json,
&request_handle,
&resource_handle);
request.request_handle = GINT_TO_POINTER(request_handle);
request.resource_handle = GINT_TO_POINTER(resource_handle);
- for (index = 0; g_variant_iter_loop(repr, "&s", &repr_json); index++) {
- iotcon_repr_h cur_repr = icl_repr_parse_json(repr_json);
- if (NULL == cur_repr) {
- ERR("icl_repr_parse_json() Fail");
- iotcon_options_free(request.header_options);
- iotcon_query_free(request.query);
- if (request.repr)
- iotcon_repr_free(request.repr);
- g_variant_iter_free(repr);
+ if (ic_utils_dbus_decode_str(repr_json)) {
+ request.repr = icl_repr_create_repr(repr_json);
+ if (NULL == request.repr) {
+ ERR("icl_repr_create_repr() Fail");
return;
}
- repr_uri_path = icl_repr_json_get_uri_path(repr_json);
- iotcon_repr_set_uri_path(cur_repr, repr_uri_path);
- free(repr_uri_path);
-
- if (0 == index)
- request.repr = cur_repr;
- else
- request.repr->children = g_list_append(request.repr->children, cur_repr);
}
- g_variant_iter_free(repr);
+
+ /* TODO remove request.uri */
+ request.uri_path = "temp_uri_path";
if (cb)
cb(&request, cb_container->user_data);
#include "icl-request.h"
/* The content of the request should not be freed by user. */
-API int iotcon_request_get_uri(iotcon_request_h request, char **uri_path)
+API int iotcon_request_get_uri_path(iotcon_request_h request, char **uri_path)
{
RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
/* The content of the resource should not be freed by user. */
-API int iotcon_resource_get_uri(iotcon_resource_h resource, char **uri_path)
+API int iotcon_resource_get_uri_path(iotcon_resource_h resource, char **uri_path)
{
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
int iotcon_resource_get_number_of_children(iotcon_resource_h resource, int *number);
int iotcon_resource_get_nth_child(iotcon_resource_h parent, int index,
iotcon_resource_h *child);
-int iotcon_resource_get_uri(iotcon_resource_h resource, char **uri_path);
+int iotcon_resource_get_uri_path(iotcon_resource_h resource, char **uri_path);
int iotcon_resource_get_types(iotcon_resource_h resource, iotcon_resource_types_h *types);
int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces);
int iotcon_resource_is_observable(iotcon_resource_h resource, bool *observable);
int iotcon_client_set_options(iotcon_client_h resource, iotcon_options_h header_options);
typedef struct icl_resource_request* iotcon_request_h;
-int iotcon_request_get_uri(iotcon_request_h request, char **uri_path);
+int iotcon_request_get_uri_path(iotcon_request_h request, char **uri_path);
int iotcon_request_get_representation(iotcon_request_h request, iotcon_repr_h *repr);
int iotcon_request_get_types(iotcon_request_h request, int *types);
int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *options);
* Even if iotcon is disconnected, it is allowed to derive elements from handles.
* On the other hand, using the functions related to connection are not allowed.
* For example, when iotcon is disconnected, it is possible to use
- * "iotcon_resource_get_uri()", but it is impossible to use "iotcon_notify_all()".
+ * "iotcon_resource_get_uri_path()", but it is impossible to use "iotcon_notify_all()".
* Thus, if you want to use functions related to connection, above all, you should free
* handles, and you should make new handles.
* In case of "iotcon_client_h", if the information of the resource owner are unchanged