[gnome-bluetooth/obexd: 3/3] Initial bluetooth-sendto port to BlueZ 5
- From: Emilio Pozuelo Monfort <epm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/obexd: 3/3] Initial bluetooth-sendto port to BlueZ 5
- Date: Fri, 10 May 2013 14:37:06 +0000 (UTC)
commit 1fff54e5f97d95864483807a444b6472b4b1d94b
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date: Fri May 10 16:36:17 2013 +0200
Initial bluetooth-sendto port to BlueZ 5
sendto/main.c | 147 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 117 insertions(+), 30 deletions(-)
---
diff --git a/sendto/main.c b/sendto/main.c
index 4846a78..5a41765 100644
--- a/sendto/main.c
+++ b/sendto/main.c
@@ -32,16 +32,12 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
-#include <obex-agent.h>
#include <bluetooth-client.h>
#include <bluetooth-chooser.h>
-#define AGENT_PATH "/org/bluez/agent/sendto"
-
#define RESPONSE_RETRY 1
static GDBusConnection *conn = NULL;
-static ObexAgent *agent = NULL;
static GDBusProxy *client_proxy = NULL;
static GtkWidget *dialog;
@@ -67,6 +63,7 @@ static gint64 last_update = 0;
static void send_notify(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data);
+#if 0
/* Agent callbacks */
static gboolean release_callback(GDBusMethodInvocation *context, gpointer user_data);
static gboolean request_callback(GDBusMethodInvocation *context, GDBusProxy *transfer, gpointer user_data);
@@ -79,6 +76,111 @@ static gboolean error_callback(GDBusMethodInvocation *context,
GDBusProxy *transfer,
const char *message,
gpointer user_data);
+#endif
+
+static void
+transfer_properties_changed (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ GStrv invalidated_properties,
+ gpointer user_data)
+{
+ g_variant_print (changed_properties, TRUE);
+}
+
+static void
+transfer_proxy (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
+{
+ GDBusProxy *transfer;
+ GError *error = NULL;
+
+ transfer = g_dbus_proxy_new_finish (res, &error);
+
+ if (error) {
+
+ }
+
+ g_signal_connect (G_OBJECT (transfer), "g-properties-changed",
+ G_CALLBACK (transfer_properties_changed), NULL);
+}
+
+static void
+transfer_created (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
+{
+ GError *error = NULL;
+ GVariant *variant;
+ GVariantBuilder *properties;
+ const gchar *transfer;
+
+ variant = g_dbus_proxy_call_finish (proxy, res, &error);
+
+ if (error) {
+
+ }
+
+ g_variant_get (variant, "oa{sv}", &transfer, &properties);
+
+ g_dbus_proxy_new (conn,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.bluez.obex",
+ transfer,
+ "org.bluez.obex.Transfer1",
+ NULL,
+ (GAsyncReadyCallback) transfer_proxy,
+ NULL);
+
+ g_variant_unref (variant);
+}
+
+static void
+session_proxy (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
+{
+ GDBusProxy *opp;
+ GError *error = NULL;
+
+ opp = g_dbus_proxy_new_finish (res, &error);
+
+ if (error) {
+
+ }
+
+ g_dbus_proxy_call (opp,
+ "SendFile",
+ g_variant_new ("(s)", option_files[0]),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ (GAsyncReadyCallback) transfer_created,
+ NULL);
+}
+
+static void
+session_created (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
+{
+ GError *error = NULL;
+ GVariant *variant;
+ const gchar *session;
+
+ variant = g_dbus_proxy_call_finish (proxy, res, &error);
+
+ if (error) {
+
+ }
+
+ session = g_variant_get_string (variant, NULL);
+
+ g_dbus_proxy_new (conn,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.bluez.obex",
+ session,
+ "org.bluez.obex.ObjectPush1",
+ NULL,
+ (GAsyncReadyCallback) session_proxy,
+ NULL);
+
+ g_variant_unref (variant);
+}
static void
send_files (void)
@@ -87,37 +189,22 @@ send_files (void)
GVariantBuilder *builder;
builder = g_variant_builder_new (G_VARIANT_TYPE_DICTIONARY);
- g_variant_builder_add (builder, "{sv}", "Destination", g_variant_new_string (option_device));
+ g_variant_builder_add (builder, "{ss}", "Target", "opp");
- parameters = g_variant_new ("(a{sv}^aso)", builder, option_files, AGENT_PATH);
+ parameters = g_variant_new ("(sa{ss})", option_device, builder);
g_dbus_proxy_call (client_proxy,
- "SendFiles",
+ "CreateSession",
parameters,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
- (GAsyncReadyCallback) send_notify,
+ (GAsyncReadyCallback) session_created,
NULL);
g_variant_builder_unref (builder);
}
-static void
-setup_agent (void)
-{
- if (agent == NULL)
- agent = obex_agent_new();
-
- obex_agent_set_release_func(agent, release_callback, NULL);
- obex_agent_set_request_func(agent, request_callback, NULL);
- obex_agent_set_progress_func(agent, progress_callback, NULL);
- obex_agent_set_complete_func(agent, complete_callback, NULL);
- obex_agent_set_error_func(agent, error_callback, NULL);
-
- obex_agent_setup(agent, AGENT_PATH);
-}
-
static gchar *filename_to_path(const gchar *filename)
{
GFile *file;
@@ -182,8 +269,6 @@ static void response_callback(GtkWidget *dialog,
gint response, gpointer user_data)
{
if (response == RESPONSE_RETRY) {
- setup_agent ();
-
/* Reset buttons */
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), RESPONSE_RETRY, FALSE);
@@ -197,6 +282,7 @@ static void response_callback(GtkWidget *dialog,
}
if (current_transfer != NULL) {
+#if 0
obex_agent_set_error_func(agent, NULL, NULL);
g_dbus_proxy_call (current_transfer,
"Cancel",
@@ -206,6 +292,7 @@ static void response_callback(GtkWidget *dialog,
NULL,
(GAsyncReadyCallback) NULL,
NULL);
+#endif
g_object_unref (current_transfer);
current_transfer = NULL;
}
@@ -387,6 +474,7 @@ static gchar *get_device_name(const gchar *address)
return found_name;
}
+#if 0
static void get_properties_callback (GDBusProxy *proxy,
GAsyncResult *res,
gpointer user_data)
@@ -577,6 +665,7 @@ static gboolean error_callback(GDBusMethodInvocation *invocation,
return TRUE;
}
+#endif
static void
send_notify (GDBusProxy *proxy,
@@ -817,14 +906,12 @@ int main(int argc, char *argv[])
client_proxy = g_dbus_proxy_new_sync (conn,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
- "org.openobex.client",
- "/",
- "org.openobex.Client",
+ "org.bluez.obex",
+ "/org/bluez/obex",
+ "org.bluez.obex.Client1",
NULL,
NULL);
- setup_agent ();
-
send_files ();
gtk_main();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]