#include <unistd.h>
#include <signal.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-
+#include <gio/gio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-
#include <contacts.h>
-
#include <TapiUtility.h>
#include <ITapiSim.h>
#define BLUETOOTH_PB_AGENT_TIMEOUT 600
typedef struct {
- GObject parent;
-
- DBusGConnection *bus;
- DBusGProxy *proxy;
-
TapiHandle *tapi_handle;
gchar *tel_number;
guint timeout_id;
-
PhoneBookType pb_type;
-} BluetoothPbAgent;
-
-typedef struct {
- GObjectClass parent;
-
- void (*clear) (BluetoothPbAgent *agent);
-} BluetoothPbAgentClass;
-
-enum {
- CLEAR,
- LAST_SIGNAL
+ guint pbagent_interface_id;
+ guint pbagent_at_interface_id;
+} PbAgentData;
+
+static gchar *bluetooth_pb_agent_folder_list[] = {
+ "/telecom/pb",
+ "/telecom/ich",
+ "/telecom/och",
+ "/telecom/mch",
+ "/telecom/cch",
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
+ "/SIM1/telecom/pb",
+#endif
+ NULL
};
-GType bluetooth_pb_agent_get_type(void);
-
-#define BLUETOOTH_PB_TYPE_AGENT (bluetooth_pb_agent_get_type())
-
-#define BLUETOOTH_PB_AGENT(object) \
- (G_TYPE_CHECK_INSTANCE_CAST((object), \
- BLUETOOTH_PB_TYPE_AGENT , BluetoothPbAgent))
-#define BLUETOOTH_PB_AGENT_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass), \
- BLUETOOTH_PB_TYPE_AGENT , BluetoothPbAgentClass))
-#define BLUETOOTH_IS_PB_AGENT(object) \
- (G_TYPE_CHECK_INSTANCE_TYPE((object), \
- BLUETOOTH_PB_TYPE_AGENT))
-#define BLUETOOTH_IS_PB_AGENT_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE((klass), \
- BLUETOOTH_PB_TYPE_AGENT))
-#define BLUETOOTH_PB_AGENT_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS((obj), \
- BLUETOOTH_PB_TYPE_AGENT , BluetoothPbAgentClass))
-
-G_DEFINE_TYPE(BluetoothPbAgent, bluetooth_pb_agent, G_TYPE_OBJECT)
-
-#define DBUS_STRUCT_STRING_STRING_UINT (dbus_g_type_get_struct("GValueArray", G_TYPE_STRING, \
- G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))
-
-static guint signals[LAST_SIGNAL] = { 0 };
static guint total_missed_call_count = 0;
static guint unnotified_missed_call_count = 0;
-static GMainLoop *mainloop = NULL;
-
-static void bluetooth_pb_agent_finalize(GObject *obj);
-
-static void bluetooth_pb_agent_clear(BluetoothPbAgent *agent);
-
-/* Dbus messages */
-static gboolean bluetooth_pb_get_phonebook_folder_list(BluetoothPbAgent *agent,
- const gchar ***folder_list,
- GError **error);
-
-static gboolean bluetooth_pb_get_phonebook(BluetoothPbAgent *agent,
- const char *name,
- guint64 filter,
- guint8 format,
- guint16 max_list_count,
- guint16 list_start_offset,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_get_phonebook_size(BluetoothPbAgent *agent,
- const char *name,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_get_phonebook_list(BluetoothPbAgent *agent,
- const char *name,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_get_phonebook_entry(BluetoothPbAgent *agent,
- const gchar *folder,
- const gchar *id,
- guint64 filter,
- guint8 format,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_get_phonebook_size_at(BluetoothPbAgent *agent,
- const gchar *command,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_get_phonebook_entries_at(BluetoothPbAgent *agent,
- const gchar *command,
- gint32 start_index,
- gint32 end_index,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_get_phonebook_entries_find_at(BluetoothPbAgent *agent,
- const gchar *command,
- const gchar *find_text,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_get_total_object_count(BluetoothPbAgent *agent,
- gchar *path,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_pb_add_contact (BluetoothPbAgent *agent,
- const char *filename,
+GMainLoop *g_mainloop;
+static GDBusConnection *pb_dbus_conn = NULL;
+
+static const gchar pb_agent_introspection_xml[] =
+"<node name='/'>"
+ "<interface name='org.bluez.PbAgent'>"
+ "<method name='GetPhonebookFolderList'>"
+ "<arg type='as' name='folder_list' direction='out'/>"
+ "</method>"
+
+ "<method name='GetPhonebook'>"
+ "<arg type='s' name='name'/>"
+ "<arg type='t' name='filter'/>"
+ "<arg type='y' name='format'/>"
+ "<arg type='q' name='max_list_count'/>"
+ "<arg type='q' name='list_start_offset'/>"
+ "<arg type='as' name='phonebook' direction='out'/>"
+ "<arg type='u' name='new_missed_call' direction='out'/>"
+ "</method>"
+
+ "<method name='GetPhonebookSize'>"
+ "<arg type='s' name='name'/>"
+ "<arg type='u' name='phonebook_size' direction='out'/>"
+ "<arg type='u' name='new_missed_call' direction='out'/>"
+ "</method>"
+
+ "<method name='GetPhonebookList'>"
+ "<arg type='s' name='name'/>"
+ "<arg type='a(ssu)' name='phonebook_list' direction='out'/>"
+ "<arg type='u' name='new_missed_call' direction='out'/>"
+ "</method>"
+
+ "<method name='GetPhonebookEntry'>"
+ "<arg type='s' name='folder'/>"
+ "<arg type='s' name='id'/>"
+ "<arg type='t' name='filter'/>"
+ "<arg type='y' name='format'/>"
+ "<arg type='s' name='phonebook_entry' direction='out'/>"
+ "</method>"
+
+ "<method name='GetTotalObjectCount'>"
+ "<arg type='s' name='path'/>"
+ "<arg type='u' name='phonebook_size' direction='out'/>"
+ "</method>"
+
+ "<method name='AddContact'>"
+ "<arg type='s' name='filename'/>"
+ "</method>"
+
+ "<method name='DestroyAgent'>"
+ "</method>"
+ "</interface>"
+
+ "<interface name='org.bluez.PbAgent.At'>"
+ "<method name='GetPhonebookSizeAt'>"
+ "<arg type='s' name='command'/>"
+ "<arg type='u' name='phonebook_size' direction='out'/>"
+ "</method>"
+
+ "<method name='GetPhonebookEntriesAt'>"
+ "<arg type='s' name='command'/>"
+ "<arg type='i' name='start_index'/>"
+ "<arg type='i' name='end_index'/>"
+ "<arg type='a(ssu)' name='phonebook_entries' direction='out'/>"
+ "</method>"
+
+ "<method name='GetPhonebookEntriesFindAt'>"
+ "<arg type='s' name='command'/>"
+ "<arg type='s' name='find_text' />"
+ "<arg type='a(ssu)' name='phonebook_entries' direction='out'/>"
+ "</method>"
+ "</interface>"
+"</node>";
+
+/* LCOV_EXCL_START */
+static void __bt_pb_agent_method(GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *method_name,
+ GVariant *parameters, GDBusMethodInvocation *invocation,
+ gpointer user_data);
+
+static GVariant *__bt_pb_get_phonebook_folder_list(GError **error);
+
+static GVariant *__bt_pb_get_phonebook(PbAgentData *agent, const char *name,
+ guint64 filter, guint8 format, guint16 max_list_count,
+ guint16 list_start_offset, GError **err);
+
+static GVariant *__bt_pb_get_phonebook_size(PbAgentData *agent,
+ const char *name, GError **err);
+
+static GVariant *__bt_pb_get_phonebook_list(PbAgentData *agent,
+ const char *name, GError **err);
+
+static GVariant *__bt_pb_get_phonebook_entry(PbAgentData *agent,
+ const gchar *folder, const gchar *id, guint64 filter,
+ guint8 format, GError **err);
+
+static GVariant *__bt_pb_get_phonebook_size_at(PbAgentData *agent,
+ const gchar *command, GError **err);
+
+static GVariant *__bt_pb_get_phonebook_entries_at(PbAgentData *agent,
+ const gchar *command, gint32 start_index,
+ gint32 end_index, GError **err);
+
+static GVariant *__bt_pb_get_phonebook_entries_find_at(PbAgentData *agent,
+ const gchar *command, const gchar *find_text,
+ GError **err);
+
+static GVariant *__bt_pb_get_total_object_count(PbAgentData *agent,
+ gchar *path, GError **err);
+
+static gboolean __bt_pb_add_contact(PbAgentData *agent, const char *filename,
GError **error);
-static gboolean bluetooth_pb_destroy_agent(BluetoothPbAgent *agent,
- DBusGMethodInvocation *context);
+static gboolean __bt_pb_destroy_agent();
-static void __bluetooth_pb_dbus_return_error(DBusGMethodInvocation *context,
- gint code,
- const gchar *message);
+static GError *__bt_pb_error(gint error_code, const gchar *error_message);
static PhoneBookType __bluetooth_pb_get_pb_type(const char *name);
static PhoneBookType __bluetooth_pb_get_storage_pb_type(const char *name);
static gint __bluetooth_pb_phone_log_filter_append(contacts_filter_h filter,
- gint *match,
- gint size);
+ gint *match, gint size);
-static contacts_query_h __bluetooth_pb_query_phone_log(gint *match,
- gint size);
+static contacts_query_h __bluetooth_pb_query_phone_log(gint *match, gint size);
static contacts_query_h __bluetooth_pb_query_person(int addressbook);
static contacts_query_h __bluetooth_pb_query_phone_log_combined(void);
-static gboolean __bluetooth_pb_get_count(PhoneBookType pb_type,
- guint *count);
+static gboolean __bluetooth_pb_get_count(PhoneBookType pb_type, guint *count);
static gboolean __bluetooth_pb_get_count_new_missed_call(guint *count);
static const char *__bluetooth_pb_phone_log_get_log_type(contacts_record_h record);
-static void __bluetooth_pb_get_vcards(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- guint64 filter,
- guint8 format,
- guint16 max_list_count,
- guint16 list_start_offset,
- GPtrArray *vcards);
-
-static void __bluetooth_pb_get_contact_list(BluetoothPbAgent *agent,
- contacts_query_h query,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_phone_log_list(BluetoothPbAgent *agent,
- contacts_query_h query,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_list(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_contact_list_number(BluetoothPbAgent *agent,
- contacts_query_h query,
- gint start_index,
- gint end_index,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_phone_log_list_number(BluetoothPbAgent *agent,
- contacts_query_h query,
- gint start_index,
- gint end_index,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_list_number(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- gint start_index,
- gint end_index,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_contact_list_name(BluetoothPbAgent *agent,
- contacts_query_h query,
- const gchar *find_text,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_phone_log_list_name(BluetoothPbAgent *agent,
- contacts_query_h query,
- const gchar *find_text,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_get_list_name(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- const gchar *find_text,
- GPtrArray *ptr_array);
-
-static void __bluetooth_pb_list_ptr_array_add(GPtrArray *ptr_array,
- const gchar *name,
- const gchar *number,
- gint handle);
-
-static void __bluetooth_pb_list_ptr_array_free(gpointer data);
+static void __bluetooth_pb_get_vcards(PbAgentData *agent, PhoneBookType pb_type,
+ guint64 filter, guint8 format, guint16 max_list_count,
+ guint16 list_start_offset, GVariantBuilder *vcards);
-static void __bluetooth_pb_agent_signal_handler(int signum);
+static void __bluetooth_pb_get_contact_list(PbAgentData *agent,
+ contacts_query_h query, GVariantBuilder *builder);
-static void __bluetooth_pb_contact_changed(const gchar *view_uri,
- void *user_data);
+static void __bluetooth_pb_get_phone_log_list(PbAgentData *agent,
+ contacts_query_h query, GVariantBuilder *builder);
-static void __bluetooth_pb_agent_timeout_add_seconds(BluetoothPbAgent *agent);
+static void __bluetooth_pb_get_list(PbAgentData *agent, PhoneBookType pb_type,
+ GVariantBuilder *builder);
-static gboolean __bluetooth_pb_agent_timeout_calback(gpointer user_data);
+static void __bluetooth_pb_get_contact_list_number(PbAgentData *agent,
+ contacts_query_h query, gint start_index,
+ gint end_index, GVariantBuilder *builder);
-static void __bluetooth_pb_tel_callback(TapiHandle *handle,
- int result,
- void *data,
- void *user_data);
+static void __bluetooth_pb_get_phone_log_list_number(PbAgentData *agent,
+ contacts_query_h query, gint start_index,
+ gint end_index, GVariantBuilder *builder);
-static void __bluetooth_pb_agent_dbus_init(BluetoothPbAgent *agent);
+static void __bluetooth_pb_get_list_number(PbAgentData *agent,
+ PhoneBookType pb_type, gint start_index,
+ gint end_index, GVariantBuilder *builder);
-#include "bluetooth_pb_agent_glue.h"
+static void __bluetooth_pb_get_contact_list_name(PbAgentData *agent,
+ contacts_query_h query, const gchar *find_text,
+ GVariantBuilder *builder);
-static void bluetooth_pb_agent_init(BluetoothPbAgent *agent)
-{
- FN_START;
- agent->bus = NULL;
- agent->proxy = NULL;
- agent->tapi_handle = NULL;
- agent->tel_number = NULL;
- agent->timeout_id = 0;
- agent->pb_type = TELECOM_NONE;
- FN_END;
-}
+static void __bluetooth_pb_get_phone_log_list_name(PbAgentData *agent,
+ contacts_query_h query, const gchar *find_text,
+ GVariantBuilder *builder);
-static void bluetooth_pb_agent_class_init(BluetoothPbAgentClass *klass)
-{
- FN_START;
- GObjectClass *object_class = (GObjectClass *) klass;
+static void __bluetooth_pb_get_list_name(PbAgentData *agent,
+ PhoneBookType pb_type, const gchar *find_text,
+ GVariantBuilder *builder);
- klass->clear = bluetooth_pb_agent_clear;
+static void __bluetooth_pb_list_ptr_array_add(GVariantBuilder *builder,
+ const gchar *name, const gchar *number, gint handle);
- object_class->finalize = bluetooth_pb_agent_finalize;
+static void __bluetooth_pb_agent_signal_handler(int signum);
- signals[CLEAR] = g_signal_new("clear",
- G_TYPE_FROM_CLASS(klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(BluetoothPbAgentClass, clear),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+static void __bluetooth_pb_contact_changed(const gchar *view_uri,
+ void *user_data);
- dbus_g_object_type_install_info(BLUETOOTH_PB_TYPE_AGENT,
- &dbus_glib_bluetooth_pb_object_info);
- FN_END;
-}
+static void __bluetooth_pb_agent_timeout_add_seconds(PbAgentData *agent);
-static void bluetooth_pb_agent_finalize(GObject *obj)
-{
- FN_START;
- BluetoothPbAgent *agent = BLUETOOTH_PB_AGENT(obj);
+static gboolean __bluetooth_pb_agent_timeout_calback(gpointer user_data);
- if (agent->tapi_handle) {
- tel_deinit(agent->tapi_handle);
- agent->tapi_handle = NULL;
- }
+static void __bluetooth_pb_tel_callback(TapiHandle *handle, int result,
+ void *data, void *user_data);
- if (agent->tel_number) {
- g_free(agent->tel_number);
- agent->tel_number = NULL;
- }
+static gboolean __bt_pb_dbus_init(PbAgentData *agent);
- if(agent->timeout_id) {
- g_source_remove(agent->timeout_id);
- agent->timeout_id = 0;
- }
+static gboolean __bt_pb_dbus_deinit(PbAgentData *agent);
- if (agent->proxy) {
- g_object_unref(agent->proxy);
- agent->proxy = NULL;
- }
+static const GDBusInterfaceVTable method_table = {
+ __bt_pb_agent_method,
+ NULL,
+ NULL,
+};
- if (agent->bus) {
- dbus_g_connection_unref(agent->bus);
- agent->bus = NULL;
+static void __bt_pb_agent_method(GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *method_name,
+ GVariant *parameters, GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ FN_START;
+ INFO("method: %s; object_path: %s", method_name, object_path);
+ PbAgentData *agent = (PbAgentData *)user_data;
+ GError *err = NULL;
+ if (g_strcmp0(interface_name, "org.bluez.PbAgent") == 0) {
+ if (g_strcmp0(method_name, "GetPhonebookFolderList") == 0) {
+ GVariant *folder_list = NULL;
+
+ folder_list = __bt_pb_get_phonebook_folder_list(&err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ folder_list);
+ } else if (g_strcmp0(method_name, "GetPhonebook") == 0) {
+ GVariant *phonebook = NULL;
+ const char *name;
+ guint64 filter;
+ guint8 format;
+ guint16 max_list_count;
+ guint16 list_start_offset;
+
+ g_variant_get(parameters, "(&styqq)", &name, &filter,
+ &format, &max_list_count,
+ &list_start_offset);
+ phonebook = __bt_pb_get_phonebook(agent, name, filter,
+ format, max_list_count,
+ list_start_offset, &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook);
+ } else if (g_strcmp0(method_name, "GetPhonebookSize") == 0) {
+ GVariant *phonebook_size = NULL;
+ const char *name;
+
+ g_variant_get(parameters, "(&s)", &name);
+ phonebook_size = __bt_pb_get_phonebook_size(agent, name,
+ &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook_size);
+ } else if (g_strcmp0(method_name, "GetPhonebookList") == 0) {
+ GVariant *phonebook_list = NULL;
+ const char *name;
+
+ g_variant_get(parameters, "(&s)", &name);
+ phonebook_list = __bt_pb_get_phonebook_list(agent, name,
+ &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook_list);
+ } else if (g_strcmp0(method_name, "GetPhonebookEntry") == 0) {
+ GVariant *phonebook_entry = NULL;
+ const gchar *folder;
+ const gchar *id;
+ guint64 filter;
+ guint8 format;
+
+ g_variant_get(parameters, "(&s&sty)", &folder, &id,
+ &filter, &format);
+ phonebook_entry = __bt_pb_get_phonebook_entry(agent,
+ folder, id, filter, format, &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook_entry);
+ } else if (g_strcmp0(method_name, "GetTotalObjectCount") == 0) {
+ GVariant *phonebook_size = NULL;
+ gchar *path;
+
+ g_variant_get(parameters, "(&s)", &path);
+ phonebook_size = __bt_pb_get_total_object_count(agent,
+ path, &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook_size);
+ } else if (g_strcmp0(method_name, "AddContact") == 0) {
+ const char *filename;
+
+ g_variant_get(parameters, "(&s)", &filename);
+ __bt_pb_add_contact(agent, filename, &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ } else if (g_strcmp0(method_name, "DestroyAgent") == 0) {
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ __bt_pb_destroy_agent();
+ }
+ } else if (g_strcmp0(interface_name, "org.bluez.PbAgent.At") == 0) {
+ if (g_strcmp0(method_name, "GetPhonebookSizeAt") == 0) {
+ GVariant *phonebook_size = NULL;
+ const gchar *command;
+
+ g_variant_get(parameters, "(&s)", &command);
+ phonebook_size = __bt_pb_get_phonebook_size_at(agent,
+ command, &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook_size);
+ } else if (g_strcmp0(method_name,
+ "GetPhonebookEntriesAt") == 0) {
+ GVariant *phonebook_entries = NULL;
+ const gchar *command;
+ gint32 start_index;
+ gint32 end_index;
+
+ g_variant_get(parameters, "(&sii)",
+ &command, &start_index, &end_index);
+ phonebook_entries = __bt_pb_get_phonebook_entries_at(agent,
+ command, start_index,
+ end_index, &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook_entries);
+ } else if (g_strcmp0(method_name,
+ "GetPhonebookEntriesFindAt") == 0) {
+ GVariant *phonebook_entries = NULL;
+ const gchar *command;
+ const gchar *find_text;
+
+ g_variant_get(parameters, "(&s&s)", &command, &find_text);
+ phonebook_entries = __bt_pb_get_phonebook_entries_find_at(agent,
+ command, find_text, &err);
+ if (err)
+ goto fail;
+ g_dbus_method_invocation_return_value(invocation,
+ phonebook_entries);
+ }
}
+ FN_END;
+ return;
- G_OBJECT_CLASS(bluetooth_pb_agent_parent_class)->finalize(obj);
+fail:
+ g_dbus_method_invocation_return_gerror(invocation, err);
+ g_clear_error(&err);
FN_END;
+ return;
}
-static void bluetooth_pb_agent_clear(BluetoothPbAgent *agent)
+static void bluetooth_pb_agent_clear(PbAgentData *agent)
{
FN_START;
agent->pb_type = TELECOM_NONE;
FN_END;
}
-static gboolean bluetooth_pb_get_phonebook_folder_list(BluetoothPbAgent *agent,
- const gchar ***folder_list,
- GError **error)
+static GDBusConnection *__bt_pb_get_gdbus_connection(void)
+{
+ FN_START;
+ GError *err = NULL;
+
+ if (pb_dbus_conn)
+ return pb_dbus_conn;
+
+ pb_dbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (!pb_dbus_conn) {
+ if (err) {
+ ERR("Unable to connect to dbus: %s", err->message);
+ g_clear_error(&err);
+ }
+ return NULL;
+ }
+ FN_END;
+ return pb_dbus_conn;
+}
+
+static GVariant *__bt_pb_get_phonebook_folder_list(GError **error)
{
FN_START;
+ GVariant *folder_list;
gint size;
gint i;
- gchar **folder;
+ GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
size = G_N_ELEMENTS(bluetooth_pb_agent_folder_list);
- folder = g_new0(gchar *, size);
for (i = 0; i < size; i++)
- folder[i] = g_strdup(bluetooth_pb_agent_folder_list[i]);
+ g_variant_builder_add(builder, "s",
+ bluetooth_pb_agent_folder_list[i]);
- *folder_list = (const gchar **)folder;
+ folder_list = g_variant_new("(as)", builder);
+ g_variant_builder_unref(builder);
FN_END;
- return TRUE;
+ return folder_list;
}
-static gboolean bluetooth_pb_get_phonebook(BluetoothPbAgent *agent,
- const char *name,
- guint64 filter,
- guint8 format,
- guint16 max_list_count,
- guint16 list_start_offset,
- DBusGMethodInvocation *context)
+
+static GVariant *__bt_pb_get_phonebook(PbAgentData *agent, const char *name,
+ guint64 filter, guint8 format, guint16 max_list_count,
+ guint16 list_start_offset, GError **err)
{
FN_START;
+ GVariant *phonebook;
PhoneBookType pb_type = TELECOM_NONE;
- GPtrArray *vcards = NULL;
- gchar **vcards_str = NULL;
+ GVariantBuilder *vcards;
INFO("name: %s filter: %lld format: %d max_list_count: %d list_start_offset: %d\n",
- name, filter, format, max_list_count, list_start_offset);
+ name, (unsigned long long int)filter, format, max_list_count, list_start_offset);
__bluetooth_pb_agent_timeout_add_seconds(agent);
pb_type = __bluetooth_pb_get_pb_type(name);
if (pb_type == TELECOM_NONE) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
- vcards = g_ptr_array_new();
+ vcards = g_variant_builder_new(G_VARIANT_TYPE("as"));
if (max_list_count > 0) {
- __bluetooth_pb_get_vcards(agent, pb_type,
- filter, format,
- max_list_count, list_start_offset,
- vcards);
-
+ __bluetooth_pb_get_vcards(agent, pb_type, filter, format,
+ max_list_count, list_start_offset, vcards);
}
- g_ptr_array_add(vcards, NULL);
-
- vcards_str = (gchar **) g_ptr_array_free(vcards, FALSE);
-
if (pb_type == TELECOM_MCH) {
- dbus_g_method_return(context, vcards_str, unnotified_missed_call_count);
- INFO("Notified [%d] missed call count", unnotified_missed_call_count);
+ phonebook = g_variant_new("(asu)", vcards,
+ unnotified_missed_call_count);
+ INFO("Notified [%d] missed call count",
+ unnotified_missed_call_count);
unnotified_missed_call_count = 0;
} else {
- dbus_g_method_return(context, vcards_str, 0);
+ phonebook = g_variant_new("(asu)", vcards, 0);
}
- g_strfreev(vcards_str);
+ g_variant_builder_unref(vcards);
FN_END;
- return TRUE;
+ return phonebook;
}
-static gboolean bluetooth_pb_get_phonebook_size(BluetoothPbAgent *agent,
- const char *name,
- DBusGMethodInvocation *context)
+static GVariant *__bt_pb_get_phonebook_size(PbAgentData *agent,
+ const char *name, GError **err)
{
FN_START;
+ GVariant *phonebook_size;
PhoneBookType pb_type = TELECOM_NONE;
guint count = 0;
pb_type = __bluetooth_pb_get_pb_type(name);
if (__bluetooth_pb_get_count(pb_type, &count) == FALSE) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
/* for owner */
-#ifdef PBAP_SIM_ENABLE
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
if (pb_type == TELECOM_PB || pb_type == SIM_PB)
count++;
#else
count++;
#endif
if (pb_type == TELECOM_MCH) {
- dbus_g_method_return(context, count, unnotified_missed_call_count);
- INFO("Notified [%d] missed call count", unnotified_missed_call_count);
+ phonebook_size = g_variant_new("(uu)", count,
+ unnotified_missed_call_count);
+ INFO("Notified [%d] missed call count",
+ unnotified_missed_call_count);
unnotified_missed_call_count = 0;
} else {
- dbus_g_method_return(context, count, 0);
+ phonebook_size = g_variant_new("(uu)", count, 0);
}
FN_END;
- return TRUE;
+ return phonebook_size;
}
-static gboolean bluetooth_pb_get_phonebook_list(BluetoothPbAgent *agent,
- const char *name,
- DBusGMethodInvocation *context)
+static GVariant *__bt_pb_get_phonebook_list(PbAgentData *agent,
+ const char *name, GError **err)
{
FN_START;
+ GVariant *phonebook_list;
PhoneBookType pb_type = TELECOM_NONE;
- GPtrArray *ptr_array;
+ GVariantBuilder *builder;
DBG_SECURE("name: %s\n", name);
pb_type = __bluetooth_pb_get_pb_type(name);
if (pb_type == TELECOM_NONE) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
- ptr_array = g_ptr_array_new_with_free_func(__bluetooth_pb_list_ptr_array_free);
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssu)"));
- __bluetooth_pb_get_list(agent, pb_type, ptr_array);
+ __bluetooth_pb_get_list(agent, pb_type, builder);
-// __bluetooth_pb_get_count_new_missed_call(&new_missed_call);
- INFO("pb_type[%d] / number of missed_call[%d]", pb_type, unnotified_missed_call_count);
+ INFO("pb_type[%d] / number of missed_call[%d]", pb_type,
+ unnotified_missed_call_count);
if (pb_type == TELECOM_MCH) {
- dbus_g_method_return(context, ptr_array, unnotified_missed_call_count);
- INFO("Notified [%d] missed call count", unnotified_missed_call_count);
+ phonebook_list = g_variant_new("(a(ssu)u)", builder,
+ unnotified_missed_call_count);
+ INFO("Notified [%d] missed call count",
+ unnotified_missed_call_count);
unnotified_missed_call_count = 0;
} else {
- dbus_g_method_return(context, ptr_array, 0);
+ phonebook_list = g_variant_new("(a(ssu)u)", builder, 0);
}
- if (ptr_array)
- g_ptr_array_free(ptr_array, TRUE);
+ g_variant_builder_unref(builder);
FN_END;
- return TRUE;
+ return phonebook_list;
}
-
-static gboolean bluetooth_pb_get_phonebook_entry(BluetoothPbAgent *agent,
- const gchar *folder,
- const gchar *id,
- guint64 filter,
- guint8 format,
- DBusGMethodInvocation *context)
+static GVariant *__bt_pb_get_phonebook_entry(PbAgentData *agent,
+ const gchar *folder, const gchar *id, guint64 filter,
+ guint8 format, GError **err)
{
FN_START;
+ GVariant *phonebook_entry;
PhoneBookType pb_type = TELECOM_NONE;
-
gint handle = 0;
gchar *str = NULL;
-
const gchar *attr = NULL;
- DBG_SECURE("folder: %s id: %s filter: %ld format: %d\n",
- folder, id, filter, format);
+ DBG_SECURE("folder: %s id: %s filter: %llu format: %d\n",
+ folder, id, (unsigned long long int)filter, format);
__bluetooth_pb_agent_timeout_add_seconds(agent);
if (!g_str_has_suffix(id, ".vcf")) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "invalid vcf file");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL, "invalid vcf file");
+ return NULL;
}
handle = (gint)g_ascii_strtoll(id, NULL, 10);
pb_type = __bluetooth_pb_get_pb_type(folder);
if (pb_type == TELECOM_NONE) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
/* create index cache */
__bluetooth_pb_get_list(agent, pb_type, NULL);
- switch(pb_type) {
+ switch (pb_type) {
case TELECOM_PB:
if (handle == 0) {
str = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
filter, format);
} else {
if (_bluetooth_get_contact_addressbook(handle) == PBAP_ADDRESSBOOK_PHONE)
- str = _bluetooth_pb_vcard_contact(handle, filter, format);
+ str = _bluetooth_pb_vcard_contact(handle,
+ filter, format);
}
break;
case TELECOM_ICH:
- str = _bluetooth_pb_vcard_call(handle, filter, format, "RECEIVED");
+ str = _bluetooth_pb_vcard_call(handle, filter, format,
+ "RECEIVED");
break;
case TELECOM_OCH:
str = _bluetooth_pb_vcard_call(handle, filter, format, "DIALED");
contacts_record_destroy(record, TRUE);
break;
}
-#ifdef PBAP_SIM_ENABLE
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
case SIM_PB:
if (handle == 0) {
str = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
filter, format);
} else {
if (_bluetooth_get_contact_addressbook(handle) == PBAP_ADDRESSBOOK_SIM)
- str = _bluetooth_pb_vcard_contact(handle, filter, format);
+ str = _bluetooth_pb_vcard_contact(handle,
+ filter, format);
}
break;
#endif
default:
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
- dbus_g_method_return(context, str);
+ phonebook_entry = g_variant_new("(s)", str);
+
g_free(str);
FN_END;
- return TRUE;
+ return phonebook_entry;
}
-static gboolean bluetooth_pb_get_phonebook_size_at(BluetoothPbAgent *agent,
- const gchar *command,
- DBusGMethodInvocation *context)
+static GVariant *__bt_pb_get_phonebook_size_at(PbAgentData *agent,
+ const gchar *command, GError **err)
{
FN_START;
+ GVariant *phonebook_size;
PhoneBookType pb_type = TELECOM_NONE;
guint count = 0;
pb_type = __bluetooth_pb_get_storage_pb_type(command);
if (__bluetooth_pb_get_count(pb_type, &count) == FALSE) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
- dbus_g_method_return(context, count);
+ phonebook_size = g_variant_new("(u)", count);
FN_END;
- return TRUE;
+ return phonebook_size;
}
-static gboolean bluetooth_pb_get_phonebook_entries_at(BluetoothPbAgent *agent,
- const gchar *command,
- gint start_index,
- gint end_index,
- DBusGMethodInvocation *context)
+static GVariant *__bt_pb_get_phonebook_entries_at(PbAgentData *agent,
+ const gchar *command, gint32 start_index,
+ gint32 end_index, GError **err)
{
FN_START;
+ GVariant *phonebook_entries;
PhoneBookType pb_type = TELECOM_NONE;
-
- GPtrArray *ptr_array = NULL;
+ GVariantBuilder *builder;
DBG("command: %s, start_index: %d, end_index: %d\n",
command, start_index, end_index);
pb_type = __bluetooth_pb_get_storage_pb_type(command);
if (pb_type == TELECOM_NONE || pb_type == TELECOM_CCH) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
- ptr_array = g_ptr_array_new_with_free_func(__bluetooth_pb_list_ptr_array_free);
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssu)"));
__bluetooth_pb_get_list_number(agent, pb_type,
- start_index, end_index,
- ptr_array);
+ start_index, end_index, builder);
- dbus_g_method_return(context, ptr_array);
-
- if (ptr_array)
- g_ptr_array_free(ptr_array, TRUE);
+ phonebook_entries = g_variant_new("(a(ssu))", builder);
+ g_variant_builder_unref(builder);
FN_END;
- return TRUE;
+ return phonebook_entries;
}
-static gboolean bluetooth_pb_get_phonebook_entries_find_at(BluetoothPbAgent *agent,
- const gchar *command,
- const gchar *find_text,
- DBusGMethodInvocation *context)
+static GVariant *__bt_pb_get_phonebook_entries_find_at(PbAgentData *agent,
+ const gchar *command, const gchar *find_text,
+ GError **err)
{
FN_START;
+ GVariant *phonebook_entries;
PhoneBookType pb_type = TELECOM_NONE;
-
- GPtrArray *ptr_array = NULL;
+ GVariantBuilder *builder;
DBG("command: %s, find text: %s\n", command, find_text);
pb_type = __bluetooth_pb_get_storage_pb_type(command);
if (pb_type == TELECOM_NONE || pb_type == TELECOM_CCH) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
- ptr_array = g_ptr_array_new_with_free_func(__bluetooth_pb_list_ptr_array_free);
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssu)"));
- __bluetooth_pb_get_list_name(agent, pb_type,
- find_text, ptr_array);
+ __bluetooth_pb_get_list_name(agent, pb_type, find_text, builder);
- dbus_g_method_return(context, ptr_array);
+ phonebook_entries = g_variant_new("(a(ssu))", builder);
- if (ptr_array)
- g_ptr_array_free(ptr_array, TRUE);
+ g_variant_builder_unref(builder);
FN_END;
- return TRUE;
+ return phonebook_entries;
}
-static gboolean bluetooth_pb_get_total_object_count(BluetoothPbAgent *agent,
- gchar *path, DBusGMethodInvocation *context)
+static GVariant *__bt_pb_get_total_object_count(PbAgentData *agent,
+ gchar *path, GError **err)
{
FN_START;
+ GVariant *phonebook_size;
guint count = 0;
PhoneBookType pb_type = TELECOM_NONE;
- DBG("%s() %d\n", __FUNCTION__, __LINE__);
-
__bluetooth_pb_agent_timeout_add_seconds(agent);
pb_type = __bluetooth_pb_get_storage_pb_type(path);
if (__bluetooth_pb_get_count(pb_type, &count) == FALSE) {
- __bluetooth_pb_dbus_return_error(context,
- G_FILE_ERROR_INVAL,
- "unsupported name defined");
- return FALSE;
+ *err = __bt_pb_error(G_FILE_ERROR_INVAL,
+ "unsupported name defined");
+ return NULL;
}
- dbus_g_method_return(context, count);
-
- DBG("%s() %d\n", __FUNCTION__, __LINE__);
+ phonebook_size = g_variant_new("(u)", count);
FN_END;
- return TRUE;
+ return phonebook_size;
}
-
#if 0
static int __bluetooth_pb_agent_read_file(const char *file_path, char **stream)
{
if (fstat(fileno(fp), &file_attr) == 0) {
received_file_size = file_attr.st_size;
- DBG("file_attr.st_size = %d, size = %d\n", file_attr.st_size, received_file_size);
+ DBG("file_attr.st_size = %d, size = %d\n", file_attr.st_size,
+ received_file_size);
if (received_file_size <= 0) {
- ERR_SECURE("Some problem in the file size [%s] \n", file_path);
+ ERR_SECURE("Some problem in the file size [%s] \n",
+ file_path);
fclose(fp);
fp = NULL;
return -1;
}
- *stream = (char *)malloc(sizeof(char) * received_file_size);
+ *stream = (char *)malloc(sizeof(char) *received_file_size);
if (NULL == *stream) {
fclose(fp);
fp = NULL;
}
#endif
-static gboolean bluetooth_pb_add_contact(BluetoothPbAgent *agent, const char *filename,
+static gboolean __bt_pb_add_contact(PbAgentData *agent, const char *filename,
GError **error)
{
FN_START;
return FALSE;
}
- is_success = contacts_svc_get_contact_from_vcard((const void *)stream, &contact_record);
+ is_success = contacts_svc_get_contact_from_vcard((const void *)stream,
+ &contact_record);
DBG("contacts_svc_get_contact_from_vcard fucntion call [is_success] = %d \n", is_success);
if (0 == is_success) {
- contacts_svc_struct_get_list(contact_record, CTS_CF_NUMBER_LIST, &numbers_list);
+ contacts_svc_struct_get_list(contact_record, CTS_CF_NUMBER_LIST,
+ &numbers_list);
cursor = numbers_list;
for (; cursor; cursor = g_slist_next(cursor)) {
if (contacts_svc_find_contact_by(CTS_FIND_BY_NUMBER,
- contacts_svc_value_get_str(cursor->data,
- CTS_NUM_VAL_NUMBER_STR)) > 0) {
+ contacts_svc_value_get_str(cursor->data,
+ CTS_NUM_VAL_NUMBER_STR)) > 0) {
DBG("is_duplicated\n");
is_duplicated = TRUE;
}
}
- if (is_duplicated == FALSE) {
+ if (is_duplicated == FALSE)
contacts_svc_insert_contact(0, contact_record);
- }
} else {
ERR("Fail \n");
}
return TRUE;
}
-static void __bluetooth_pb_dbus_return_error(DBusGMethodInvocation *context,
- gint code,
- const gchar *message)
+/* Create GError from error code and error message*/
+static GError *__bt_pb_error(gint error_code, const gchar *error_message)
{
- FN_START;
- GQuark quark;
- GError *error = NULL;
-
- quark = g_type_qname(bluetooth_pb_agent_get_type());
- error = g_error_new_literal(quark, code, message);
-
- DBG("%s\n", message);
-
- dbus_g_method_return_error(context, error);
- g_error_free(error);
- FN_END;
+ return g_error_new(g_quark_from_string("PB Agent"),
+ error_code, "PB Agent Error: %s", error_message);
}
static PhoneBookType __bluetooth_pb_get_pb_type(const char *name)
if (name == NULL)
return TELECOM_NONE;
- if (g_strcmp0(name, "\"ME\"") == 0 )
+ if (g_strcmp0(name, "\"ME\"") == 0)
return TELECOM_PB;
if (g_strcmp0(name, "\"RC\"") == 0)
if (g_strcmp0(name, "\"MC\"") == 0)
return TELECOM_MCH;
-
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
+ if (g_strcmp0(name, "\"SM\"") == 0)
+ return SIM_PB;
+#endif
FN_END;
return TELECOM_NONE;
}
static gint __bluetooth_pb_phone_log_filter_append(contacts_filter_h filter,
- gint *match,
- gint size)
+ gint *match, gint size)
{
FN_START;
gint i;
for (i = 0; i < size; i++) {
- if ( i > 0) {
+ if (i > 0) {
status = contacts_filter_add_operator(filter,
CONTACTS_FILTER_OPERATOR_OR);
}
status = contacts_filter_add_int(filter,
- _contacts_phone_log.log_type,
- CONTACTS_MATCH_EQUAL,
- match[i]);
+ _contacts_phone_log.log_type,
+ CONTACTS_MATCH_EQUAL, match[i]);
if (status != CONTACTS_ERROR_NONE)
return status;
return CONTACTS_ERROR_NONE;
}
-static contacts_query_h __bluetooth_pb_query_phone_log(gint *match,
- gint size)
+static contacts_query_h __bluetooth_pb_query_phone_log(gint *match, gint size)
{
FN_START;
contacts_query_h query = NULL;
contacts_filter_h filter = NULL;
-
gint status;
- status = contacts_query_create(_contacts_phone_log._uri,
- &query);
+ status = contacts_query_create(_contacts_phone_log._uri, &query);
if (status != CONTACTS_ERROR_NONE)
return NULL;
return NULL;
}
- status = contacts_query_set_sort(query,
- _contacts_phone_log.log_time,
- false);
+ status = contacts_query_set_sort(query, _contacts_phone_log.log_time,
+ false);
if (status != CONTACTS_ERROR_NONE) {
contacts_filter_destroy(filter);
contacts_filter_h filter = NULL;
contacts_list_h recordList = NULL;
contacts_record_h record = NULL;
-
- char* addressbook_name = NULL;
+ char *addressbook_name = NULL;
int address_book_id = 0;
int count = 0;
unsigned int i = 0;
gint status;
bool is_first_condition = true;
+
DBG("Addressbook [%d]", addressbook);
/* Create query*/
status = contacts_query_create(_contacts_person_contact._uri, &query);
}
/* Create addressbook Filter*/
- contacts_db_get_all_records(_contacts_address_book._uri, 0, 0, &recordList);
+ status = contacts_db_get_all_records(_contacts_address_book._uri, 0, 0,
+ &recordList);
+ if (status != CONTACTS_ERROR_NONE)
+ ERR("Contact list get api failed %d", status);
+
contacts_filter_create(_contacts_person_contact._uri, &filter);
contacts_list_get_count(recordList, &count);
ERR("Contact list get api failed %d", status);
goto next;
}
- status = contacts_record_get_str_p(record, _contacts_address_book.name,
- &addressbook_name);
+ status = contacts_record_get_str_p(record,
+ _contacts_address_book.name,
+ &addressbook_name);
if (status != CONTACTS_ERROR_NONE) {
ERR("Contact record get api failed %d", status);
goto next;
}
- status = contacts_record_get_int(record, _contacts_address_book.id,
- &address_book_id);
+ status = contacts_record_get_int(record,
+ _contacts_address_book.id,
+ &address_book_id);
if (status != CONTACTS_ERROR_NONE) {
ERR("contacts record get int api failed %d", status);
goto next;
address_book_id, addressbook_name);
if (__bt_is_matching_addressbook(addressbook_name,
- addressbook)) {
+ addressbook)) {
if (is_first_condition)
is_first_condition = false;
else
contacts_list_destroy(recordList, true);
+ if (is_first_condition) {
+ ERR("ADDRESSBOOK NOT FOUND");
+ contacts_filter_destroy(filter);
+ contacts_query_destroy(query);
+ return NULL;
+ }
+
status = contacts_query_set_filter(query, filter);
if (status != CONTACTS_ERROR_NONE)
ERR("Could not Apply Filter");
{
FN_START;
contacts_query_h query = NULL;
-
gint status;
- status = contacts_query_create(_contacts_person_number._uri,
- &query);
+ status = contacts_query_create(_contacts_person_number._uri, &query);
if (status != CONTACTS_ERROR_NONE)
return NULL;
{
FN_START;
contacts_query_h query = NULL;
-
gint status;
gint signed_count;
case TELECOM_CCH:
query = __bluetooth_pb_query_phone_log_combined();
break;
-#ifdef PBAP_SIM_ENABLE
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
case SIM_PB:
query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_SIM);
break;
{
FN_START;
contacts_query_h query = NULL;
-
gint status;
gint signed_count;
-
gint size = 2;
gint match[] = {
CONTACTS_PLOG_TYPE_VOICE_INCOMING_UNSEEN,
gint status;
gint log_type;
- status = contacts_record_get_int(record,
- _contacts_phone_log.log_type,
- &log_type);
+ status = contacts_record_get_int(record, _contacts_phone_log.log_type,
+ &log_type);
if (status != CONTACTS_ERROR_NONE)
return NULL;
FN_END;
}
-static void __bluetooth_pb_get_vcards(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- guint64 filter,
- guint8 format,
- guint16 max_list_count,
- guint16 list_start_offset,
- GPtrArray *vcards)
+static void __bluetooth_pb_get_vcards(PbAgentData *agent, PhoneBookType pb_type,
+ guint64 filter, guint8 format, guint16 max_list_count,
+ guint16 list_start_offset, GVariantBuilder *vcards)
{
FN_START;
contacts_list_h record_list = NULL;
contacts_query_h query = NULL;
-
gint status;
-
gint limit;
gint offset;
-
guint property_id = 0;
-
const char *attr = NULL;
-
gboolean get_log = FALSE;
/* contact offset is n - 1 of PBAP */
offset = (gint)list_start_offset - 1;
- if ( max_list_count >= 65535)
+ if (max_list_count >= 65535)
limit = -1; /* contact limit -1 means unrestricted */
else
limit = (gint)max_list_count;
switch (pb_type) {
case TELECOM_PB:
-#ifdef PBAP_SIM_ENABLE
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
case SIM_PB:
#endif
/* for owner */
vcard = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
filter, format);
if (vcard)
- g_ptr_array_add(vcards, vcard);
+ g_variant_builder_add(vcards, "s", vcard);
offset = 0;
if (pb_type == TELECOM_PB)
query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_PHONE);
-#ifdef PBAP_SIM_ENABLE
- else if(pb_type == SIM_PB)
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
+ else if (pb_type == SIM_PB)
query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_SIM);
#endif
}
INFO("Limit is = %d and offset is =%d\n", limit, offset);
- /* When limit is passed as ZERO to contacts_db_get_records_with_query API
- * then this API will provide all available contacts in its database (unrestricted).
- * Now consider a case when client requests for maxlistcount of 1 and start offset as 0
- * then we have already read the owner card in above switch case and when it reads owner
- * card it decrements the limit by 1.
+ if (query == NULL) {
+ ERR("Query is NULL");
+ return;
+ }
+ /* When limit is passed as ZERO to contacts_db_get_records_with_query
+ * API then this API will provide all available contacts in its database
+ * (unrestricted). Now consider a case when client requests for
+ * maxlistcount of 1 and start offset as 0 then we have already read the
+ * owner card in above switch case and when it reads owner card it
+ * decrements the limit by 1.
*/
- if(limit != 0)
- {
- status = contacts_db_get_records_with_query(query, offset, limit, &record_list);
+ if (limit != 0) {
+ status = contacts_db_get_records_with_query(query, offset,
+ limit, &record_list);
if (status != CONTACTS_ERROR_NONE) {
contacts_list_destroy(record_list, TRUE);
do {
contacts_record_h record;
-
gint id;
-
gchar *vcard = NULL;
- record = NULL;
- status = contacts_list_get_current_record_p(record_list, &record);
+ status = contacts_list_get_current_record_p(record_list,
+ &record);
if (status != CONTACTS_ERROR_NONE)
continue;
- id = 0;
- status = contacts_record_get_int(record, property_id, &id);
+ status = contacts_record_get_int(record, property_id,
+ &id);
if (status != CONTACTS_ERROR_NONE)
continue;
if (property_id == _contacts_person.id)
- vcard = _bluetooth_pb_vcard_contact(id, filter, format);
+ vcard = _bluetooth_pb_vcard_contact(id, filter,
+ format);
else {
if (get_log)
attr = __bluetooth_pb_phone_log_get_log_type(record);
- vcard = _bluetooth_pb_vcard_call(id, filter, format, attr);
+ vcard = _bluetooth_pb_vcard_call(id, filter,
+ format, attr);
}
if (vcard)
- g_ptr_array_add(vcards, vcard);
+ g_variant_builder_add(vcards, "s", vcard);
} while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
contacts_list_destroy(record_list, TRUE);
FN_END;
}
-static void __bluetooth_pb_get_contact_list(BluetoothPbAgent *agent,
- contacts_query_h query,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_contact_list(PbAgentData *agent,
+ contacts_query_h query, GVariantBuilder *builder)
{
FN_START;
contacts_list_h record_list = NULL;
-
gint status;
/* Add owner */
- if (ptr_array) {
+ if (builder) {
gchar *tmp;
gchar *name;
name = g_strdup_printf("%s;;;;", tmp);
g_free(tmp);
- __bluetooth_pb_list_ptr_array_add(ptr_array,
- name, agent->tel_number, 0);
+ __bluetooth_pb_list_ptr_array_add(builder, name,
+ agent->tel_number, 0);
g_free(name);
}
- status = contacts_db_get_records_with_query(query,
- -1, -1, &record_list);
+ if (query == NULL) {
+ ERR("Query is NULL");
+ return;
+ }
+
+ status = contacts_db_get_records_with_query(query, -1, -1,
+ &record_list);
if (status != CONTACTS_ERROR_NONE) {
contacts_list_destroy(record_list, TRUE);
do {
contacts_record_h record;
-
gint id;
- record = NULL;
status = contacts_list_get_current_record_p(record_list,
- &record);
+ &record);
if (status != CONTACTS_ERROR_NONE)
continue;
- id = 0;
status = contacts_record_get_int(record,
- _contacts_person_contact.person_id,
- &id);
+ _contacts_person_contact.person_id, &id);
if (status != CONTACTS_ERROR_NONE)
continue;
/* create list */
- if (ptr_array) {
+ if (builder) {
gchar *name;
gchar *number;
name = _bluetooth_pb_name_from_person_id(id);
number = _bluetooth_pb_number_from_person_id(id);
- __bluetooth_pb_list_ptr_array_add(ptr_array,
- name, number, id);
+ __bluetooth_pb_list_ptr_array_add(builder, name,
+ number, id);
g_free(name);
g_free(number);
FN_END;
}
-static void __bluetooth_pb_get_phone_log_list(BluetoothPbAgent *agent,
- contacts_query_h query,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_phone_log_list(PbAgentData *agent,
+ contacts_query_h query, GVariantBuilder *builder)
{
FN_START;
contacts_list_h record_list = NULL;
-
gint status;
- status = contacts_db_get_records_with_query(query,
- -1, -1, &record_list);
+ status = contacts_db_get_records_with_query(query, -1, -1,
+ &record_list);
if (status != CONTACTS_ERROR_NONE)
return;
do {
contacts_record_h record;
-
gint id;
- record = NULL;
status = contacts_list_get_current_record_p(record_list,
- &record);
+ &record);
if (status != CONTACTS_ERROR_NONE)
continue;
- id = 0;
status = contacts_record_get_int(record,
- _contacts_phone_log.id,
- &id);
+ _contacts_phone_log.id, &id);
if (status != CONTACTS_ERROR_NONE)
continue;
/* create list */
- if (ptr_array) {
+ if (builder) {
gchar *name;
gchar *number;
name = _bluetooth_pb_name_from_phonelog_id(id);
- number = NULL;
contacts_record_get_str_p(record,
- _contacts_phone_log.address,
- &number);
+ _contacts_phone_log.address, &number);
- __bluetooth_pb_list_ptr_array_add(ptr_array,
- name, number, id);
+ __bluetooth_pb_list_ptr_array_add(builder, name,
+ number, id);
g_free(name);
}
}
-static void __bluetooth_pb_get_list(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_list(PbAgentData *agent, PhoneBookType pb_type,
+ GVariantBuilder *builder)
{
FN_START;
contacts_query_h query;
/* no requires refresh cache */
- if (ptr_array == NULL && agent->pb_type == pb_type)
+ if (builder == NULL && agent->pb_type == pb_type)
return;
switch (pb_type) {
case TELECOM_PB:
query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_PHONE);
- __bluetooth_pb_get_contact_list(agent, query, ptr_array);
+ __bluetooth_pb_get_contact_list(agent, query, builder);
break;
case TELECOM_ICH:
query = __bluetooth_pb_query_phone_log_incoming();
- __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
+ __bluetooth_pb_get_phone_log_list(agent, query, builder);
break;
case TELECOM_OCH:
query = __bluetooth_pb_query_phone_log_outgoing();
- __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
+ __bluetooth_pb_get_phone_log_list(agent, query, builder);
break;
case TELECOM_MCH:
query = __bluetooth_pb_query_phone_log_missed();
- __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
+ __bluetooth_pb_get_phone_log_list(agent, query, builder);
break;
case TELECOM_CCH:
query = __bluetooth_pb_query_phone_log_combined();
- __bluetooth_pb_get_phone_log_list(agent, query, ptr_array);
+ __bluetooth_pb_get_phone_log_list(agent, query, builder);
break;
-#ifdef PBAP_SIM_ENABLE
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
case SIM_PB:
query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_SIM);
- __bluetooth_pb_get_contact_list(agent, query, ptr_array);
+ __bluetooth_pb_get_contact_list(agent, query, builder);
break;
#endif
default:
FN_END;
}
-static void __bluetooth_pb_get_contact_list_number(BluetoothPbAgent *agent,
- contacts_query_h query,
- gint start_index,
- gint end_index,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_contact_list_number(PbAgentData *agent,
+ contacts_query_h query, gint start_index,
+ gint end_index, GVariantBuilder *builder)
{
FN_START;
contacts_list_h record_list = NULL;
i = from;
- status = contacts_db_get_records_with_query(query,
- from - 1 , offset,
+ status = contacts_db_get_records_with_query(query, from - 1 , offset,
&record_list);
if (status != CONTACTS_ERROR_NONE) {
do {
contacts_record_h record;
-
gchar *display_name;
gchar *number;
- record = NULL;
status = contacts_list_get_current_record_p(record_list,
- &record);
+ &record);
if (status != CONTACTS_ERROR_NONE)
continue;
- display_name = NULL;
- number = NULL;
-
contacts_record_get_str_p(record,
- _contacts_person_number.display_name,
- &display_name);
+ _contacts_person_number.display_name,
+ &display_name);
contacts_record_get_str_p(record,
- _contacts_person_number.number,
- &number);
+ _contacts_person_number.number, &number);
- __bluetooth_pb_list_ptr_array_add(ptr_array,
- display_name, number, i);
+ __bluetooth_pb_list_ptr_array_add(builder, display_name,
+ number, i);
i++;
} while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
FN_END;
}
-static void __bluetooth_pb_get_phone_log_list_number(BluetoothPbAgent *agent,
- contacts_query_h query,
- gint start_index,
- gint end_index,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_phone_log_list_number(PbAgentData *agent,
+ contacts_query_h query, gint start_index,
+ gint end_index, GVariantBuilder *builder)
{
FN_START;
contacts_list_h record_list = NULL;
-
gint status;
-
gint i;
-
gint from;
gint to;
gint offset;
i = from;
- status = contacts_db_get_records_with_query(query,
- from - 1 , offset,
+ status = contacts_db_get_records_with_query(query, from - 1 , offset,
&record_list);
if (status != CONTACTS_ERROR_NONE) {
}
do {
- contacts_record_h record = NULL;
-
+ contacts_record_h record;
gint id;
-
gchar *display_name;
gchar *number;
- record = NULL;
status = contacts_list_get_current_record_p(record_list,
- &record);
+ &record);
if (status != CONTACTS_ERROR_NONE)
continue;
- id = 0;
status = contacts_record_get_int(record,
- _contacts_phone_log.id,
- &id);
+ _contacts_phone_log.id, &id);
if (status != CONTACTS_ERROR_NONE) {
ERR("contact_record_get_int api failed %d", status);
continue;
display_name = _bluetooth_pb_fn_from_phonelog_id(id);
- number = NULL;
- contacts_record_get_str_p(record,
- _contacts_phone_log.address,
- &number);
-
+ contacts_record_get_str_p(record, _contacts_phone_log.address,
+ &number);
- __bluetooth_pb_list_ptr_array_add(ptr_array,
- display_name, number, i);
+ __bluetooth_pb_list_ptr_array_add(builder, display_name,
+ number, i);
i++;
FN_END;
}
-static void __bluetooth_pb_get_list_number(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- gint start_index,
- gint end_index,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_list_number(PbAgentData *agent,
+ PhoneBookType pb_type, gint start_index,
+ gint end_index, GVariantBuilder *builder)
{
FN_START;
contacts_query_h query;
+ DBG("type = %d", pb_type);
switch (pb_type) {
case TELECOM_PB:
- query = __bluetooth_pb_query_person_number();
+ query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_PHONE);
__bluetooth_pb_get_contact_list_number(agent, query,
- start_index, end_index, ptr_array);
+ start_index, end_index, builder);
break;
case TELECOM_ICH:
query = __bluetooth_pb_query_phone_log_incoming();
__bluetooth_pb_get_phone_log_list_number(agent, query,
- start_index, end_index, ptr_array);
+ start_index, end_index, builder);
break;
case TELECOM_OCH:
query = __bluetooth_pb_query_phone_log_outgoing();
__bluetooth_pb_get_phone_log_list_number(agent, query,
- start_index, end_index, ptr_array);
+ start_index, end_index, builder);
break;
case TELECOM_MCH:
query = __bluetooth_pb_query_phone_log_missed();
__bluetooth_pb_get_phone_log_list_number(agent, query,
- start_index, end_index, ptr_array);
+ start_index, end_index, builder);
break;
case TELECOM_CCH:
query = __bluetooth_pb_query_phone_log_combined();
__bluetooth_pb_get_phone_log_list_number(agent, query,
- start_index, end_index, ptr_array);
+ start_index, end_index, builder);
+ break;
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
+ case SIM_PB:
+ query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_SIM);
+ __bluetooth_pb_get_contact_list_number(agent, query,
+ start_index, end_index, builder);
break;
+#endif
+
default:
return;
}
FN_END;
}
-static void __bluetooth_pb_get_contact_list_name(BluetoothPbAgent *agent,
- contacts_query_h query,
- const gchar *find_text,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_contact_list_name(PbAgentData *agent,
+ contacts_query_h query, const gchar *find_text,
+ GVariantBuilder *builder)
{
FN_START;
contacts_list_h record_list = NULL;
-
gint status;
gint i = 1;
do {
contacts_record_h record;
-
gchar *display_name;
- record = NULL;
status = contacts_list_get_current_record_p(record_list,
- &record);
+ &record);
if (status != CONTACTS_ERROR_NONE)
continue;
- display_name = NULL;
contacts_record_get_str_p(record,
- _contacts_person_number.display_name,
- &display_name);
+ _contacts_person_number.display_name, &display_name);
if (g_str_has_prefix(display_name, find_text)) {
gchar *number;
- number = NULL;
contacts_record_get_str_p(record,
- _contacts_person_number.number,
- &number);
+ _contacts_person_number.number, &number);
- __bluetooth_pb_list_ptr_array_add(ptr_array,
- display_name, number, i);
+ __bluetooth_pb_list_ptr_array_add(builder, display_name,
+ number, i);
}
i++;
FN_END;
}
-static void __bluetooth_pb_get_phone_log_list_name(BluetoothPbAgent *agent,
- contacts_query_h query,
- const gchar *find_text,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_phone_log_list_name(PbAgentData *agent,
+ contacts_query_h query, const gchar *find_text,
+ GVariantBuilder *builder)
{
FN_START;
contacts_list_h record_list = NULL;
-
gint status;
-
gint i = 1;
- status = contacts_db_get_records_with_query(query,
- -1, -1,
- &record_list);
+ status = contacts_db_get_records_with_query(query, -1, -1,
+ &record_list);
if (status != CONTACTS_ERROR_NONE) {
contacts_list_destroy(record_list, TRUE);
}
do {
- contacts_record_h record = NULL;
-
+ contacts_record_h record;
gint id;
-
gchar *display_name;
- record = NULL;
status = contacts_list_get_current_record_p(record_list,
&record);
if (status != CONTACTS_ERROR_NONE)
continue;
- id = 0;
status = contacts_record_get_int(record,
- _contacts_phone_log.id,
- &id);
+ _contacts_phone_log.id, &id);
if (status != CONTACTS_ERROR_NONE) {
ERR("contacts_record_get_int failed %d", status);
continue;
display_name = _bluetooth_pb_fn_from_phonelog_id(id);
if (g_str_has_prefix(display_name, find_text)) {
- gchar *number = NULL;
+ gchar *number;
- number = NULL;
contacts_record_get_str_p(record,
- _contacts_phone_log.address,
- &number);
+ _contacts_phone_log.address, &number);
- __bluetooth_pb_list_ptr_array_add(ptr_array,
- display_name, number, i);
+ __bluetooth_pb_list_ptr_array_add(builder, display_name,
+ number, i);
}
i++;
FN_END;
}
-static void __bluetooth_pb_get_list_name(BluetoothPbAgent *agent,
- PhoneBookType pb_type,
- const gchar *find_text,
- GPtrArray *ptr_array)
+static void __bluetooth_pb_get_list_name(PbAgentData *agent,
+ PhoneBookType pb_type, const gchar *find_text,
+ GVariantBuilder *builder)
{
FN_START;
contacts_query_h query;
case TELECOM_PB:
query = __bluetooth_pb_query_person_number();
__bluetooth_pb_get_contact_list_name(agent, query,
- find_text, ptr_array);
+ find_text, builder);
break;
case TELECOM_ICH:
query = __bluetooth_pb_query_phone_log_incoming();
__bluetooth_pb_get_phone_log_list_name(agent, query,
- find_text, ptr_array);
+ find_text, builder);
break;
case TELECOM_OCH:
query = __bluetooth_pb_query_phone_log_outgoing();
__bluetooth_pb_get_phone_log_list_name(agent, query,
- find_text, ptr_array);
+ find_text, builder);
break;
case TELECOM_MCH:
query = __bluetooth_pb_query_phone_log_missed();
__bluetooth_pb_get_phone_log_list_name(agent, query,
- find_text, ptr_array);
+ find_text, builder);
break;
case TELECOM_CCH:
query = __bluetooth_pb_query_phone_log_combined();
__bluetooth_pb_get_phone_log_list_name(agent, query,
- find_text, ptr_array);
+ find_text, builder);
break;
default:
return;
FN_END;
}
-static void __bluetooth_pb_list_ptr_array_add(GPtrArray *ptr_array,
- const gchar *name,
- const gchar *number,
- gint handle)
+static void __bluetooth_pb_list_ptr_array_add(GVariantBuilder *builder,
+ const gchar *name, const gchar *number, gint handle)
{
FN_START;
- GValue value = { 0, };
gchar *temp_name = g_strdup(name);
gchar *temp_number = g_strdup(number);
- g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
- g_value_take_boxed(&value,
- dbus_g_type_specialized_construct(DBUS_STRUCT_STRING_STRING_UINT));
+ g_variant_builder_add(builder, "(ssu)", temp_name, temp_number, handle);
- dbus_g_type_struct_set(&value,
- 0, temp_name,
- 1, temp_number,
- 2, handle,
- G_MAXUINT);
-
- g_ptr_array_add(ptr_array, g_value_get_boxed(&value));
g_free(temp_name);
g_free(temp_number)
FN_END;
}
-static void __bluetooth_pb_list_ptr_array_free(gpointer data)
-{
- FN_START;
- GValue value = { 0, };
-
- gchar *name = NULL;
- gchar *number = NULL;
-
- if(data == NULL)
- return;
-
- g_value_init(&value, DBUS_STRUCT_STRING_STRING_UINT);
- g_value_set_boxed(&value, data);
-
- dbus_g_type_struct_get(&value,
- 0, &name,
- 1, &number,
- G_MAXUINT);
-
- g_free(name);
- g_free(number);
- FN_END;
-}
-
static void __bluetooth_pb_agent_signal_handler(int signum)
{
FN_START;
- if (mainloop) {
- g_main_loop_quit(mainloop);
+ if (g_mainloop) {
+ g_main_loop_quit(g_mainloop);
} else {
DBG("Terminate Bluetooth PBAP agent");
exit(0);
}
}
-
static void __bluetooth_pb_contact_changed(const gchar *view_uri,
void *user_data)
{
FN_START;
- BluetoothPbAgent *agent;
guint new_missed_call;
+ PbAgentData *agent = (PbAgentData *)user_data;
+ GDBusConnection *conn = __bt_pb_get_gdbus_connection();
DBG("Received contact changed cb");
- g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
- agent = BLUETOOTH_PB_AGENT(user_data);
- g_object_ref(agent);
- g_signal_emit(agent, signals[CLEAR], 0);
- g_object_unref(agent);
+ g_dbus_connection_emit_signal(conn, NULL,
+ "/org/bluez/pb_agent", "org.bluez.PbAgent",
+ "clear", NULL, NULL);
+
+ bluetooth_pb_agent_clear(agent);
__bluetooth_pb_get_count_new_missed_call(&new_missed_call);
if (new_missed_call > total_missed_call_count)
- unnotified_missed_call_count += new_missed_call - total_missed_call_count;
+ unnotified_missed_call_count += new_missed_call -
+ total_missed_call_count;
INFO("Missed call count : #prev[%d], #current[%d], #unnotified[%d]",
- total_missed_call_count, new_missed_call, unnotified_missed_call_count);
+ total_missed_call_count, new_missed_call,
+ unnotified_missed_call_count);
total_missed_call_count = new_missed_call;
FN_END;
}
-static void __bluetooth_pb_agent_timeout_add_seconds(BluetoothPbAgent *agent)
+static void __bluetooth_pb_agent_timeout_add_seconds(PbAgentData *agent)
{
FN_START;
- g_return_if_fail(BLUETOOTH_IS_PB_AGENT(agent));
- if(agent->timeout_id)
+ if (agent->timeout_id)
g_source_remove(agent->timeout_id);
agent->timeout_id = g_timeout_add_seconds(BLUETOOTH_PB_AGENT_TIMEOUT,
- __bluetooth_pb_agent_timeout_calback,
- agent);
+ __bluetooth_pb_agent_timeout_calback, agent);
FN_END;
}
static gboolean __bluetooth_pb_agent_timeout_calback(gpointer user_data)
{
FN_START;
- BluetoothPbAgent *agent;
-
- g_return_val_if_fail(BLUETOOTH_IS_PB_AGENT(user_data), FALSE);
+ PbAgentData *agent = (PbAgentData *)user_data;
- agent = BLUETOOTH_PB_AGENT(user_data);
agent->timeout_id = 0;
- if (mainloop)
- g_main_loop_quit(mainloop);
+ if (g_mainloop)
+ g_main_loop_quit(g_mainloop);
FN_END;
return FALSE;
}
-static void __bluetooth_pb_tel_callback(TapiHandle *handle,
- int result,
- void *data,
- void *user_data)
+static void __bluetooth_pb_tel_callback(TapiHandle *handle, int result,
+ void *data, void *user_data)
{
FN_START;
- BluetoothPbAgent *agent;
+ PbAgentData *agent = (PbAgentData *)user_data;
TelSimMsisdnList_t *number;
- g_return_if_fail(BLUETOOTH_IS_PB_AGENT(user_data));
-
- agent = BLUETOOTH_PB_AGENT(user_data);
-
- __bluetooth_pb_agent_dbus_init(agent);
+ __bt_pb_dbus_init(agent);
if (data != NULL) {
number = (TelSimMsisdnList_t *)data;
FN_END;
}
-static void __bluetooth_pb_agent_dbus_init(BluetoothPbAgent *agent)
+static gboolean __bt_pb_destroy_agent()
{
FN_START;
- guint result = 0;
- GError *error = NULL;
+ g_main_loop_quit(g_mainloop);
+ FN_END;
+ return TRUE;
+}
- agent->bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+static GDBusNodeInfo *__bt_pb_create_method_node_info
+ (const gchar *introspection_data)
+{
+ GError *err = NULL;
+ GDBusNodeInfo *node_info = NULL;
- if (error != NULL) {
- ERR("Couldn't connect to system bus[%s]\n", error->message);
- g_error_free(error);
- return;
+ if (introspection_data == NULL)
+ return NULL;
+
+ node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
+
+ if (err) {
+ ERR("Unable to create node: %s", err->message);
+ g_clear_error(&err);
}
+ return node_info;
+}
- agent->proxy = dbus_g_proxy_new_for_name(agent->bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
+static gboolean __bt_pb_dbus_init(PbAgentData *agent)
+{
+ guint owner_id = 0;
+ guint pb_id;
+ GDBusNodeInfo *node_info = NULL;
+ GError *error = NULL;
+ GDBusConnection *conn = __bt_pb_get_gdbus_connection();
- if (agent->proxy == NULL) {
- ERR("Failed to get a proxy for D-Bus\n");
- return;
+ if (conn == NULL) {
+ ERR("Error in creating the gdbus connection");
+ goto fail;
}
- if (!dbus_g_proxy_call(agent->proxy,
- "RequestName", &error,
- G_TYPE_STRING, BT_PB_SERVICE_NAME,
- G_TYPE_UINT, 0,
- G_TYPE_INVALID,
- G_TYPE_UINT, &result,
- G_TYPE_INVALID)) {
- if (error != NULL) {
- ERR("RequestName RPC failed[%s]\n", error->message);
- g_error_free(error);
- }
+ owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, BT_PB_SERVICE_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE, NULL,
+ NULL, NULL, NULL, NULL);
+ if (owner_id == 0)
+ goto fail;
- g_object_unref(agent->proxy);
- agent->proxy = NULL;
+ node_info = __bt_pb_create_method_node_info(pb_agent_introspection_xml);
+ if (node_info == NULL)
+ goto fail;
- return;
+ pb_id = g_dbus_connection_register_object(conn, BT_PB_SERVICE_OBJECT_PATH,
+ node_info->interfaces[0], &method_table,
+ agent, NULL, &error);
+
+ if (pb_id == 0) {
+ ERR("Failed to register: %s", error->message);
+ g_clear_error(&error);
+ goto fail;
}
- DBG("result : %d %d\n", result, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
- if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- ERR("Failed to get the primary well-known name.\n");
- g_object_unref(agent->proxy);
- agent->proxy = NULL;
+ agent->pbagent_interface_id = pb_id;
- return;
+ pb_id = g_dbus_connection_register_object(conn, BT_PB_SERVICE_OBJECT_PATH,
+ node_info->interfaces[1], &method_table,
+ agent, NULL, &error);
+
+ if (pb_id == 0) {
+ ERR("Failed to register: %s", error->message);
+ g_clear_error(&error);
+ goto fail;
}
- g_object_unref(agent->proxy);
- agent->proxy = NULL;
+ g_dbus_node_info_unref(node_info);
- dbus_g_connection_register_g_object(agent->bus,
- BT_PB_SERVICE_OBJECT_PATH,
- G_OBJECT(agent));
- FN_END;
+ agent->pbagent_at_interface_id = pb_id;
+
+ return TRUE;
+
+fail:
+ if (pb_dbus_conn) {
+ g_object_unref(pb_dbus_conn);
+ pb_dbus_conn = NULL;
+ }
+
+ if (conn)
+ g_object_unref(conn);
+
+ if (node_info)
+ g_dbus_node_info_unref(node_info);
+
+ if (owner_id > 0)
+ g_bus_unown_name(owner_id);
+
+ return FALSE;
}
-static gboolean bluetooth_pb_destroy_agent(BluetoothPbAgent *agent,
- DBusGMethodInvocation *context)
+static gboolean __bt_pb_dbus_deinit(PbAgentData *agent)
{
- FN_START;
- g_main_loop_quit(mainloop);
- FN_END;
- return TRUE;
+ if (pb_dbus_conn) {
+ if (agent->pbagent_interface_id != 0) {
+ g_dbus_connection_unregister_object(pb_dbus_conn,
+ agent->pbagent_interface_id);
+ agent->pbagent_interface_id = 0;
+ }
+ if (agent->pbagent_at_interface_id != 0) {
+ g_dbus_connection_unregister_object(pb_dbus_conn,
+ agent->pbagent_at_interface_id);
+ agent->pbagent_at_interface_id = 0;
+ }
+ if (pb_dbus_conn) {
+ g_object_unref(pb_dbus_conn);
+ pb_dbus_conn = NULL;
+ }
+ return TRUE;
+ }
+ return FALSE;
}
int main(void)
{
FN_START;
- BluetoothPbAgent *agent;
-
+ PbAgentData *agent;
gint ret = EXIT_SUCCESS;
gint tapi_result;
-
struct sigaction sa;
- DBG("Starting Bluetooth PBAP agent");
- g_type_init();
+ DBG("Starting Bluetooth PBAP agent");
- mainloop = g_main_loop_new(NULL, FALSE);
- if (mainloop == NULL) {
+ g_mainloop = g_main_loop_new(NULL, FALSE);
+ if (g_mainloop == NULL) {
ERR("Couldn't create GMainLoop\n");
return EXIT_FAILURE;
}
- agent = g_object_new(BLUETOOTH_PB_TYPE_AGENT, NULL);
+ agent = (PbAgentData *)g_malloc(sizeof(PbAgentData));
+
+ if (agent == NULL)
+ return EXIT_FAILURE;
+
+ agent->pbagent_interface_id = 0;
+ agent->pbagent_at_interface_id = 0;
+ agent->tel_number = NULL;
/* connect contact */
if (contacts_connect() != CONTACTS_ERROR_NONE) {
ERR("Can not connect contacts server\n");
- g_object_unref(agent);
+ g_free(agent);
return EXIT_FAILURE;
}
tapi_result = tel_get_sim_msisdn(agent->tapi_handle,
__bluetooth_pb_tel_callback, agent);
- if (tapi_result != TAPI_API_SUCCESS) {
- __bluetooth_pb_agent_dbus_init(agent);
- }
-
+ if (tapi_result != TAPI_API_SUCCESS)
+ __bt_pb_dbus_init(agent);
__bluetooth_pb_agent_timeout_add_seconds(agent);
- g_main_loop_run(mainloop);
+ g_main_loop_run(g_mainloop);
if (contacts_db_remove_changed_cb(_contacts_phone_log._uri,
__bluetooth_pb_contact_changed,
if (contacts_disconnect() != CONTACTS_ERROR_NONE)
ERR("contacts_disconnect failed \n");
- g_signal_emit(agent, signals[CLEAR], 0);
+ g_dbus_connection_emit_signal(pb_dbus_conn, NULL,
+ "/org/bluez/pb_agent", "org.bluez.PbAgent",
+ "clear", NULL, NULL);
+
+ bluetooth_pb_agent_clear(agent);
+
+ if (agent->tapi_handle)
+ tel_deinit(agent->tapi_handle);
+ if (agent->tel_number)
+ g_free(agent->tel_number);
+
+ __bt_pb_dbus_deinit(agent);
- g_object_unref(agent);
+ g_free(agent);
DBG("Terminate Bluetooth PBAP agent");
FN_END;
return ret;
}
+/* LCOV_EXCL_STOP */