Allow multiple presence
authoryoungman <yman.jung@samsung.com>
Thu, 5 Nov 2015 06:14:09 +0000 (15:14 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Nov 2015 05:54:46 +0000 (14:54 +0900)
Change-Id: I2e4a0cf651a8f823e3558eff8fabf7ca02928349
Signed-off-by: youngman <yman.jung@samsung.com>
16 files changed:
common/ic-common.h
common/ic-dbus.xml
daemon/icd-dbus.c
daemon/icd-dbus.h
daemon/icd-ioty-ocprocess.c
daemon/icd-ioty.c
daemon/icd-ioty.h
lib/icl-dbus.c
lib/icl-dbus.h
lib/icl-device.c
lib/icl-lite-resource.c
lib/icl-presence.c
lib/icl-remote-resource-caching.c
lib/icl-remote-resource-crud.c
lib/icl-remote-resource.c
lib/icl-resource.c

index 2529d709930d86d7a4d873522b09e645f4c828d6..52484c4739a1a06ea4c2e8a9f3300335b187f9db 100644 (file)
@@ -25,7 +25,7 @@
 
 #define IOTCON_DBUS_OBJPATH "/org/tizen/iotcon/dbus"
 
-#define IC_DBUS_SIGNAL_LENGTH 20
+#define IC_DBUS_SIGNAL_LENGTH 30
 
 #define IC_DBUS_SIGNAL_REQUEST_HANDLER "REQ"
 #define IC_DBUS_SIGNAL_FOUND_RESOURCE "RES"
index 7302b9402243f07401b36c4cfe6b9a89940ff44c..3ff15a761a2cdadfae1a61d4c53613814c0cc6d4 100644 (file)
@@ -5,7 +5,7 @@
                        <arg type="as" name="resource_types" direction="in"/>
                        <arg type="i" name="ifaces" direction="in"/>
                        <arg type="i" name="properties" direction="in"/>
-                       <arg type="u" name="signal_number" direction="in"/>
+                       <arg type="x" name="signal_number" direction="in"/>
                        <arg type="x" name="resource" direction="out"/>
                </method>
                <method name="unregisterResource">
@@ -45,7 +45,7 @@
                        <arg type="s" name="host_address" direction="in"/>
                        <arg type="i" name="connectivity" direction="in"/>
                        <arg type="s" name="type" direction="in"/>
-                       <arg type="u" name="signal_number" direction="in"/>
+                       <arg type="x" name="signal_number" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="get">
@@ -73,7 +73,7 @@
                        <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
                        <arg type="i" name="observe_type" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
-                       <arg type="u" name="signal_number" direction="in"/>
+                       <arg type="x" name="signal_number" direction="in"/>
                        <arg type="x" name="observe_h" direction="out"/>
                </method>
                <method name="observerStop">
                <method name="getDeviceInfo">
                        <arg type="s" name="host_address" direction="in"/>
                        <arg type="i" name="connectivity" direction="in"/>
-                       <arg type="u" name="signal_number" direction="in"/>
+                       <arg type="x" name="signal_number" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="getPlatformInfo">
                        <arg type="s" name="host_address" direction="in"/>
                        <arg type="i" name="connectivity" direction="in"/>
-                       <arg type="u" name="signal_number" direction="in"/>
+                       <arg type="x" name="signal_number" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="getTizenInfo">
                        <arg type="s" name="host_address" direction="in"/>
                        <arg type="i" name="connectivity" direction="in"/>
                        <arg type="s" name="type" direction="in"/>
-                       <arg type="u" name="signal_number" direction="in"/>
                        <arg type="x" name="presence_h" direction="out"/>
                </method>
                <method name="unsubscribePresence">
                        <arg type="x" name="presence_h" direction="in"/>
+                       <arg type="s" name="host_address" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="startPresence">
index e19a0d701bdfe2cbe81f6706efbffacaab418e33..cbf74c8323dba52d5815c3392a9e4838769519b9 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdint.h>
 #include <stdlib.h>
 #include <gio/gio.h>
 
@@ -39,7 +40,7 @@ typedef struct _icd_dbus_client_s {
 
 typedef struct _icd_resource_handle {
        OCResourceHandle handle;
-       unsigned int signal_number;
+       int64_t signal_number;
 } icd_resource_handle_s;
 
 
@@ -88,7 +89,7 @@ static void _icd_dbus_resource_handle_free(OCResourceHandle handle)
 }
 
 int icd_dbus_client_list_get_info(OCResourceHandle handle,
-               unsigned int *signal_number, gchar **bus_name)
+               int64_t *signal_number, gchar **bus_name)
 {
        FN_CALL;
        icd_dbus_client_s *client;
@@ -152,12 +153,14 @@ int icd_dbus_emit_signal(const char *dest, const char *signal_name, GVariant *va
        if (FALSE == ret) {
                ERR("g_dbus_connection_emit_signal() Fail(%s)", error->message);
                g_error_free(error);
+               g_variant_unref(value);
                return IOTCON_ERROR_DBUS;
        }
 
        if (FALSE == g_dbus_connection_flush_sync(conn, NULL, &error)) {
                ERR("g_dbus_connection_flush_sync() Fail(%s)", error->message);
                g_error_free(error);
+               g_variant_unref(value);
                return IOTCON_ERROR_DBUS;
        }
 
@@ -287,7 +290,7 @@ static int _icd_dbus_subscribe_name_owner_changed(GDBusConnection *conn)
 }
 
 static int _icd_dbus_resource_list_append_handle(const gchar *bus_name,
-               OCResourceHandle handle, unsigned int signal_number)
+               OCResourceHandle handle, int64_t signal_number)
 {
        FN_CALL;
        GList *cur_client, *cur_hd;
@@ -383,7 +386,7 @@ static gboolean _dbus_handle_register_resource(icDbus *object,
                const gchar* const *resource_types,
                gint ifaces,
                gint properties,
-               guint signal_number)
+               gint64 signal_number)
 {
        FN_CALL;
        int ret;
@@ -498,7 +501,7 @@ static gboolean _dbus_handle_find_resource(icDbus *object,
                const gchar *host_address,
                gint connectivity,
                const gchar *type,
-               guint signal_number)
+               gint64 signal_number)
 {
        int ret;
        const gchar *sender;
@@ -519,7 +522,7 @@ static gboolean _dbus_handle_observer_start(icDbus *object,
                GVariant *resource,
                gint observe_policy,
                GVariant *query,
-               guint signal_number)
+               gint64 signal_number)
 {
        OCDoHandle observe_h;
        const gchar *sender;
@@ -590,7 +593,7 @@ static gboolean _dbus_handle_get_device_info(icDbus *object,
                GDBusMethodInvocation *invocation,
                const gchar *host_address,
                gint connectivity,
-               guint signal_number)
+               gint64 signal_number)
 {
        int ret;
        const gchar *sender;
@@ -610,7 +613,7 @@ static gboolean _dbus_handle_get_platform_info(icDbus *object,
                GDBusMethodInvocation *invocation,
                const gchar *host_address,
                gint connectivity,
-               guint signal_number)
+               gint64 signal_number)
 {
        int ret;
        const gchar *sender;
@@ -662,15 +665,11 @@ static gboolean _dbus_handle_subscribe_presence(icDbus *object,
                GDBusMethodInvocation *invocation,
                const gchar *host_address,
                gint connectivity,
-               const gchar *type,
-               guint signal_number)
+               const gchar *type)
 {
        OCDoHandle presence_h;
-       const gchar *sender;
 
-       sender = g_dbus_method_invocation_get_sender(invocation);
-       presence_h = icd_ioty_subscribe_presence(host_address, connectivity, type,
-                       signal_number, sender);
+       presence_h = icd_ioty_subscribe_presence(host_address, connectivity, type);
        if (NULL == presence_h)
                ERR("icd_ioty_subscribe_presence() Fail");
 
@@ -683,11 +682,12 @@ static gboolean _dbus_handle_subscribe_presence(icDbus *object,
 
 static gboolean _dbus_handle_unsubscribe_presence(icDbus *object,
                GDBusMethodInvocation *invocation,
-               gint64 presence_h)
+               gint64 presence_h,
+               const gchar *host_address)
 {
        int ret;
 
-       ret = icd_ioty_unsubscribe_presence(ICD_INT64_TO_POINTER(presence_h));
+       ret = icd_ioty_unsubscribe_presence(ICD_INT64_TO_POINTER(presence_h), host_address);
        if (IOTCON_ERROR_NONE != ret)
                ERR("icd_ioty_unsubscribe_presence() Fail(%d)", ret);
 
index 3088fac205bd9969c5432e82b29e8fa2d4200fda..18e469ee0ad539dd1c3356945bc8f780bb52904b 100644 (file)
@@ -24,7 +24,7 @@
 #define ICD_POINTER_TO_INT64(p) ((int64_t)(intptr_t)(p))
 
 icDbus* icd_dbus_get_object();
-int icd_dbus_client_list_get_info(void *handle, unsigned int *signal_number,
+int icd_dbus_client_list_get_info(void *handle, int64_t *signal_number,
                gchar **bus_name);
 int icd_dbus_emit_signal(const char *dest, const char *signal_name,
                GVariant *value);
index c71ecc88131338ce76797080aaf9d579bea5b74d..85254e7bad22691f8947ec0169eb594ad7e6e39e 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h> /* for usleep() */
 #include <glib.h>
@@ -43,7 +44,7 @@ struct icd_ioty_worker
 
 
 struct icd_req_context {
-       unsigned int signal_number;
+       int64_t signal_number;
        char *bus_name;
        int request_type;
        int observe_id;
@@ -58,7 +59,7 @@ struct icd_req_context {
 
 
 struct icd_find_context {
-       unsigned int signal_number;
+       int64_t signal_number;
        char *bus_name;
        int conn_type;
        GVariant **payload;
@@ -75,7 +76,7 @@ struct icd_crud_context {
 
 
 struct icd_info_context {
-       unsigned int signal_number;
+       int64_t signal_number;
        int info_type;
        char *bus_name;
        GVariant *payload;
@@ -90,7 +91,7 @@ struct icd_tizen_info_context {
 
 
 struct icd_observe_context {
-       unsigned int signal_number;
+       int64_t signal_number;
        int res;
        int seqnum;
        char *bus_name;
@@ -100,8 +101,7 @@ struct icd_observe_context {
 
 
 struct icd_presence_context {
-       unsigned int signal_number;
-       char *bus_name;
+       OCDoHandle handle;
        int result;
        unsigned int nonce;
        OCDevAddr *dev_addr;
@@ -174,12 +174,12 @@ static int _ocprocess_worker_start(_ocprocess_cb cb, void *ctx)
 
 
 static int _ocprocess_response_signal(const char *dest, const char *signal_prefix,
-               unsigned int signal_number, GVariant *value)
+               int64_t signal_number, GVariant *value)
 {
        int ret;
        char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
 
-       ret = snprintf(signal_name, sizeof(signal_name), "%s_%u", signal_prefix, signal_number);
+       ret = snprintf(signal_name, sizeof(signal_name), "%s_%llx", signal_prefix, signal_number);
        if (ret <= 0 || sizeof(signal_name) <= ret) {
                ERR("snprintf() Fail(%d)", ret);
                return IOTCON_ERROR_IO_ERROR;
@@ -296,7 +296,7 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
 {
        FN_CALL;
        int ret;
-       unsigned int signal_number;
+       int64_t signal_number;
        char *query_str, *query_key, *query_value;
        char *token, *save_ptr1, *save_ptr2;
        char *bus_name = NULL;
@@ -757,7 +757,7 @@ static int _worker_observe_cb(void *context)
 
 
 static void _observe_cb_response_error(const char *dest,
-               unsigned int signal_number, int ret_val)
+               int64_t signal_number, int ret_val)
 {
        int ret;
        GVariant *value;
@@ -832,9 +832,11 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx,
 
 static int _worker_presence_cb(void *context)
 {
-       GVariant *value;
-       int ret, conn_type;
+       int conn_type;
+       OCDoHandle handle;
        char *host_address;
+       GVariant *value, *value2;
+       int ret = IOTCON_ERROR_NONE;
        struct icd_presence_context *ctx = context;
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
@@ -843,7 +845,6 @@ static int _worker_presence_cb(void *context)
        if (IOTCON_ERROR_NONE != ret) {
                ERR("icd_ioty_get_host_address() Fail(%d)", ret);
                free(ctx->resource_type);
-               free(ctx->bus_name);
                free(ctx->dev_addr);
                free(ctx);
                return ret;
@@ -851,17 +852,27 @@ static int _worker_presence_cb(void *context)
 
        value = g_variant_new("(iusiis)", ctx->result, ctx->nonce, host_address, conn_type,
                        ctx->trigger, ic_utils_dbus_encode_str(ctx->resource_type));
+       value2 = g_variant_ref(value);
 
        free(host_address);
 
-       ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_PRESENCE,
-                       ctx->signal_number, value);
+       ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
+                       ICD_POINTER_TO_INT64(ctx->handle), value);
        if (IOTCON_ERROR_NONE != ret)
                ERR("_ocprocess_response_signal() Fail(%d)", ret);
 
+       handle = icd_ioty_presence_table_get_handle(ICD_MULTICAST_ADDRESS);
+       if (handle && (handle != ctx->handle)) {
+               ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
+                               ICD_POINTER_TO_INT64(handle), value2);
+               if (IOTCON_ERROR_NONE != ret)
+                       ERR("_ocprocess_response_signal() Fail(%d)", ret);
+       } else {
+               g_variant_unref(value2);
+       }
+
        /* ctx was allocated from icd_ioty_ocprocess_presence_cb() */
        free(ctx->resource_type);
-       free(ctx->bus_name);
        free(ctx->dev_addr);
        free(ctx);
 
@@ -869,19 +880,31 @@ static int _worker_presence_cb(void *context)
 }
 
 
-static void _presence_cb_response_error(const char *dest, unsigned int signal_number,
-               int ret_val)
+static void _presence_cb_response_error(OCDoHandle handle, int ret_val)
 {
        FN_CALL;
        int ret;
-       GVariant *value;
+       OCDoHandle handle2;
+       GVariant *value, *value2;
 
        value = g_variant_new("(iusiis)", ret_val, 0, IC_STR_NULL, IOTCON_CONNECTIVITY_ALL,
                        IOTCON_PRESENCE_TRIGGER_RESOURCE_CREATED, IC_STR_NULL);
+       value2 = g_variant_ref(value);
 
-       ret = _ocprocess_response_signal(dest, IC_DBUS_SIGNAL_PRESENCE, signal_number, value);
+       ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
+                       ICD_POINTER_TO_INT64(handle), value);
        if (IOTCON_ERROR_NONE != ret)
                ERR("_ocprocess_response_signal() Fail(%d)", ret);
+
+       handle2 = icd_ioty_presence_table_get_handle(ICD_MULTICAST_ADDRESS);
+       if (handle2 && (handle2 != handle)) {
+               ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
+                               ICD_POINTER_TO_INT64(handle), value2);
+               if (IOTCON_ERROR_NONE != ret)
+                       ERR("_ocprocess_response_signal() Fail(%d)", ret);
+       } else {
+               g_variant_unref(value2);
+       }
 }
 
 
@@ -916,25 +939,21 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha
        int ret;
        OCDevAddr *dev_addr;
        OCPresencePayload *payload;
-       icd_sig_ctx_s *sig_context = ctx;
        struct icd_presence_context *presence_ctx;
 
-       RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
        RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
 
        presence_ctx = calloc(1, sizeof(struct icd_presence_context));
        if (NULL == presence_ctx) {
                ERR("calloc() Fail(%d)", errno);
-               _presence_cb_response_error(sig_context->bus_name, sig_context->signal_number,
-                               IOTCON_ERROR_OUT_OF_MEMORY);
+               _presence_cb_response_error(handle, IOTCON_ERROR_OUT_OF_MEMORY);
                return OC_STACK_KEEP_TRANSACTION;
        }
 
        dev_addr = calloc(1, sizeof(OCDevAddr));
        if (NULL == dev_addr) {
                ERR("calloc() Fail(%d)", errno);
-               _presence_cb_response_error(sig_context->bus_name, sig_context->signal_number,
-                               IOTCON_ERROR_OUT_OF_MEMORY);
+               _presence_cb_response_error(handle, IOTCON_ERROR_OUT_OF_MEMORY);
                free(presence_ctx);
                return OC_STACK_KEEP_TRANSACTION;
        }
@@ -948,8 +967,7 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha
                ret = _presence_trigger_to_ioty_trigger(payload->trigger, &presence_ctx->trigger);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("_presence_trigger_to_ioty_trigger() Fail(%d)", ret);
-                       _presence_cb_response_error(sig_context->bus_name, sig_context->signal_number,
-                                       ret);
+                       _presence_cb_response_error(handle, ret);
                        free(presence_ctx);
                        return OC_STACK_KEEP_TRANSACTION;
                }
@@ -966,8 +984,7 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha
                presence_ctx->result = IOTCON_ERROR_IOTIVITY;
        }
 
-       presence_ctx->signal_number = sig_context->signal_number;
-       presence_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
+       presence_ctx->handle = handle;
        presence_ctx->nonce = resp->sequenceNumber;
        presence_ctx->dev_addr = dev_addr;
 
@@ -977,15 +994,13 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha
        ret = _ocprocess_worker_start(_worker_presence_cb, presence_ctx);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker_start() Fail(%d)", ret);
-               _presence_cb_response_error(sig_context->bus_name, sig_context->signal_number, ret);
+               _presence_cb_response_error(handle, ret);
                free(presence_ctx->resource_type);
-               free(presence_ctx->bus_name);
                free(presence_ctx->dev_addr);
                free(presence_ctx);
                return OC_STACK_KEEP_TRANSACTION;
        }
 
-       /* DO NOT FREE sig_context. It MUST be freed in the ocstack */
        /* DO NOT FREE presence_ctx. It MUST be freed in the _worker_presence_cb func */
 
        return OC_STACK_KEEP_TRANSACTION;
index 5a231674b9815f440826e4f58fc99c54f43acc26..b5f9714f02d5ac4028adb088d47b850686b309ce 100644 (file)
@@ -35,7 +35,6 @@
 #include "icd-ioty-type.h"
 #include "icd-ioty-ocprocess.h"
 
-#define ICD_MULTICAST_ADDRESS "224.0.1.187:5683"
 #define ICD_UUID_LENGTH 37
 
 static const char *ICD_SYSTEM_INFO_TIZEN_ID = "http://tizen.org/system/tizenid";
@@ -52,6 +51,8 @@ typedef struct {
 
 static icd_tizen_info_s icd_tizen_info = {0};
 
+static GHashTable *icd_ioty_presence_table;
+
 static GMutex icd_csdk_mutex;
 
 void icd_ioty_csdk_lock()
@@ -411,7 +412,7 @@ static void _ioty_free_signal_context(void *data)
 
 
 int icd_ioty_find_resource(const char *host_address, int conn_type,
-               const char *resource_type, unsigned int signal_number, const char *bus_name)
+               const char *resource_type, int64_t signal_number, const char *bus_name)
 {
        int len;
        OCStackResult result;
@@ -707,7 +708,7 @@ gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
 
 
 OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_policy,
-               GVariant *query, unsigned int signal_number, const char *bus_name)
+               GVariant *query, int64_t signal_number, const char *bus_name)
 {
        bool is_secure;
        OCMethod method;
@@ -829,7 +830,7 @@ int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options)
 }
 
 int icd_ioty_get_info(int type, const char *host_address, int conn_type,
-               unsigned int signal_number, const char *bus_name)
+               int64_t signal_number, const char *bus_name)
 {
        OCStackResult result;
        icd_sig_ctx_s *context;
@@ -1120,40 +1121,114 @@ int icd_ioty_tizen_info_get_property(char **device_name, char **tizen_device_id)
 }
 
 
+static void _icd_ioty_presence_table_create()
+{
+       if (icd_ioty_presence_table)
+               return;
+
+       icd_ioty_presence_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+}
+
+
+static icd_presence_handle_info* _icd_ioty_presence_table_add(const char *host_address)
+{
+       icd_presence_handle_info *handle_info;
+
+       handle_info = calloc(1, sizeof(icd_presence_handle_info));
+       if (NULL == handle_info) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       handle_info->client_count = 1;
+
+       g_hash_table_insert(icd_ioty_presence_table, ic_utils_strdup(host_address),
+                       handle_info);
+
+       return handle_info;
+}
+
+
+static void _icd_ioty_presence_table_destroy()
+{
+       g_hash_table_destroy(icd_ioty_presence_table);
+       icd_ioty_presence_table = NULL;
+}
+
+
+static void _icd_ioty_presence_table_remove(const char *host_address)
+{
+       icd_presence_handle_info *handle_info;
+
+       handle_info = g_hash_table_lookup(icd_ioty_presence_table, host_address);
+       if (NULL == handle_info)
+               return;
+
+       handle_info->client_count--;
+       if (0 < handle_info->client_count)
+               return;
+
+       g_hash_table_remove(icd_ioty_presence_table, host_address);
+
+       if (0 == g_hash_table_size(icd_ioty_presence_table))
+               _icd_ioty_presence_table_destroy();
+
+       return;
+}
+
+
+static icd_presence_handle_info* _icd_ioty_presence_table_get_handle_info(
+               const char *host_address)
+{
+       return g_hash_table_lookup(icd_ioty_presence_table, host_address);
+}
+
+
+OCDoHandle icd_ioty_presence_table_get_handle(const char *host_address)
+{
+       icd_presence_handle_info *handle_info;
+
+       handle_info = g_hash_table_lookup(icd_ioty_presence_table, host_address);
+       if (NULL == handle_info)
+               return NULL;
+
+       return handle_info->handle;
+}
+
+
 OCDoHandle icd_ioty_subscribe_presence(const char *host_address, int conn_type,
-               const char *resource_type, unsigned int signal_number, const char *bus_name)
+               const char *resource_type)
 {
-       int len;
        OCDoHandle handle;
+       const char *address;
        OCStackResult result;
-       icd_sig_ctx_s *context;
        char uri[PATH_MAX] = {0};
        OCCallbackData cbdata = {0};
        OCConnectivityType oic_conn_type;
+       icd_presence_handle_info *handle_info;
 
-       if (IC_STR_EQUAL == strcmp(IC_STR_NULL, host_address) || '\0' == host_address[0]) {
-               len = snprintf(uri, sizeof(uri), "%s%s", ICD_MULTICAST_ADDRESS,
-                               OC_RSRVD_PRESENCE_URI);
-       } else {
-               len = snprintf(uri, sizeof(uri), "%s%s", host_address, OC_RSRVD_PRESENCE_URI);
-       }
-       if (len <= 0 || sizeof(uri) <= len) {
-               ERR("snprintf() Fail(%d)", len);
-               return NULL;
-       }
+       _icd_ioty_presence_table_create();
 
-       if (IC_STR_EQUAL != strcmp(IC_STR_NULL, resource_type))
-               snprintf(uri + len, sizeof(uri) - len, "?rt=%s", resource_type);
+       if (IC_STR_EQUAL == strcmp(IC_STR_NULL, host_address) || '\0' == host_address[0])
+               address = ICD_MULTICAST_ADDRESS;
+       else
+               address = host_address;
 
-       context = calloc(1, sizeof(icd_sig_ctx_s));
-       if (NULL == context) {
-               ERR("calloc() Fail(%d)", errno);
+       handle_info = _icd_ioty_presence_table_get_handle_info(address);
+       if (handle_info) {
+               DBG("Already subscribe presence(%s)", address);
+               handle_info->client_count++;
+               return handle_info->handle;
+       }
+
+       handle_info = _icd_ioty_presence_table_add(address);
+       if (NULL == handle_info) {
+               ERR("_icd_ioty_presence_table_add() Fail");
                return NULL;
        }
-       context->bus_name = ic_utils_strdup(bus_name);
-       context->signal_number = signal_number;
 
-       cbdata.context = context;
+       snprintf(uri, sizeof(uri), "%s%s", address, OC_RSRVD_PRESENCE_URI);
+
        cbdata.cb = icd_ioty_ocprocess_presence_cb;
        cbdata.cd = _ioty_free_signal_context;
 
@@ -1166,15 +1241,17 @@ OCDoHandle icd_ioty_subscribe_presence(const char *host_address, int conn_type,
 
        if (OC_STACK_OK != result) {
                ERR("OCDoResource() Fail(%d)", result);
-               free(context->bus_name);
-               free(context);
+               _icd_ioty_presence_table_remove(address);
                return NULL;
        }
+
+       handle_info->handle = handle;
+
        return handle;
 }
 
 
-int icd_ioty_unsubscribe_presence(OCDoHandle handle)
+int icd_ioty_unsubscribe_presence(OCDoHandle handle, const char *host_address)
 {
        OCStackResult ret;
 
@@ -1186,6 +1263,8 @@ int icd_ioty_unsubscribe_presence(OCDoHandle handle)
                return icd_ioty_convert_error(ret);
        }
 
+       _icd_ioty_presence_table_remove(host_address);
+
        return IOTCON_ERROR_NONE;
 }
 
index 4b7df2b13bef6c54bd5a58c8afcfeceb5f389b0f..dfa36b5e75175b742b48a3c3f36abc26040da2c4 100644 (file)
@@ -29,6 +29,8 @@
 #define ICD_IOTY_COAP "coap://"
 #define ICD_IOTY_COAPS "coaps://"
 
+#define ICD_MULTICAST_ADDRESS "224.0.1.187:5683"
+
 /* TODO Define Tizen Information Resource(uri, resource type) */
 #define ICD_IOTY_TIZEN_INFO_URI "/org/tizen/iot/d"
 #define ICD_IOTY_TIZEN_INFO_TYPE "org.tizen.iot.d"
 #define ICD_IOTY_TIZEN_INFO_TIZEN_DEVICE_ID "tizen_device_id"
 
 typedef struct {
-       unsigned int signal_number;
+       int64_t signal_number;
        char *bus_name;
 } icd_sig_ctx_s;
 
+typedef struct {
+       OCDoHandle handle;
+       int client_count;
+} icd_presence_handle_info;
+
 enum {
        ICD_CRUD_GET,
        ICD_CRUD_PUT,
@@ -77,7 +84,7 @@ int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers)
 int icd_ioty_send_response(GVariant *resp);
 
 int icd_ioty_find_resource(const char *host_address, int conn_type,
-               const char *resource_type, unsigned int signal_number, const char *bus_name);
+               const char *resource_type, int64_t signal_number, const char *bus_name);
 
 void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *value);
 void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int ret_val);
@@ -95,12 +102,12 @@ gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource);
 
 OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type,
