Apply ipc handle policy 05/47405/1
authorSunggoo Kim <sung.goo.kim@samsung.com>
Wed, 6 May 2015 23:54:12 +0000 (08:54 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Thu, 3 Sep 2015 06:41:05 +0000 (15:41 +0900)
Change-Id: I82f2fec224f902c4a6f9967c3956b9d0b646b358

client/ctsvc_client_ipc.c
client/ctsvc_client_ipc.h
client/ctsvc_client_service_helper.c

index 910d17f..c46357e 100644 (file)
@@ -40,8 +40,6 @@
 #include "ctsvc_mutex.h"
 #include "ctsvc_handle.h"
 
-#define CTS_STR_SHORT_LEN 1024 //short sql string length
-
 struct ctsvc_ipc_s {
        pims_ipc_h ipc;
        GList *list_handle;
@@ -51,40 +49,33 @@ static GHashTable *_ctsvc_ipc_table = NULL;
 static bool _ctsvc_ipc_disconnected = false;
 static int disconnected_cb_count = 0;
 
-static inline void _ctsvc_ipc_get_pid_str(char *buf, int buf_size)
+void ctsvc_ipc_get_pid_str(char *buf, int buf_size)
 {
        pid_t pid = getpid();
        snprintf(buf, buf_size, "%d", (unsigned int)pid);
 }
 
-static inline void _ctsvc_ipc_get_tid_str(char *buf, int buf_size)
+void ctsvc_ipc_get_tid_str(char *buf, int buf_size)
 {
        pthread_t tid = pthread_self();
        snprintf(buf, buf_size, "%d", (unsigned int)tid);
 }
 
-static struct ctsvc_ipc_s* _ctsvc_get_ipc_data()
+static pims_ipc_h _ctsvc_get_ipc_handle()
 {
        struct ctsvc_ipc_s *ipc_data = NULL;
-       char ipc_key[CTS_STR_SHORT_LEN] = {0};
+       char ipc_key[CTSVC_STR_SHORT_LEN] = {0};
        RETVM_IF(NULL == _ctsvc_ipc_table, NULL, "contacts not connected");
 
-       _ctsvc_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
+       ctsvc_ipc_get_tid_str(ipc_key, sizeof(ipc_key)); // get ipc_data by tid
        ipc_data = g_hash_table_lookup(_ctsvc_ipc_table, ipc_key);
        if (NULL == ipc_data) {
-               _ctsvc_ipc_get_pid_str(ipc_key, sizeof(ipc_key));
+               ctsvc_ipc_get_pid_str(ipc_key, sizeof(ipc_key)); // get ipc_data by pid
                ipc_data = g_hash_table_lookup(_ctsvc_ipc_table, ipc_key);
        }
-       return ipc_data;
-}
-
-static pims_ipc_h _ctsvc_get_ipc_handle()
-{
-       struct ctsvc_ipc_s *ipc_data = _ctsvc_get_ipc_data();
-       if (ipc_data)
-               return ipc_data->ipc;
+       RETVM_IF(NULL == ipc_data, NULL, "g_hash_table_lookup(%s) Fail", ipc_key);
 
-       return NULL;
+       return ipc_data->ipc;
 }
 
 bool ctsvc_ipc_is_busy()
@@ -174,16 +165,13 @@ static int _ctsvc_ipc_connect(contacts_h contact, pims_ipc_h ipc)
        return ret;
 }
 
-int ctsvc_ipc_connect(contacts_h contact)
+int ctsvc_ipc_connect(contacts_h contact, const char *ipc_key)
 {
        int ret = CONTACTS_ERROR_NONE;
        struct ctsvc_ipc_s *ipc_data = NULL;
-       char ipc_key[CTS_STR_SHORT_LEN] = {0};
 
        RETV_IF(_ctsvc_ipc_disconnected, CONTACTS_ERROR_IPC_NOT_AVALIABLE);
 
-       _ctsvc_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
-
        if (NULL == _ctsvc_ipc_table)
                _ctsvc_ipc_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _ctsvc_ipc_data_free);
        else
@@ -205,10 +193,9 @@ int ctsvc_ipc_connect(contacts_h contact)
 }
 
 
