*.sw*
.cproject
.project
+common/ic-dbus.c
+common/ic-dbus.h
--- /dev/null
+#!/bin/sh
+
+DIR_PATH=`dirname $0`
+
+gdbus-codegen --generate-c-code "$DIR_PATH"/ic-dbus\
+ --interface-prefix org.tizen.iotcon.\
+ --c-namespace ic\
+ "$DIR_PATH"/ic-dbus.xml
+
#define IC_DBUS_SIGNAL_REQUEST_HANDLER "REQ"
#define IC_DBUS_SIGNAL_FOUND_RESOURCE "RES"
-#define IC_DBUS_SIGNAL_GET "GET"
-#define IC_DBUS_SIGNAL_PUT "PUT"
-#define IC_DBUS_SIGNAL_POST "POST"
-#define IC_DBUS_SIGNAL_DELETE "DELETE"
#define IC_DBUS_SIGNAL_OBSERVE "OBSERVE"
#define IC_DBUS_SIGNAL_DEVICE "DEVICE"
#define IC_DBUS_SIGNAL_PLATFORM "PLATFORM"
<method name="get">
<arg type="(ssba(qs)iii)" name="client" direction="in"/>
<arg type="a(ss)" name="query" direction="in"/>
- <arg type="u" name="signal_number" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
+ <arg type="(a(qs)si)" name="ret" direction="out"/>
</method>
<method name="put">
<arg type="(ssba(qs)asii)" name="client" direction="in"/>
<arg type="s" name="repr" direction="in"/>
<arg type="a(ss)" name="query" direction="in"/>
- <arg type="u" name="signal_number" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
+ <arg type="(a(qs)si)" name="ret" direction="out"/>
</method>
<method name="post">
<arg type="(ssba(qs)asii)" name="client" direction="in"/>
<arg type="s" name="repr" direction="in"/>
<arg type="a(ss)" name="query" direction="in"/>
- <arg type="u" name="signal_number" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
+ <arg type="(a(qs)si)" name="ret" direction="out"/>
</method>
<method name="delete">
<arg type="(ssba(qs)asii)" name="client" direction="in"/>
- <arg type="u" name="signal_number" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
+ <arg type="(a(qs)i)" name="ret" direction="out"/>
</method>
<method name="observerStart">
<arg type="(ssba(qs)asii)" name="client" direction="in"/>
#include "icd-ioty.h"
#include "icd-dbus.h"
-static GDBusConnection *icd_dbus_conn;
+static icDbus *icd_dbus_object;
-static GList *icd_dbus_client_list; /* global list to care resource handle for each sender bus */
+/* global list to care resource handle for each client */
+static GList *icd_dbus_client_list;
static GMutex icd_dbus_client_list_mutex;
typedef struct _icd_dbus_client_s {
- gchar *sender;
+ gchar *bus_name;
GList *hdlist;
} icd_dbus_client_s;
} icd_resource_handle_s;
-static void _icd_dbus_client_list_lock()
+icDbus* icd_dbus_get_object()
{
- g_mutex_lock(&icd_dbus_client_list_mutex);
-}
-
-
-static void _icd_dbus_client_list_unlock()
-{
- g_mutex_unlock(&icd_dbus_client_list_mutex);
+ return icd_dbus_object;
}
static void _icd_dbus_resource_handle_free(void *handle)
{
- icd_dbus_client_s *bus;
- GList *cur_bus, *cur_hd;
+ icd_dbus_client_s *client;
+ GList *cur_client, *cur_hd;
icd_resource_handle_s *rsrc_handle;
- _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();
+ g_mutex_lock(&icd_dbus_client_list_mutex);
+ cur_client = icd_dbus_client_list;
+ while (cur_client) {
+ client = cur_client->data;
+ if (NULL == client) {
+ ERR("client is NULL");
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return;
}
- cur_hd = bus->hdlist;
+ cur_hd = client->hdlist;
while (cur_hd) {
rsrc_handle = cur_hd->data;
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);
+ client->hdlist = g_list_delete_link(client->hdlist, cur_hd);
free(rsrc_handle);
- _icd_dbus_client_list_unlock();
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return;
}
cur_hd = cur_hd->next;
}
- cur_bus = cur_bus->next;
+ cur_client = cur_client->next;
}
- _icd_dbus_client_list_unlock();
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return;
}
-int icd_dbus_bus_list_get_info(void *handle, unsigned int *sig_num, gchar **sender)
+int icd_dbus_client_list_get_info(void *handle, unsigned int *sig_num, gchar **bus_name)
{
FN_CALL;
- icd_dbus_client_s *bus;
- GList *cur_bus, *cur_hd;
+ icd_dbus_client_s *client;
+ GList *cur_client, *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);
-
- _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();
+ RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
+
+ g_mutex_lock(&icd_dbus_client_list_mutex);
+ cur_client = icd_dbus_client_list;
+ while (cur_client) {
+ client = cur_client->data;
+ if (NULL == client) {
+ ERR("client is NULL");
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_NO_DATA;
}
- cur_hd = bus->hdlist;
+ cur_hd = client->hdlist;
while (cur_hd) {
rsrc_handle = cur_hd->data;
DBG("signal_number(%u) for resource handle(%u) found",
rsrc_handle->number, handle);
*sig_num = rsrc_handle->number;
- *sender = ic_utils_strdup(bus->sender);
- _icd_dbus_client_list_unlock();
+ *bus_name = ic_utils_strdup(client->bus_name);
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_NONE;
}
cur_hd = cur_hd->next;
}
- cur_bus = cur_bus->next;
+ cur_client = cur_client->next;
}
- _icd_dbus_client_list_unlock();
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_NO_DATA;
}
{
gboolean ret;
GError *error = NULL;
+ GDBusConnection *conn;
+ icDbusSkeleton *skeleton;
DBG("SIG : %s, %s", signal_name, g_variant_print(value, FALSE));
- ret = g_dbus_connection_emit_signal(icd_dbus_conn,
+ skeleton = IC_DBUS_SKELETON(icd_dbus_get_object());
+ conn = g_dbus_interface_skeleton_get_connection(G_DBUS_INTERFACE_SKELETON(skeleton));
+
+ ret = g_dbus_connection_emit_signal(conn,
dest,
IOTCON_DBUS_OBJPATH,
IOTCON_DBUS_INTERFACE,
return IOTCON_ERROR_DBUS;
}
- if (FALSE == g_dbus_connection_flush_sync(icd_dbus_conn, NULL, &error)) {
+ if (FALSE == g_dbus_connection_flush_sync(conn, NULL, &error)) {
ERR("g_dbus_connection_flush_sync() Fail(%s)", error->message);
g_error_free(error);
return IOTCON_ERROR_DBUS;
free(rsrc_handle);
}
-static int _icd_dbus_bus_list_cleanup_handle_list(GList *list)
+static int _icd_dbus_client_list_cleanup_handle_list(GList *client_list)
{
- icd_dbus_client_s *bus;
+ icd_dbus_client_s *client;
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == client_list, IOTCON_ERROR_INVALID_PARAMETER);
- bus = list->data;
- g_list_free_full(bus->hdlist, _icd_dbus_cleanup_handle);
- free(bus->sender);
- bus->sender = NULL;
- free(bus);
+ client = client_list->data;
+ g_list_free_full(client->hdlist, _icd_dbus_cleanup_handle);
+ free(client->bus_name);
+ client->bus_name = NULL;
+ free(client);
return IOTCON_ERROR_NONE;
}
-static int _icd_dbus_bus_list_find_sender(const gchar *owner, GList **ret_list)
+static int _icd_dbus_client_list_find_client(const gchar *owner, GList **ret_list)
{
- GList *cur;
- icd_dbus_client_s *bus;
+ GList *client_list;
+ icd_dbus_client_s *client;
RETV_IF(NULL == owner, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
- cur = icd_dbus_client_list;
- while (cur) {
- bus = cur->data;
- if (NULL == bus) {
- ERR("bus is NULL");
+ client_list = icd_dbus_client_list;
+ while (client_list) {
+ client = client_list->data;
+ if (NULL == client) {
+ ERR("client is NULL");
return IOTCON_ERROR_NO_DATA;
}
- if (IC_STR_EQUAL == g_strcmp0(bus->sender, owner)) {
- *ret_list = cur;
+ if (IC_STR_EQUAL == g_strcmp0(client->bus_name, owner)) {
+ *ret_list = client_list;
return IOTCON_ERROR_NONE;
}
- cur = cur->next;
+ client_list = client_list->next;
}
- return IOTCON_ERROR_NONE;
+ return IOTCON_ERROR_NO_DATA;
}
-static void _icd_dbus_name_owner_changed_cb(GDBusConnection *connection,
+static void _icd_dbus_name_owner_changed_cb(GDBusConnection *conn,
const gchar *sender_name,
const gchar *object_path,
const gchar *interface_name,
gpointer user_data)
{
int ret;
- GList *sender = NULL;
+ GList *client = NULL;
gchar *name, *old_owner, *new_owner;
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);
+ g_mutex_lock(&icd_dbus_client_list_mutex);
+ ret = _icd_dbus_client_list_find_client(old_owner, &client);
if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_bus_list_find_sender() Fail(%d)", ret);
- _icd_dbus_client_list_unlock();
+ ERR("_icd_dbus_client_list_find_client() Fail(%d)", ret);
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return;
}
- if (sender) { /* found bus name in our bus list */
+ if (client) { /* found bus name in our bus list */
DBG("bus(%s) stopped", old_owner);
- ret = _icd_dbus_bus_list_cleanup_handle_list(sender);
+ ret = _icd_dbus_client_list_cleanup_handle_list(client);
if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_bus_list_cleanup_handle_list() Fail(%d)", ret);
- _icd_dbus_client_list_unlock();
+ ERR("_icd_dbus_client_list_cleanup_handle_list() Fail(%d)", ret);
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return;
}
- icd_dbus_client_list = g_list_delete_link(icd_dbus_client_list, sender);
+ icd_dbus_client_list = g_list_delete_link(icd_dbus_client_list, client);
}
- _icd_dbus_client_list_unlock();
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
}
}
-static int _icd_dbus_subscribe_name_owner_changed()
+static int _icd_dbus_subscribe_name_owner_changed(GDBusConnection *conn)
{
FN_CALL;
unsigned int id;
- id = g_dbus_connection_signal_subscribe(icd_dbus_conn,
+ id = g_dbus_connection_signal_subscribe(conn,
"org.freedesktop.DBus", /* bus name */
"org.freedesktop.DBus", /* interface */
"NameOwnerChanged", /* member */
return IOTCON_ERROR_NONE;
}
-static int _icd_dbus_resource_list_append_handle(const gchar *sender, void *handle,
+static int _icd_dbus_resource_list_append_handle(const gchar *bus_name, void *handle,
unsigned int signal_number)
{
FN_CALL;
- char *sender_dup;
- GList *cur_bus, *cur_hd;
- bool sender_exist = false;
+ GList *cur_client, *cur_hd;
+ bool client_exist = false;
icd_resource_handle_s *rsrc_handle;
- icd_dbus_client_s *new_bus = NULL;
- icd_dbus_client_s *bus;
+ icd_dbus_client_s *client = NULL;
- RETV_IF(NULL == sender, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == handle, IOTCON_ERROR_INVALID_PARAMETER);
- _icd_dbus_client_list_lock();
- cur_bus = icd_dbus_client_list;
+ g_mutex_lock(&icd_dbus_client_list_mutex);
+ cur_client = icd_dbus_client_list;
- while (cur_bus) {
- bus = cur_bus->data;
- if (NULL == bus) {
- ERR("bus is NULL");
- _icd_dbus_client_list_unlock();
+ while (cur_client) {
+ client = cur_client->data;
+ if (NULL == client) {
+ ERR("client is NULL");
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_NO_DATA;
}
- if (IC_STR_EQUAL == g_strcmp0(bus->sender, sender)) {
- DBG("sender(%s) already exist", sender);
- sender_exist = true;
+ if (IC_STR_EQUAL == g_strcmp0(client->bus_name, bus_name)) {
+ DBG("bus_name(%s) already exist", bus_name);
+ client_exist = true;
break;
}
- cur_bus = cur_bus->next;
+ cur_client = cur_client->next;
}
- if (true == sender_exist) {
- cur_hd = bus->hdlist;
+ if (true == client_exist) {
+ cur_hd = client->hdlist;
while (cur_hd) {
rsrc_handle = cur_hd->data;
if (rsrc_handle->handle == handle) {
ERR("resource handle(%u, %u) already exist", rsrc_handle->handle,
rsrc_handle->number);
- _icd_dbus_client_list_unlock();
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_ALREADY;
}
cur_hd = cur_hd->next;
}
} else {
- DBG("sender(%s) not exist. make new one.", sender);
+ DBG("bus_name(%s) not exist. make new one.", bus_name);
- new_bus = calloc(1, sizeof(icd_dbus_client_s));
- if (NULL == new_bus) {
- ERR("calloc(bus) Fail(%d)", errno);
- _icd_dbus_client_list_unlock();
+ client = calloc(1, sizeof(icd_dbus_client_s));
+ if (NULL == client) {
+ ERR("calloc(client) Fail(%d)", errno);
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- sender_dup = ic_utils_strdup(sender);
- if (NULL == sender_dup) {
+ client->bus_name = ic_utils_strdup(bus_name);
+ if (NULL == client->bus_name) {
ERR("ic_utils_strdup() Fail");
- free(new_bus);
- _icd_dbus_client_list_unlock();
+ free(client);
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- new_bus->sender = sender_dup;
- DBG("new bus(%s, %d) added", sender, signal_number);
- bus = new_bus;
+ DBG("new client(%s, %d) added", bus_name, signal_number);
}
rsrc_handle = calloc(1, sizeof(icd_resource_handle_s));
if (NULL == rsrc_handle) {
ERR("calloc(handle) Fail(%d)", errno);
- if (false == sender_exist) {
- free(new_bus->sender);
- free(new_bus);
+ if (false == client_exist) {
+ free(client->bus_name);
+ free(client);
}
- _icd_dbus_client_list_unlock();
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
rsrc_handle->handle = handle;
rsrc_handle->number = signal_number;
- DBG("handle(%u) added in the bus(%s, %u)", handle, sender, signal_number);
+ DBG("handle(%u) added in the client(%s, %u)", handle, bus_name, signal_number);
- bus->hdlist = g_list_append(bus->hdlist, rsrc_handle);
+ client->hdlist = g_list_append(client->hdlist, rsrc_handle);
- if (false == sender_exist)
- icd_dbus_client_list = g_list_append(icd_dbus_client_list, bus);
+ if (false == client_exist)
+ icd_dbus_client_list = g_list_append(icd_dbus_client_list, client);
- _icd_dbus_client_list_unlock();
+ g_mutex_unlock(&icd_dbus_client_list_mutex);
return IOTCON_ERROR_NONE;
}
}
-static gboolean _dbus_handle_get(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *client, GVariant *query, guint signal_number)
-{
- int ret;
- const gchar *sender;
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- ret = icd_ioty_get(client, query, signal_number, sender);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_get() Fail(%d)", ret);
-
- ic_dbus_complete_get(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_put(icDbus *object,
- GDBusMethodInvocation *invocation,
- GVariant *client,
- const gchar *repr,
- GVariant *query,
- guint signal_number)
-{
- int ret;
- const gchar *sender;
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- ret = icd_ioty_put(client, repr, query, signal_number, sender);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_put() Fail(%d)", ret);
-
- ic_dbus_complete_put(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_post(icDbus *object,
- GDBusMethodInvocation *invocation,
- GVariant *client,
- const gchar *repr,
- GVariant *query,
- guint signal_number)
-{
- int ret;
- const gchar *sender;
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- ret = icd_ioty_post(client, repr, query, signal_number, sender);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_post() Fail(%d)", ret);
-
- ic_dbus_complete_post(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_delete(icDbus *object,
- GDBusMethodInvocation *invocation,
- GVariant *client,
- guint signal_number)
-{
- int ret;
- const gchar *sender;
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- ret = icd_ioty_delete(client, signal_number, sender);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_delete() Fail(%d)", ret);
-
- ic_dbus_complete_delete(object, invocation, ret);
-
- return TRUE;
-}
-
-
static gboolean _dbus_handle_observer_start(icDbus *object,
GDBusMethodInvocation *invocation,
GVariant *client,
gpointer user_data)
{
gboolean ret;
- icDbus *dbus_object;
GError *error = NULL;
-
- icd_dbus_conn = conn;
-
- dbus_object = ic_dbus_skeleton_new();
- if (NULL == dbus_object) {
+ icd_dbus_object = ic_dbus_skeleton_new();
+ if (NULL == icd_dbus_object) {
ERR("ic_iotcon_skeletion_new() Fail");
return;
}
- g_signal_connect(dbus_object, "handle-register-resource",
+ g_signal_connect(icd_dbus_object, "handle-register-resource",
G_CALLBACK(_dbus_handle_register_resource), NULL);
- g_signal_connect(dbus_object, "handle-unregister-resource",
+ g_signal_connect(icd_dbus_object, "handle-unregister-resource",
G_CALLBACK(_dbus_handle_unregister_resource), NULL);
- g_signal_connect(dbus_object, "handle-bind-interface",
+ g_signal_connect(icd_dbus_object, "handle-bind-interface",
G_CALLBACK(_dbus_handle_bind_interface), NULL);
- g_signal_connect(dbus_object, "handle-bind-type",
+ g_signal_connect(icd_dbus_object, "handle-bind-type",
G_CALLBACK(_dbus_handle_bind_type), NULL);
- g_signal_connect(dbus_object, "handle-bind-resource",
+ g_signal_connect(icd_dbus_object, "handle-bind-resource",
G_CALLBACK(_dbus_handle_bind_resource), NULL);
- g_signal_connect(dbus_object, "handle-unbind-resource",
+ g_signal_connect(icd_dbus_object, "handle-unbind-resource",
G_CALLBACK(_dbus_handle_unbind_resource), NULL);
- g_signal_connect(dbus_object, "handle-find-resource",
+ g_signal_connect(icd_dbus_object, "handle-find-resource",
G_CALLBACK(_dbus_handle_find_resource), NULL);
- g_signal_connect(dbus_object, "handle-get",
- G_CALLBACK(_dbus_handle_get), NULL);
- g_signal_connect(dbus_object, "handle-put",
- G_CALLBACK(_dbus_handle_put), NULL);
- g_signal_connect(dbus_object, "handle-post",
- G_CALLBACK(_dbus_handle_post), NULL);
- g_signal_connect(dbus_object, "handle-delete",
- G_CALLBACK(_dbus_handle_delete), NULL);
- g_signal_connect(dbus_object, "handle-observer-start",
+ g_signal_connect(icd_dbus_object, "handle-get",
+ G_CALLBACK(icd_ioty_get), NULL);
+ g_signal_connect(icd_dbus_object, "handle-put",
+ G_CALLBACK(icd_ioty_put), NULL);
+ g_signal_connect(icd_dbus_object, "handle-post",
+ G_CALLBACK(icd_ioty_post), NULL);
+ g_signal_connect(icd_dbus_object, "handle-delete",
+ G_CALLBACK(icd_ioty_delete), NULL);
+ g_signal_connect(icd_dbus_object, "handle-observer-start",
G_CALLBACK(_dbus_handle_observer_start), NULL);
- g_signal_connect(dbus_object, "handle-observer-stop",
+ g_signal_connect(icd_dbus_object, "handle-observer-stop",
G_CALLBACK(_dbus_handle_observer_stop), NULL);
- g_signal_connect(dbus_object, "handle-notify-list-of-observers",
+ g_signal_connect(icd_dbus_object, "handle-notify-list-of-observers",
G_CALLBACK(_dbus_handle_notify_list_of_observers), NULL);
- g_signal_connect(dbus_object, "handle-notify-all",
+ g_signal_connect(icd_dbus_object, "handle-notify-all",
G_CALLBACK(_dbus_handle_notify_all), NULL);
- g_signal_connect(dbus_object, "handle-send-response",
+ g_signal_connect(icd_dbus_object, "handle-send-response",
G_CALLBACK(_dbus_handle_send_response), NULL);
#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
- g_signal_connect(dbus_object, "handle-register-device-info",
+ g_signal_connect(icd_dbus_object, "handle-register-device-info",
G_CALLBACK(_dbus_handle_register_device_info), NULL);
- g_signal_connect(dbus_object, "handle-get-device-info",
+ g_signal_connect(icd_dbus_object, "handle-get-device-info",
G_CALLBACK(_dbus_handle_get_device_info), NULL);
#endif
- g_signal_connect(dbus_object, "handle-register-platform-info",
+ g_signal_connect(icd_dbus_object, "handle-register-platform-info",
G_CALLBACK(_dbus_handle_register_platform_info), NULL);
- g_signal_connect(dbus_object, "handle-get-platform-info",
+ g_signal_connect(icd_dbus_object, "handle-get-platform-info",
G_CALLBACK(_dbus_handle_get_platform_info), NULL);
- g_signal_connect(dbus_object, "handle-start-presence",
+ g_signal_connect(icd_dbus_object, "handle-start-presence",
G_CALLBACK(_dbus_handle_start_presence), NULL);
- g_signal_connect(dbus_object, "handle-stop-presence",
+ g_signal_connect(icd_dbus_object, "handle-stop-presence",
G_CALLBACK(_dbus_handle_stop_presence), NULL);
- g_signal_connect(dbus_object, "handle-subscribe-presence",
+ g_signal_connect(icd_dbus_object, "handle-subscribe-presence",
G_CALLBACK(_dbus_handle_subscribe_presence), NULL);
- g_signal_connect(dbus_object, "handle-unsubscribe-presence",
+ g_signal_connect(icd_dbus_object, "handle-unsubscribe-presence",
G_CALLBACK(_dbus_handle_unsubscribe_presence), NULL);
- ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(dbus_object), conn,
- IOTCON_DBUS_OBJPATH, &error);
+ ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(icd_dbus_object),
+ conn, IOTCON_DBUS_OBJPATH, &error);
if (FALSE == ret) {
ERR("g_dbus_interface_skeleton_export() Fail(%s)", error->message);
g_error_free(error);
}
- ret = _icd_dbus_subscribe_name_owner_changed();
+ ret = _icd_dbus_subscribe_name_owner_changed(conn);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icd_dbus_subscribe_name_owner_changed() Fail(%d)", ret);
return;
}
-static void _dbus_on_name_lost(GDBusConnection *connection, const gchar *name,
+static void _dbus_on_name_lost(GDBusConnection *conn, const gchar *name,
gpointer user_data)
{
DBG("Lost the name %s", name);
}
-static void _dbus_on_name_acquired(GDBusConnection *connection, const gchar *name,
+static void _dbus_on_name_acquired(GDBusConnection *conn, const gchar *name,
gpointer user_data)
{
DBG("Acquired the name %s", name);
#define __IOT_CONNECTIVITY_MANAGER_DAEMON_DBUS_H__
#include <glib.h>
+#include "ic-dbus.h"
-int icd_dbus_bus_list_get_info(void *handle, unsigned int *sig_num, gchar **sender);
+icDbus* icd_dbus_get_object();
+int icd_dbus_client_list_get_info(void *handle, unsigned int *sig_num, gchar **bus_name);
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);
struct icd_req_context {
unsigned int signum;
- char *sender;
+ char *bus_name;
char *payload;
int types;
int observer_id;
struct icd_find_context {
unsigned int signum;
- char *sender;
+ char *bus_name;
char *payload;
OCDevAddr *dev_addr;
int conn_type;
struct icd_get_context {
- unsigned int signum;
int res;
- char *sender;
char *payload;
GVariantBuilder *options;
+ GDBusMethodInvocation *invocation;
};
GPOINTER_TO_INT(ctx->request_h),
GPOINTER_TO_INT(ctx->resource_h));
- ret = _ocprocess_response_signal(ctx->sender, IC_DBUS_SIGNAL_REQUEST_HANDLER,
+ ret = _ocprocess_response_signal(ctx->bus_name, 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->bus_name);
free(ctx->payload);
g_variant_builder_unref(ctx->options);
g_variant_builder_unref(ctx->query);
unsigned int signal_number;
char *query_str, *query_key, *query_value;
char *token, *save_ptr1, *save_ptr2;
- char *sender = NULL;
+ char *bus_name = NULL;
struct icd_req_context *req_ctx;
RETV_IF(NULL == request, OC_EH_ERROR);
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);
+ ret = icd_dbus_client_list_get_info(req_ctx->resource_h, &signal_number, &bus_name);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_dbus_bus_list_get_info() Fail(%d)", ret);
+ ERR("icd_dbus_client_list_get_info() Fail(%d)", ret);
free(req_ctx);
return OC_EH_ERROR;
}
- /* signal number & sender */
+ /* signal number & bus_name */
req_ctx->signum = signal_number;
- req_ctx->sender = sender;
+ req_ctx->bus_name = bus_name;
/* request type */
if (OC_REQUEST_FLAG & flag) {
req_ctx->payload = strdup(IC_STR_NULL);
break;
default:
- free(req_ctx->sender);
+ free(req_ctx->bus_name);
free(req_ctx);
return OC_EH_ERROR;
}
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->bus_name);
free(req_ctx->payload);
g_variant_builder_unref(req_ctx->options);
g_variant_builder_unref(req_ctx->query);
/* TODO : If one device has multi resources, it comes as bulk data.
* To reduce the number of emit_signal, let's send signal only one time for one device.
* for ex, client list. */
- ret = _ocprocess_response_signal(ctx->sender, IC_DBUS_SIGNAL_FOUND_RESOURCE,
+ ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_FOUND_RESOURCE,
ctx->signum, value);
if (IOTCON_ERROR_NONE != ret) {
ERR("_ocprocess_response_signal() Fail(%d)", ret);
ERR("_find_cb_handle_context() Fail(%d)", ret);
/* ctx was allocated from icd_ioty_ocprocess_find_cb() */
- free(ctx->sender);
+ free(ctx->bus_name);
free(ctx->payload);
free(ctx->dev_addr);
free(ctx);
memcpy(dev_addr, resp->addr, sizeof(OCDevAddr));
find_ctx->signum = sig_context->signum;
- find_ctx->sender = ic_utils_strdup(sig_context->sender);
+ find_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
find_ctx->payload = ic_utils_strdup(resp->resJSONPayload);
find_ctx->dev_addr = dev_addr;
find_ctx->conn_type = resp->connType;
ret = _ocprocess_worker_start(_worker_find_cb, find_ctx);
if (IOTCON_ERROR_NONE != ret) {
ERR("_ocprocess_worker_start() Fail(%d)", ret);
- free(find_ctx->sender);
+ free(find_ctx->bus_name);
free(find_ctx->payload);
free(find_ctx->dev_addr);
free(find_ctx);
RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
value = g_variant_new("(a(qs)si)", ctx->options, ctx->payload, ctx->res);
-
- ret = _ocprocess_response_signal(ctx->sender, IC_DBUS_SIGNAL_GET, ctx->signum, value);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
+ icd_ioty_get_complete(ctx->invocation, value);
/* ctx was allocated from icd_ioty_ocprocess_get_cb() */
- free(ctx->sender);
free(ctx->payload);
g_variant_builder_unref(ctx->options);
free(ctx);
}
-static void _get_cb_response_error(const char *dest, unsigned int signum, int ret_val)
-{
- int ret;
- GVariant *value;
-
- value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
-
- ret = _ocprocess_response_signal(dest, IC_DBUS_SIGNAL_GET, signum, value);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
-}
-
-
OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
OCClientResponse *resp)
{
OCStackResult result;
GVariantBuilder *options;
struct icd_get_context *get_ctx;
- icd_sig_ctx_s *sig_context = ctx;
RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
ERR("json payload is empty");
- _get_cb_response_error(sig_context->sender, sig_context->signum,
- IOTCON_ERROR_IOTIVITY);
+ icd_ioty_get_complete_error(ctx, IOTCON_ERROR_IOTIVITY);
return OC_STACK_DELETE_TRANSACTION;
}
get_ctx = calloc(1, sizeof(struct icd_get_context));
if (NULL == get_ctx) {
ERR("calloc() Fail(%d)", errno);
- _get_cb_response_error(sig_context->sender, sig_context->signum,
- IOTCON_ERROR_OUT_OF_MEMORY);
+ icd_ioty_get_complete_error(ctx, IOTCON_ERROR_OUT_OF_MEMORY);
return OC_STACK_DELETE_TRANSACTION;
}
}
get_ctx->payload = strdup(resp->resJSONPayload);
- get_ctx->signum = sig_context->signum;
get_ctx->res = res;
- get_ctx->sender = ic_utils_strdup(sig_context->sender);
get_ctx->options = options;
+ get_ctx->invocation = ctx;
ret = _ocprocess_worker_start(_worker_get_cb, get_ctx);
if (IOTCON_ERROR_NONE != ret) {
ERR("_ocprocess_worker_start() Fail(%d)", ret);
- _get_cb_response_error(sig_context->sender, sig_context->signum, ret);
- free(get_ctx->sender);
+ icd_ioty_get_complete_error(ctx, ret);
free(get_ctx->payload);
g_variant_builder_unref(get_ctx->options);
free(get_ctx);
return OC_STACK_DELETE_TRANSACTION;
}
- /* DO NOT FREE sig_context. It MUST be freed in the ocstack */
/* DO NOT FREE get_ctx. It MUST be freed in the _worker_get_cb func */
return OC_STACK_DELETE_TRANSACTION;
#include <ocstack.h>
#include "iotcon.h"
+#include "ic-dbus.h"
#include "ic-utils.h"
#include "icd.h"
+#include "icd-dbus.h"
#include "icd-ioty.h"
#include "icd-ioty-ocprocess.h"
static void _ioty_free_signal_context(void *data)
{
icd_sig_ctx_s *context = data;
- free(context->sender);
+ free(context->bus_name);
free(context);
}
int icd_ioty_find_resource(const char *host_address, const char *resource_type,
- unsigned int signum, const char *sender)
+ unsigned int signum, const char *bus_name)
{
int len;
OCStackResult result;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- context->sender = ic_utils_strdup(sender);
+ context->bus_name = ic_utils_strdup(bus_name);
context->signum = signum;
cbdata.context = context;
if (OC_STACK_OK != result) {
ERR("OCDoResource() Fail(%d)", result);
- free(context->sender);
+ free(context->bus_name);
free(context);
return IOTCON_ERROR_IOTIVITY;
}
int len;
bool loop_first = true;
char *key, *value;
- GVariantIter *queryIter;
+ GVariantIter query_iter;
char uri_buf[PATH_MAX] = {0};
len = snprintf(uri_buf, sizeof(uri_buf), "%s%s", host, uri_path);
len--;
}
- g_variant_get(query, "a(ss)", &queryIter);
+ g_variant_iter_init(&query_iter, query);
- while (g_variant_iter_loop(queryIter, "(&s&s)", &key, &value)) {
+ while (g_variant_iter_loop(&query_iter, "(&s&s)", &key, &value)) {
int query_len;
DBG("query exist. key(%s), value(%s)", key, value);
len += query_len;
}
- g_variant_iter_free(queryIter);
return strdup(uri_buf);
}
-int icd_ioty_get(GVariant *resource, GVariant *query, unsigned int signal_number,
- const char *sender)
+void icd_ioty_get_complete(GDBusMethodInvocation *invocation, GVariant *value)
+{
+ ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
+}
+
+
+void icd_ioty_get_complete_error(GDBusMethodInvocation *invocation, int ret_val)
+{
+ GVariant *value;
+
+ value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
+
+ ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
+}
+
+
+gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource, GVariant *query)
{
- FN_CALL;
- int conn_type, options_size;
- char *uri_path, *host, *uri;
OCStackResult result;
GVariantIter *options;
OCCallbackData cbdata = {0};
- icd_sig_ctx_s *context;
+ int conn_type, options_size;
+ char *uri_path, *host, *uri;
int is_observable, ifaces, observe_handle;
OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
if (NULL == uri) {
ERR("_icd_ioty_resource_generate_uri() Fail");
g_variant_iter_free(options);
- return IOTCON_ERROR_INVALID_PARAMETER;
+ icd_ioty_get_complete_error(invocation, IOTCON_ERROR_INVALID_PARAMETER);
+ return TRUE;
}
- context = calloc(1, sizeof(icd_sig_ctx_s));
- if (NULL == context) {
- ERR("calloc() Fail(%d)", errno);
- g_variant_iter_free(options);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- context->sender = ic_utils_strdup(sender);
- context->signum = signal_number;
-
- cbdata.context = context;
+ cbdata.context = invocation;
cbdata.cb = icd_ioty_ocprocess_get_cb;
- cbdata.cd = _ioty_free_signal_context;
options_size = g_variant_iter_n_children(options);
if (0 != options_size) {
sizeof(oic_options) / sizeof(oic_options[0]));
if (IOTCON_ERROR_NONE != ret) {
ERR("_ioty_get_header_options() Fail(%d)", ret);
- free(context->sender);
- free(context);
free(uri);
g_variant_iter_free(options);
- return ret;
+ icd_ioty_get_complete_error(invocation, ret);
+ return TRUE;
}
}
g_variant_iter_free(options);
if (OC_STACK_OK != result) {
ERR("OCDoResource() Fail(%d)", result);
- free(context->sender);
- free(context);
- return IOTCON_ERROR_IOTIVITY;
+ icd_ioty_get_complete_error(invocation, IOTCON_ERROR_IOTIVITY);
+ return TRUE;
}
- return IOTCON_ERROR_NONE;
+ return TRUE;
}
-int icd_ioty_put(GVariant *resource, const char *repr, GVariant *query,
- unsigned int signal_number, const char *sender)
+void icd_ioty_put_complete(GDBusMethodInvocation *invocation, GVariant *value)
+{
+ ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
+}
+
+
+void icd_ioty_put_complete_error(GDBusMethodInvocation *invocation, int ret_val)
+{
+ GVariant *value;
+
+ value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
+
+ ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
+}
+
+
+gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource, const char *repr, GVariant *query)
{
// TODO : To be implemented
return IOTCON_ERROR_NONE;
}
-int icd_ioty_post(GVariant *resource, const char *repr, GVariant *query,
- unsigned int signal_number, const char *sender)
+void icd_ioty_post_complete(GDBusMethodInvocation *invocation, GVariant *value)
+{
+ ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
+}
+
+
+void icd_ioty_post_complete_error(GDBusMethodInvocation *invocation, int ret_val)
+{
+ GVariant *value;
+
+ value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
+
+ ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
+}
+
+
+gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource, const char *repr, GVariant *query)
{
// TODO : To be implemented
return IOTCON_ERROR_NONE;
}
-int icd_ioty_delete(GVariant *resource, unsigned int signal_number,
- const char *sender)
+void icd_ioty_delete_complete(GDBusMethodInvocation *invocation, GVariant *value)
+{
+ ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
+}
+
+
+void icd_ioty_delete_complete_error(GDBusMethodInvocation *invocation, int ret_val)
+{
+ GVariant *value;
+
+ value = g_variant_new("(a(qs)i)", NULL, IC_STR_NULL, ret_val);
+
+ ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
+}
+
+
+gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource)
{
// TODO : To be implemented
return IOTCON_ERROR_NONE;
int icd_ioty_observer_start(GVariant *resource, int observe_type,
- GVariant *query, unsigned int signal_number, const char *sender, int *observe_h)
+ GVariant *query, unsigned int signal_number, const char *bus_name, int *observe_h)
{
// TODO : To be implemented
return IOTCON_ERROR_NONE;
int icd_ioty_get_device_info(const char *host_address,
- unsigned int signal_number, const char *sender)
+ unsigned int signal_number, const char *bus_name)
{
// TODO : To be implemented
return IOTCON_ERROR_NONE;
int icd_ioty_get_platform_info(const char *host_address, unsigned int signal_number,
- const char *sender)
+ const char *bus_name)
{
// TODO : To be implemented
return IOTCON_ERROR_NONE;
OCDoHandle icd_ioty_subscribe_presence(const char *host_address,
- const char *resource_type, unsigned int signal_number, const char *sender)
+ const char *resource_type, unsigned int signal_number, const char *bus_name)
{
// TODO : To be implemented
return NULL;
typedef struct {
unsigned int signum;
- char *sender;
+ char *bus_name;
} icd_sig_ctx_s;
int icd_ioty_send_response(GVariant *resp);
int icd_ioty_find_resource(const char *host_address, const char *resource_type,
- unsigned int signal_number, const char *sender);
+ unsigned int signal_number, const char *bus_name);
-int icd_ioty_get(GVariant *resource, GVariant *query, unsigned int signal_number,
- const char *sender);
+void icd_ioty_get_complete(GDBusMethodInvocation *invocation, GVariant *value);
+void icd_ioty_get_complete_error(GDBusMethodInvocation *invocation, int ret_val);
+gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource, GVariant *query);
-int icd_ioty_put(GVariant *resource, const char *repr, GVariant *query,
- unsigned int signal_number, const char *sender);
+void icd_ioty_put_complete(GDBusMethodInvocation *invocation, GVariant *value);
+void icd_ioty_put_complete_error(GDBusMethodInvocation *invocation, int ret_val);
+gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource, const char *repr, GVariant *query);
-int icd_ioty_post(GVariant *resource, const char *repr, GVariant *query,
- unsigned int signal_number, const char *sender);
+void icd_ioty_post_complete(GDBusMethodInvocation *invocation, GVariant *value);
+void icd_ioty_post_complete_error(GDBusMethodInvocation *invocation, int ret_val);
+gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource, const char *repr, GVariant *query);
-int icd_ioty_delete(GVariant *resource, unsigned int signal_number, const char *sender);
+void icd_ioty_delete_complete(GDBusMethodInvocation *invocation, GVariant *value);
+void icd_ioty_delete_complete_error(GDBusMethodInvocation *invocation, int ret_val);
+gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *resource);
int icd_ioty_observer_start(GVariant *resource, int observe_type, GVariant *query,
- unsigned int signal_number, const char *sender, int *observe_h);
+ unsigned int signal_number, const char *bus_name, int *observe_h);
int icd_ioty_observer_stop(void *observe_h);
int icd_ioty_register_device_info(GVariant *value);
int icd_ioty_get_device_info(const char *host_address, unsigned int signal_number,
- const char *sender);
+ const char *bus_name);
#endif
int icd_ioty_register_platform_info(GVariant *value);
int icd_ioty_get_platform_info(const char *host_address, unsigned int signal_number,
- const char *sender);
+ const char *bus_name);
void* icd_ioty_subscribe_presence(const char *host_address, const char *resource_type,
- unsigned int signal_number, const char *sender);
+ unsigned int signal_number, const char *bus_name);
int icd_ioty_unsubscribe_presence(void *presence_handle);
#include "iotcon.h"
#include "ic-utils.h"
+#include "ic-dbus.h"
#include "icl.h"
#include "icl-options.h"
#include "icl-dbus.h"
iotcon_on_cru_cb cb;
void *user_data;
iotcon_client_h resource;
- unsigned int id;
} icl_on_cru_s;
typedef struct {
iotcon_on_delete_cb cb;
void *user_data;
iotcon_client_h resource;
- unsigned int id;
} icl_on_delete_s;
typedef struct {
} icl_on_observe_s;
-static void _icl_on_cru_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
+static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container)
{
int res;
+ iotcon_repr_h repr;
GVariantIter *options;
unsigned short option_id;
- char *option_data;
+ char *option_data, *repr_json;
iotcon_options_h header_options = NULL;
- iotcon_repr_h repr = NULL;
- char *repr_json = NULL;
-
- icl_on_cru_s *cb_container = user_data;
iotcon_on_cru_cb cb = cb_container->cb;
- icl_dbus_unsubscribe_signal(cb_container->id);
-
- g_variant_get(parameters, "(a(qs)si)", &options, &repr_json, &res);
+ g_variant_get(result, "(a(qs)si)", &options, &repr_json, &res);
if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
header_options = iotcon_options_new();
ERR("icl_repr_create_repr() Fail");
if (header_options)
iotcon_options_free(header_options);
+
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
return;
}
}
if (header_options)
iotcon_options_free(header_options);
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
}
-static void _icl_cru_conn_cleanup(icl_on_cru_s *cb_container)
+static void _icl_on_get_cb(GObject *object, GAsyncResult *g_async_res,
+ gpointer user_data)
{
- iotcon_client_free(cb_container->resource);
- free(cb_container);
+ GVariant *result;
+ GError *error = NULL;
+ icl_on_cru_s *cb_container = user_data;
+
+ ic_dbus_call_get_finish(IC_DBUS(object), &result, g_async_res, &error);
+ if (error) {
+ ERR("ic_dbus_call_get_finish() Fail(%s)", error->message);
+ g_error_free(error);
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
+ return;
+ }
+
+ _icl_on_cru_cb(result, cb_container);
}
-API int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
- iotcon_on_cru_cb cb, void *user_data)
+static void _icl_on_put_cb(GObject *object, GAsyncResult *g_async_res,
+ gpointer user_data)
{
- int ret;
+ GVariant *result;
GError *error = NULL;
- unsigned int sub_id;
- int signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
- icl_on_cru_s *cb_container;
- GVariant *arg_client;
- GVariant *arg_query;
+ icl_on_cru_s *cb_container = user_data;
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+ ic_dbus_call_put_finish(IC_DBUS(object), &result, g_async_res, &error);
+ if (error) {
+ ERR("ic_dbus_call_put_finish() Fail(%s)", error->message);
+ g_error_free(error);
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
+ return;
+ }
- signal_number = icl_dbus_generate_signal_number();
+ _icl_on_cru_cb(result, cb_container);
+}
- arg_client = icl_dbus_client_to_gvariant(resource);
- arg_query = icl_dbus_query_to_gvariant(query);
- ic_dbus_call_get_sync(icl_dbus_get_object(), arg_client, arg_query, signal_number,
- &ret, NULL, &error);
+static void _icl_on_post_cb(GObject *object, GAsyncResult *g_async_res,
+ gpointer user_data)
+{
+ GVariant *result;
+ GError *error = NULL;
+ icl_on_cru_s *cb_container = user_data;
+
+ ic_dbus_call_post_finish(IC_DBUS(object), &result, g_async_res, &error);
if (error) {
- ERR("ic_dbus_call_get_sync() Fail(%s)", error->message);
+ ERR("ic_dbus_call_post_finish() Fail(%s)", error->message);
g_error_free(error);
- g_variant_unref(arg_query);
- g_variant_unref(arg_client);
- return IOTCON_ERROR_DBUS;
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
+ return;
}
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
+ _icl_on_cru_cb(result, cb_container);
+}
- snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_GET,
- signal_number);
+
+API int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
+ iotcon_on_cru_cb cb, void *user_data)
+{
+ GVariant *arg_client;
+ GVariant *arg_query;
+ icl_on_cru_s *cb_container;
+
+ RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+ RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
cb_container = calloc(1, sizeof(icl_on_cru_s));
if (NULL == cb_container) {
cb_container->cb = cb;
cb_container->user_data = user_data;
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, _icl_cru_conn_cleanup,
- _icl_on_cru_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- _icl_cru_conn_cleanup(cb_container);
- return IOTCON_ERROR_DBUS;
- }
+ arg_client = icl_dbus_client_to_gvariant(resource);
+ arg_query = icl_dbus_query_to_gvariant(query);
- cb_container->id = sub_id;
+ ic_dbus_call_get(icl_dbus_get_object(), arg_client, arg_query, NULL, _icl_on_get_cb,
+ cb_container);
- return ret;
+ return IOTCON_ERROR_NONE;
}
API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr,
iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
{
- int ret;
- GError *error = NULL;
- unsigned int sub_id;
- int signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
char *arg_repr;
- icl_on_cru_s *cb_container;
GVariant *arg_client;
GVariant *arg_query;
+ icl_on_cru_s *cb_container;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- signal_number = icl_dbus_generate_signal_number();
-
- arg_repr = icl_repr_generate_json(repr, FALSE);
- if (NULL == arg_repr) {
- ERR("icl_repr_generate_json() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- arg_client = icl_dbus_client_to_gvariant(resource);
- arg_query = icl_dbus_query_to_gvariant(query);
-
- ic_dbus_call_put_sync(icl_dbus_get_object(), arg_client, arg_repr, arg_query,
- signal_number, &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_put_sync() Fail(%s)", error->message);
- g_error_free(error);
- g_variant_unref(arg_query);
- g_variant_unref(arg_client);
- free(arg_repr);
- return IOTCON_ERROR_DBUS;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- free(arg_repr);
- return icl_dbus_convert_daemon_error(ret);
- }
- free(arg_repr);
-
- snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PUT,
- signal_number);
-
cb_container = calloc(1, sizeof(icl_on_cru_s));
if (NULL == cb_container) {
ERR("calloc() Fail(%d)", errno);
cb_container->cb = cb;
cb_container->user_data = user_data;
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, _icl_cru_conn_cleanup,
- _icl_on_cru_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- _icl_cru_conn_cleanup(cb_container);
- return IOTCON_ERROR_DBUS;
+ arg_repr = icl_repr_generate_json(repr, FALSE);
+ if (NULL == arg_repr) {
+ ERR("icl_repr_generate_json() Fail");
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
+ return IOTCON_ERROR_REPRESENTATION;
}
- cb_container->id = sub_id;
+ arg_client = icl_dbus_client_to_gvariant(resource);
+ arg_query = icl_dbus_query_to_gvariant(query);
- return ret;
+ ic_dbus_call_put(icl_dbus_get_object(), arg_client, arg_repr, arg_query, NULL,
+ _icl_on_put_cb, cb_container);
+
+ free(arg_repr);
+
+ return IOTCON_ERROR_NONE;
}
API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr,
iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
{
- int ret;
- GError *error = NULL;
- unsigned int sub_id;
- int signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
char *arg_repr;
- icl_on_cru_s *cb_container;
GVariant *arg_client;
GVariant *arg_query;
+ icl_on_cru_s *cb_container;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- signal_number = icl_dbus_generate_signal_number();
-
- arg_repr = icl_repr_generate_json(repr, FALSE);
- if (NULL == arg_repr) {
- ERR("icl_repr_generate_json() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- arg_client = icl_dbus_client_to_gvariant(resource);
- arg_query = icl_dbus_query_to_gvariant(query);
-
- ic_dbus_call_post_sync(icl_dbus_get_object(), arg_client, arg_repr, arg_query,
- signal_number, &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_post_sync() Fail(%s)", error->message);
- g_error_free(error);
- g_variant_unref(arg_client);
- g_variant_unref(arg_query);
- free(arg_repr);
- return IOTCON_ERROR_DBUS;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- free(arg_repr);
- return icl_dbus_convert_daemon_error(ret);
- }
- free(arg_repr);
-
- snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_POST,
- signal_number);
-
cb_container = calloc(1, sizeof(icl_on_cru_s));
if (NULL == cb_container) {
ERR("calloc() Fail(%d)", errno);
cb_container->cb = cb;
cb_container->user_data = user_data;
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, _icl_cru_conn_cleanup,
- _icl_on_cru_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- _icl_cru_conn_cleanup(cb_container);
- return IOTCON_ERROR_DBUS;
+ arg_repr = icl_repr_generate_json(repr, FALSE);
+ if (NULL == arg_repr) {
+ ERR("icl_repr_generate_json() Fail");
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
+ return IOTCON_ERROR_REPRESENTATION;
}
- cb_container->id = sub_id;
+ arg_client = icl_dbus_client_to_gvariant(resource);
+ arg_query = icl_dbus_query_to_gvariant(query);
+
+ ic_dbus_call_post(icl_dbus_get_object(), arg_client, arg_repr, arg_query, NULL,
+ _icl_on_post_cb, cb_container);
- return ret;
+ free(arg_repr);
+
+ return IOTCON_ERROR_NONE;
}
-static void _icl_on_delete_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
+static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res,
gpointer user_data)
{
+ int res;
+ GVariant *result;
+ char *option_data;
+ GError *error = NULL;
GVariantIter *options;
unsigned short option_id;
- char *option_data;
iotcon_options_h header_options = NULL;
- int res;
icl_on_delete_s *cb_container = user_data;
iotcon_on_delete_cb cb = cb_container->cb;
- g_variant_get(parameters, "(a(qs)i)", &options, &res);
+ ic_dbus_call_delete_finish(IC_DBUS(object), &result, g_async_res, &error);
+ if (error) {
+ ERR("ic_dbus_call_delete_finish() Fail(%s)", error->message);
+ g_error_free(error);
+ iotcon_client_free(cb_container->resource);
+ free(cb_container);
+ return;
+ }
+ g_variant_get(result, "(a(qs)i)", &options, &res);
- if (g_variant_iter_n_children(options)) {
+ if (IOTCON_ERROR_NONE != res && g_variant_iter_n_children(options)) {
header_options = iotcon_options_new();
while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
iotcon_options_insert(header_options, option_id, option_data);
}
g_variant_iter_free(options);
+ res = icl_dbus_convert_daemon_error(res);
+
if (cb)
cb(cb_container->resource, header_options, res, cb_container->user_data);
if (header_options)
iotcon_options_free(header_options);
- icl_dbus_unsubscribe_signal(cb_container->id);
-}
-
-
-static void _icl_delete_conn_cleanup(icl_on_delete_s *cb_container)
-{
iotcon_client_free(cb_container->resource);
free(cb_container);
}
API int iotcon_delete(iotcon_client_h resource, iotcon_on_delete_cb cb, void *user_data)
{
- int ret;
- GError *error = NULL;
- unsigned int sub_id;
- int signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
- icl_on_delete_s *cb_container;
GVariant *arg_client;
+ icl_on_delete_s *cb_container;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- signal_number = icl_dbus_generate_signal_number();
-
- arg_client = icl_dbus_client_to_gvariant(resource);
-
- ic_dbus_call_delete_sync(icl_dbus_get_object(), arg_client, signal_number, &ret,
- NULL, &error);
- if (error) {
- ERR("ic_dbus_call_delete_sync() Fail(%s)", error->message);
- g_error_free(error);
- g_variant_unref(arg_client);
- return IOTCON_ERROR_DBUS;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DELETE,
- signal_number);
-
cb_container = calloc(1, sizeof(icl_on_delete_s));
if (NULL == cb_container) {
ERR("calloc() Fail(%d)", errno);
cb_container->cb = cb;
cb_container->user_data = user_data;
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, _icl_delete_conn_cleanup,
- _icl_on_delete_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- _icl_delete_conn_cleanup(cb_container);
- return IOTCON_ERROR_DBUS;
- }
+ arg_client = icl_dbus_client_to_gvariant(resource);
- cb_container->id = sub_id;
+ ic_dbus_call_delete(icl_dbus_get_object(), arg_client, NULL, _icl_on_delete_cb,
+ cb_container);
- return ret;
+ return IOTCON_ERROR_NONE;
}
GVariant* icl_dbus_notimsg_to_gvariant(struct icl_notify_msg *msg)
{
char *repr_json = NULL;
- GVariant *value;
- GVariantBuilder *builder;
+ GVariantBuilder builder;
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(is)"));
+ g_variant_builder_init(&builder, 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);
+ g_variant_builder_clear(&builder);
return NULL;
}
- g_variant_builder_add(builder, "(is)", msg->error_code, repr_json);
- }
- value = g_variant_new("a(is)", builder);
+ g_variant_builder_add(&builder, "(is)", msg->error_code, repr_json);
- free(repr_json);
- g_variant_builder_unref(builder);
+ free(repr_json);
+ }
- return value;
+ return g_variant_builder_end(&builder);
}
GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response)
{
char *repr_json;
+ GVariant *value;
GHashTableIter iter;
- GVariantBuilder *options;
+ GVariantBuilder options;
gpointer option_id, option_data;
- GVariant *value;
-
- options = g_variant_builder_new(G_VARIANT_TYPE("a(qs)"));
+ g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
if (response->header_options) {
g_hash_table_iter_init(&iter, response->header_options->hash);
- while (g_hash_table_iter_next(&iter, &option_id, &option_data))
- g_variant_builder_add(options, "(qs)", GPOINTER_TO_INT(option_id), option_data);
+ while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
+ g_variant_builder_add(&options, "(qs)", GPOINTER_TO_INT(option_id),
+ option_data);
+ }
}
/* 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);
+ g_variant_builder_clear(&options);
return NULL;
}
value = g_variant_new("(sia(qs)isii)",
ic_utils_dbus_encode_str(response->new_uri_path),
response->error_code,
- options,
+ &options,
response->result,
repr_json,
GPOINTER_TO_INT(response->request_handle),
GPOINTER_TO_INT(response->resource_handle));
- g_variant_builder_unref(options);
-
return value;
}
GVariant* icl_dbus_client_to_gvariant(struct icl_remote_resource *resource)
{
- FN_CALL;
GVariant *value;
- GVariantBuilder *options;
GHashTableIter iter;
+ GVariantBuilder options;
gpointer option_id, option_data;
- options = g_variant_builder_new(G_VARIANT_TYPE("a(qs)"));
+ g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
if (resource->header_options) {
g_hash_table_iter_init(&iter, resource->header_options->hash);
- while (g_hash_table_iter_next(&iter, &option_id, &option_data))
- g_variant_builder_add(options, "(qs)", GPOINTER_TO_INT(option_id), option_data);
+ while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
+ g_variant_builder_add(&options, "(qs)", GPOINTER_TO_INT(option_id),
+ option_data);
+ }
}
value = g_variant_new("(ssba(qs)iii)",
resource->uri_path,
resource->host,
resource->is_observable,
- options,
+ &options,
resource->ifaces,
resource->conn_type,
GPOINTER_TO_INT(resource->observe_handle));
- g_variant_builder_unref(options);
-
return value;
}
GVariant* icl_dbus_query_to_gvariant(iotcon_query_h query)
{
- FN_CALL;
- GVariant *query_value;
- GVariantBuilder *builder;
- GHashTableIter iter;
gpointer key, value;
+ GHashTableIter iter;
+ GVariantBuilder builder;
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)"));
if (query) {
g_hash_table_iter_init(&iter, query->hash);
while (g_hash_table_iter_next(&iter, &key, &value))
- g_variant_builder_add(builder, "(ss)", key, value);
+ g_variant_builder_add(&builder, "(ss)", key, value);
}
- query_value = g_variant_new("a(ss)", builder);
-
- g_variant_builder_unref(builder);
-
- return query_value;
+ return g_variant_builder_end(&builder);
}
GVariant* icl_dbus_observers_to_gvariant(iotcon_observers_h observers)
{
GList *node;
- GVariant *obs;
- GVariantBuilder *builder;
+ GVariantBuilder builder;
- builder = g_variant_builder_new(G_VARIANT_TYPE("ai"));
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("ai"));
for (node = observers; node; node = node->next)
- g_variant_builder_add(builder, "i", GPOINTER_TO_INT(node->data));
-
- obs = g_variant_new("ai", builder);
-
- g_variant_builder_unref(builder);
+ g_variant_builder_add(&builder, "i", GPOINTER_TO_INT(node->data));
- return obs;
+ return g_variant_builder_end(&builder);
}