summaryrefslogtreecommitdiff
path: root/client/pbap.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2011-08-12 11:45:13 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2011-08-12 15:23:17 +0300
commitedf89e293cd332facdbebdb7d73b8323d9a829db (patch)
treee38b08abb923d72c6f4106688fa7b92e5be9d2d3 /client/pbap.c
parent571b824cfe2d0533dd902b8d3f15a51482265dde (diff)
downloadobexd-edf89e293cd332facdbebdb7d73b8323d9a829db.tar.gz
client: add pbap target
pbap target implements phonebook access driver
Diffstat (limited to 'client/pbap.c')
-rw-r--r--client/pbap.c82
1 files changed, 66 insertions, 16 deletions
diff --git a/client/pbap.c b/client/pbap.c
index 2b8afbf..1fa4cb3 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -32,9 +32,13 @@
#include <glib.h>
#include <gdbus.h>
+#include <bluetooth/bluetooth.h>
+
#include "log.h"
+
#include "transfer.h"
#include "session.h"
+#include "driver.h"
#include "pbap.h"
#define ERROR_INF PBAP_INTERFACE ".Error"
@@ -115,11 +119,11 @@ static const char *filter_list[] = {
#define FILTER_ALL 0xFFFFFFFFFFFFFFFFULL
#define PBAP_INTERFACE "org.openobex.PhonebookAccess"
+#define PBAP_UUID "0000112f-0000-1000-8000-00805f9b34fb"
struct pbap_data {
struct obc_session *session;
char *path;
- DBusConnection *conn;
DBusMessage *msg;
guint8 format;
guint8 order;
@@ -158,6 +162,8 @@ struct apparam_hdr {
#define APPARAM_HDR_SIZE 2
+static DBusConnection *conn = NULL;
+
static void listing_element(GMarkupParseContext *ctxt,
const gchar *element,
const gchar **names,
@@ -374,7 +380,7 @@ static void pull_phonebook_callback(struct obc_session *session,
obc_transfer_clear_buffer(transfer);
send:
- g_dbus_send_message(pbap->conn, reply);
+ g_dbus_send_message(conn, reply);
dbus_message_unref(pbap->msg);
pbap->msg = NULL;
@@ -412,7 +418,7 @@ static void phonebook_size_callback(struct obc_session *session,
obc_transfer_clear_buffer(transfer);
send:
- g_dbus_send_message(pbap->conn, reply);
+ g_dbus_send_message(conn, reply);
dbus_message_unref(pbap->msg);
pbap->msg = NULL;
@@ -460,7 +466,7 @@ static void pull_vcard_listing_callback(struct obc_session *session,
obc_transfer_clear_buffer(transfer);
send:
- g_dbus_send_message(pbap->conn, reply);
+ g_dbus_send_message(conn, reply);
dbus_message_unref(pbap->msg);
pbap->msg = NULL;
complete:
@@ -986,33 +992,77 @@ static void pbap_free(void *data)
struct pbap_data *pbap = data;
obc_session_unref(pbap->session);
- dbus_connection_unref(pbap->conn);
g_free(pbap);
}
-gboolean pbap_register_interface(DBusConnection *connection, const char *path,
- void *user_data)
+static int pbap_probe(struct obc_session *session)
{
- struct obc_session *session = user_data;
struct pbap_data *pbap;
+ const char *path;
+
+ path = obc_session_get_path(session);
+
+ DBG("%s", path);
pbap = g_try_new0(struct pbap_data, 1);
if (!pbap)
- return FALSE;
+ return -ENOMEM;
pbap->session = obc_session_ref(session);
- pbap->conn = dbus_connection_ref(connection);
- if (g_dbus_register_interface(connection, path, PBAP_INTERFACE,
- pbap_methods, NULL, NULL, pbap, pbap_free) == FALSE) {
+ if (!g_dbus_register_interface(conn, path, PBAP_INTERFACE, pbap_methods,
+ NULL, NULL, pbap, pbap_free)) {
pbap_free(pbap);
- return FALSE;
+ return -ENOMEM;
}
- return TRUE;
+ return 0;
}
-void pbap_unregister_interface(DBusConnection *connection, const char *path)
+static void pbap_remove(struct obc_session *session)
+{
+ const char *path = obc_session_get_path(session);
+
+ DBG("%s", path);
+
+ g_dbus_unregister_interface(conn, path, PBAP_INTERFACE);
+}
+
+static struct obc_driver pbap = {
+ .service = "PBAP",
+ .uuid = PBAP_UUID,
+ .target = OBEX_PBAP_UUID,
+ .target_len = OBEX_PBAP_UUID_LEN,
+ .probe = pbap_probe,
+ .remove = pbap_remove
+};
+
+int pbap_init(void)
{
- g_dbus_unregister_interface(connection, path, PBAP_INTERFACE);
+ int err;
+
+ DBG("");
+
+ conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
+ if (!conn)
+ return -EIO;
+
+ err = obc_driver_register(&pbap);
+ if (err < 0) {
+ dbus_connection_unref(conn);
+ conn = NULL;
+ return err;
+ }
+
+ return 0;
+}
+
+void pbap_exit(void)
+{
+ DBG("");
+
+ dbus_connection_unref(conn);
+ conn = NULL;
+
+ obc_driver_unregister(&pbap);
}