-               GVariant *query, unsigned int signal_number, const char *bus_name);
+               GVariant *query, int64_t signal_number, const char *bus_name);
 
 int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options);
 
 int icd_ioty_get_info(int type, const char *host_address, int conn_type,
-               unsigned int signal_number, const char *bus_name);
+               int64_t signal_number, const char *bus_name);
 
 int icd_ioty_set_device_info();
 int icd_ioty_set_platform_info();
@@ -111,10 +118,12 @@ gboolean icd_ioty_get_tizen_info(icDbus *object, GDBusMethodInvocation *invocati
 
 int icd_ioty_tizen_info_get_property(char **device_name, char **tizen_device_id);
 
+OCDoHandle icd_ioty_presence_table_get_handle(const char *host_address);
+
 OCDoHandle icd_ioty_subscribe_presence(const char *host_address, int conn_type,
-               const char *resource_type, unsigned int signal_number, const char *bus_name);
+               const char *resource_type);
 
-int icd_ioty_unsubscribe_presence(OCDoHandle handle);
+int icd_ioty_unsubscribe_presence(OCDoHandle handle, const char *host_address);
 
 int icd_ioty_start_presence(unsigned int time_to_live);
 
index 9181069b1fde40593f1460ace35f00594860292f..e845db5f4b26c8de18e3a04e521894c282bb7636 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <gio/gio.h>
 #include <tizen_type.h>
