fixed disconnected cb 44/47844/1
authorGukhwan Cho <gh78.cho@samsung.com>
Thu, 13 Aug 2015 06:56:31 +0000 (15:56 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Wed, 9 Sep 2015 10:38:05 +0000 (19:38 +0900)
Change-Id: Ic0f0d45802e0bb465158e713375b65ea9234702b
Signed-off-by: Gukhwan Cho <gh78.cho@samsung.com>
client/ctsvc_client_ipc.c
client/ctsvc_client_noti.c

index a971e96..73ba11e 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <glib.h>
 #include <pims-ipc-data.h>
+#include <pthread.h>
 
 #include "ctsvc_client_ipc.h"
 #include "ctsvc_client_utils.h"
@@ -45,6 +46,7 @@ struct ctsvc_ipc_s {
        GList *list_handle;
 };
 
+static pthread_mutex_t _ctsvc_mutex_disconnected = PTHREAD_MUTEX_INITIALIZER;
 static GHashTable *_ctsvc_ipc_table = NULL;
 static bool _ctsvc_ipc_disconnected = false;
 
@@ -110,8 +112,10 @@ static void _ctsvc_ipc_data_free(gpointer p)
        if (NULL == ipc_data)
                return;
 
-       if (ipc_data->ipc)
+       if (ipc_data->ipc) {
+               ctsvc_ipc_unset_disconnected_cb(ipc_data->ipc);
                pims_ipc_destroy(ipc_data->ipc);
+       }
 
        g_list_free(ipc_data->list_handle);
 
@@ -351,12 +355,16 @@ int ctsvc_ipc_unset_disconnected_cb(pims_ipc_h ipc)
 
 void ctsvc_ipc_set_disconnected(bool is_disconnected)
 {
+       pthread_mutex_lock(&_ctsvc_mutex_disconnected);
        _ctsvc_ipc_disconnected = is_disconnected;
+       pthread_mutex_unlock(&_ctsvc_mutex_disconnected);
 }
 
 int ctsvc_ipc_get_disconnected()
 {
+       pthread_mutex_lock(&_ctsvc_mutex_disconnected);
        CTS_DBG("_ctsvc_ipc_disconnected=%d", _ctsvc_ipc_disconnected);
+       pthread_mutex_unlock(&_ctsvc_mutex_disconnected);
        return _ctsvc_ipc_disconnected;
 }
 
@@ -365,6 +373,7 @@ static void _ctsvc_ipc_recovery_foreach_cb(gpointer key, gpointer value, gpointe
        GList *c;
        struct ctsvc_ipc_s *ipc_data = value;
 
+       ctsvc_ipc_unset_disconnected_cb(ipc_data->ipc);
        int ret = _ctsvc_ipc_create(&(ipc_data->ipc));
        RETM_IF(CONTACTS_ERROR_NONE != ret, "_ctsvc_ipc_create() Fail(%d)", ret);
        ctsvc_ipc_set_disconnected_cb(ipc_data->ipc, _ctsvc_ipc_disconnected_cb, NULL);
index 1c68e35..f87f2f7 100644 (file)
@@ -114,8 +114,6 @@ int ctsvc_ipc_recover_for_change_subscription()
                ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
                return CONTACTS_ERROR_NONE;
        }
-       if (__ipc)
-               ctsvc_ipc_unset_disconnected_cb(__ipc);
        __ipc = pims_ipc_create_for_subscribe(CTSVC_IPC_SOCKET_PATH_FOR_CHANGE_SUBSCRIPTION);
        if (!__ipc) {
                CTS_ERR("pims_ipc_create_for_subscribe error\n");
@@ -131,7 +129,6 @@ int ctsvc_ipc_destroy_for_change_subscription()
        ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
 
        if (1 == __ipc_pubsub_ref) {
-               ctsvc_ipc_unset_disconnected_cb(__ipc);
                pims_ipc_destroy_for_subscribe(__ipc);
                __ipc = NULL;
        }