[gnome-bluetooth] Add support for Error callbacks to ObexAgent



commit 949856fdd904b00a734c82d0125dd6a3d1b0ac2f
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Dec 14 15:04:18 2009 +0000

    Add support for Error callbacks to ObexAgent

 lib/obex-agent.c   |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/obex-agent.h   |    7 ++++++-
 lib/obex-agent.xml |    6 ++++++
 3 files changed, 60 insertions(+), 1 deletions(-)
---
diff --git a/lib/obex-agent.c b/lib/obex-agent.c
index 276fcb3..b53c2cc 100644
--- a/lib/obex-agent.c
+++ b/lib/obex-agent.c
@@ -65,6 +65,9 @@ struct _ObexAgentPrivate {
 
 	ObexAgentCompleteFunc complete_func;
 	gpointer complete_data;
+
+	ObexAgentErrorFunc error_func;
+	gpointer error_data;
 };
 
 G_DEFINE_TYPE(ObexAgent, obex_agent, G_TYPE_OBJECT)
@@ -198,6 +201,40 @@ static gboolean obex_agent_release(ObexAgent *agent,
 	return result;
 }
 
+static gboolean obex_agent_error(ObexAgent *agent,
+				 const char *path,
+				 const char *message,
+				 DBusGMethodInvocation *context)
+{
+	ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
+	char *sender = dbus_g_method_get_sender(context);
+	gboolean result = FALSE;
+
+	DBG("agent %p sender %s", agent, sender);
+
+	if (g_str_equal(sender, priv->busname) == FALSE) {
+		g_free (sender);
+		return FALSE;
+	}
+
+	g_free (sender);
+
+	if (priv->error_func) {
+		DBusGProxy *proxy;
+
+		proxy = dbus_g_proxy_new_for_name(connection, OBEX_SERVICE,
+						path, OBEX_TRANSFER_INTERFACE);
+
+		result = priv->error_func(context, proxy, message,
+							priv->progress_data);
+
+		g_object_unref(proxy);
+	} else
+		dbus_g_method_return(context);
+
+	return result;
+}
+
 #include "obex-agent-glue.h"
 
 static void obex_agent_init(ObexAgent *agent)
@@ -331,3 +368,14 @@ void obex_agent_set_complete_func(ObexAgent *agent,
 	priv->complete_func = func;
 	priv->complete_data = data;
 }
+
+void obex_agent_set_error_func(ObexAgent *agent,
+			       ObexAgentErrorFunc func, gpointer data)
+{
+	ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
+
+	DBG("agent %p", agent);
+
+	priv->error_func = func;
+	priv->error_data = data;
+}
diff --git a/lib/obex-agent.h b/lib/obex-agent.h
index e8c8a61..fbdb6bd 100644
--- a/lib/obex-agent.h
+++ b/lib/obex-agent.h
@@ -67,6 +67,10 @@ typedef gboolean (*ObexAgentProgressFunc) (DBusGMethodInvocation *context,
 					guint64 transferred, gpointer data);
 typedef gboolean (*ObexAgentCompleteFunc) (DBusGMethodInvocation *context,
 					DBusGProxy *transfer, gpointer data);
+typedef gboolean (*ObexAgentErrorFunc) (DBusGMethodInvocation *context,
+					DBusGProxy *transfer,
+					const char *message,
+					gpointer data);
 
 void obex_agent_set_release_func(ObexAgent *agent,
 				ObexAgentReleaseFunc func, gpointer data);
@@ -76,7 +80,8 @@ void obex_agent_set_progress_func(ObexAgent *agent,
 				ObexAgentProgressFunc func, gpointer data);
 void obex_agent_set_complete_func(ObexAgent *agent,
 				ObexAgentCompleteFunc func, gpointer data);
-
+void obex_agent_set_error_func(ObexAgent *agent,
+			       ObexAgentErrorFunc func, gpointer data);
 G_END_DECLS
 
 #endif /* __OBEX_AGENT_H */
diff --git a/lib/obex-agent.xml b/lib/obex-agent.xml
index 540a926..082ca95 100644
--- a/lib/obex-agent.xml
+++ b/lib/obex-agent.xml
@@ -22,5 +22,11 @@
     <method name="Release">
       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
     </method>
+
+    <method name="Error">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <arg type="o" name="transfer"/>
+      <arg type="s" name="message"/>
+    </method>
   </interface>
 </node>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]