#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;
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()
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
}
-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;
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");
#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);
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);
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);
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);
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);