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
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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,
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,
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);
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);
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);
*
*/
-#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;
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};
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);
#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__ */
*/
#include <stdio.h>
-#include <sys/types.h>
#include <unistd.h>
#include <glib.h>
#include <stdlib.h>
#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"
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;
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);
}
-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");
#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);
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);
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);
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);
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);
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);
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);
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);
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);
#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"
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;
}
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);
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;
}
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;
}
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;
}
#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"
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);
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();
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);
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();
-/*\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);
+}
+
--- /dev/null
+/*
+ * 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__ */
+
+
+++ /dev/null
-/*
- * 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__
-
* limitations under the License.
*
*/
-#include <sys/types.h>
-#include <sys/syscall.h>
#include <fcntl.h>
#include <unistd.h>
*
*/
#include <ctype.h>
-#include <sys/types.h>
-#include <sys/syscall.h>
#include <fcntl.h>
#include <unistd.h>