Apply contact handle policy 09/47409/1
authorSunggoo Kim <sung.goo.kim@samsung.com>
Thu, 7 May 2015 08:57:33 +0000 (17:57 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Thu, 3 Sep 2015 07:05:07 +0000 (16:05 +0900)
Change-Id: Ibaa716d087ba3c7f8d095d996c7c4b6406fc8bcc

18 files changed:
client/CMakeLists.txt
client/ctsvc_client_activity.c
client/ctsvc_client_db.c
client/ctsvc_client_db_notification.c
client/ctsvc_client_group.c
client/ctsvc_client_handle.c
client/ctsvc_client_handle.h
client/ctsvc_client_ipc.c
client/ctsvc_client_ipc.h
client/ctsvc_client_person.c
client/ctsvc_client_phonelog.c
client/ctsvc_client_service.c
client/ctsvc_client_service_helper.c
client/ctsvc_client_utils.c
client/ctsvc_client_utils.h [new file with mode: 0644]
include/contacts_utils.h [deleted file]
server/db/ctsvc_db_plugin_contact.c
server/db/ctsvc_db_plugin_contact_helper.c

index b11e2df..0415821 100644 (file)
@@ -16,6 +16,7 @@ SET(SRCS
        ctsvc_client_noti.c
        ctsvc_client_setting.c
        ctsvc_client_handle.c
+       ctsvc_client_utils.c
 
        ctsvc_client_service_helper.c
        ctsvc_client_db_helper.c
index e555832..bd5dd5f 100644 (file)
@@ -27,8 +27,8 @@ API int contacts_activity_delete_by_contact_id(int contact_id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_activity_delete_by_contact_id(contact, contact_id);
 
@@ -40,8 +40,8 @@ API int contacts_activity_delete_by_account_id(int account_id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_activity_delete_by_account_id(contact, account_id);
 
index 27f96bb..11e6a37 100644 (file)
@@ -31,8 +31,8 @@ API int contacts_db_insert_record(contacts_record_h record, int *id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_insert_record(contact, record, id);
 
@@ -44,8 +44,8 @@ API int contacts_db_get_record(const char* view_uri, int id, contacts_record_h*
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
 
@@ -57,8 +57,8 @@ API int contacts_db_update_record(contacts_record_h record)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_update_record(contact, record);
 
@@ -70,8 +70,8 @@ API int contacts_db_delete_record(const char* view_uri, int id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_delete_record(contact, view_uri, id);
 
@@ -83,8 +83,8 @@ API int contacts_db_replace_record(contacts_record_h record, int id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_replace_record(contact, record, id);
 
@@ -97,8 +97,8 @@ API int contacts_db_get_all_records(const char* view_uri, int offset, int limit,
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
 
@@ -110,8 +110,8 @@ API int contacts_db_get_records_with_query(contacts_query_h query, int offset, i
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
 
@@ -124,8 +124,8 @@ API int contacts_db_get_count(const char* view_uri, int *out_count)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
 
@@ -137,8 +137,8 @@ API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
 
@@ -150,8 +150,8 @@ API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_insert_records(contact, list, ids, count);
 
@@ -163,8 +163,8 @@ API int contacts_db_update_records(contacts_list_h list)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_update_records(contact, list);
 
@@ -176,8 +176,8 @@ API int contacts_db_delete_records(const char* view_uri, int ids[], int count)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
 
@@ -189,8 +189,8 @@ API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_replace_records(contact, list, ids, count);
 
@@ -203,8 +203,8 @@ API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
 
@@ -216,8 +216,8 @@ API int contacts_db_get_current_version(int* contacts_db_version)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
 
@@ -231,8 +231,8 @@ API int contacts_db_search_records(const char* view_uri, const char *keyword,
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
 
@@ -245,8 +245,8 @@ API int contacts_db_search_records_with_range(const char* view_uri, const char *
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
 
@@ -259,8 +259,8 @@ API int contacts_db_search_records_with_query(contacts_query_h query, const char
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
 
@@ -272,8 +272,8 @@ API int contacts_db_get_last_change_version(int* last_version)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_last_change_version(contact, last_version);
 
@@ -285,8 +285,8 @@ API int contacts_db_get_status(contacts_db_status_e *status)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_get_status(contact, status);
 
@@ -299,8 +299,8 @@ API int contacts_db_add_status_changed_cb(
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_add_status_changed_cb(contact, cb, user_data);
 
@@ -313,8 +313,8 @@ API int contacts_db_remove_status_changed_cb(
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);
 
index c3360d4..f62e406 100644 (file)
@@ -33,8 +33,8 @@ API int contacts_db_add_changed_cb(const char* view_uri, contacts_db_changed_cb
        RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
                        "Invalid parameter : callback is null");
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_inotify_subscribe(contact, view_uri, cb, user_data);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret,
@@ -54,8 +54,8 @@ API int contacts_db_remove_changed_cb(const char* view_uri, contacts_db_changed_
        RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
                        "Invalid parameter : callback is null");
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_inotify_unsubscribe(contact, view_uri, cb, user_data);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret,
index 7641e62..ecbbb58 100644 (file)
@@ -27,8 +27,8 @@ API int contacts_group_add_contact(int group_id, int contact_id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_group_add_contact(contact, group_id, contact_id);
 
@@ -40,8 +40,8 @@ API int contacts_group_remove_contact(int group_id, int contact_id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_group_remove_contact(contact, group_id, contact_id);
 
@@ -53,8 +53,8 @@ API int contacts_group_set_group_order(int group_id, int previous_group_id, int
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_group_set_group_order(contact, group_id, previous_group_id, next_group_id);
 
index 0b34d63..2354765 100644 (file)
  *
  */
 
-#include <unistd.h>
-#include <pthread.h>
 #include <glib.h>
+#include <unistd.h>
 
 #include "ctsvc_internal.h"
 #include "ctsvc_handle.h"
 #include "ctsvc_mutex.h"
+#include "ctsvc_client_utils.h"
 #include "ctsvc_client_handle.h"
 
 static GHashTable *_ctsvc_handle_table = NULL;
 
-static int _ctsvc_client_handle_get_key(char *key, int key_len)
+static int _ctsvc_client_handle_get_key(unsigned int id, char *key, int key_len)
 {
        int ret;
        int len;
@@ -37,12 +37,12 @@ static int _ctsvc_client_handle_get_key(char *key, int key_len)
        RETVM_IF(0 != ret, CONTACTS_ERROR_SYSTEM, "gethostname() Failed(%d)", errno);
 
        len = strlen(key);
-       snprintf(key+len, key_len-len, ":%d", (int)pthread_self());
+       snprintf(key+len, key_len-len, ":%u", id);
 
        return CONTACTS_ERROR_NONE;
 }
 
-int ctsvc_client_handle_get_current_p(contacts_h *p_contact)
+int ctsvc_client_handle_get_p_with_id(unsigned int id, contacts_h *p_contact)
 {
        int ret;
        char key[CTSVC_STR_SHORT_LEN] = {0};
@@ -50,64 +50,79 @@ int ctsvc_client_handle_get_current_p(contacts_h *p_contact)
 
        RETVM_IF(NULL == _ctsvc_handle_table, CONTACTS_ERROR_NO_DATA, "_ctsvc_handle_table is NULL");
 
-       ret = _ctsvc_client_handle_get_key(key, sizeof(key));
+       ret = _ctsvc_client_handle_get_key(id, key, sizeof(key));
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
 
        ctsvc_mutex_lock(CTS_MUTEX_HANDLE);
        contact = g_hash_table_lookup(_ctsvc_handle_table, key);
        ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
-       RETVM_IF(NULL == contact, CONTACTS_ERROR_NO_DATA, "g_hash_table_lookup() return NULL");
 
        *p_contact = contact;
        return CONTACTS_ERROR_NONE;
 }
 
-static int _ctsvc_client_handle_add(contacts_h contact)
+int ctsvc_client_handle_get_p(contacts_h *p_contact)
 {
        int ret;
        char key[CTSVC_STR_SHORT_LEN] = {0};
+       contacts_h contact = NULL;
 
-       if (NULL == _ctsvc_handle_table)
-               _ctsvc_handle_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+       RETVM_IF(NULL == _ctsvc_handle_table, CONTACTS_ERROR_NO_DATA, "_ctsvc_handle_table is NULL");
 
-       ret = _ctsvc_client_handle_get_key(key, sizeof(key));
+       ret = _ctsvc_client_handle_get_key(ctsvc_client_get_tid(), key, sizeof(key));
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
 
-       g_hash_table_insert(_ctsvc_handle_table, strdup(key), contact);
-
+       ctsvc_mutex_lock(CTS_MUTEX_HANDLE);
+       contact = g_hash_table_lookup(_ctsvc_handle_table, key);
        ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
+
+       if (NULL == contact) {
+               ret = _ctsvc_client_handle_get_key(ctsvc_client_get_pid(), key, sizeof(key));
+               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
+
+               ctsvc_mutex_lock(CTS_MUTEX_HANDLE);
+               contact = g_hash_table_lookup(_ctsvc_handle_table, key);
+               ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
+
+               RETVM_IF(NULL == contact, CONTACTS_ERROR_NO_DATA, "g_hash_table_lookup() return NULL");
+       }
+       *p_contact = contact;
        return CONTACTS_ERROR_NONE;
 }
 
-int ctsvc_client_handle_create(contacts_h *p_contact)
+int ctsvc_client_handle_create(unsigned int id, contacts_h *p_contact)
 {
        int ret;
+       char handle_key[CTSVC_STR_SHORT_LEN] = {0};
        contacts_h contact = NULL;
 
        RETVM_IF(NULL == p_contact, CONTACTS_ERROR_INVALID_PARAMETER, "p_contact is NULL");
        *p_contact = NULL;
 
+       ret = _ctsvc_client_handle_get_key(id, handle_key, sizeof(handle_key));
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
+
        ret = ctsvc_handle_create(&contact);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_handle_create() Fail(%d)", ret);
 
-       ret = _ctsvc_client_handle_add(contact);
-       if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("_ctsvc_client_handle_add() Fail(%d)", ret);
-               ctsvc_handle_destroy(contact);
-               return ret;
-       }
+       ctsvc_mutex_lock(CTS_MUTEX_HANDLE);
+       if (NULL == _ctsvc_handle_table)
+               _ctsvc_handle_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+
+       g_hash_table_insert(_ctsvc_handle_table, strdup(handle_key), contact);
+       ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
 
        *p_contact = contact;
        return CONTACTS_ERROR_NONE;
 }
 
-int ctsvc_client_handle_remove(contacts_h contact)
+int ctsvc_client_handle_remove(unsigned int id, contacts_h contact)
 {
        int ret;
        char key[CTSVC_STR_SHORT_LEN] = {0};
        RETVM_IF(NULL == _ctsvc_handle_table, CONTACTS_ERROR_NONE, "_ctsvc_handle_table is NULL");
 
-       ret = _ctsvc_client_handle_get_key(key, sizeof(key));
+       ret = _ctsvc_client_handle_get_key(id, key, sizeof(key));
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
 
        ctsvc_mutex_lock(CTS_MUTEX_HANDLE);
index c39e002..1d8bf99 100644 (file)
@@ -21,8 +21,9 @@
 #define __CTSVC_CLIENT_HANDLE_H__
 #include "contacts_types.h"
 
-int ctsvc_client_handle_get_current_p(contacts_h *p_contact);
-int ctsvc_client_handle_remove(contacts_h contact);
-int ctsvc_client_handle_create(contacts_h *p_contact);
+int ctsvc_client_handle_get_p(contacts_h *p_contact);
+int ctsvc_client_handle_get_p_with_id(unsigned int id, contacts_h *p_contact);
+int ctsvc_client_handle_remove(unsigned int id, contacts_h contact);
+int ctsvc_client_handle_create(unsigned int id, contacts_h *p_contact);
 
 #endif /* __CTSVC_CLIENT_HANDLE_H__ */
index c46357e..3c17bea 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #include <stdio.h>
-#include <sys/types.h>
 #include <unistd.h>
 #include <glib.h>
 #include <stdlib.h>
@@ -27,6 +26,7 @@
 #include <pims-ipc-data.h>
 
 #include "ctsvc_client_ipc.h"
+#include "ctsvc_client_utils.h"
 #include "ctsvc_client_service_helper.h"
 
 #include "ctsvc_internal.h"
@@ -49,30 +49,20 @@ static GHashTable *_ctsvc_ipc_table = NULL;
 static bool _ctsvc_ipc_disconnected = false;
 static int disconnected_cb_count = 0;
 
-void ctsvc_ipc_get_pid_str(char *buf, int buf_size)
-{
-       pid_t pid = getpid();
-       snprintf(buf, buf_size, "%d", (unsigned int)pid);
-}
-
-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 pims_ipc_h _ctsvc_get_ipc_handle()
 {
        struct ctsvc_ipc_s *ipc_data = NULL;
        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)); // get ipc_data by tid
+       snprintf(ipc_key, sizeof(ipc_key), "%u", ctsvc_client_get_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)); // get ipc_data by pid
+               snprintf(ipc_key, sizeof(ipc_key), "%u", ctsvc_client_get_pid());
                ipc_data = g_hash_table_lookup(_ctsvc_ipc_table, ipc_key);
        }
+
        RETVM_IF(NULL == ipc_data, NULL, "g_hash_table_lookup(%s) Fail", ipc_key);
 
        return ipc_data->ipc;
@@ -165,12 +155,14 @@ static int _ctsvc_ipc_connect(contacts_h contact, pims_ipc_h ipc)
        return ret;
 }
 
-int ctsvc_ipc_connect(contacts_h contact, const char *ipc_key)
+int ctsvc_ipc_connect(contacts_h contact, unsigned int handle_id)
 {
        int ret = CONTACTS_ERROR_NONE;
        struct ctsvc_ipc_s *ipc_data = NULL;
+       char ipc_key[CTSVC_STR_SHORT_LEN] = {0};
 
        RETV_IF(_ctsvc_ipc_disconnected, CONTACTS_ERROR_IPC_NOT_AVALIABLE);
+       snprintf(ipc_key, sizeof(ipc_key), "%u", handle_id);
 
        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);
@@ -193,15 +185,17 @@ 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_disconnect(contacts_h contact, unsigned int handle_id, int connection_count)
 {
        int ret = CONTACTS_ERROR_NONE;
        struct ctsvc_ipc_s *ipc_data = NULL;
        pims_ipc_data_h outdata = NULL;
        pims_ipc_data_h indata = NULL;
+       char ipc_key[CTSVC_STR_SHORT_LEN] = {0};
 
        RETV_IF(_ctsvc_ipc_disconnected, CONTACTS_ERROR_IPC_NOT_AVALIABLE);
        RETVM_IF(NULL == _ctsvc_ipc_table, CONTACTS_ERROR_IPC, "contacts not connected");
+       snprintf(ipc_key, sizeof(ipc_key), "%u", handle_id);
 
        ipc_data = g_hash_table_lookup(_ctsvc_ipc_table, ipc_key);
        RETVM_IF(ipc_data == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
index 174b9e1..2550151 100644 (file)
 #include <pims-ipc.h>
 #include "contacts_types.h"
 
-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(contacts_h contact, unsigned int handle_id);
+int ctsvc_ipc_disconnect(contacts_h contact, unsigned int handle_id, 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 b566690..e64bf04 100644 (file)
@@ -27,8 +27,8 @@ API int contacts_person_link_person(int base_person_id, int person_id)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_person_link_person(contact, base_person_id, person_id);
 
@@ -40,8 +40,8 @@ API int contacts_person_unlink_contact(int person_id, int contact_id, int* unlin
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_person_unlink_contact(contact, person_id, contact_id, unlinked_person_id);
 
@@ -54,8 +54,8 @@ API int contacts_person_reset_usage(int person_id, contacts_usage_type_e type)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_person_reset_usage(contact, person_id, type);
 
@@ -67,8 +67,8 @@ API int contacts_person_set_favorite_order(int person_id, int previous_person_id
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_person_set_favorite_order(contact, person_id, previous_person_id, next_person_id);
 
@@ -81,8 +81,8 @@ API int contacts_person_set_default_property(contacts_person_property_e property
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_person_set_default_property(contact, property, person_id, id);
 
@@ -95,8 +95,8 @@ API int contacts_person_get_default_property(contacts_person_property_e property
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_person_get_default_property(contact, property, person_id, id);
 
index 7fd6e29..fa73d60 100644 (file)
@@ -27,8 +27,8 @@ API int contacts_phone_log_reset_statistics(void)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        ret = ctsvc_client_phone_log_reset_statistics(contact);
 
@@ -40,8 +40,8 @@ API int contacts_phone_log_delete(contacts_phone_log_delete_e op, ...)
        int ret;
        contacts_h contact = NULL;
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       ret = ctsvc_client_handle_get_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
 
        va_list args;
        va_start(args, op);
index 2336248..62df6ad 100644 (file)
@@ -23,6 +23,7 @@
 #include "contacts.h"
 #include "ctsvc_internal.h"
 #include "ctsvc_client_ipc.h"
+#include "ctsvc_client_utils.h"
 #include "ctsvc_client_handle.h"
 #include "ctsvc_client_service_helper.h"
 
@@ -31,14 +32,15 @@ API int contacts_connect_with_flags(unsigned int flags)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_pid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        if (CONTACTS_ERROR_NO_DATA == ret) {
-               ret = ctsvc_client_handle_create(&contact);
+               ret = ctsvc_client_handle_create(id, &contact);
                RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
        }
        else if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
                return ret;
        }
 
@@ -52,14 +54,15 @@ API int contacts_connect(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_pid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        if (CONTACTS_ERROR_NO_DATA == ret) {
-               ret = ctsvc_client_handle_create(&contact);
+               ret = ctsvc_client_handle_create(id, &contact);
                RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
        }
        else if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
                return ret;
        }
        ret = ctsvc_client_connect(contact);
@@ -72,14 +75,20 @@ API int contacts_disconnect(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_pid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
 
        ret = ctsvc_client_disconnect(contact);
        WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
 
+       if (0 == ((ctsvc_base_s *)contact)->connection_count) {
+               ret = ctsvc_client_handle_remove(id, contact);
+               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);
+       }
+
        return ret;
 }
 
@@ -88,14 +97,15 @@ API int contacts_connect_on_thread(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_tid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        if (CONTACTS_ERROR_NO_DATA == ret) {
-               ret = ctsvc_client_handle_create(&contact);
+               ret = ctsvc_client_handle_create(id, &contact);
                RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
        }
        else if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
                return ret;
        }
 
@@ -110,14 +120,20 @@ API int contacts_disconnect_on_thread(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_tid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
 
        ret = ctsvc_client_disconnect_on_thread(contact);
        WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
 
+       if (0 == ((ctsvc_base_s *)contact)->connection_count) {
+               ret = ctsvc_client_handle_remove(id, contact);
+               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);
+       }
+
        return ret;
 }
 
index ffff946..62fdd44 100644 (file)
@@ -31,6 +31,7 @@
 #include "ctsvc_mutex.h"
 #include "ctsvc_inotify.h"
 #include "ctsvc_client_ipc.h"
+#include "ctsvc_client_utils.h"
 #include "ctsvc_client_handle.h"
 #include "ctsvc_client_service_helper.h"
 
@@ -95,10 +96,7 @@ int ctsvc_client_connect(contacts_h contact)
 
        ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
        if (0 == base->connection_count) {
-               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);
+               ret = ctsvc_ipc_connect(contact, ctsvc_client_get_pid());
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_connect() Fail(%d)", ret);
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
@@ -146,21 +144,15 @@ int ctsvc_client_disconnect(contacts_h contact)
 
        ctsvc_base_s *base = (ctsvc_base_s *)contact;
        if (1 == base->connection_count) {
-               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);
+               ret = ctsvc_ipc_disconnect(contact, ctsvc_client_get_pid(), _ctsvc_connection);
                if (ret != CONTACTS_ERROR_NONE) {
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
                        CTS_ERR("ctsvc_ipc_disconnect() Fail(%d)", ret);
                        return ret;
                }
                ctsvc_inotify_unsubscribe_ipc_ready(contact);
-               ctsvc_client_handle_remove((contacts_h)base);
-       }
-       else {
-               base->connection_count--;
        }
+       base->connection_count--;
 
        if (1 == _ctsvc_connection) {
                ctsvc_ipc_destroy_for_change_subscription();
@@ -191,11 +183,7 @@ int ctsvc_client_connect_on_thread(contacts_h contact)
        ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
 
        if (0 == base->connection_count) {
-
-               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);
+               ret = ctsvc_ipc_connect(contact, ctsvc_client_get_tid());
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_connect() Fail(%d)", ret);
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
@@ -244,21 +232,15 @@ int ctsvc_client_disconnect_on_thread(contacts_h contact)
        ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
 
        if (1 == base->connection_count) {
-               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);
+               ret = ctsvc_ipc_disconnect(contact, ctsvc_client_get_tid(), _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);
                        return ret;
                }
                ctsvc_inotify_unsubscribe_ipc_ready(contact);
-               ctsvc_client_handle_remove((contacts_h)base);
-       }
-       else {
-               base->connection_count--;
        }
+       base->connection_count--;
 
        if (1 == _ctsvc_connection_on_thread) {
                ctsvc_ipc_destroy_for_change_subscription();
index 32912d2..52cfe54 100644 (file)
@@ -1,57 +1,34 @@
-/*\r
- * Contacts Service\r
- *\r
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- */\r
-\r
-#include <glib.h>\r
-#include <pims-ipc-data.h>\r
-\r
-#include "contacts.h"\r
-#include "ctsvc_internal.h"\r
-#include "ctsvc_ipc_define.h"\r
-#include "ctsvc_ipc_marshal.h"\r
-#include "ctsvc_client_ipc.h"\r
-\r
-API int contacts_utils_get_index_characters(char **index_string)\r
-{\r
-       int ret = CONTACTS_ERROR_NONE;\r
-       pims_ipc_data_h outdata = NULL;\r
-\r
-       RETVM_IF(index_string == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL");\r
-       *index_string = NULL;\r
-       RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC, "contacts not connected");\r
-\r
-       if (ctsvc_ipc_call(CTSVC_IPC_UTILS_MODULE, CTSVC_IPC_SERVER_UTILS_GET_INDEX_CHARACTERS, NULL, &outdata) != 0) {\r
-               CTS_ERR("ctsvc_ipc_call Fail");\r
-               return CONTACTS_ERROR_IPC;\r
-       }\r
-\r
-       if (outdata) {\r
-               unsigned int size = 0;\r
-               ret = *(int*) pims_ipc_data_get(outdata, &size);\r
-               if (CONTACTS_ERROR_NONE == ret) {\r
-                       ret = ctsvc_ipc_unmarshal_string(outdata, index_string);\r
-                       if (CONTACTS_ERROR_NONE != ret) {\r
-                               CTS_ERR("ctsvc_ipc_unmarshal_string Fail9(%d)", ret);\r
-                       }\r
-               }\r
-               pims_ipc_data_destroy(outdata);\r
-       }\r
-\r
-       return ret;\r
-}\r
-\r
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+
+inline unsigned int ctsvc_client_get_pid()
+{
+       return (unsigned int)getpid();
+}
+
+inline unsigned int ctsvc_client_get_tid()
+{
+       return (unsigned int)syscall(SYS_gettid);
+}
+
diff --git a/client/ctsvc_client_utils.h b/client/ctsvc_client_utils.h
new file mode 100644 (file)
index 0000000..3c84dc7
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CTSVC_CLIENT_UTILS_H__
+#define __CTSVC_CLIENT_UTILS_H__
+
+unsigned int ctsvc_client_get_pid();
+unsigned int ctsvc_client_get_tid();
+
+#endif /*  __CTSVC_CLIENT_UTILS_H__ */
+
+
diff --git a/include/contacts_utils.h b/include/contacts_utils.h
deleted file mode 100644 (file)
index 991cab2..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Contacts Service
- *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __TIZEN_SOCIAL_CONTACTS_UTILS_H__
-#define __TIZEN_SOCIAL_CONTACTS_UTILS_H__
-
-#ifndef API
-#define API __attribute__ ((visibility("default")))
-#endif
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * @addtogroup CAPI_SOCIAL_CONTACTS_SVC_UTILS_MODULE
- * @{
- */
-
-/**
- * Gets normalized string.
- *
- * @param[out] index_string            The pointer of language index (number, first language, second language(if differ from first), #).
- *
- * @return  0 on success, otherwise a negative error value.
- *
- * @retval  #CONTACTS_ERROR_NONE       Successful
-*/
-API int contacts_utils_get_index_characters(char **index_string);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__TIZEN_SOCIAL_CONTACTS_UTILS_H__
-
index 0982b1e..351775e 100644 (file)
@@ -16,8 +16,6 @@
  * limitations under the License.
  *
  */
-#include <sys/types.h>
-#include <sys/syscall.h>
 #include <fcntl.h>
 #include <unistd.h>
 
index e7e27e3..76cf728 100644 (file)
@@ -17,8 +17,6 @@
  *
  */
 #include <ctype.h>
-#include <sys/types.h>
-#include <sys/syscall.h>
 #include <fcntl.h>
 #include <unistd.h>