4 * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <pims-ipc-svc.h>
22 #include <pims-ipc-data.h>
25 #include "ctsvc_internal.h"
26 #include "ctsvc_ipc_define.h"
27 #include "ctsvc_ipc_marshal.h"
28 #include "ctsvc_server_change_subject.h"
30 #define CTSVC_SUBSCRIBE_MAX_LEN 1024
32 #ifdef ENABLE_LOG_FEATURE
33 static __thread char *__phone_log_chanaged_info = NULL;
34 static __thread unsigned int __phone_log_buf_size = 0;
35 #endif /* ENABLE_LOG_FEATURE */
37 static __thread char *__person_changed_info = NULL;
38 static __thread unsigned int __person_buf_size = 0;
40 static gboolean __ctsvc_publish_changes_with_data(const char *view_uri, char *data)
42 pims_ipc_data_h indata = NULL;
46 indata = pims_ipc_data_create(0);
48 CTS_ERR("pims_ipc_data_create error\n");
52 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_string(data, indata)) {
53 CTS_ERR("ctsvc_ipc_marshal_string() Fail");
54 pims_ipc_data_destroy(indata);
58 if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri, indata) != 0) {
59 CTS_ERR("pims_ipc_svc_publish error (%s)\n", view_uri);
63 pims_ipc_data_destroy(indata);
68 void ctsvc_change_subject_publish_changed_info()
70 __ctsvc_publish_changes_with_data(_contacts_person._uri, __person_changed_info);
71 #ifdef ENABLE_LOG_FEATURE
72 __ctsvc_publish_changes_with_data(_contacts_phone_log._uri, __phone_log_chanaged_info);
73 #endif /* ENABLE_LOG_FEATURE */
74 ctsvc_change_subject_clear_changed_info();
77 void ctsvc_change_subject_clear_changed_info()
79 #ifdef ENABLE_LOG_FEATURE
80 free(__phone_log_chanaged_info);
81 __phone_log_chanaged_info = NULL;
82 __phone_log_buf_size = 0;
83 #endif /* ENABLE_LOG_FEATURE */
85 free(__person_changed_info);
86 __person_changed_info = NULL;
87 __person_buf_size = 0;
90 #ifdef ENABLE_LOG_FEATURE
91 void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int id)
96 char changed_info[30] = {0};
98 if (NULL == __phone_log_chanaged_info) {
99 __phone_log_chanaged_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));
100 __phone_log_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;
101 __phone_log_chanaged_info[0] = '\0';
104 info_len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id);
105 cur_len = strlen(__phone_log_chanaged_info);
106 CTS_DBG("%s(info_len : %d), %s(crrent_len : %d), max_len : %u",
107 changed_info, info_len, __phone_log_chanaged_info, cur_len, __phone_log_buf_size);
109 if (__phone_log_buf_size <= (cur_len + info_len)) {
110 __phone_log_buf_size *= 2;
111 __phone_log_chanaged_info = realloc(__phone_log_chanaged_info, __phone_log_buf_size);
113 snprintf(__phone_log_chanaged_info + cur_len, __phone_log_buf_size - cur_len, "%s", changed_info);
114 CTS_DBG("%s", __phone_log_chanaged_info);
116 #endif /* ENABLE_LOG_FEATURE */
118 void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id)
123 char changed_info[30] = {0};
125 if (NULL == __person_changed_info) {
126 __person_changed_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));
127 __person_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;
128 __person_changed_info[0] = '\0';
131 info_len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id);
132 cur_len = strlen(__person_changed_info);
133 CTS_DBG("%s(info_len : %d), %s(crrent_len : %d), max_len : %u",
134 changed_info, info_len, __person_changed_info, cur_len, __person_buf_size);
136 if (__person_buf_size <= (cur_len + info_len)) {
137 __person_buf_size *= 2;
138 __person_changed_info = realloc(__person_changed_info, __person_buf_size);
140 snprintf(__person_changed_info + cur_len, __person_buf_size - cur_len, "%s", changed_info);
143 void ctsvc_change_subject_publish_setting(const char *setting_id, int value)
145 pims_ipc_data_h indata = NULL;
146 indata = pims_ipc_data_create(0);
147 RETM_IF(NULL == indata, "pims_ipc_data_create() Fail");
149 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(value, indata)) {
150 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
151 pims_ipc_data_destroy(indata);
155 if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)setting_id, indata) != 0)
156 CTS_ERR("pims_ipc_svc_publish error (%s)", setting_id);
158 pims_ipc_data_destroy(indata);
161 void ctsvc_change_subject_publish_status(contacts_db_status_e status)
163 pims_ipc_data_h indata = NULL;
164 indata = pims_ipc_data_create(0);
165 RETM_IF(NULL == indata, "pims_ipc_data_create() Fail");
167 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(status, indata)) {
168 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
169 pims_ipc_data_destroy(indata);
173 if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED, indata) != 0)
174 CTS_ERR("pims_ipc_svc_publish error(service status)");
176 pims_ipc_data_destroy(indata);