@@ -42,9 +43,9 @@ icDbus* icl_dbus_get_object()
 }
 
 
-unsigned int icl_dbus_generate_signal_number()
+int64_t icl_dbus_generate_signal_number()
 {
-       static unsigned int i = 0;
+       static int64_t i = 0;
 
        return i++;
 }
index d835d33e60292329c1b9ee20f10ba32a3f3e3fac..f6f68061e22ef6a4daaec7d03013925b463603bd 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_DBUS_H__
 #define __IOT_CONNECTIVITY_MANAGER_DBUS_H__
 
+#include <stdint.h>
+
 #include "ic-dbus.h"
 
 #define ICL_DBUS_TIMEOUT_DEFAULT 30 /* 30 sec */
@@ -23,7 +25,7 @@
 
 
 icDbus* icl_dbus_get_object();
-unsigned int icl_dbus_generate_signal_number();
+int64_t icl_dbus_generate_signal_number();
 
 unsigned int icl_dbus_subscribe_signal(char *signal_name, void *cb_container,
                void *cb_free, GDBusSignalCallback sig_handler);
index 53dc13ac81a8a2215175228936143b3909b4653c..f43fbb0777cc566280cf525e8d5b0bb5da3f7d52 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -139,9 +140,10 @@ API int iotcon_get_device_info(const char *host_address,
                void *user_data)
 {
        int ret;
+       unsigned int sub_id;
        GError *error = NULL;
        icl_device_info_s *cb_container;
-       unsigned int sub_id, signal_number;
+       int64_t signal_number;
        char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
@@ -168,7 +170,7 @@ API int iotcon_get_device_info(const char *host_address,
                return icl_dbus_convert_daemon_error(ret);
        }
 
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
+       snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_DEVICE,
                        signal_number);
 
        cb_container = calloc(1, sizeof(icl_device_info_s));
