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);
1355 contacts_query_destroy(query);
1359 __bluetooth_pb_list_hash_reset(agent);
1362 contacts_record_h record;
1367 status = contacts_list_get_current_record_p(record_list,
1370 if (status != CONTACTS_ERROR_NONE)
1374 status = contacts_record_get_int(record,
1375 _contacts_person.id,
1378 if (status != CONTACTS_ERROR_NONE)
1381 __bluetooth_pb_list_hash_insert(agent, i, id);
1388 name = _bluetooth_pb_name_from_person_id(id);
1389 number = _bluetooth_pb_number_from_person_id(id);
1391 __bluetooth_pb_list_ptr_array_add(ptr_array,
1400 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1402 contacts_list_destroy(record_list, TRUE);
1405 static void __bluetooth_pb_get_phone_log_list(BluetoothPbAgent *agent,
1406 contacts_query_h query,
1407 GPtrArray *ptr_array)
1409 contacts_list_h record_list = NULL;
1414 status = contacts_db_get_records_with_query(query,
1415 -1, -1, &record_list);
1417 if (status != CONTACTS_ERROR_NONE)
1420 status = contacts_list_first(record_list);
1422 if (status != CONTACTS_ERROR_NONE) {
1423 contacts_list_destroy(record_list, TRUE);
1424 contacts_query_destroy(query);
1428 __bluetooth_pb_list_hash_reset(agent);
1431 contacts_record_h record;
1436 status = contacts_list_get_current_record_p(record_list,
1439 if (status != CONTACTS_ERROR_NONE)
1443 status = contacts_record_get_int(record,
1444 _contacts_phone_log.id,
1447 if (status != CONTACTS_ERROR_NONE)
1450 __bluetooth_pb_list_hash_insert(agent, i, id);
1457 name = _bluetooth_pb_name_from_phonelog_id(id);
1460 contacts_record_get_str_p(record,
1461 _contacts_phone_log.address,
1464 __bluetooth_pb_list_ptr_array_add(ptr_array,
1472 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1474 contacts_list_destroy(record_list, TRUE);
1478 static void __bluetooth_pb_get_list(BluetoothPbAgent *agent,
1479 PhoneBookType pb_type,
1480 GPtrArray *ptr_array)
1482 contacts_query_h query;
1484 /* no requires refresh cache */
1485 if (ptr_array == NULL && agent->pb_type == pb_type)
1490 query = __bluetooth_pb_query_person();
1491 __bluetooth_pb_get_contact_list(agent, query, ptr_array);
1494 query = __bluetooth_pb_query_phone_log_incoming();
1495 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1498 query = __bluetooth_pb_query_phone_log_outgoing();
1499 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1502 query = __bluetooth_pb_query_phone_log_missed();
1503 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1506 query = __bluetooth_pb_query_phone_log_combined();
1507 __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
1513 agent->pb_type = pb_type;
1516 contacts_query_destroy(query);
1519 static void __bluetooth_pb_get_contact_list_number(BluetoothPbAgent *agent,
1520 contacts_query_h query,
1523 GPtrArray *ptr_array)
1525 contacts_list_h record_list = NULL;
1544 offset = to - from + 1;
1550 status = contacts_db_get_records_with_query(query,
1554 if (status != CONTACTS_ERROR_NONE)
1557 status = contacts_list_first(record_list);
1559 if (status != CONTACTS_ERROR_NONE) {
1560 contacts_list_destroy(record_list, TRUE);
1565 contacts_record_h record;
1567 gchar *display_name;
1571 status = contacts_list_get_current_record_p(record_list,
1574 if (status != CONTACTS_ERROR_NONE)
1577 display_name = NULL;
1580 contacts_record_get_str_p(record,
1581 _contacts_person_number.display_name,
1583 contacts_record_get_str_p(record,
1584 _contacts_person_number.number,
1587 __bluetooth_pb_list_ptr_array_add(ptr_array,
1588 display_name, number, i);
1591 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1593 contacts_list_destroy(record_list, TRUE);
1596 static void __bluetooth_pb_get_phone_log_list_number(BluetoothPbAgent *agent,
1597 contacts_query_h query,
1600 GPtrArray *ptr_array)
1602 contacts_list_h record_list = NULL;
1621 offset = to - from + 1;
1627 status = contacts_db_get_records_with_query(query,
1631 if (status != CONTACTS_ERROR_NONE)
1634 status = contacts_list_first(record_list);
1635 if (status != CONTACTS_ERROR_NONE) {
1636 contacts_list_destroy(record_list, TRUE);
1641 contacts_record_h record = NULL;
1645 gchar *display_name;
1649 status = contacts_list_get_current_record_p(record_list,
1652 if (status != CONTACTS_ERROR_NONE)
1656 status = contacts_record_get_int(record,
1657 _contacts_phone_log.id,
1660 display_name = _bluetooth_pb_fn_from_phonelog_id(id);
1663 contacts_record_get_str_p(record,
1664 _contacts_phone_log.address,
1668 __bluetooth_pb_list_ptr_array_add(ptr_array,
1669 display_name, number, i);
1673 g_free(display_name);
1675 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1677 contacts_list_destroy(record_list, TRUE);
1680 static void __bluetooth_pb_get_list_number(BluetoothPbAgent *agent,
1681 PhoneBookType pb_type,
1684 GPtrArray *ptr_array)
1686 contacts_query_h query;
1690 query = __bluetooth_pb_query_person_number();
1691 __bluetooth_pb_get_contact_list_number(agent, query,
1692 start_index, end_index, ptr_array);
1695 query = __bluetooth_pb_query_phone_log_incoming();
1696 __bluetooth_pb_get_phone_log_list_number(agent, query,
1697 start_index, end_index, ptr_array);
1700 query = __bluetooth_pb_query_phone_log_outgoing();
1701 __bluetooth_pb_get_phone_log_list_number(agent, query,
1702 start_index, end_index, ptr_array);
1705 query = __bluetooth_pb_query_phone_log_missed();
1706 __bluetooth_pb_get_phone_log_list_number(agent, query,
1707 start_index, end_index, ptr_array);
1710 query = __bluetooth_pb_query_phone_log_combined();
1711 __bluetooth_pb_get_phone_log_list_number(agent, query,
1712 start_index, end_index, ptr_array);
1719 contacts_query_destroy(query);
1722 static void __bluetooth_pb_get_contact_list_name(BluetoothPbAgent *agent,
1723 contacts_query_h query,
1724 const gchar *find_text,
1725 GPtrArray *ptr_array)
1727 contacts_list_h record_list = NULL;
1732 status = contacts_db_get_records_with_query(query,
1733 -1, -1, &record_list);
1735 if (status != CONTACTS_ERROR_NONE)
1738 status = contacts_list_first(record_list);
1740 if (status != CONTACTS_ERROR_NONE) {
1741 contacts_list_destroy(record_list, TRUE);
1746 contacts_record_h record;
1748 gchar *display_name;
1751 status = contacts_list_get_current_record_p(record_list,
1754 if (status != CONTACTS_ERROR_NONE)
1757 display_name = NULL;
1758 contacts_record_get_str_p(record,
1759 _contacts_person_number.display_name,
1762 if (g_str_has_prefix(display_name, find_text)) {
1766 contacts_record_get_str_p(record,
1767 _contacts_person_number.number,
1770 __bluetooth_pb_list_ptr_array_add(ptr_array,
1771 display_name, number, i);
1775 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1778 static void __bluetooth_pb_get_phone_log_list_name(BluetoothPbAgent *agent,
1779 contacts_query_h query,
1780 const gchar *find_text,
1781 GPtrArray *ptr_array)
1783 contacts_list_h record_list = NULL;
1789 status = contacts_db_get_records_with_query(query,
1793 if (status != CONTACTS_ERROR_NONE)
1796 status = contacts_list_first(record_list);
1798 if (status != CONTACTS_ERROR_NONE) {
1799 contacts_list_destroy(record_list, TRUE);
1804 contacts_record_h record = NULL;
1808 gchar *display_name;
1811 status = contacts_list_get_current_record_p(record_list,
1814 if (status != CONTACTS_ERROR_NONE)
1818 status = contacts_record_get_int(record,
1819 _contacts_phone_log.id,
1822 display_name = _bluetooth_pb_fn_from_phonelog_id(id);
1824 if (g_str_has_prefix(display_name, find_text)) {
1825 gchar *number = NULL;
1828 contacts_record_get_str_p(record,
1829 _contacts_phone_log.address,
1832 __bluetooth_pb_list_ptr_array_add(ptr_array,
1833 display_name, number, i);
1838 g_free(display_name);
1840 } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
1842 contacts_list_destroy(record_list, TRUE);
1845 static void __bluetooth_pb_get_list_name(BluetoothPbAgent *agent,
1846 PhoneBookType pb_type,
1847 const gchar *find_text,
1848 GPtrArray *ptr_array)
1850 contacts_query_h query;
1854 query = __bluetooth_pb_query_person_number();
1855 __bluetooth_pb_get_contact_list_name(agent, query,
1856 find_text, ptr_array);
1859 query = __bluetooth_pb_query_phone_log_incoming();
1860 __bluetooth_pb_get_phone_log_list_name(agent, query,
1861 find_text, ptr_array);
1864 query = __bluetooth_pb_query_phone_log_outgoing();
1865 __bluetooth_pb_get_phone_log_list_name(agent, query,
1866 find_text, ptr_array);
1869 query = __bluetooth_pb_query_phone_log_missed();
1870 __bluetooth_pb_get_phone_log_list_name(agent, query,
1871 find_text, ptr_array);
1874 query = __bluetooth_pb_query_phone_log_combined();
1875 __bluetooth_pb_get_phone_log_list_name(agent, query,
1876 find_text, ptr_array);
1883 contacts_query_destroy(query);
1886 static void __bluetooth_pb_list_hash_reset(BluetoothPbAgent *agent)
1888 if(agent->contact_list)
1889 g_hash_table_destroy(agent->contact_list);
1891 agent->contact_list = g_hash_table_new(g_direct_hash, g_direct_equal);
1894 static gboolean __bluetooth_pb_list_hash_insert(BluetoothPbAgent *agent,
1898 if (agent->contact_list == NULL)
1901 g_hash_table_insert(agent->contact_list,
1902 GINT_TO_POINTER(handle), GINT_TO_POINTER(id));
1907 static gint __bluetooth_pb_list_hash_lookup_id(BluetoothPbAgent *agent,
1912 if (agent->contact_list == NULL)
1915 id = GPOINTER_TO_INT(g_hash_table_lookup(agent->contact_list,
1916 GINT_TO_POINTER(handle)));
1921 static void __bluetooth_pb_list_ptr_array_add(GPtrArray *ptr_array,
1923 const gchar *number,
1926 GValue value = { 0, };
1928 g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
1929 g_value_take_boxed(&value,
1930 dbus_g_type_specialized_construct(DBUS_STRUCT_STRING_STRING_UINT));
1932 dbus_g_type_struct_set(&value,
1934 1, g_strdup(number),
1938 g_ptr_array_add(ptr_array, g_value_get_boxed(&value));
1941 static void __bluetooth_pb_list_ptr_array_free(gpointer data)
1943 GValue value = { 0, };
1946 gchar *number = NULL;
1951 g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
1952 g_value_set_boxed(&value, data);
1954 dbus_g_type_struct_get(&value,
1963 static void __bluetooth_pb_agent_signal_handler(int signum)
1966 g_main_loop_quit(mainloop);
1972 static void __bluetooth_pb_contact_changed(const gchar *view_uri,
1975 BluetoothPbAgent *agent;
1977 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
1978 agent = BLUETOOTH_PB_AGENT(user_data);
1980 g_signal_emit(agent, signals[CLEAR], 0);
1981 g_object_unref(agent);
1984 static void __bluetooth_pb_agent_timeout_add_seconds(BluetoothPbAgent *agent)
1986 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(agent));
1988 if(agent->timeout_id)
1989 g_source_remove(agent->timeout_id);
1991 agent->timeout_id = g_timeout_add_seconds(BLUETOOTH_PB_AGENT_TIMEOUT,
1992 __bluetooth_pb_agent_timeout_calback,
1996 static gboolean __bluetooth_pb_agent_timeout_calback(gpointer user_data)
1998 BluetoothPbAgent *agent;
2000 g_return_val_if_fail(BLUETOOTH_IS_PB_AGENT(user_data), FALSE);
2002 agent = BLUETOOTH_PB_AGENT(user_data);
2003 agent->timeout_id = 0;
2006 g_main_loop_quit(mainloop);
2011 static void __bluetooth_pb_tel_callback(TapiHandle *handle,
2016 BluetoothPbAgent *agent;
2017 TelSimMsisdnList_t *number;
2019 g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
2021 agent = BLUETOOTH_PB_AGENT(user_data);
2023 __bluetooth_pb_agent_dbus_init(agent);
2025 number = (TelSimMsisdnList_t *)data;
2026 agent->tel_number = g_strdup(number->list[0].num);
2028 tel_deinit(agent->tapi_handle);
2029 agent->tapi_handle = NULL;
2032 static void __bluetooth_pb_agent_dbus_init(BluetoothPbAgent *agent)
2035 GError *error = NULL;
2037 agent->bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2039 if (error != NULL) {
2040 DBG("Couldn't connect to system bus[%s]\n", error->message);
2041 g_error_free(error);
2045 agent->proxy = dbus_g_proxy_new_for_name(agent->bus,
2048 DBUS_INTERFACE_DBUS);
2050 if (agent->proxy == NULL) {
2051 DBG("Failed to get a proxy for D-Bus\n");
2055 if (!dbus_g_proxy_call(agent->proxy,
2056 "RequestName", &error,
2057 G_TYPE_STRING, BT_PB_SERVICE_NAME,
2060 G_TYPE_UINT, &result,
2062 if (error != NULL) {
2063 DBG("RequestName RPC failed[%s]\n", error->message);
2064 g_error_free(error);
2067 g_object_unref(agent->proxy);
2068 agent->proxy = NULL;
2072 DBG("result : %d %d\n", result, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
2073 if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
2074 DBG("Failed to get the primary well-known name.\n");
2076 g_object_unref(agent->proxy);
2077 agent->proxy = NULL;
2082 g_object_unref(agent->proxy);
2083 agent->proxy = NULL;
2085 dbus_g_connection_register_g_object(agent->bus,
2086 BT_PB_SERVICE_OBJECT_PATH,
2090 int main(int argc, char **argv)
2092 BluetoothPbAgent *agent;
2094 gint ret = EXIT_SUCCESS;
2097 struct sigaction sa;
2101 mainloop = g_main_loop_new(NULL, FALSE);
2102 if (mainloop == NULL) {
2103 DBG("Couldn't create GMainLoop\n");
2104 return EXIT_FAILURE;
2107 agent = g_object_new(BLUETOOTH_PB_TYPE_AGENT, NULL);
2109 /* connect contact */
2110 if (contacts_connect2() != CONTACTS_ERROR_NONE) {
2111 DBG("Can not connect contacts server\n");
2112 g_object_unref(agent);
2113 return EXIT_FAILURE;
2116 if (contacts_db_add_changed_cb(_contacts_event._uri,
2117 __bluetooth_pb_contact_changed,
2118 g_object_ref(agent)) != CONTACTS_ERROR_NONE) {
2119 DBG("Can not add changed callback");
2123 memset(&sa, 0, sizeof(sa));
2124 sa.sa_handler = __bluetooth_pb_agent_signal_handler;
2125 sigaction(SIGTERM, &sa, NULL);
2126 sigaction(SIGINT, &sa, NULL);
2129 agent->tapi_handle = tel_init(NULL);
2130 tapi_result = tel_get_sim_msisdn(agent->tapi_handle,
2131 __bluetooth_pb_tel_callback, agent);
2133 if (tapi_result != TAPI_API_SUCCESS) {
2134 __bluetooth_pb_agent_dbus_init(agent);
2138 __bluetooth_pb_agent_timeout_add_seconds(agent);
2140 g_main_loop_run(mainloop);
2142 DBG("Terminate the bluetooth-pb-agent\n");
2145 contacts_db_remove_changed_cb(_contacts_event._uri,
2146 __bluetooth_pb_contact_changed,
2147 g_object_ref(agent));
2149 g_object_unref(agent);
2153 contacts_disconnect2();
2155 g_signal_emit(agent, signals[CLEAR], 0);
2158 g_object_unref(agent);