bool ctsvc_ipc_is_busy();
+pims_ipc_h ctsvc_ipc_get_handle_for_change_subsciption();
int ctsvc_ipc_create_for_change_subscription();
int 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 <pims-ipc.h>\r
-#include <pims-ipc-svc.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_mutex.h"\r
-\r
-typedef struct\r
-{\r
- contacts_db_change_cb_with_info cb;\r
- void *user_data;\r
-}callback_info_s;\r
-\r
-typedef struct\r
-{\r
- char *view_uri;\r
- GSList *callbacks;\r
-}subscribe_info_s;\r
-\r
-static pims_ipc_h __ipc = NULL;\r
-static GSList *__subscribe_list = NULL;\r
-\r
-static void __ctsvc_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)\r
-{\r
- unsigned int size = 0;\r
- char *str = NULL;\r
- subscribe_info_s *info = user_data;\r
-\r
+/*
+ * 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.
+ *
+ */
+
+#include <pims-ipc.h>
+#include <pims-ipc-svc.h>
+#include <pims-ipc-data.h>
+
+#include "contacts.h"
+#include "ctsvc_internal.h"
+#include "ctsvc_ipc_define.h"
+#include "ctsvc_mutex.h"
+
+typedef struct
+{
+ contacts_db_change_cb_with_info cb;
+ void *user_data;
+}db_callback_info_s;
+
+typedef struct
+{
+ char *view_uri;
+ GSList *callbacks;
+}subscribe_info_s;
+
+static pims_ipc_h __ipc = NULL;
+static GSList *__db_change_subscribe_list = NULL;
+
+static void __ctsvc_db_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
+{
+ unsigned int size = 0;
+ char *str = NULL;
+ subscribe_info_s *info = user_data;
+
if (data)
- str = (char*)pims_ipc_data_get(data, &size);\r
+ str = (char*)pims_ipc_data_get(data, &size);
if (!str) {
CTS_ERR("There is no changed data");
return;
- }\r
-
- if (info) {\r
- GSList *l;\r
- for (l = info->callbacks;l;l=l->next) {\r
- callback_info_s *cb_info = l->data;\r
- cb_info->cb(info->view_uri, str, cb_info->user_data);\r
- }\r
- }\r
-}\r
-\r
-int ctsvc_ipc_create_for_change_subscription()\r
-{\r
- ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
-\r
- if (!__ipc) {\r
- __ipc = pims_ipc_create_for_subscribe(CTSVC_IPC_SOCKET_PATH_FOR_CHANGE_SUBSCRIPTION);\r
- if (!__ipc) {\r
- CTS_ERR("pims_ipc_create_for_subscribe error\n");\r
- ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
- return CONTACTS_ERROR_IPC;\r
- }\r
- }\r
- ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
- return CONTACTS_ERROR_NONE;\r
-}\r
-\r
-int ctsvc_ipc_destroy_for_change_subscription()\r
-{\r
- ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
-\r
- pims_ipc_destroy_for_subscribe(__ipc);\r
- __ipc = NULL;\r
-\r
- ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
- return CONTACTS_ERROR_NONE;\r
-}\r
-\r
-API int contacts_db_add_changed_cb_with_info(const char* view_uri,\r
- contacts_db_change_cb_with_info cb, void* user_data)\r
-{\r
- GSList *it = NULL;\r
- subscribe_info_s *info = NULL;\r
- callback_info_s *cb_info;\r
-\r
- ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
-\r
- for (it=__subscribe_list;it;it=it->next) {\r
- if (!it->data) continue;\r
-\r
- info = it->data;\r
- if (strcmp(info->view_uri, view_uri) == 0)\r
- break;\r
- else\r
- info = NULL;\r
- }\r
-\r
- if (!info) {\r
- info = calloc(1, sizeof(subscribe_info_s));\r
- if (NULL == info) {\r
- CTS_ERR("calloc() Failed");\r
- ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
- return CONTACTS_ERROR_OUT_OF_MEMORY;\r
- }\r
-\r
- if (pims_ipc_subscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri,\r
- __ctsvc_subscriber_callback, (void*)info) != 0) {\r
- CTS_ERR("pims_ipc_subscribe error\n");\r
- free(info);\r
- ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
- return CONTACTS_ERROR_IPC;\r
- }\r
- info->view_uri = strdup(view_uri);\r
- __subscribe_list = g_slist_append(__subscribe_list, info);\r
- }\r
-\r
- cb_info = calloc(1, sizeof(callback_info_s));\r
- cb_info->user_data = user_data;\r
- cb_info->cb = cb;\r
- info->callbacks = g_slist_append(info->callbacks, cb_info);\r
-\r
- ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
- return CONTACTS_ERROR_NONE;\r
-}\r
-\r
-API int contacts_db_remove_changed_cb_with_info(const char* view_uri,\r
- contacts_db_change_cb_with_info cb, void* user_data)\r
-{\r
- GSList *it = NULL;\r
- subscribe_info_s *info = NULL;\r
-\r
- ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
-\r
- for (it=__subscribe_list;it;it=it->next) {\r
- if (!it->data) continue;\r
-\r
- info = it->data;\r
- if (strcmp(info->view_uri, view_uri) == 0)\r
- break;\r
- else\r
- info = NULL;\r
- }\r
-\r
- if (info) {\r
- GSList *l;\r
- for(l = info->callbacks;l;l=l->next) {\r
- callback_info_s *cb_info = l->data;\r
- if (cb == cb_info->cb && user_data == cb_info->user_data) {\r
- info->callbacks = g_slist_remove(info->callbacks, cb_info);\r
- break;\r
- }\r
- }\r
- if (g_slist_length(info->callbacks) == 0) {\r
- pims_ipc_unsubscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, info->view_uri);\r
- __subscribe_list = g_slist_remove(__subscribe_list, info);\r
- free(info->view_uri);\r
- free(info);\r
- }\r
- }\r
-\r
- ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);\r
- return CONTACTS_ERROR_NONE;\r
-}\r
-\r
+ }
+
+ if (info) {
+ GSList *l;
+ for (l = info->callbacks;l;l=l->next) {
+ db_callback_info_s *cb_info = l->data;
+ cb_info->cb(info->view_uri, str, cb_info->user_data);
+ }
+ }
+}
+
+// This API should be called in CTS_MUTEX_PIMS_IPC_PUBSUB mutex
+pims_ipc_h ctsvc_ipc_get_handle_for_change_subsciption()
+{
+ return __ipc;
+}
+
+int ctsvc_ipc_create_for_change_subscription()
+{
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ if (!__ipc) {
+ __ipc = pims_ipc_create_for_subscribe(CTSVC_IPC_SOCKET_PATH_FOR_CHANGE_SUBSCRIPTION);
+ if (!__ipc) {
+ CTS_ERR("pims_ipc_create_for_subscribe error\n");
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_IPC;
+ }
+ }
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_ipc_destroy_for_change_subscription()
+{
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ pims_ipc_destroy_for_subscribe(__ipc);
+ __ipc = NULL;
+
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
+
+API int contacts_db_add_changed_cb_with_info(const char* view_uri,
+ contacts_db_change_cb_with_info cb, void* user_data)
+{
+ GSList *it = NULL;
+ subscribe_info_s *info = NULL;
+ db_callback_info_s *cb_info;
+
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ for (it=__db_change_subscribe_list;it;it=it->next) {
+ if (!it->data) continue;
+
+ info = it->data;
+ if (strcmp(info->view_uri, view_uri) == 0)
+ break;
+ else
+ info = NULL;
+ }
+
+ if (!info) {
+ info = calloc(1, sizeof(subscribe_info_s));
+ if (NULL == info) {
+ CTS_ERR("calloc() Failed");
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (pims_ipc_subscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri,
+ __ctsvc_db_subscriber_callback, (void*)info) != 0) {
+ CTS_ERR("pims_ipc_subscribe error\n");
+ free(info);
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_IPC;
+ }
+ info->view_uri = strdup(view_uri);
+ __db_change_subscribe_list = g_slist_append(__db_change_subscribe_list, info);
+ }
+ else {
+ GSList *l;
+ for (l = info->callbacks;l;l=l->next) {
+ db_callback_info_s *cb_info = l->data;
+ if (cb_info->cb == cb && cb_info->user_data == user_data) {
+ CTS_ERR("The same callback(%s) is already exist", view_uri);
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_INVALID_PARAMETER;
+ }
+ }
+ }
+
+ cb_info = calloc(1, sizeof(db_callback_info_s));
+ cb_info->user_data = user_data;
+ cb_info->cb = cb;
+ info->callbacks = g_slist_append(info->callbacks, cb_info);
+
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
+
+API int contacts_db_remove_changed_cb_with_info(const char* view_uri,
+ contacts_db_change_cb_with_info cb, void* user_data)
+{
+ GSList *it = NULL;
+ subscribe_info_s *info = NULL;
+
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ for (it=__db_change_subscribe_list;it;it=it->next) {
+ if (!it->data) continue;
+
+ info = it->data;
+ if (strcmp(info->view_uri, view_uri) == 0)
+ break;
+ else
+ info = NULL;
+ }
+
+ if (info) {
+ GSList *l;
+ for(l = info->callbacks;l;l=l->next) {
+ db_callback_info_s *cb_info = l->data;
+ if (cb == cb_info->cb && user_data == cb_info->user_data) {
+ info->callbacks = g_slist_remove(info->callbacks, cb_info);
+ break;
+ }
+ }
+ if (g_slist_length(info->callbacks) == 0) {
+ pims_ipc_unsubscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, info->view_uri);
+ __db_change_subscribe_list = g_slist_remove(__db_change_subscribe_list, info);
+ free(info->view_uri);
+ free(info);
+ }
+ }
+
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
-/*\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_setting_get_name_display_order(contacts_name_display_order_e *name_display_order)\r
-{\r
- int ret = CONTACTS_ERROR_NONE;\r
- pims_ipc_data_h outdata = NULL;\r
-\r
- RETVM_IF(name_display_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL");\r
- *name_display_order = 0;\r
- RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
-\r
- if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_DISPLAY_ORDER, NULL, &outdata) != 0) {\r
- CTS_ERR("ctsvc_ipc_call failed");\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
- *name_display_order = *(int*) pims_ipc_data_get(outdata, &size);\r
- }\r
- pims_ipc_data_destroy(outdata);\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *name_sorting_order)\r
-{\r
- int ret = CONTACTS_ERROR_NONE;\r
- pims_ipc_data_h outdata = NULL;\r
-\r
- RETVM_IF(name_sorting_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL");\r
- *name_sorting_order = 0;\r
- RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
-\r
- if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_SORTING_ORDER, NULL, &outdata) != 0) {\r
- CTS_ERR("ctsvc_ipc_call failed");\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
- *name_sorting_order = *(int*) pims_ipc_data_get(outdata, &size);\r
- }\r
- pims_ipc_data_destroy(outdata);\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-API int contacts_setting_set_name_display_order(contacts_name_display_order_e name_display_order)\r
-{\r
- int ret = CONTACTS_ERROR_NONE;\r
- pims_ipc_data_h indata = NULL;\r
- pims_ipc_data_h outdata = NULL;\r
-\r
- RETVM_IF(name_display_order != CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST\r
- && name_display_order != CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST,\r
- CONTACTS_ERROR_INVALID_PARAMETER, "name display order is invalid : %d", name_display_order);\r
- RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
-\r
- indata = pims_ipc_data_create(0);\r
- if (indata == NULL) {\r
- CTS_ERR("ipc data created fail!");\r
- ret = CONTACTS_ERROR_OUT_OF_MEMORY;\r
- return ret;\r
- }\r
-\r
- ret = ctsvc_ipc_marshal_int(name_display_order, indata);\r
- if (ret != CONTACTS_ERROR_NONE) {\r
- CTS_ERR("marshal fail");\r
- pims_ipc_data_destroy(indata);\r
- return ret;\r
- }\r
-\r
- if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_DISPLAY_ORDER, indata, &outdata) != 0) {\r
- CTS_ERR("ctsvc_ipc_call failed");\r
- pims_ipc_data_destroy(indata);\r
- return CONTACTS_ERROR_IPC;\r
- }\r
- pims_ipc_data_destroy(indata);\r
-\r
- if (outdata) {\r
- unsigned int size = 0;\r
- ret = *(int*) pims_ipc_data_get(outdata, &size);\r
- pims_ipc_data_destroy(outdata);\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorint_order)\r
-{\r
- int ret = CONTACTS_ERROR_NONE;\r
- pims_ipc_data_h indata = NULL;\r
- pims_ipc_data_h outdata = NULL;\r
-\r
- RETVM_IF(name_sorint_order != CONTACTS_NAME_SORTING_ORDER_FIRSTLAST\r
- && name_sorint_order != CONTACTS_NAME_SORTING_ORDER_LASTFIRST,\r
- CONTACTS_ERROR_INVALID_PARAMETER, "name sorting order is invalid : %d", name_sorint_order);\r
- RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
-\r
- indata = pims_ipc_data_create(0);\r
- if (indata == NULL) {\r
- CTS_ERR("ipc data created fail!");\r
- ret = CONTACTS_ERROR_OUT_OF_MEMORY;\r
- return ret;\r
- }\r
-\r
- ret = ctsvc_ipc_marshal_int(name_sorint_order, indata);\r
- if (ret != CONTACTS_ERROR_NONE) {\r
- CTS_ERR("marshal fail");\r
- pims_ipc_data_destroy(indata);\r
- return ret;\r
- }\r
-\r
- if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_SORTING_ORDER, indata, &outdata) != 0) {\r
- CTS_ERR("ctsvc_ipc_call failed");\r
- pims_ipc_data_destroy(indata);\r
- return CONTACTS_ERROR_IPC;\r
- }\r
- pims_ipc_data_destroy(indata);\r
-\r
- if (outdata) {\r
- unsigned int size = 0;\r
- ret = *(int*) pims_ipc_data_get(outdata, &size);\r
- pims_ipc_data_destroy(outdata);\r
- }\r
-\r
- return ret;\r
-}\r
-\r
+/*
+ * 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.
+ *
+ */
+
+#include <glib.h>
+#include <pims-ipc-data.h>
+
+#include "contacts.h"
+#include "ctsvc_internal.h"
+#include "ctsvc_notify.h"
+#include "ctsvc_ipc_define.h"
+#include "ctsvc_ipc_marshal.h"
+#include "ctsvc_client_ipc.h"
+#include "ctsvc_mutex.h"
+
+API int contacts_setting_get_name_display_order(contacts_name_display_order_e *name_display_order)
+{
+ int ret = CONTACTS_ERROR_NONE;
+ pims_ipc_data_h outdata = NULL;
+
+ RETVM_IF(name_display_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL");
+ *name_display_order = 0;
+ RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
+
+ if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_DISPLAY_ORDER, NULL, &outdata) != 0) {
+ CTS_ERR("ctsvc_ipc_call failed");
+ return CONTACTS_ERROR_IPC;
+ }
+
+ if (outdata) {
+ unsigned int size = 0;
+ ret = *(int*) pims_ipc_data_get(outdata, &size);
+ if (CONTACTS_ERROR_NONE == ret) {
+ *name_display_order = *(int*) pims_ipc_data_get(outdata, &size);
+ }
+ pims_ipc_data_destroy(outdata);
+ }
+
+ return ret;
+}
+
+API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *name_sorting_order)
+{
+ int ret = CONTACTS_ERROR_NONE;
+ pims_ipc_data_h outdata = NULL;
+
+ RETVM_IF(name_sorting_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL");
+ *name_sorting_order = 0;
+ RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
+
+ if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_SORTING_ORDER, NULL, &outdata) != 0) {
+ CTS_ERR("ctsvc_ipc_call failed");
+ return CONTACTS_ERROR_IPC;
+ }
+
+ if (outdata) {
+ unsigned int size = 0;
+ ret = *(int*) pims_ipc_data_get(outdata, &size);
+ if (CONTACTS_ERROR_NONE == ret) {
+ *name_sorting_order = *(int*) pims_ipc_data_get(outdata, &size);
+ }
+ pims_ipc_data_destroy(outdata);
+ }
+
+ return ret;
+}
+
+API int contacts_setting_set_name_display_order(contacts_name_display_order_e name_display_order)
+{
+ int ret = CONTACTS_ERROR_NONE;
+ pims_ipc_data_h indata = NULL;
+ pims_ipc_data_h outdata = NULL;
+
+ RETVM_IF(name_display_order != CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST
+ && name_display_order != CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST,
+ CONTACTS_ERROR_INVALID_PARAMETER, "name display order is invalid : %d", name_display_order);
+ RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
+
+ indata = pims_ipc_data_create(0);
+ if (indata == NULL) {
+ CTS_ERR("ipc data created fail!");
+ ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+ return ret;
+ }
+
+ ret = ctsvc_ipc_marshal_int(name_display_order, indata);
+ if (ret != CONTACTS_ERROR_NONE) {
+ CTS_ERR("marshal fail");
+ pims_ipc_data_destroy(indata);
+ return ret;
+ }
+
+ if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_DISPLAY_ORDER, indata, &outdata) != 0) {
+ CTS_ERR("ctsvc_ipc_call failed");
+ pims_ipc_data_destroy(indata);
+ return CONTACTS_ERROR_IPC;
+ }
+ pims_ipc_data_destroy(indata);
+
+ if (outdata) {
+ unsigned int size = 0;
+ ret = *(int*) pims_ipc_data_get(outdata, &size);
+ pims_ipc_data_destroy(outdata);
+ }
+
+ return ret;
+}
+
+API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorint_order)
+{
+ int ret = CONTACTS_ERROR_NONE;
+ pims_ipc_data_h indata = NULL;
+ pims_ipc_data_h outdata = NULL;
+
+ RETVM_IF(name_sorint_order != CONTACTS_NAME_SORTING_ORDER_FIRSTLAST
+ && name_sorint_order != CONTACTS_NAME_SORTING_ORDER_LASTFIRST,
+ CONTACTS_ERROR_INVALID_PARAMETER, "name sorting order is invalid : %d", name_sorint_order);
+ RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
+
+ indata = pims_ipc_data_create(0);
+ if (indata == NULL) {
+ CTS_ERR("ipc data created fail!");
+ ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+ return ret;
+ }
+
+ ret = ctsvc_ipc_marshal_int(name_sorint_order, indata);
+ if (ret != CONTACTS_ERROR_NONE) {
+ CTS_ERR("marshal fail");
+ pims_ipc_data_destroy(indata);
+ return ret;
+ }
+
+ if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_SORTING_ORDER, indata, &outdata) != 0) {
+ CTS_ERR("ctsvc_ipc_call failed");
+ pims_ipc_data_destroy(indata);
+ return CONTACTS_ERROR_IPC;
+ }
+ pims_ipc_data_destroy(indata);
+
+ if (outdata) {
+ unsigned int size = 0;
+ ret = *(int*) pims_ipc_data_get(outdata, &size);
+ pims_ipc_data_destroy(outdata);
+ }
+
+ return ret;
+}
+
+typedef struct
+{
+ contacts_setting_name_display_order_changed_cb cb;
+ void *user_data;
+}ctsvc_name_display_order_changed_cb_info_s;
+
+static GSList *__setting_name_display_order_subscribe_list = NULL;
+
+static void __ctsvc_setting_name_display_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
+{
+ int value = -1;
+ unsigned int size = 0;
+ if (data)
+ value = *(int*)pims_ipc_data_get(data, &size);
+
+ if (__setting_name_display_order_subscribe_list) {
+ GSList *l;
+ for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
+ ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
+ if (cb_info->cb)
+ cb_info->cb((contacts_name_display_order_e)value, cb_info->user_data);
+ }
+ }
+}
+
+API int contacts_setting_add_name_display_order_changed_cb(
+ contacts_setting_name_display_order_changed_cb cb, void* user_data)
+{
+ GSList *l;
+ ctsvc_name_display_order_changed_cb_info_s *cb_info;
+
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ if (!__setting_name_display_order_subscribe_list) {
+ if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
+ CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED,
+ __ctsvc_setting_name_display_order_subscriber_callback, NULL) != 0) {
+ CTS_ERR("pims_ipc_subscribe error\n");
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_IPC;
+ }
+ }
+
+ for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
+ ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
+ if (cb_info->cb == cb && cb_info->user_data == user_data) {
+ CTS_ERR("The same callback(%s) is already exist");
+ return CONTACTS_ERROR_SYSTEM;
+ }
+ }
+
+ cb_info = calloc(1, sizeof(ctsvc_name_display_order_changed_cb_info_s));
+ cb_info->user_data = user_data;
+ cb_info->cb = cb;
+ __setting_name_display_order_subscribe_list = g_slist_append(__setting_name_display_order_subscribe_list, cb_info);
+
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
+
+API int contacts_setting_remove_name_display_order_changed_cb(
+ contacts_setting_name_display_order_changed_cb cb, void* user_data)
+{
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ if (__setting_name_display_order_subscribe_list) {
+ GSList *l;
+ for(l = __setting_name_display_order_subscribe_list;l;l=l->next) {
+ ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
+ if (cb == cb_info->cb && user_data == cb_info->user_data) {
+ __setting_name_display_order_subscribe_list = g_slist_remove(__setting_name_display_order_subscribe_list, cb_info);
+ free(cb_info);
+ break;
+ }
+ }
+ if (g_slist_length(__setting_name_display_order_subscribe_list) == 0) {
+ pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
+ CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED);
+ g_slist_free(__setting_name_display_order_subscribe_list);
+ __setting_name_display_order_subscribe_list = NULL;
+ }
+ }
+
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
+
+typedef struct
+{
+ contacts_setting_name_sorting_order_changed_cb cb;
+ void *user_data;
+}ctsvc_name_sorting_order_changed_cb_info_s;
+
+static GSList *__setting_name_sorting_order_subscribe_list = NULL;
+
+static void __ctsvc_setting_name_sorting_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
+{
+ int value = -1;
+ unsigned int size = 0;
+ if (data)
+ value = *(int*)pims_ipc_data_get(data, &size);
+
+ if (__setting_name_sorting_order_subscribe_list) {
+ GSList *l;
+ for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
+ ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
+ if (cb_info->cb)
+ cb_info->cb((contacts_name_sorting_order_e)value, cb_info->user_data);
+ }
+ }
+}
+
+API int contacts_setting_add_name_sorting_order_changed_cb(
+ contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
+{
+ GSList *l;
+ ctsvc_name_sorting_order_changed_cb_info_s *cb_info;
+
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ if (!__setting_name_sorting_order_subscribe_list) {
+ if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
+ CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED,
+ __ctsvc_setting_name_sorting_order_subscriber_callback, NULL) != 0) {
+ CTS_ERR("pims_ipc_subscribe error\n");
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_IPC;
+ }
+ }
+
+ for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
+ ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
+ if (cb_info->cb == cb && cb_info->user_data == user_data) {
+ CTS_ERR("The same callback(%s) is already exist");
+ return CONTACTS_ERROR_SYSTEM;
+ }
+ }
+
+ cb_info = calloc(1, sizeof(ctsvc_name_sorting_order_changed_cb_info_s));
+ cb_info->user_data = user_data;
+ cb_info->cb = cb;
+ __setting_name_sorting_order_subscribe_list = g_slist_append(__setting_name_sorting_order_subscribe_list, cb_info);
+
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
+
+API int contacts_setting_remove_name_sorting_order_changed_cb(
+ contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
+{
+ ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+ if (__setting_name_sorting_order_subscribe_list) {
+ GSList *l;
+ for(l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
+ ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
+ if (cb == cb_info->cb && user_data == cb_info->user_data) {
+ __setting_name_sorting_order_subscribe_list = g_slist_remove(__setting_name_sorting_order_subscribe_list, cb_info);
+ free(cb_info);
+ break;
+ }
+ }
+ if (g_slist_length(__setting_name_sorting_order_subscribe_list) == 0) {
+ pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
+ CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED);
+ g_slist_free(__setting_name_sorting_order_subscribe_list);
+ __setting_name_sorting_order_subscribe_list = NULL;
+ }
+ }
+
+ ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+ return CONTACTS_ERROR_NONE;
+}
+
#define CTSVC_NOTI_PHONELOG_CHANGED "/opt/usr/data/contacts-svc/.CONTACTS_SVC_PLOG_CHANGED"\r
#define CTSVC_NOTI_SPEEDDIAL_CHANGED "/opt/usr/data/contacts-svc/.CONTACTS_SVC_SPEED_CHANGED"\r
\r
+#define CTSVC_SETTING_DISPLAY_ORDER_CHANGED "contacts.setting.display_order"\r
+#define CTSVC_SETTING_SORTING_ORDER_CHANGED "contacts.setting.sorting_order"\r
\r
#endif /* __TIZEN_SOCIAL_CTSVC_NOTIFY_H__ */\r
API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorting_order);
/**
+ * @brief Called when designated view changes.
+ *
+ * @param[in] name_display_order Name display order setting value
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @see contacts_setting_add_name_display_order_changed_cb()
+ * @see contacts_setting_remove_name_display_order_changed_cb()
+ */
+typedef void (*contacts_setting_name_display_order_changed_cb)(contacts_name_display_order_e name_display_order, void* user_data);
+
+
+/**
+ * @brief Registers a callback function.
+ *
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #CONTACTS_ERROR_NONE Successful
+ * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre This function requires an open connection to the contacts service by contacts_connect2().
+ *
+ * @see contacts_connect2()
+ * @see contacts_setting_remove_name_display_order_changed_cb()
+ */
+
+API int contacts_setting_add_name_display_order_changed_cb(contacts_setting_name_display_order_changed_cb callback, void* user_data);
+
+/**
+ * @brief Unregisters a callback function.
+ *
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #CONTACTS_ERROR_NONE Successful
+ * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre This function requires an open connection to the contacts service by contacts_connect2().
+ *
+ * @see contacts_connect2()
+ * @see contacts_setting_add_name_display_order_changed_cb()
+ */
+
+API int contacts_setting_remove_name_display_order_changed_cb(contacts_setting_name_display_order_changed_cb callback, void* user_data);
+
+/**
+ * @brief Called when designated view changes.
+ *
+ * @param[in] name_sorting_order Name sorting order setting value
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @see contacts_setting_add_name_sorting_order_changed_cb()
+ * @see contacts_setting_remove_name_sorting_order_changed_cb()
+ */
+typedef void (*contacts_setting_name_sorting_order_changed_cb)(contacts_name_sorting_order_e name_sorting_order, void* user_data);
+
+
+/**
+ * @brief Registers a callback function.
+ *
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #CONTACTS_ERROR_NONE Successful
+ * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre This function requires an open connection to the contacts service by contacts_connect2().
+ *
+ * @see contacts_connect2()
+ * @see contacts_setting_remove_name_sorting_order_changed_cb()
+ */
+
+API int contacts_setting_add_name_sorting_order_changed_cb(contacts_setting_name_sorting_order_changed_cb callback, void* user_data);
+
+/**
+ * @brief Unregisters a callback function.
+ *
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #CONTACTS_ERROR_NONE Successful
+ * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre This function requires an open connection to the contacts service by contacts_connect2().
+ *
+ * @see contacts_connect2()
+ * @see contacts_setting_add_name_sorting_order_changed_cb()
+ */
+
+API int contacts_setting_remove_name_sorting_order_changed_cb(contacts_setting_name_sorting_order_changed_cb callback, void* user_data);
+
+/**
* @}
*/
#include "contacts.h"
#include "ctsvc_internal.h"
+#include "ctsvc_notify.h"
#include "ctsvc_setting.h"
#include "ctsvc_normalize.h"
#include "ctsvc_localize.h"
+#ifdef _CONTACTS_IPC_SERVER
+#include "ctsvc_server_change_subject.h"
+#endif
+
static int primary_sort = -1;
static int secondary_sort = -1;
RETVM_IF(CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST != order && CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST != order,
CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : The parameter(order:%d) is Invalid", name_display_order);
+ if (order == name_display_order)
+ return CONTACTS_ERROR_NONE;
+
ret = vconf_set_int(CTSVC_VCONF_DISPLAY_ORDER, order);
RETVM_IF(ret<0, CONTACTS_ERROR_SYSTEM, "System : vconf_set_int(display order) Failed(%d)", ret);
RETVM_IF(CONTACTS_NAME_SORTING_ORDER_FIRSTLAST != order && CONTACTS_NAME_SORTING_ORDER_LASTFIRST != order,
CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : The parameter(order:%d) is Invalid", name_sorting_order);
+ if (order == name_sorting_order)
+ return CONTACTS_ERROR_NONE;
+
ret = vconf_set_int(CTSVC_VCONF_SORTING_ORDER, order);
RETVM_IF(ret<0, CONTACTS_ERROR_SYSTEM, "System : vconf_set_int(sort order) Failed(%d)", ret);
static void ctsvc_vconf_display_order_cb(keynode_t *key, void *data)
{
name_display_order = vconf_keynode_get_int(key);
+
+#ifdef _CONTACTS_IPC_SERVER
+ // publish display order changed
+ ctsvc_change_subject_publish_setting(CTSVC_SETTING_DISPLAY_ORDER_CHANGED, name_display_order);
+#endif
}
static void ctsvc_vconf_sorting_order_cb(keynode_t *key, void *data)
{
name_sorting_order = vconf_keynode_get_int(key);
+
+#ifdef _CONTACTS_IPC_SERVER
+ // publish sort order changed
+ ctsvc_change_subject_publish_setting(CTSVC_SETTING_SORTING_ORDER_CHANGED, name_sorting_order);
+#endif
}
void ctscts_set_sort_memory(int sort_type)
return secondary_sort;
}
+#ifdef _CONTACTS_NATIVE
+API int contacts_setting_add_name_display_order_changed_cb(
+ contacts_setting_name_display_order_changed_cb cb, void* user_data)
+{
+ CTS_ERR("Please use contacts-service2 instead of contacts-service3");
+ return CONTACTS_ERROR_INTERNAL;
+}
+
+API int contacts_setting_remove_name_display_order_changed_cb(
+ contacts_setting_name_display_order_changed_cb cb, void* user_data)
+{
+ CTS_ERR("Please use contacts-service2 instead of contacts-service3");
+ return CONTACTS_ERROR_INTERNAL;
+
+}
+
+API int contacts_setting_add_name_sorting_order_changed_cb(
+ contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
+{
+ CTS_ERR("Please use contacts-service2 instead of contacts-service3");
+ return CONTACTS_ERROR_INTERNAL;
+}
+
+
+API int contacts_setting_remove_name_sorting_order_changed_cb(
+ contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
+{
+ CTS_ERR("Please use contacts-service2 instead of contacts-service3");
+ return CONTACTS_ERROR_INTERNAL;
+}
+
+#endif
-/*\r
- * Contacts Service Helper\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 <pims-ipc.h>\r
-#include <pims-ipc-svc.h>\r
-#include <pims-ipc-data.h>\r
-\r
-#include "contacts.h"\r
-#include "ctsvc_internal.h"\r
-\r
-#include "ctsvc_ipc_define.h"\r
-#include "ctsvc_server_change_subject.h"\r
-\r
-#define CTSVC_SUBSCRIBE_MAX_LEN 1024\r
-\r
-static __thread char *__phone_log_chanaged_info = NULL;\r
-static __thread unsigned int __phone_log_buf_size = 0;\r
-\r
-static __thread char *__person_changed_info = NULL;\r
-static __thread unsigned int __person_buf_size = 0;\r
-\r
-static gboolean __ctsvc_publish_changes_with_data(const char *view_uri, char *data)\r
-{\r
- pims_ipc_data_h indata = NULL;\r
- if( NULL == data )\r
- return true;\r
-\r
- indata = pims_ipc_data_create(0);\r
- if (!indata) {\r
- CTS_ERR("pims_ipc_data_create error\n");\r
- return false;\r
- }\r
-\r
- if (pims_ipc_data_put(indata, data, strlen(data) + 1) != 0) {\r
- CTS_ERR("pims_ipc_data_put error\n");\r
- return false;\r
- }\r
-\r
- if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri, indata) != 0) {\r
- CTS_ERR("pims_ipc_svc_publish error (%s)\n", view_uri);\r
- return false;\r
- }\r
-\r
- pims_ipc_data_destroy(indata);\r
-\r
- return true;\r
-}\r
-\r
-void ctsvc_change_subject_publish_changed_info()\r
-{\r
- __ctsvc_publish_changes_with_data(_contacts_person._uri, __person_changed_info);\r
- __ctsvc_publish_changes_with_data(_contacts_phone_log._uri, __phone_log_chanaged_info);\r
- ctsvc_change_subject_clear_changed_info();\r
-}\r
-\r
-void ctsvc_change_subject_clear_changed_info()\r
-{\r
- free(__phone_log_chanaged_info);\r
- __phone_log_chanaged_info = NULL;\r
- __phone_log_buf_size = 0;\r
-\r
- free(__person_changed_info);\r
- __person_changed_info = NULL;\r
- __person_buf_size = 0;\r
-}\r
-\r
-void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int id)\r
-{\r
- CTS_FN_CALL;\r
- int len = 0;\r
- int info_len = 0;\r
- char changed_info[30] = {0};\r
-\r
- if (!__phone_log_chanaged_info) {\r
- __phone_log_chanaged_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));\r
- __phone_log_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;\r
- __phone_log_chanaged_info[0] = '\0';\r
- }\r
-\r
- len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id);\r
- info_len = strlen(__phone_log_chanaged_info);\r
- CTS_DBG("%s(len : %d), %s (crrent_len : %d), max_len : %d",\r
- changed_info, len, __phone_log_chanaged_info, info_len, __phone_log_buf_size);\r
- if (info_len + len > __phone_log_buf_size) {\r
- __phone_log_chanaged_info = realloc(__phone_log_chanaged_info, __phone_log_buf_size * 2);\r
- __phone_log_buf_size *= 2;\r
- }\r
- snprintf(__phone_log_chanaged_info + info_len, __phone_log_buf_size - info_len, "%s", changed_info);\r
- CTS_DBG("%s", __phone_log_chanaged_info);\r
-}\r
-\r
-void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id)\r
-{\r
- CTS_FN_CALL;\r
- int len = 0;\r
- int info_len = 0;\r
- char changed_info[30] = {0};\r
-\r
- if (!__person_changed_info) {\r
- __person_changed_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));\r
- __person_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;\r
- __person_changed_info[0] = '\0';\r
- }\r
-\r
- len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id);\r
- info_len = strlen(__person_changed_info);\r
- if (info_len + len > __person_buf_size) {\r
- __person_changed_info = realloc(__person_changed_info, __person_buf_size * 2);\r
- __person_buf_size *= 2;\r
- }\r
- snprintf(__person_changed_info + info_len, __person_buf_size - info_len, "%s", changed_info);\r
-}\r
+/*
+ * Contacts Service Helper
+ *
+ * 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.
+ *
+ */
+
+#include <pims-ipc.h>
+#include <pims-ipc-svc.h>
+#include <pims-ipc-data.h>
+
+#include "contacts.h"
+#include "ctsvc_internal.h"
+
+#include "ctsvc_ipc_define.h"
+#include "ctsvc_server_change_subject.h"
+
+#define CTSVC_SUBSCRIBE_MAX_LEN 1024
+
+static __thread char *__phone_log_chanaged_info = NULL;
+static __thread unsigned int __phone_log_buf_size = 0;
+
+static __thread char *__person_changed_info = NULL;
+static __thread unsigned int __person_buf_size = 0;
+
+static gboolean __ctsvc_publish_changes_with_data(const char *view_uri, char *data)
+{
+ pims_ipc_data_h indata = NULL;
+ if( NULL == data )
+ return true;
+
+ indata = pims_ipc_data_create(0);
+ if (!indata) {
+ CTS_ERR("pims_ipc_data_create error\n");
+ return false;
+ }
+
+ if (pims_ipc_data_put(indata, data, strlen(data) + 1) != 0) {
+ CTS_ERR("pims_ipc_data_put error\n");
+ return false;
+ }
+
+ if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri, indata) != 0) {
+ CTS_ERR("pims_ipc_svc_publish error (%s)\n", view_uri);
+ return false;
+ }
+
+ pims_ipc_data_destroy(indata);
+
+ return true;
+}
+
+void ctsvc_change_subject_publish_changed_info()
+{
+ __ctsvc_publish_changes_with_data(_contacts_person._uri, __person_changed_info);
+ __ctsvc_publish_changes_with_data(_contacts_phone_log._uri, __phone_log_chanaged_info);
+ ctsvc_change_subject_clear_changed_info();
+}
+
+void ctsvc_change_subject_clear_changed_info()
+{
+ free(__phone_log_chanaged_info);
+ __phone_log_chanaged_info = NULL;
+ __phone_log_buf_size = 0;
+
+ free(__person_changed_info);
+ __person_changed_info = NULL;
+ __person_buf_size = 0;
+}
+
+void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int id)
+{
+ CTS_FN_CALL;
+ int len = 0;
+ int info_len = 0;
+ char changed_info[30] = {0};
+
+ if (!__phone_log_chanaged_info) {
+ __phone_log_chanaged_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));
+ __phone_log_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;
+ __phone_log_chanaged_info[0] = '\0';
+ }
+
+ len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id);
+ info_len = strlen(__phone_log_chanaged_info);
+ CTS_DBG("%s(len : %d), %s (crrent_len : %d), max_len : %d",
+ changed_info, len, __phone_log_chanaged_info, info_len, __phone_log_buf_size);
+ if (info_len + len > __phone_log_buf_size) {
+ __phone_log_chanaged_info = realloc(__phone_log_chanaged_info, __phone_log_buf_size * 2);
+ __phone_log_buf_size *= 2;
+ }
+ snprintf(__phone_log_chanaged_info + info_len, __phone_log_buf_size - info_len, "%s", changed_info);
+ CTS_DBG("%s", __phone_log_chanaged_info);
+}
+
+void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id)
+{
+ CTS_FN_CALL;
+ int len = 0;
+ int info_len = 0;
+ char changed_info[30] = {0};
+
+ if (!__person_changed_info) {
+ __person_changed_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));
+ __person_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;
+ __person_changed_info[0] = '\0';
+ }
+
+ len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id);
+ info_len = strlen(__person_changed_info);
+ if (info_len + len > __person_buf_size) {
+ __person_changed_info = realloc(__person_changed_info, __person_buf_size * 2);
+ __person_buf_size *= 2;
+ }
+ snprintf(__person_changed_info + info_len, __person_buf_size - info_len, "%s", changed_info);
+}
+
+void ctsvc_change_subject_publish_setting(const char *setting_id, int value)
+{
+ pims_ipc_data_h indata = NULL;
+ indata = pims_ipc_data_create(0);
+ RETM_IF(NULL == indata, "pims_ipc_data_create error");
+
+ if (pims_ipc_data_put(indata, (void*)&value, sizeof(int)) != 0) {
+ CTS_ERR("pims_ipc_data_put error");
+ pims_ipc_data_destroy(indata);
+ return;
+ }
+
+ if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)setting_id, indata) != 0)
+ CTS_ERR("pims_ipc_svc_publish error (%s)", setting_id);
+
+ pims_ipc_data_destroy(indata);
+}
/*\r
- * Contacts Service Helper\r
+ * Contacts Service\r
*\r
* Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
*\r
void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int id);\r
void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id);\r
\r
-#endif // __CTSVC_SERVER_CHANGE_SUBJECT_H__
\ No newline at end of file
+void ctsvc_change_subject_publish_setting(const char *setting_id, int value);\r
+\r
+#endif // __CTSVC_SERVER_CHANGE_SUBJECT_H__\r