4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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.
26 #include <dbus/dbus-glib.h>
29 #include <sys/types.h>
35 #include <TapiUtility.h>
38 #include "bluetooth_pb_agent.h"
39 #include "bluetooth_pb_vcard.h"
41 #define BLUETOOTH_PB_AGENT_TIMEOUT 600
43 static gchar *bluetooth_pb_agent_folder_list[] = {
67 TapiHandle *tapi_handle;
70 GHashTable *contact_list;
74 PhoneBookType pb_type;
80 void (*clear) (BluetoothPbAgent *agent);
81 } BluetoothPbAgentClass;
88 GType bluetooth_pb_agent_get_type(void);
90 #define BLUETOOTH_PB_TYPE_AGENT (bluetooth_pb_agent_get_type())
92 #define BLUETOOTH_PB_AGENT(object) \
93 (G_TYPE_CHECK_INSTANCE_CAST((object), \
94 BLUETOOTH_PB_TYPE_AGENT , BluetoothPbAgent))
95 #define BLUETOOTH_PB_AGENT_CLASS(klass) \
96 (G_TYPE_CHECK_CLASS_CAST((klass), \
97 BLUETOOTH_PB_TYPE_AGENT , BluetoothPbAgentClass))
98 #define BLUETOOTH_IS_PB_AGENT(object) \
99 (G_TYPE_CHECK_INSTANCE_TYPE((object), \
100 BLUETOOTH_PB_TYPE_AGENT))
101 #define BLUETOOTH_IS_PB_AGENT_CLASS(klass) \
102 (G_TYPE_CHECK_CLASS_TYPE((klass), \
103 BLUETOOTH_PB_TYPE_AGENT))
104 #define BLUETOOTH_PB_AGENT_GET_CLASS(obj) \
105 (G_TYPE_INSTANCE_GET_CLASS((obj), \
106 BLUETOOTH_PB_TYPE_AGENT , BluetoothPbAgentClass))
108 G_DEFINE_TYPE(BluetoothPbAgent, bluetooth_pb_agent, G_TYPE_OBJECT)
110 #define DBUS_STRUCT_STRING_STRING_UINT (dbus_g_type_get_struct("GValueArray", G_TYPE_STRING, \
111 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))
113 static guint signals[LAST_SIGNAL] = { 0 };
115 static GMainLoop *mainloop = NULL;
117 static void bluetooth_pb_agent_finalize(GObject *obj);
119 static void bluetooth_pb_agent_clear(BluetoothPbAgent *agent);
122 static gboolean bluetooth_pb_get_phonebook_folder_list(BluetoothPbAgent *agent,
123 const gchar ***folder_list,
126 static gboolean bluetooth_pb_get_phonebook(BluetoothPbAgent *agent,
130 guint16 max_list_count,
131 guint16 list_start_offset,
132 DBusGMethodInvocation *context);
134 static gboolean bluetooth_pb_get_phonebook_size(BluetoothPbAgent *agent,
136 DBusGMethodInvocation *context);
138 static gboolean bluetooth_pb_get_phonebook_list(BluetoothPbAgent *agent,
140 DBusGMethodInvocation *context);
142 static gboolean bluetooth_pb_get_phonebook_entry(BluetoothPbAgent *agent,
147 DBusGMethodInvocation *context);
149 static gboolean bluetooth_pb_get_phonebook_size_at(BluetoothPbAgent *agent,
150 const gchar *command,
151 DBusGMethodInvocation *context);
153 static gboolean bluetooth_pb_get_phonebook_entries_at(BluetoothPbAgent *agent,
154 const gchar *command,
157 DBusGMethodInvocation *context);
159 static gboolean bluetooth_pb_get_phonebook_entries_find_at(BluetoothPbAgent *agent,
160 const gchar *command,
161 const gchar *find_text,
162 DBusGMethodInvocation *context);
164 static gboolean bluetooth_pb_get_total_object_count(BluetoothPbAgent *agent,
166 DBusGMethodInvocation *context);
168 static gboolean bluetooth_pb_add_contact (BluetoothPbAgent *agent,
169 const char *filename,
172 static void __bluetooth_pb_dbus_return_error(DBusGMethodInvocation *context,
174 const gchar *message);
176 static PhoneBookType __bluetooth_pb_get_pb_type(const char *name);
178 static PhoneBookType __bluetooth_pb_get_storage_pb_type(const char *name);
180 static gint __bluetooth_pb_phone_log_filter_append(contacts_filter_h filter,
184 static contacts_query_h __bluetooth_pb_query_phone_log(gint *match,
187 static contacts_query_h __bluetooth_pb_query_person(void);
189 static contacts_query_h __bluetooth_pb_query_person_number(void);
191 static contacts_query_h __bluetooth_pb_query_phone_log_incoming(void);
193 static contacts_query_h __bluetooth_pb_query_phone_log_outgoing(void);
195 static contacts_query_h __bluetooth_pb_query_phone_log_missed(void);
197 static contacts_query_h __bluetooth_pb_query_phone_log_combined(void);
199 static gboolean __bluetooth_pb_get_count(PhoneBookType pb_type,
202 static gboolean __bluetooth_pb_get_count_new_missed_call(guint *count);
204 static const char *__bluetooth_pb_phone_log_get_log_type(contacts_record_h record);
206 static void __bluetooth_pb_get_vcards(BluetoothPbAgent *agent,
207 PhoneBookType pb_type,
210 guint16 max_list_count,
211 guint16 list_start_offset,
214 static void __bluetooth_pb_get_contact_list(BluetoothPbAgent *agent,
215 contacts_query_h query,
216 GPtrArray *ptr_array);
218 static void __bluetooth_pb_get_phone_log_list(BluetoothPbAgent *agent,
219 contacts_query_h query,
220 GPtrArray *ptr_array);
222 static void __bluetooth_pb_get_list(BluetoothPbAgent *agent,
223 PhoneBookType pb_type,
224 GPtrArray *ptr_array);
226 static void __bluetooth_pb_get_contact_list_number(BluetoothPbAgent *agent,
227 contacts_query_h query,
230 GPtrArray *ptr_array);
232 static void __bluetooth_pb_get_phone_log_list_number(BluetoothPbAgent *agent,
233 contacts_query_h query,
236 GPtrArray *ptr_array);
238 static void __bluetooth_pb_get_list_number(BluetoothPbAgent *agent,
239 PhoneBookType pb_type,
242 GPtrArray *ptr_array);
244 static void __bluetooth_pb_get_contact_list_name(BluetoothPbAgent *agent,
245 contacts_query_h query,
246 const gchar *find_text,
247 GPtrArray *ptr_array);
249 static void __bluetooth_pb_get_phone_log_list_name(BluetoothPbAgent *agent,
250 contacts_query_h query,
251 const gchar *find_text,
252 GPtrArray *ptr_array);
254 static void __bluetooth_pb_get_list_name(BluetoothPbAgent *agent,
255 PhoneBookType pb_type,
256 const gchar *find_text,
257 GPtrArray *ptr_array);
259 static void __bluetooth_pb_list_hash_reset(BluetoothPbAgent *agent);
261 static gboolean __bluetooth_pb_list_hash_insert(BluetoothPbAgent *agent,
265 static gint __bluetooth_pb_list_hash_lookup_id(BluetoothPbAgent *agent,
268 static void __bluetooth_pb_list_ptr_array_add(GPtrArray *ptr_array,
273 static void __bluetooth_pb_list_ptr_array_free(gpointer data);
275 static void __bluetooth_pb_agent_signal_handler(int signum);
277 static void __bluetooth_pb_contact_changed(const gchar *view_uri,
280 static void __bluetooth_pb_agent_timeout_add_seconds(BluetoothPbAgent *agent);
282 static gboolean __bluetooth_pb_agent_timeout_calback(gpointer user_data);
284 static void __bluetooth_pb_tel_callback(TapiHandle *handle,
289 static void __bluetooth_pb_agent_dbus_init(BluetoothPbAgent *agent);
291 #include "bluetooth_pb_agent_glue.h"
293 static void bluetooth_pb_agent_init(BluetoothPbAgent *agent)
298 agent->tapi_handle = NULL;
299 agent->tel_number = NULL;
301 agent->contact_list = NULL;
302 agent->timeout_id = 0;
304 agent->pb_type = TELECOM_NONE;
307 static void bluetooth_pb_agent_class_init(BluetoothPbAgentClass *klass)
309 GObjectClass *object_class = (GObjectClass *) klass;
311 klass->clear = bluetooth_pb_agent_clear;
313 object_class->finalize = bluetooth_pb_agent_finalize;
315 signals[CLEAR] = g_signal_new("clear",
316 G_TYPE_FROM_CLASS(klass),
318 G_STRUCT_OFFSET(BluetoothPbAgentClass, clear),
320 g_cclosure_marshal_VOID__VOID,
323 dbus_g_object_type_install_info(BLUETOOTH_PB_TYPE_AGENT,
324 &dbus_glib_bluetooth_pb_object_info);
327 static void bluetooth_pb_agent_finalize(GObject *obj)
329 BluetoothPbAgent *agent = BLUETOOTH_PB_AGENT(obj);
333 if (agent->tapi_handle) {
334 tel_deinit(agent->tapi_handle);
335 agent->tapi_handle = NULL;
338 if (agent->tel_number) {
339 g_free(agent->tel_number);
340 agent->tel_number = NULL;
343 if(agent->timeout_id) {
344 g_source_remove(agent->timeout_id);
345 agent->timeout_id = 0;
348 if (agent->contact_list) {
349 g_hash_table_destroy(agent->contact_list);
350 agent->contact_list = NULL;
354 g_object_unref(agent->proxy);
359 dbus_g_connection_unref(agent->bus);
364 G_OBJECT_CLASS(bluetooth_pb_agent_parent_class)->finalize(obj);
367 static void bluetooth_pb_agent_clear(BluetoothPbAgent *agent)
371 if (agent->contact_list) {
372 g_hash_table_destroy(agent->contact_list);
373 agent->contact_list = NULL;
376 agent->pb_type = TELECOM_NONE;
379 static gboolean bluetooth_pb_get_phonebook_folder_list(BluetoothPbAgent *agent,
380 const gchar ***folder_list,
387 size = G_N_ELEMENTS(bluetooth_pb_agent_folder_list);
388 folder = g_new0(gchar *, size);
390 for (i = 0; i < size; i++)
391 folder[i] = g_strdup(bluetooth_pb_agent_folder_list[i]);
393 *folder_list = (const gchar **)folder;
398 static gboolean bluetooth_pb_get_phonebook(BluetoothPbAgent *agent,
402 guint16 max_list_count,
403 guint16 list_start_offset,
404 DBusGMethodInvocation *context)
406 PhoneBookType pb_type = TELECOM_NONE;
407 GPtrArray *vcards = NULL;
408 gchar **vcards_str = NULL;
410 guint new_missed_call = 0;
412 DBG("name: %s filter: %lld format: %d max_list_count: %d list_start_offset: %d\n",
413 name, filter, format, max_list_count, list_start_offset);
415 __bluetooth_pb_agent_timeout_add_seconds(agent);
417 pb_type = __bluetooth_pb_get_pb_type(name);
419 if (pb_type == TELECOM_NONE) {
420 __bluetooth_pb_dbus_return_error(context,
422 "unsupported name defined");
426 vcards = g_ptr_array_new();
428 if (max_list_count > 0) {
429 __bluetooth_pb_get_vcards(agent, pb_type,
431 max_list_count, list_start_offset,
436 g_ptr_array_add(vcards, NULL);
438 vcards_str = (gchar **) g_ptr_array_free(vcards, FALSE);
440 dbus_g_method_return(context, vcards_str, new_missed_call);
442 g_strfreev(vcards_str);
447 static gboolean bluetooth_pb_get_phonebook_size(BluetoothPbAgent *agent,
449 DBusGMethodInvocation *context)
451 PhoneBookType pb_type = TELECOM_NONE;
453 guint new_missed_call = 0;
456 DBG("name: %s\n", name);
458 __bluetooth_pb_agent_timeout_add_seconds(agent);
460 pb_type = __bluetooth_pb_get_pb_type(name);
462 if (__bluetooth_pb_get_count(pb_type, &count) == FALSE) {
463 __bluetooth_pb_dbus_return_error(context,
465 "unsupported name defined");
470 if (pb_type == TELECOM_PB)
473 __bluetooth_pb_get_count_new_missed_call(&new_missed_call);
475 dbus_g_method_return(context, count, new_missed_call);
481 static gboolean bluetooth_pb_get_phonebook_list(BluetoothPbAgent *agent,
483 DBusGMethodInvocation *context)
485 PhoneBookType pb_type = TELECOM_NONE;
487 GPtrArray *ptr_array;
489 DBG("name: %s\n", name);
491 __bluetooth_pb_agent_timeout_add_seconds(agent);
493 pb_type = __bluetooth_pb_get_pb_type(name);
495 if (pb_type == TELECOM_NONE) {
496 __bluetooth_pb_dbus_return_error(context,
498 "unsupported name defined");
502 ptr_array = g_ptr_array_new_with_free_func(__bluetooth_pb_list_ptr_array_free);
504 __bluetooth_pb_get_list(agent, pb_type, ptr_array);
506 dbus_g_method_return(context, ptr_array);
509 g_ptr_array_free(ptr_array, TRUE);
515 static gboolean bluetooth_pb_get_phonebook_entry(BluetoothPbAgent *agent,
520 DBusGMethodInvocation *context)
522 PhoneBookType pb_type = TELECOM_NONE;
528 const gchar *attr = NULL;
530 DBG("folder: %s id: %s filter: %ld format: %d\n",
531 folder, id, filter, format);
533 __bluetooth_pb_agent_timeout_add_seconds(agent);
535 if (!g_str_has_suffix(id, ".vcf")) {
536 __bluetooth_pb_dbus_return_error(context,
542 handle = (gint)g_ascii_strtoll(id, NULL, 10);
544 pb_type = __bluetooth_pb_get_pb_type(folder);
546 if (pb_type == TELECOM_NONE) {
547 __bluetooth_pb_dbus_return_error(context,
549 "unsupported name defined");
553 /* create index cache */
554 __bluetooth_pb_get_list(agent, pb_type, NULL);
556 cid = __bluetooth_pb_list_hash_lookup_id(agent, handle);
561 str = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
564 str = _bluetooth_pb_vcard_contact(cid, filter, format);
568 str = _bluetooth_pb_vcard_call(cid, filter, format, "RECEIVED");
571 str = _bluetooth_pb_vcard_call(cid, filter, format, "DIALED");
574 str = _bluetooth_pb_vcard_call(cid, filter, format, "MISSED");
577 contacts_record_h record = NULL;
581 status = contacts_db_get_record(_contacts_phone_log._uri,
584 if (status != CONTACTS_ERROR_NONE)
587 attr = __bluetooth_pb_phone_log_get_log_type(record);
588 str = _bluetooth_pb_vcard_call(cid, filter, format, attr);
590 contacts_record_destroy(record, TRUE);
594 __bluetooth_pb_dbus_return_error(context,
596 "unsupported name defined");
600 dbus_g_method_return(context, str);
606 static gboolean bluetooth_pb_get_phonebook_size_at(BluetoothPbAgent *agent,
607 const gchar *command,
608 DBusGMethodInvocation *context)
610 PhoneBookType pb_type = TELECOM_NONE;
613 DBG("command: %s\n", command);
615 __bluetooth_pb_agent_timeout_add_seconds(agent);
617 pb_type = __bluetooth_pb_get_storage_pb_type(command);
619 if (__bluetooth_pb_get_count(pb_type, &count) == FALSE) {
620 __bluetooth_pb_dbus_return_error(context,
622 "unsupported name defined");
626 dbus_g_method_return(context, count);
631 static gboolean bluetooth_pb_get_phonebook_entries_at(BluetoothPbAgent *agent,
632 const gchar *command,
635 DBusGMethodInvocation *context)
637 PhoneBookType pb_type = TELECOM_NONE;
639 GPtrArray *ptr_array = NULL;
641 DBG("command: %s, start_index: %d, end_index: %d\n",
642 command, start_index, end_index);
644 __bluetooth_pb_agent_timeout_add_seconds(agent);
646 pb_type = __bluetooth_pb_get_storage_pb_type(command);
648 if (pb_type == TELECOM_NONE || pb_type == TELECOM_CCH) {
649 __bluetooth_pb_dbus_return_error(context,
651 "unsupported name defined");
655 ptr_array = g_ptr_array_new_with_free_func(__bluetooth_pb_list_ptr_array_free);
657 __bluetooth_pb_get_list_number(agent, pb_type,
658 start_index, end_index,
661 dbus_g_method_return(context, ptr_array);
664 g_ptr_array_free(ptr_array, TRUE);
669 static gboolean bluetooth_pb_get_phonebook_entries_find_at(BluetoothPbAgent *agent,
670 const gchar *command,
671 const gchar *find_text,
672 DBusGMethodInvocation *context)
674 PhoneBookType pb_type = TELECOM_NONE;
676 GPtrArray *ptr_array = NULL;
678 DBG("command: %s, find text: %s\n", command, find_text);
680 __bluetooth_pb_agent_timeout_add_seconds(agent);
682 pb_type = __bluetooth_pb_get_storage_pb_type(command);
684 if (pb_type == TELECOM_NONE || pb_type == TELECOM_CCH) {
685 __bluetooth_pb_dbus_return_error(context,
687 "unsupported name defined");
691 ptr_array = g_ptr_array_new_with_free_func(__bluetooth_pb_list_ptr_array_free);
693 __bluetooth_pb_get_list_name(agent, pb_type,
694 find_text, ptr_array);
696 dbus_g_method_return(context, ptr_array);
699 g_ptr_array_free(ptr_array, TRUE);
704 static gboolean bluetooth_pb_get_total_object_count(BluetoothPbAgent *agent,
705 gchar *path, DBusGMethodInvocation *context)
708 PhoneBookType pb_type = TELECOM_NONE;
710 DBG("%s() %d\n", __FUNCTION__, __LINE__);
712 __bluetooth_pb_agent_timeout_add_seconds(agent);
714 pb_type = __bluetooth_pb_get_storage_pb_type(path);
716 if (__bluetooth_pb_get_count(pb_type, &count) == FALSE) {
717 __bluetooth_pb_dbus_return_error(context,
719 "unsupported name defined");
723 dbus_g_method_return(context, count);
725 DBG("%s() %d\n", __FUNCTION__, __LINE__);
732 static int __bluetooth_pb_agent_read_file(const char *file_path, char **stream)
736 int received_file_size = 0;
737 struct stat file_attr;
739 if (file_path == NULL || stream == NULL) {
740 DBG("Invalid data \n");
744 DBG("file_path = %s\n", file_path);
746 if ((fp = fopen(file_path, "r+")) == NULL) {
747 DBG("Cannot open %s\n", file_path);
751 if (fstat(fileno(fp), &file_attr) == 0) {
752 received_file_size = file_attr.st_size;
753 DBG("file_attr.st_size = %d, size = %d\n", file_attr.st_size, received_file_size);
755 if (received_file_size <= 0) {
756 DBG("Some problem in the file size [%s] \n", file_path);
762 *stream = (char *)malloc(sizeof(char) * received_file_size);
763 if (NULL == *stream) {
769 DBG("Some problem in the file [%s] \n", file_path);
775 read_len = fread(*stream, 1, received_file_size, fp);
782 DBG("Cannot open %s\n", file_path);
794 static gboolean bluetooth_pb_add_contact(BluetoothPbAgent *agent, const char *filename,
797 /* Contact API is changed, Temporary blocked */
799 CTSstruct *contact_record = NULL;
800 GSList *numbers_list = NULL, *cursor;
802 int is_duplicated = 0;
806 DBG("file_path = %s\n", filename);
808 err = contacts_svc_connect();
809 DBG("contact_db_service_connect fucntion call [error] = %d \n", err);
811 err = __bluetooth_pb_agent_read_file(filename, &stream);
814 contacts_svc_disconnect();
815 DBG("contacts_svc_disconnect fucntion call [error] = %d \n", err);
817 if (NULL != stream) {
824 is_success = contacts_svc_get_contact_from_vcard((const void *)stream, &contact_record);
826 DBG("contacts_svc_get_contact_from_vcard fucntion call [is_success] = %d \n", is_success);
828 if (0 == is_success) {
829 contacts_svc_struct_get_list(contact_record, CTS_CF_NUMBER_LIST, &numbers_list);
830 cursor = numbers_list;
832 for (; cursor; cursor = g_slist_next(cursor)) {
833 if (contacts_svc_find_contact_by(CTS_FIND_BY_NUMBER,
834 contacts_svc_value_get_str(cursor->data,
835 CTS_NUM_VAL_NUMBER_STR)) > 0) {
836 DBG("is_duplicated\n");
837 is_duplicated = TRUE;
841 if (is_duplicated == FALSE) {
842 contacts_svc_insert_contact(0, contact_record);
848 err = contacts_svc_disconnect();
849 DBG("contacts_svc_disconnect fucntion call [error] = %d \n", err);
851 if (NULL != stream) {
860 static void __bluetooth_pb_dbus_return_error(DBusGMethodInvocation *context,
862 const gchar *message)
865 GError *error = NULL;
867 quark = g_type_qname(bluetooth_pb_agent_get_type());
868 error = g_error_new_literal(quark, code, message);
870 DBG("%s\n", message);
872 dbus_g_method_return_error(context, error);
876 static PhoneBookType __bluetooth_pb_get_pb_type(const char *name)
878 gchar *suffix = ".vcf";
888 if (g_str_has_suffix(name, suffix))
889 len -= strlen(suffix);
891 size = G_N_ELEMENTS(bluetooth_pb_agent_folder_list) - 1;
892 for (i = 0; i < size; i++) {
893 if (strncmp(name, bluetooth_pb_agent_folder_list[i], len) == 0)
900 static PhoneBookType __bluetooth_pb_get_storage_pb_type(const char *name)
905 if (g_strcmp0(name, "\"ME\"") == 0 )
908 if (g_strcmp0(name, "\"RC\"") == 0)
911 if (g_strcmp0(name, "\"DC\"") == 0)
914 if (g_strcmp0(name, "\"MC\"") == 0)
920 static gint __bluetooth_pb_phone_log_filter_append(contacts_filter_h filter,
927 for (i = 0; i < size; i++) {
930 status = contacts_filter_add_operator(filter,
931 CONTACTS_FILTER_OPERATOR_OR);
933 if (status != CONTACTS_ERROR_NONE)
937 status = contacts_filter_add_int(filter,
938 _contacts_phone_log.log_type,
939 CONTACTS_MATCH_EQUAL,
942 if (status != CONTACTS_ERROR_NONE)
946 return CONTACTS_ERROR_NONE;
949 static contacts_query_h __bluetooth_pb_query_phone_log(gint *match,
952 contacts_query_h query = NULL;
953 contacts_filter_h filter = NULL;
957 status = contacts_query_create(_contacts_phone_log._uri,
960 if (status != CONTACTS_ERROR_NONE)
963 status = contacts_filter_create(_contacts_phone_log._uri, &filter);
965 if (status != CONTACTS_ERROR_NONE) {
966 contacts_query_destroy(query);
970 status = __bluetooth_pb_phone_log_filter_append(filter, match, size);
972 if (status != CONTACTS_ERROR_NONE) {
973 contacts_filter_destroy(filter);
974 contacts_query_destroy(query);
978 status = contacts_query_set_filter(query, filter);
980 if (status != CONTACTS_ERROR_NONE) {
981 contacts_filter_destroy(filter);
982 contacts_query_destroy(query);
986 status = contacts_query_set_sort(query,
987 _contacts_phone_log.log_time,
990 if (status != CONTACTS_ERROR_NONE) {
991 contacts_filter_destroy(filter);
992 contacts_query_destroy(query);
996 contacts_filter_destroy(filter);
1001 static contacts_query_h __bluetooth_pb_query_person(void)
1003 contacts_query_h query = NULL;
1007 status = contacts_query_create(_contacts_person._uri,
1010 if (status != CONTACTS_ERROR_NONE)
1016 static contacts_query_h __bluetooth_pb_query_person_number(void)
1018 contacts_query_h query = NULL;
1022 status = contacts_query_create(_contacts_person_number._uri,
1025 if (status != CONTACTS_ERROR_NONE)
1031 static contacts_query_h __bluetooth_pb_query_phone_log_incoming(void)
1035 CONTACTS_PLOG_TYPE_VOICE_INCOMMING,
1036 CONTACTS_PLOG_TYPE_VIDEO_INCOMMING
1039 return __bluetooth_pb_query_phone_log(match, size);
1042 static contacts_query_h __bluetooth_pb_query_phone_log_outgoing(void)
1046 CONTACTS_PLOG_TYPE_VOICE_OUTGOING,
1047 CONTACTS_PLOG_TYPE_VIDEO_OUTGOING
1050 return __bluetooth_pb_query_phone_log(match, size);
1054 static contacts_query_h __bluetooth_pb_query_phone_log_missed(void)
1058 CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN,
1059 CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN,
1060 CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN,
1061 CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN
1064 return __bluetooth_pb_query_phone_log(match, size);
1067 static contacts_query_h __bluetooth_pb_query_phone_log_combined(void)
1071 CONTACTS_PLOG_TYPE_VOICE_INCOMMING,
1072 CONTACTS_PLOG_TYPE_VIDEO_INCOMMING,
1073 CONTACTS_PLOG_TYPE_VOICE_OUTGOING,
1074 CONTACTS_PLOG_TYPE_VIDEO_OUTGOING,
1075 CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN,
1076 CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN,
1077 CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN,
1078 CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN
1081 return __bluetooth_pb_query_phone_log(match, size);
1084 static gboolean __bluetooth_pb_get_count(PhoneBookType pb_type,
1087 contacts_query_h query = NULL;
1094 query = __bluetooth_pb_query_person();
1097 query = __bluetooth_pb_query_phone_log_incoming();
1100 query = __bluetooth_pb_query_phone_log_outgoing();
1103 query = __bluetooth_pb_query_phone_log_missed();
1106 query = __bluetooth_pb_query_phone_log_combined();
1115 status = contacts_db_get_count_with_query(query, &signed_count);
1117 if (status != CONTACTS_ERROR_NONE) {
1118 contacts_query_destroy(query);
1122 contacts_query_destroy(query);
1124 if (signed_count < 0)
1127 *count = (gint) signed_count;
1132 static gboolean __bluetooth_pb_get_count_new_missed_call(guint *count)
1134 contacts_query_h query = NULL;
1141 CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN,
1142 CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN
1145 query = __bluetooth_pb_query_phone_log(match, size);
1150 status = contacts_db_get_count_with_query(query, &signed_count);
1152 if (status != CONTACTS_ERROR_NONE) {
1153 contacts_query_destroy(query);
1157 contacts_query_destroy(query);
1159 if (signed_count < 0)
1162 *count = (guint)signed_count;
1167 static const char *__bluetooth_pb_phone_log_get_log_type(contacts_record_h record)
1172 status = contacts_record_get_int(record,
1173 _contacts_phone_log.log_type,
1176 if (status != CONTACTS_ERROR_NONE)
1180 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING:
1181 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING:
1183 case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
1184 case CONTACTS_PLOG_TYPE_VIDEO_OUTGOING:
1186 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
1187 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
1188 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
1189 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
1196 static void __bluetooth_pb_get_vcards(BluetoothPbAgent *agent,
1197 PhoneBookType pb_type,
1200 guint16 max_list_count,
1201 guint16 list_start_offset,
1204 contacts_list_h record_list = NULL;
1205 contacts_query_h query = NULL;
1212 guint property_id = 0;
1214 const char *attr = NULL;
1216 gboolean get_log = FALSE;
1218 /* contact offset is n - 1 of PBAP */
1219 offset = (gint)list_start_offset - 1;
1221 if ( max_list_count >= 65535)
1222 limit = -1; /* contact limit -1 means unrestricted */
1224 limit = (gint)max_list_count;
1229 if (list_start_offset == 0) {
1232 vcard = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
1235 g_ptr_array_add(vcards, vcard);
1243 query = __bluetooth_pb_query_person();
1244 property_id = _contacts_person.id;
1247 query = __bluetooth_pb_query_phone_log_incoming();
1248 property_id = _contacts_phone_log.id;
1252 query = __bluetooth_pb_query_phone_log_outgoing();
1253 property_id = _contacts_phone_log.id;
1257 query = __bluetooth_pb_query_phone_log_missed();
1258 property_id = _contacts_phone_log.id;
1262 query = __bluetooth_pb_query_phone_log_combined();
1263 property_id = _contacts_phone_log.id;
1270 status = contacts_db_get_records_with_query(query, offset, limit, &record_list);
1272 if (status != CONTACTS_ERROR_NONE) {
1273 contacts_query_destroy(query);
1277 status = contacts_list_first(record_list);
1279 if (status != CONTACTS_ERROR_NONE) {
1280 contacts_list_destroy(record_list, TRUE);
1285 contacts_record_h record;
1289 gchar *vcard = NULL;
1292 status = contacts_list_get_current_record_p(record_list, &record);
1294 if (status != CONTACTS_ERROR_NONE)
1297 status = contacts_record_get_int(record, property_id, &id);
1299 if (status != CONTACTS_ERROR_NONE)
1302 if (property_id == _contacts_person.id)
1303 vcard = _bluetooth_pb_vcard_contact(id, filter, format);
1306 attr = __bluetooth_pb_phone_log_get_log_type(record);
1308 vcard = _bluetooth_pb_vcard_call(id, filter, format, attr);
1312 g_ptr_array_add(vcards, vcard);
1314 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1316 contacts_list_destroy(record_list, TRUE);
1317 contacts_query_destroy(query);
1320 static void __bluetooth_pb_get_contact_list(BluetoothPbAgent *agent,
1321 contacts_query_h query,
1322 GPtrArray *ptr_array)
1324 contacts_list_h record_list = NULL;
1334 tmp = _bluetooth_pb_owner_name();
1335 name = g_strdup_printf("%s;;;;", tmp);
1338 __bluetooth_pb_list_ptr_array_add(ptr_array,
1339 name, agent->tel_number, 0);
1344 status = contacts_db_get_records_with_query(query,
1345 -1, -1, &record_list);
1347 if (status != CONTACTS_ERROR_NONE)
1350 status = contacts_list_first(record_list);
1352 if (status != CONTACTS_ERROR_NONE) {
1353 contacts_list_destroy(record_list, TRUE);
1357 __bluetooth_pb_list_hash_reset(agent);
1360 contacts_record_h record;
1365 status = contacts_list_get_current_record_p(record_list,
1368 if (status != CONTACTS_ERROR_NONE)
1372 status = contacts_record_get_int(record,
1373 _contacts_person.id,
1376 if (status != CONTACTS_ERROR_NONE)
1379 __bluetooth_pb_list_hash_insert(agent, i, id);
1386 name = _bluetooth_pb_name_from_person_id(id);
1387 number = _bluetooth_pb_number_from_person_id(id);
1389 __bluetooth_pb_list_ptr_array_add(ptr_array,
1398 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1400 contacts_list_destroy(record_list, TRUE);
1403 static void __bluetooth_pb_get_phone_log_list(BluetoothPbAgent *agent,
1404 contacts_query_h query,
1405 GPtrArray *ptr_array)
1407 contacts_list_h record_list = NULL;
1412 status = contacts_db_get_records_with_query(query,
1413 -1, -1, &record_list);
1415 if (status != CONTACTS_ERROR_NONE)
1418 status = contacts_list_first(record_list);
1420 if (status != CONTACTS_ERROR_NONE) {
1421 contacts_list_destroy(record_list, TRUE);
1425 __bluetooth_pb_list_hash_reset(agent);
1428 contacts_record_h record;
1433 status = contacts_list_get_current_record_p(record_list,
1436 if (status != CONTACTS_ERROR_NONE)
1440 status = contacts_record_get_int(record,
1441 _contacts_phone_log.id,
1444 if (status != CONTACTS_ERROR_NONE)
1447 __bluetooth_pb_list_hash_insert(agent, i, id);
1454 name = _bluetooth_pb_name_from_phonelog_id(id);
1457 contacts_record_get_str_p(record,
1458 _contacts_phone_log.address,
1461 __bluetooth_pb_list_ptr_array_add(ptr_array,
1469 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1471 contacts_list_destroy(record_list, TRUE);
1475 static void __bluetooth_pb_get_list(BluetoothPbAgent *agent,
1476 PhoneBookType pb_type,
1477 GPtrArray *ptr_array)
1479 contacts_query_h query;
1481 /* no requires refresh cache */
1482 if (ptr_array == NULL && agent->pb_type == pb_type)
1487 query = __bluetooth_pb_query_person();
1488 __bluetooth_pb_get_contact_list(agent, query, ptr_array);
1491 query = __bluetooth_pb_query_phone_log_incoming();
1492 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1495 query = __bluetooth_pb_query_phone_log_outgoing();
1496 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1499 query = __bluetooth_pb_query_phone_log_missed();
1500 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1503 query = __bluetooth_pb_query_phone_log_combined();
1504 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1510 agent->pb_type = pb_type;
1513 contacts_query_destroy(query);
1516 static void __bluetooth_pb_get_contact_list_number(BluetoothPbAgent *agent,
1517 contacts_query_h query,
1520 GPtrArray *ptr_array)
1522 contacts_list_h record_list = NULL;
1541 offset = to - from + 1;
1547 status = contacts_db_get_records_with_query(query,
1551 if (status != CONTACTS_ERROR_NONE)
1554 status = contacts_list_first(record_list);
1556 if (status != CONTACTS_ERROR_NONE) {
1557 contacts_list_destroy(record_list, TRUE);
1562 contacts_record_h record;
1564 gchar *display_name;
1568 status = contacts_list_get_current_record_p(record_list,
1571 if (status != CONTACTS_ERROR_NONE)
1574 display_name = NULL;
1577 contacts_record_get_str_p(record,
1578 _contacts_person_number.display_name,
1580 contacts_record_get_str_p(record,
1581 _contacts_person_number.number,
1584 __bluetooth_pb_list_ptr_array_add(ptr_array,
1585 display_name, number, i);
1588 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1590 contacts_list_destroy(record_list, TRUE);
1593 static void __bluetooth_pb_get_phone_log_list_number(BluetoothPbAgent *agent,
1594 contacts_query_h query,
1597 GPtrArray *ptr_array)
1599 contacts_list_h record_list = NULL;
1618 offset = to - from + 1;
1624 status = contacts_db_get_records_with_query(query,
1628 if (status != CONTACTS_ERROR_NONE)
1631 status = contacts_list_first(record_list);
1632 if (status != CONTACTS_ERROR_NONE) {
1633 contacts_list_destroy(record_list, TRUE);
1638 contacts_record_h record = NULL;
1642 gchar *display_name;
1646 status = contacts_list_get_current_record_p(record_list,
1649 if (status != CONTACTS_ERROR_NONE)
1653 status = contacts_record_get_int(record,
1654 _contacts_phone_log.id,
1657 display_name = _bluetooth_pb_fn_from_phonelog_id(id);
1660 contacts_record_get_str_p(record,
1661 _contacts_phone_log.address,
1665 __bluetooth_pb_list_ptr_array_add(ptr_array,
1666 display_name, number, i);
1670 g_free(display_name);
1672 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1674 contacts_list_destroy(record_list, TRUE);
1677 static void __bluetooth_pb_get_list_number(BluetoothPbAgent *agent,
1678 PhoneBookType pb_type,
1681 GPtrArray *ptr_array)
1683 contacts_query_h query;
1687 query = __bluetooth_pb_query_person_number();
1688 __bluetooth_pb_get_contact_list_number(agent, query,
1689 start_index, end_index, ptr_array);
1692 query = __bluetooth_pb_query_phone_log_incoming();
1693 __bluetooth_pb_get_phone_log_list_number(agent, query,
1694 start_index, end_index, ptr_array);
1697 query = __bluetooth_pb_query_phone_log_outgoing();
1698 __bluetooth_pb_get_phone_log_list_number(agent, query,
1699 start_index, end_index, ptr_array);
1702 query = __bluetooth_pb_query_phone_log_missed();
1703 __bluetooth_pb_get_phone_log_list_number(agent, query,
1704 start_index, end_index, ptr_array);
1707 query = __bluetooth_pb_query_phone_log_combined();
1708 __bluetooth_pb_get_phone_log_list_number(agent, query,
1709 start_index, end_index, ptr_array);
1716 contacts_query_destroy(query);
1719 static void __bluetooth_pb_get_contact_list_name(BluetoothPbAgent *agent,
1720 contacts_query_h query,
1721 const gchar *find_text,
1722 GPtrArray *ptr_array)
1724 contacts_list_h record_list = NULL;
1729 status = contacts_db_get_records_with_query(query,
1730 -1, -1, &record_list);
1732 if (status != CONTACTS_ERROR_NONE)
1735 status = contacts_list_first(record_list);
1737 if (status != CONTACTS_ERROR_NONE) {
1738 contacts_list_destroy(record_list, TRUE);
1743 contacts_record_h record;
1745 gchar *display_name;
1748 status = contacts_list_get_current_record_p(record_list,
1751 if (status != CONTACTS_ERROR_NONE)
1754 display_name = NULL;
1755 contacts_record_get_str_p(record,
1756 _contacts_person_number.display_name,
1759 if (g_str_has_prefix(display_name, find_text)) {
1763 contacts_record_get_str_p(record,
1764 _contacts_person_number.number,
1767 __bluetooth_pb_list_ptr_array_add(ptr_array,
1768 display_name, number, i);
1772 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1775 static void __bluetooth_pb_get_phone_log_list_name(BluetoothPbAgent *agent,
1776 contacts_query_h query,
1777 const gchar *find_text,
1778 GPtrArray *ptr_array)
1780 contacts_list_h record_list = NULL;
1786 status = contacts_db_get_records_with_query(query,
1790 if (status != CONTACTS_ERROR_NONE)
1793 status = contacts_list_first(record_list);
1795 if (status != CONTACTS_ERROR_NONE) {
1796 contacts_list_destroy(record_list, TRUE);
1801 contacts_record_h record = NULL;
1805 gchar *display_name;
1808 status = contacts_list_get_current_record_p(record_list,
1811 if (status != CONTACTS_ERROR_NONE)
1815 status = contacts_record_get_int(record,
1816 _contacts_phone_log.id,
1819 display_name = _bluetooth_pb_fn_from_phonelog_id(id);
1821 if (g_str_has_prefix(display_name, find_text)) {
1822 gchar *number = NULL;
1825 contacts_record_get_str_p(record,
1826 _contacts_phone_log.address,
1829 __bluetooth_pb_list_ptr_array_add(ptr_array,
1830 display_name, number, i);
1835 g_free(display_name);
1837 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1839 contacts_list_destroy(record_list, TRUE);
1842 static void __bluetooth_pb_get_list_name(BluetoothPbAgent *agent,
1843 PhoneBookType pb_type,
1844 const gchar *find_text,
1845 GPtrArray *ptr_array)
1847 contacts_query_h query;
1851 query = __bluetooth_pb_query_person_number();
1852 __bluetooth_pb_get_contact_list_name(agent, query,
1853 find_text, ptr_array);
1856 query = __bluetooth_pb_query_phone_log_incoming();
1857 __bluetooth_pb_get_phone_log_list_name(agent, query,
1858 find_text, ptr_array);
1861 query = __bluetooth_pb_query_phone_log_outgoing();
1862 __bluetooth_pb_get_phone_log_list_name(agent, query,
1863 find_text, ptr_array);
1866 query = __bluetooth_pb_query_phone_log_missed();
1867 __bluetooth_pb_get_phone_log_list_name(agent, query,
1868 find_text, ptr_array);
1871 query = __bluetooth_pb_query_phone_log_combined();
1872 __bluetooth_pb_get_phone_log_list_name(agent, query,
1873 find_text, ptr_array);
1880 contacts_query_destroy(query);
1883 static void __bluetooth_pb_list_hash_reset(BluetoothPbAgent *agent)
1885 if(agent->contact_list)
1886 g_hash_table_destroy(agent->contact_list);
1888 agent->contact_list = g_hash_table_new(g_direct_hash, g_direct_equal);
1891 static gboolean __bluetooth_pb_list_hash_insert(BluetoothPbAgent *agent,
1895 if (agent->contact_list == NULL)
1898 g_hash_table_insert(agent->contact_list,
1899 GINT_TO_POINTER(handle), GINT_TO_POINTER(id));
1904 static gint __bluetooth_pb_list_hash_lookup_id(BluetoothPbAgent *agent,
1909 if (agent->contact_list == NULL)
1912 id = GPOINTER_TO_INT(g_hash_table_lookup(agent->contact_list,
1913 GINT_TO_POINTER(handle)));
1918 static void __bluetooth_pb_list_ptr_array_add(GPtrArray *ptr_array,
1920 const gchar *number,
1923 GValue value = { 0, };
1925 g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
1926 g_value_take_boxed(&value,
1927 dbus_g_type_specialized_construct(DBUS_STRUCT_STRING_STRING_UINT));
1929 dbus_g_type_struct_set(&value,
1931 1, g_strdup(number),
1935 g_ptr_array_add(ptr_array, g_value_get_boxed(&value));
1938 static void __bluetooth_pb_list_ptr_array_free(gpointer data)
1940 GValue value = { 0, };
1943 gchar *number = NULL;
1948 g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
1949 g_value_set_boxed(&value, data);
1951 dbus_g_type_struct_get(&value,
1960 static void __bluetooth_pb_agent_signal_handler(int signum)
1963 g_main_loop_quit(mainloop);
1969 static void __bluetooth_pb_contact_changed(const gchar *view_uri,
1972 BluetoothPbAgent *agent;
1974 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
1975 agent = BLUETOOTH_PB_AGENT(user_data);
1977 g_signal_emit(agent, signals[CLEAR], 0);
1978 g_object_unref(agent);
1981 static void __bluetooth_pb_agent_timeout_add_seconds(BluetoothPbAgent *agent)
1983 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(agent));
1985 if(agent->timeout_id)
1986 g_source_remove(agent->timeout_id);
1988 agent->timeout_id = g_timeout_add_seconds(BLUETOOTH_PB_AGENT_TIMEOUT,
1989 __bluetooth_pb_agent_timeout_calback,
1993 static gboolean __bluetooth_pb_agent_timeout_calback(gpointer user_data)
1995 BluetoothPbAgent *agent;
1997 g_return_val_if_fail(BLUETOOTH_IS_PB_AGENT(user_data), FALSE);
1999 agent = BLUETOOTH_PB_AGENT(user_data);
2000 agent->timeout_id = 0;
2003 g_main_loop_quit(mainloop);
2008 static void __bluetooth_pb_tel_callback(TapiHandle *handle,
2013 BluetoothPbAgent *agent;
2014 TelSimMsisdnList_t *number;
2016 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
2018 agent = BLUETOOTH_PB_AGENT(user_data);
2020 __bluetooth_pb_agent_dbus_init(agent);
2022 number = (TelSimMsisdnList_t *)data;
2023 agent->tel_number = g_strdup(number->list[0].num);
2025 tel_deinit(agent->tapi_handle);
2026 agent->tapi_handle = NULL;
2029 static void __bluetooth_pb_agent_dbus_init(BluetoothPbAgent *agent)
2032 GError *error = NULL;
2034 agent->bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2036 if (error != NULL) {
2037 DBG("Couldn't connect to system bus[%s]\n", error->message);
2038 g_error_free(error);
2042 agent->proxy = dbus_g_proxy_new_for_name(agent->bus,
2045 DBUS_INTERFACE_DBUS);
2047 if (agent->proxy == NULL) {
2048 DBG("Failed to get a proxy for D-Bus\n");
2052 if (!dbus_g_proxy_call(agent->proxy,
2053 "RequestName", &error,
2054 G_TYPE_STRING, BT_PB_SERVICE_NAME,
2057 G_TYPE_UINT, &result,
2059 if (error != NULL) {
2060 DBG("RequestName RPC failed[%s]\n", error->message);
2061 g_error_free(error);
2064 g_object_unref(agent->proxy);
2065 agent->proxy = NULL;
2069 DBG("result : %d %d\n", result, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
2070 if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
2071 DBG("Failed to get the primary well-known name.\n");
2073 g_object_unref(agent->proxy);
2074 agent->proxy = NULL;
2079 g_object_unref(agent->proxy);
2080 agent->proxy = NULL;
2082 dbus_g_connection_register_g_object(agent->bus,
2083 BT_PB_SERVICE_OBJECT_PATH,
2087 int main(int argc, char **argv)
2089 BluetoothPbAgent *agent;
2091 gint ret = EXIT_SUCCESS;
2094 struct sigaction sa;
2098 mainloop = g_main_loop_new(NULL, FALSE);
2099 if (mainloop == NULL) {
2100 DBG("Couldn't create GMainLoop\n");
2101 return EXIT_FAILURE;
2104 agent = g_object_new(BLUETOOTH_PB_TYPE_AGENT, NULL);
2106 /* connect contact */
2107 if (contacts_connect2() != CONTACTS_ERROR_NONE) {
2108 DBG("Can not connect contacts server\n");
2109 g_object_unref(agent);
2110 return EXIT_FAILURE;
2113 if (contacts_db_add_changed_cb(_contacts_event._uri,
2114 __bluetooth_pb_contact_changed,
2115 g_object_ref(agent)) != CONTACTS_ERROR_NONE) {
2116 DBG("Can not add changed callback");
2120 memset(&sa, 0, sizeof(sa));
2121 sa.sa_handler = __bluetooth_pb_agent_signal_handler;
2122 sigaction(SIGTERM, &sa, NULL);
2123 sigaction(SIGINT, &sa, NULL);
2126 agent->tapi_handle = tel_init(NULL);
2127 tapi_result = tel_get_sim_msisdn(agent->tapi_handle,
2128 __bluetooth_pb_tel_callback, agent);
2130 if (tapi_result != TAPI_API_SUCCESS) {
2131 __bluetooth_pb_agent_dbus_init(agent);
2135 __bluetooth_pb_agent_timeout_add_seconds(agent);
2137 g_main_loop_run(mainloop);
2139 DBG("Terminate the bluetooth-pb-agent\n");
2142 contacts_db_remove_changed_cb(_contacts_event._uri,
2143 __bluetooth_pb_contact_changed,
2144 g_object_ref(agent));
2146 g_object_unref(agent);
2150 contacts_disconnect2();
2152 g_signal_emit(agent, signals[CLEAR], 0);
2155 g_object_unref(agent);