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);
1281 contacts_query_destroy(query);
1286 contacts_record_h record;
1290 gchar *vcard = NULL;
1293 status = contacts_list_get_current_record_p(record_list, &record);
1295 if (status != CONTACTS_ERROR_NONE)
1298 status = contacts_record_get_int(record, property_id, &id);
1300 if (status != CONTACTS_ERROR_NONE)
1303 if (property_id == _contacts_person.id)
1304 vcard = _bluetooth_pb_vcard_contact(id, filter, format);
1307 attr = __bluetooth_pb_phone_log_get_log_type(record);
1309 vcard = _bluetooth_pb_vcard_call(id, filter, format, attr);
1313 g_ptr_array_add(vcards, vcard);
1315 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1317 contacts_list_destroy(record_list, TRUE);
1318 contacts_query_destroy(query);
1321 static void __bluetooth_pb_get_contact_list(BluetoothPbAgent *agent,
1322 contacts_query_h query,
1323 GPtrArray *ptr_array)
1325 contacts_list_h record_list = NULL;
1335 tmp = _bluetooth_pb_owner_name();
1336 name = g_strdup_printf("%s;;;;", tmp);
1339 __bluetooth_pb_list_ptr_array_add(ptr_array,
1340 name, agent->tel_number, 0);
1345 status = contacts_db_get_records_with_query(query,
1346 -1, -1, &record_list);
1348 if (status != CONTACTS_ERROR_NONE)
1351 status = contacts_list_first(record_list);
1353 if (status != CONTACTS_ERROR_NONE) {
1354 contacts_list_destroy(record_list, TRUE);
1358 __bluetooth_pb_list_hash_reset(agent);
1361 contacts_record_h record;
1366 status = contacts_list_get_current_record_p(record_list,
1369 if (status != CONTACTS_ERROR_NONE)
1373 status = contacts_record_get_int(record,
1374 _contacts_person.id,
1377 if (status != CONTACTS_ERROR_NONE)
1380 __bluetooth_pb_list_hash_insert(agent, i, id);
1387 name = _bluetooth_pb_name_from_person_id(id);
1388 number = _bluetooth_pb_number_from_person_id(id);
1390 __bluetooth_pb_list_ptr_array_add(ptr_array,
1399 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1401 contacts_list_destroy(record_list, TRUE);
1404 static void __bluetooth_pb_get_phone_log_list(BluetoothPbAgent *agent,
1405 contacts_query_h query,
1406 GPtrArray *ptr_array)
1408 contacts_list_h record_list = NULL;
1413 status = contacts_db_get_records_with_query(query,
1414 -1, -1, &record_list);
1416 if (status != CONTACTS_ERROR_NONE)
1419 status = contacts_list_first(record_list);
1421 if (status != CONTACTS_ERROR_NONE) {
1422 contacts_list_destroy(record_list, TRUE);
1426 __bluetooth_pb_list_hash_reset(agent);
1429 contacts_record_h record;
1434 status = contacts_list_get_current_record_p(record_list,
1437 if (status != CONTACTS_ERROR_NONE)
1441 status = contacts_record_get_int(record,
1442 _contacts_phone_log.id,
1445 if (status != CONTACTS_ERROR_NONE)
1448 __bluetooth_pb_list_hash_insert(agent, i, id);
1455 name = _bluetooth_pb_name_from_phonelog_id(id);
1458 contacts_record_get_str_p(record,
1459 _contacts_phone_log.address,
1462 __bluetooth_pb_list_ptr_array_add(ptr_array,
1470 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1472 contacts_list_destroy(record_list, TRUE);
1476 static void __bluetooth_pb_get_list(BluetoothPbAgent *agent,
1477 PhoneBookType pb_type,
1478 GPtrArray *ptr_array)
1480 contacts_query_h query;
1482 /* no requires refresh cache */
1483 if (ptr_array == NULL && agent->pb_type == pb_type)
1488 query = __bluetooth_pb_query_person();
1489 __bluetooth_pb_get_contact_list(agent, query, ptr_array);
1492 query = __bluetooth_pb_query_phone_log_incoming();
1493 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1496 query = __bluetooth_pb_query_phone_log_outgoing();
1497 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1500 query = __bluetooth_pb_query_phone_log_missed();
1501 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1504 query = __bluetooth_pb_query_phone_log_combined();
1505 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1511 agent->pb_type = pb_type;
1514 contacts_query_destroy(query);
1517 static void __bluetooth_pb_get_contact_list_number(BluetoothPbAgent *agent,
1518 contacts_query_h query,
1521 GPtrArray *ptr_array)
1523 contacts_list_h record_list = NULL;
1542 offset = to - from + 1;
1548 status = contacts_db_get_records_with_query(query,
1552 if (status != CONTACTS_ERROR_NONE)
1555 status = contacts_list_first(record_list);
1557 if (status != CONTACTS_ERROR_NONE) {
1558 contacts_list_destroy(record_list, TRUE);
1563 contacts_record_h record;
1565 gchar *display_name;
1569 status = contacts_list_get_current_record_p(record_list,
1572 if (status != CONTACTS_ERROR_NONE)
1575 display_name = NULL;
1578 contacts_record_get_str_p(record,
1579 _contacts_person_number.display_name,
1581 contacts_record_get_str_p(record,
1582 _contacts_person_number.number,
1585 __bluetooth_pb_list_ptr_array_add(ptr_array,
1586 display_name, number, i);
1589 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1591 contacts_list_destroy(record_list, TRUE);
1594 static void __bluetooth_pb_get_phone_log_list_number(BluetoothPbAgent *agent,
1595 contacts_query_h query,
1598 GPtrArray *ptr_array)
1600 contacts_list_h record_list = NULL;
1619 offset = to - from + 1;
1625 status = contacts_db_get_records_with_query(query,
1629 if (status != CONTACTS_ERROR_NONE)
1632 status = contacts_list_first(record_list);
1633 if (status != CONTACTS_ERROR_NONE) {
1634 contacts_list_destroy(record_list, TRUE);
1639 contacts_record_h record = NULL;
1643 gchar *display_name;
1647 status = contacts_list_get_current_record_p(record_list,
1650 if (status != CONTACTS_ERROR_NONE)
1654 status = contacts_record_get_int(record,
1655 _contacts_phone_log.id,
1658 display_name = _bluetooth_pb_fn_from_phonelog_id(id);
1661 contacts_record_get_str_p(record,
1662 _contacts_phone_log.address,
1666 __bluetooth_pb_list_ptr_array_add(ptr_array,
1667 display_name, number, i);
1671 g_free(display_name);
1673 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1675 contacts_list_destroy(record_list, TRUE);
1678 static void __bluetooth_pb_get_list_number(BluetoothPbAgent *agent,
1679 PhoneBookType pb_type,
1682 GPtrArray *ptr_array)
1684 contacts_query_h query;
1688 query = __bluetooth_pb_query_person_number();
1689 __bluetooth_pb_get_contact_list_number(agent, query,
1690 start_index, end_index, ptr_array);
1693 query = __bluetooth_pb_query_phone_log_incoming();
1694 __bluetooth_pb_get_phone_log_list_number(agent, query,
1695 start_index, end_index, ptr_array);
1698 query = __bluetooth_pb_query_phone_log_outgoing();
1699 __bluetooth_pb_get_phone_log_list_number(agent, query,
1700 start_index, end_index, ptr_array);
1703 query = __bluetooth_pb_query_phone_log_missed();
1704 __bluetooth_pb_get_phone_log_list_number(agent, query,
1705 start_index, end_index, ptr_array);
1708 query = __bluetooth_pb_query_phone_log_combined();
1709 __bluetooth_pb_get_phone_log_list_number(agent, query,
1710 start_index, end_index, ptr_array);
1717 contacts_query_destroy(query);
1720 static void __bluetooth_pb_get_contact_list_name(BluetoothPbAgent *agent,
1721 contacts_query_h query,
1722 const gchar *find_text,
1723 GPtrArray *ptr_array)
1725 contacts_list_h record_list = NULL;
1730 status = contacts_db_get_records_with_query(query,
1731 -1, -1, &record_list);
1733 if (status != CONTACTS_ERROR_NONE)
1736 status = contacts_list_first(record_list);
1738 if (status != CONTACTS_ERROR_NONE) {
1739 contacts_list_destroy(record_list, TRUE);
1744 contacts_record_h record;
1746 gchar *display_name;
1749 status = contacts_list_get_current_record_p(record_list,
1752 if (status != CONTACTS_ERROR_NONE)
1755 display_name = NULL;
1756 contacts_record_get_str_p(record,
1757 _contacts_person_number.display_name,
1760 if (g_str_has_prefix(display_name, find_text)) {
1764 contacts_record_get_str_p(record,
1765 _contacts_person_number.number,
1768 __bluetooth_pb_list_ptr_array_add(ptr_array,
1769 display_name, number, i);
1773 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1776 static void __bluetooth_pb_get_phone_log_list_name(BluetoothPbAgent *agent,
1777 contacts_query_h query,
1778 const gchar *find_text,
1779 GPtrArray *ptr_array)
1781 contacts_list_h record_list = NULL;
1787 status = contacts_db_get_records_with_query(query,
1791 if (status != CONTACTS_ERROR_NONE)
1794 status = contacts_list_first(record_list);
1796 if (status != CONTACTS_ERROR_NONE) {
1797 contacts_list_destroy(record_list, TRUE);
1802 contacts_record_h record = NULL;
1806 gchar *display_name;
1809 status = contacts_list_get_current_record_p(record_list,
1812 if (status != CONTACTS_ERROR_NONE)
1816 status = contacts_record_get_int(record,
1817 _contacts_phone_log.id,
1820 display_name = _bluetooth_pb_fn_from_phonelog_id(id);
1822 if (g_str_has_prefix(display_name, find_text)) {
1823 gchar *number = NULL;
1826 contacts_record_get_str_p(record,
1827 _contacts_phone_log.address,
1830 __bluetooth_pb_list_ptr_array_add(ptr_array,
1831 display_name, number, i);
1836 g_free(display_name);
1838 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1840 contacts_list_destroy(record_list, TRUE);
1843 static void __bluetooth_pb_get_list_name(BluetoothPbAgent *agent,
1844 PhoneBookType pb_type,
1845 const gchar *find_text,
1846 GPtrArray *ptr_array)
1848 contacts_query_h query;
1852 query = __bluetooth_pb_query_person_number();
1853 __bluetooth_pb_get_contact_list_name(agent, query,
1854 find_text, ptr_array);
1857 query = __bluetooth_pb_query_phone_log_incoming();
1858 __bluetooth_pb_get_phone_log_list_name(agent, query,
1859 find_text, ptr_array);
1862 query = __bluetooth_pb_query_phone_log_outgoing();
1863 __bluetooth_pb_get_phone_log_list_name(agent, query,
1864 find_text, ptr_array);
1867 query = __bluetooth_pb_query_phone_log_missed();
1868 __bluetooth_pb_get_phone_log_list_name(agent, query,
1869 find_text, ptr_array);
1872 query = __bluetooth_pb_query_phone_log_combined();
1873 __bluetooth_pb_get_phone_log_list_name(agent, query,
1874 find_text, ptr_array);
1881 contacts_query_destroy(query);
1884 static void __bluetooth_pb_list_hash_reset(BluetoothPbAgent *agent)
1886 if(agent->contact_list)
1887 g_hash_table_destroy(agent->contact_list);
1889 agent->contact_list = g_hash_table_new(g_direct_hash, g_direct_equal);
1892 static gboolean __bluetooth_pb_list_hash_insert(BluetoothPbAgent *agent,
1896 if (agent->contact_list == NULL)
1899 g_hash_table_insert(agent->contact_list,
1900 GINT_TO_POINTER(handle), GINT_TO_POINTER(id));
1905 static gint __bluetooth_pb_list_hash_lookup_id(BluetoothPbAgent *agent,
1910 if (agent->contact_list == NULL)
1913 id = GPOINTER_TO_INT(g_hash_table_lookup(agent->contact_list,
1914 GINT_TO_POINTER(handle)));
1919 static void __bluetooth_pb_list_ptr_array_add(GPtrArray *ptr_array,
1921 const gchar *number,
1924 GValue value = { 0, };
1926 g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
1927 g_value_take_boxed(&value,
1928 dbus_g_type_specialized_construct(DBUS_STRUCT_STRING_STRING_UINT));
1930 dbus_g_type_struct_set(&value,
1932 1, g_strdup(number),
1936 g_ptr_array_add(ptr_array, g_value_get_boxed(&value));
1939 static void __bluetooth_pb_list_ptr_array_free(gpointer data)
1941 GValue value = { 0, };
1944 gchar *number = NULL;
1949 g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
1950 g_value_set_boxed(&value, data);
1952 dbus_g_type_struct_get(&value,
1961 static void __bluetooth_pb_agent_signal_handler(int signum)
1964 g_main_loop_quit(mainloop);
1970 static void __bluetooth_pb_contact_changed(const gchar *view_uri,
1973 BluetoothPbAgent *agent;
1975 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
1976 agent = BLUETOOTH_PB_AGENT(user_data);
1978 g_signal_emit(agent, signals[CLEAR], 0);
1979 g_object_unref(agent);
1982 static void __bluetooth_pb_agent_timeout_add_seconds(BluetoothPbAgent *agent)
1984 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(agent));
1986 if(agent->timeout_id)
1987 g_source_remove(agent->timeout_id);
1989 agent->timeout_id = g_timeout_add_seconds(BLUETOOTH_PB_AGENT_TIMEOUT,
1990 __bluetooth_pb_agent_timeout_calback,
1994 static gboolean __bluetooth_pb_agent_timeout_calback(gpointer user_data)
1996 BluetoothPbAgent *agent;
1998 g_return_val_if_fail(BLUETOOTH_IS_PB_AGENT(user_data), FALSE);
2000 agent = BLUETOOTH_PB_AGENT(user_data);
2001 agent->timeout_id = 0;
2004 g_main_loop_quit(mainloop);
2009 static void __bluetooth_pb_tel_callback(TapiHandle *handle,
2014 BluetoothPbAgent *agent;
2015 TelSimMsisdnList_t *number;
2017 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
2019 agent = BLUETOOTH_PB_AGENT(user_data);
2021 __bluetooth_pb_agent_dbus_init(agent);
2023 number = (TelSimMsisdnList_t *)data;
2024 agent->tel_number = g_strdup(number->list[0].num);
2026 tel_deinit(agent->tapi_handle);
2027 agent->tapi_handle = NULL;
2030 static void __bluetooth_pb_agent_dbus_init(BluetoothPbAgent *agent)
2033 GError *error = NULL;
2035 agent->bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2037 if (error != NULL) {
2038 DBG("Couldn't connect to system bus[%s]\n", error->message);
2039 g_error_free(error);
2043 agent->proxy = dbus_g_proxy_new_for_name(agent->bus,
2046 DBUS_INTERFACE_DBUS);
2048 if (agent->proxy == NULL) {
2049 DBG("Failed to get a proxy for D-Bus\n");
2053 if (!dbus_g_proxy_call(agent->proxy,
2054 "RequestName", &error,
2055 G_TYPE_STRING, BT_PB_SERVICE_NAME,
2058 G_TYPE_UINT, &result,
2060 if (error != NULL) {
2061 DBG("RequestName RPC failed[%s]\n", error->message);
2062 g_error_free(error);
2065 g_object_unref(agent->proxy);
2066 agent->proxy = NULL;
2070 DBG("result : %d %d\n", result, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
2071 if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
2072 DBG("Failed to get the primary well-known name.\n");
2074 g_object_unref(agent->proxy);
2075 agent->proxy = NULL;
2080 g_object_unref(agent->proxy);
2081 agent->proxy = NULL;
2083 dbus_g_connection_register_g_object(agent->bus,
2084 BT_PB_SERVICE_OBJECT_PATH,
2088 int main(int argc, char **argv)
2090 BluetoothPbAgent *agent;
2092 gint ret = EXIT_SUCCESS;
2095 struct sigaction sa;
2099 mainloop = g_main_loop_new(NULL, FALSE);
2100 if (mainloop == NULL) {
2101 DBG("Couldn't create GMainLoop\n");
2102 return EXIT_FAILURE;
2105 agent = g_object_new(BLUETOOTH_PB_TYPE_AGENT, NULL);
2107 /* connect contact */
2108 if (contacts_connect2() != CONTACTS_ERROR_NONE) {
2109 DBG("Can not connect contacts server\n");
2110 g_object_unref(agent);
2111 return EXIT_FAILURE;
2114 if (contacts_db_add_changed_cb(_contacts_event._uri,
2115 __bluetooth_pb_contact_changed,
2116 g_object_ref(agent)) != CONTACTS_ERROR_NONE) {
2117 DBG("Can not add changed callback");
2121 memset(&sa, 0, sizeof(sa));
2122 sa.sa_handler = __bluetooth_pb_agent_signal_handler;
2123 sigaction(SIGTERM, &sa, NULL);
2124 sigaction(SIGINT, &sa, NULL);
2127 agent->tapi_handle = tel_init(NULL);
2128 tapi_result = tel_get_sim_msisdn(agent->tapi_handle,
2129 __bluetooth_pb_tel_callback, agent);
2131 if (tapi_result != TAPI_API_SUCCESS) {
2132 __bluetooth_pb_agent_dbus_init(agent);
2136 __bluetooth_pb_agent_timeout_add_seconds(agent);
2138 g_main_loop_run(mainloop);
2140 DBG("Terminate the bluetooth-pb-agent\n");
2143 contacts_db_remove_changed_cb(_contacts_event._uri,
2144 __bluetooth_pb_contact_changed,
2145 g_object_ref(agent));
2147 g_object_unref(agent);
2151 contacts_disconnect2();
2153 g_signal_emit(agent, signals[CLEAR], 0);
2156 g_object_unref(agent);