@@ -316,9 +318,10 @@ API int iotcon_get_platform_info(const char *host_address,
                void *user_data)
 {
        int ret;
+       unsigned int sub_id;
        GError *error = NULL;
        icl_platform_info_s *cb_container;
-       unsigned int sub_id, signal_number;
+       int64_t signal_number;
        char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
@@ -345,7 +348,7 @@ API int iotcon_get_platform_info(const char *host_address,
                return icl_dbus_convert_daemon_error(ret);
        }
 
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PLATFORM,
+       snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_PLATFORM,
                        signal_number);
 
        cb_container = calloc(1, sizeof(icl_platform_info_s));
index 54f6f13115f40d1df09c68b3faee4cae5b01c2d3..a00e08b39407b28d734f3d610210526918c49a5c 100644 (file)
@@ -274,10 +274,11 @@ API int iotcon_lite_resource_create(const char *uri_path,
                iotcon_lite_resource_h *resource_handle)
 {
        int ret, iface;
+       unsigned int sub_id;
        const gchar **types;
        GError *error = NULL;
        iotcon_lite_resource_h resource;
-       unsigned int sub_id, signal_number;
+       int64_t signal_number;
        char signal_name[IC_DBUS_SIGNAL_LENGTH];
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
@@ -332,7 +333,7 @@ API int iotcon_lite_resource_create(const char *uri_path,
                return ret;
        }
 
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_REQUEST_HANDLER,
+       snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
                        signal_number);
 
        sub_id = icl_dbus_subscribe_signal(signal_name, resource,
index 4fb8e514a5c7c113074cd9a35f57ae61bca6f8a5..8ae81c9eb84cbac0e2da7af4e0b6ef0e983a97a0 100644 (file)
@@ -120,14 +120,20 @@ static void _icl_presence_cb(GDBusConnection *connection,
        g_variant_get(parameters, "(iu&sii&s)", &res, &nonce, &host_address,
                        &connectivity_type, &trigger, &resource_type);
 
+       response.resource_type = ic_utils_dbus_decode_str(resource_type);
+
+       if (response.resource_type && presence->resource_type) {
+               if (IC_STR_EQUAL != strcmp(response.resource_type, presence->resource_type))
+                       return;
+       }
+
        if (res < IOTCON_ERROR_NONE && cb)
                cb(presence, icl_dbus_convert_daemon_error(res), NULL, presence->user_data);
 
-       DBG("presence nonce : %d", nonce);
+       DBG("presence nonce : %u", nonce);
 
        response.host_address = host_address;
        response.connectivity_type = connectivity_type;
-       response.resource_type = ic_utils_dbus_decode_str(resource_type);
        response.result = res;
        response.trigger = trigger;
 
@@ -161,9 +167,9 @@ API int iotcon_add_presence_cb(const char *host_address,
 {
        FN_CALL;
        int ret;
+       unsigned int sub_id;
        GError *error = NULL;
        icl_presence_s *presence;
-       unsigned int sub_id, signal_number;
        char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_INVALID_PARAMETER);
@@ -181,21 +187,16 @@ API int iotcon_add_presence_cb(const char *host_address,
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       signal_number = icl_dbus_generate_signal_number();
-
        presence = calloc(1, sizeof(icl_presence_s));
        if (NULL == presence) {
                ERR("calloc() Fail(%d)", errno);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
 
-       resource_type = ic_utils_dbus_encode_str(resource_type);
-
        ic_dbus_call_subscribe_presence_sync(icl_dbus_get_object(),
                        ic_utils_dbus_encode_str(host_address),
                        connectivity_type,
-                       resource_type,
-                       signal_number,
+                       ic_utils_dbus_encode_str(resource_type),
                        &(presence->handle),
                        NULL,
                        &error);
@@ -213,8 +214,8 @@ API int iotcon_add_presence_cb(const char *host_address,
                return IOTCON_ERROR_IOTIVITY;
        }
 
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PRESENCE,
-                       signal_number);
+       snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_PRESENCE,
+                       presence->handle);
 
        presence->cb = cb;
        presence->user_data = user_data;
@@ -265,7 +266,7 @@ API int iotcon_remove_presence_cb(iotcon_presence_h presence)
        }
 
        ic_dbus_call_unsubscribe_presence_sync(icl_dbus_get_object(), presence->handle,
-                       &ret, NULL, &error);
+                       presence->host_address, &ret, NULL, &error);
        if (error) {
                ERR("ic_dbus_call_unsubscribe_presence_sync() Fail(%s)", error->message);
                ret = icl_dbus_convert_dbus_error(error->code);
index 0ef72fa8d849c074e52d11a3dc35e034c7c23eb2..11ef098efa62bbcd6f94a2342fd054ef5405e36b 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <glib.h>
index b41f87fe1ea06d1cf502bb99ace5209f7c5eb61f..c218fb93d21fd772a16d8772b06f6d9457eac985 100644 (file)
@@ -464,7 +464,7 @@ int icl_remote_resource_observer_start(iotcon_remote_resource_h resource,
 {
        int ret;
        GError *error = NULL;
-       unsigned int signal_number;
+       int64_t signal_number;
        GVariant *arg_query, *arg_remote_resource;
        char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
 
@@ -491,7 +491,7 @@ int icl_remote_resource_observer_start(iotcon_remote_resource_h resource,
                return IOTCON_ERROR_IOTIVITY;
        }
 
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_OBSERVE,
+       snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_OBSERVE,
                        signal_number);
 
        *sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, cb_free, sig_handler);
index 238e4bba2c15dc75c26ed35fabe54b0e0c228b85..838b0bf72b6b3f3d16e5ca49dee8a79e9b499177 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -99,9 +100,10 @@ API int iotcon_find_resource(const char *host_address,
                void *user_data)
 {
        int ret;
+       unsigned int sub_id;
        GError *error = NULL;
+       int64_t signal_number;
        icl_found_resource_s *cb_container;
-       unsigned int sub_id, signal_number;
        char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
@@ -133,7 +135,7 @@ API int iotcon_find_resource(const char *host_address,
                return icl_dbus_convert_daemon_error(ret);
        }
 
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_FOUND_RESOURCE,
+       snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_FOUND_RESOURCE,
                        signal_number);
 
        cb_container = calloc(1, sizeof(icl_found_resource_s));
index d0c2760bf64cbd3aff8d126772ada79f0b512edd..6e67fe34aadd1defdb9260ff94417b7d148156fa 100644 (file)
@@ -159,10 +159,11 @@ API int iotcon_resource_create(const char *uri_path,
                iotcon_resource_h *resource_handle)
 {
        int ret;
+       unsigned int sub_id;
        const gchar **types;
        GError *error = NULL;
        iotcon_resource_h resource;
-       unsigned int sub_id, signal_number;
+       int64_t signal_number;
        char signal_name[IC_DBUS_SIGNAL_LENGTH];
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
@@ -213,7 +214,7 @@ API int iotcon_resource_create(const char *uri_path,
        resource->ifaces = ifaces;
        resource->properties = properties;
 
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_REQUEST_HANDLER,
+       snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
                        signal_number);
 
        sub_id = icl_dbus_subscribe_signal(signal_name, resource, _icl_resource_conn_cleanup,