-int ctsvc_ipc_disconnect(contacts_h contact, int connection_count)
+int ctsvc_ipc_disconnect(contacts_h contact, const char *ipc_key, int connection_count)
 {
        int ret = CONTACTS_ERROR_NONE;
-       char ipc_key[CTS_STR_SHORT_LEN] = {0};
        struct ctsvc_ipc_s *ipc_data = NULL;
        pims_ipc_data_h outdata = NULL;
        pims_ipc_data_h indata = NULL;
@@ -216,8 +203,6 @@ int ctsvc_ipc_disconnect(contacts_h contact, int connection_count)
        RETV_IF(_ctsvc_ipc_disconnected, CONTACTS_ERROR_IPC_NOT_AVALIABLE);
        RETVM_IF(NULL == _ctsvc_ipc_table, CONTACTS_ERROR_IPC, "contacts not connected");
 
-       _ctsvc_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
-
        ipc_data = g_hash_table_lookup(_ctsvc_ipc_table, ipc_key);
        RETVM_IF(ipc_data == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
 
index d28273d..174b9e1 100644 (file)
 #include <pims-ipc.h>
 #include "contacts_types.h"
 
-int ctsvc_ipc_connect(contacts_h contact);
-int ctsvc_ipc_disconnect(contacts_h contact, int connection_count);
+void ctsvc_ipc_get_pid_str(char *buf, int buf_size);
+void ctsvc_ipc_get_tid_str(char *buf, int buf_size);
+
+int ctsvc_ipc_connect(contacts_h contact, const char *ipc_key);
+int ctsvc_ipc_disconnect(contacts_h contact, const char *ipc_key, int connection_count);
 
 int ctsvc_ipc_connect_on_thread(contacts_h contact);
 int ctsvc_ipc_disconnect_on_thread(contacts_h contact, int connection_count);
index 72368a1..ffff946 100644 (file)
@@ -95,7 +95,10 @@ int ctsvc_client_connect(contacts_h contact)
 
        ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
        if (0 == base->connection_count) {
-               ret = ctsvc_ipc_connect(contact);
+               char ipc_key[CTSVC_STR_SHORT_LEN] = {0};
+               ctsvc_ipc_get_pid_str(ipc_key, sizeof(ipc_key));
+
+               ret = ctsvc_ipc_connect(contact, ipc_key);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_connect() Fail(%d)", ret);
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
@@ -143,7 +146,10 @@ int ctsvc_client_disconnect(contacts_h contact)
 
        ctsvc_base_s *base = (ctsvc_base_s *)contact;
        if (1 == base->connection_count) {
-               ret = ctsvc_ipc_disconnect(contact, _ctsvc_connection);
+               char ipc_key[CTSVC_STR_SHORT_LEN] = {0};
+               ctsvc_ipc_get_pid_str(ipc_key, sizeof(ipc_key));
+
+               ret = ctsvc_ipc_disconnect(contact, ipc_key, _ctsvc_connection);
                if (ret != CONTACTS_ERROR_NONE) {
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
                        CTS_ERR("ctsvc_ipc_disconnect() Fail(%d)", ret);
@@ -185,7 +191,11 @@ int ctsvc_client_connect_on_thread(contacts_h contact)
        ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
 
        if (0 == base->connection_count) {
-               ret = ctsvc_ipc_connect(contact);
+
+               char ipc_key[CTSVC_STR_SHORT_LEN] = {0};
+               ctsvc_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
+
+               ret = ctsvc_ipc_connect(contact, ipc_key);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_connect() Fail(%d)", ret);
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
@@ -234,7 +244,10 @@ int ctsvc_client_disconnect_on_thread(contacts_h contact)
        ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
 
        if (1 == base->connection_count) {
-               ret = ctsvc_ipc_disconnect(contact, _ctsvc_connection_on_thread);
+               char ipc_key[CTSVC_STR_SHORT_LEN] = {0};
+               ctsvc_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
+
+               ret = ctsvc_ipc_disconnect(contact, ipc_key, _ctsvc_connection_on_thread);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_disconnect_on_thread() Fail(%d)", ret);
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);