[Xfce4-commits] [xfce/tumbler] 02/11: Port tumbler-service to gdbus. Also get rid of some dbus low level code in favor of their gdbus equivalents.

noreply at xfce.org noreply at xfce.org
Mon May 15 13:20:30 CEST 2017


This is an automated email from the git hooks/post-receive script.

ali pushed a commit to branch master
in repository xfce/tumbler.

commit 91111b97d8b43a216c8c37ea734b789f79e48421
Author: Ali Abdallah <aliovx at gmail.com>
Date:   Sat Oct 10 13:07:56 2015 +0200

    Port tumbler-service to gdbus.
    Also get rid of some dbus low level code
    in favor of their gdbus equivalents.
---
 tumblerd/Makefile.am              |  21 +-
 tumblerd/main.c                   |  37 ++-
 tumblerd/tumbler-service-dbus.xml |  10 +-
 tumblerd/tumbler-service.c        | 555 +++++++++++++++++---------------------
 tumblerd/tumbler-service.h        |  24 +-
 tumblerd/tumbler-utils.h          |  30 +++
 6 files changed, 312 insertions(+), 365 deletions(-)

diff --git a/tumblerd/Makefile.am b/tumblerd/Makefile.am
index b4b9110..7ce05ab 100644
--- a/tumblerd/Makefile.am
+++ b/tumblerd/Makefile.am
@@ -25,9 +25,11 @@ tumblerd_PROGRAMS =							\
 
 tumblerd_built_sources =						\
 	tumbler-cache-service-dbus-bindings.h				\
-	tumbler-service-dbus-bindings.h			\
-	tumbler-manager-gdbus.c					\
-	tumbler-manager-gdbus.h
+	tumbler-manager-gdbus.c					        \
+	tumbler-manager-gdbus.h                                         \
+	tumbler-service-gdbus.c					        \
+	tumbler-service-gdbus.h
+
 
 tumblerd_SOURCES =							\
 	main.c								\
@@ -120,10 +122,6 @@ BUILT_SOURCES =								\
 tumbler-cache-service-dbus-bindings.h: tumbler-cache-service-dbus.xml Makefile
 	$(AM_V_GEN) $(DBUS_BINDING_TOOL) --mode=glib-server --prefix=tumbler_cache_service $< > $@
 
-
-tumbler-service-dbus-bindings.h: tumbler-service-dbus.xml Makefile
-	$(AM_V_GEN) $(DBUS_BINDING_TOOL) --mode=glib-server --prefix=tumbler_service $< > $@
-
 tumbler-manager-gdbus.h:
 tumbler-manager-gdbus.c: tumbler-manager-dbus.xml Makefile
 	$(AM_V_GEN) $(GDBUS_CODEGEN) \
@@ -131,3 +129,12 @@ tumbler-manager-gdbus.c: tumbler-manager-dbus.xml Makefile
 	--c-namespace Tumbler 	\
 	--generate-c-code tumbler-manager-gdbus \
 	$(srcdir)/tumbler-manager-dbus.xml
+
+tumbler-service-gdbus.h:
+tumbler-service-gdbus.c: tumbler-service-dbus.xml Makefile
+	$(AM_V_GEN) $(GDBUS_CODEGEN) \
+	--interface-prefix org.freedesktop.thumbnails.Thumbnailer1 \
+	--c-namespace Tumbler 	\
+	--generate-c-code tumbler-service-gdbus \
+	$(srcdir)/tumbler-service-dbus.xml
+
diff --git a/tumblerd/main.c b/tumblerd/main.c
index e498218..54ffe79 100644
--- a/tumblerd/main.c
+++ b/tumblerd/main.c
@@ -1,7 +1,8 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
  * Copyright (c) 2009-2012 Jannis Pohlmann <jannis at xfce.org>
- *
+ * Copyright (c) 2015      Ali Abdallah    <ali at xfce.org>
+ *  
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation; either version 2 of 
@@ -376,7 +377,7 @@ main (int    argc,
   manager = tumbler_manager_new (gconnection, lifecycle_manager, registry);
 
   /* create the generic thumbnailer service */
-  service = tumbler_service_new (connection, lifecycle_manager, registry);
+  service = tumbler_service_new (gconnection, lifecycle_manager, registry);
 
   /* try to load specialized thumbnailers and exit if that fails */
   if (!tumbler_registry_load (registry, &error))
@@ -402,24 +403,22 @@ main (int    argc,
   
   /* Acquire the manager dbus name */
   g_bus_own_name_on_connection (gconnection,
-				"org.freedesktop.thumbnails.Manager1",
-				G_BUS_NAME_OWNER_FLAGS_REPLACE,
-				NULL, /* We dont need to do anything on name acquired*/
-				on_dbus_name_lost,
-				main_loop,
-				NULL);
-
+				                        "org.freedesktop.thumbnails.Manager1",
+				                        G_BUS_NAME_OWNER_FLAGS_REPLACE,
+				                        NULL, /* We dont need to do anything on name acquired*/
+				                        on_dbus_name_lost,
+				                        main_loop,
+				                        NULL);
+	
+  /* Acquire the thumbnailer service dbus name */
+  g_bus_own_name_on_connection (gconnection,
+				                        "org.freedesktop.thumbnails.Thumbnailer1",
+				                        G_BUS_NAME_OWNER_FLAGS_REPLACE,
+				                        NULL, /* We dont need to do anything on name acquired*/
+				                        on_dbus_name_lost,
+				                        main_loop,
+				                        NULL);
   
-  /* try to start the service and exit if that fails */
-  if (!tumbler_service_start (service, &error))
-    {
-      g_warning (_("Failed to start the thumbnailer service: %s"), error->message);
-      g_error_free (error);
-
-      /* service already running, exit gracefully to not break clients */
-      goto exit_tumbler;
-    }
-
   /* create a new main loop */
   main_loop = g_main_loop_new (NULL, FALSE);
 
diff --git a/tumblerd/tumbler-service-dbus.xml b/tumblerd/tumbler-service-dbus.xml
index 9076691..4aa77ec 100644
--- a/tumblerd/tumbler-service-dbus.xml
+++ b/tumblerd/tumbler-service-dbus.xml
@@ -1,8 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <node name="/org/freedesktop/thumbnails/Thumbnailer1">
-  <interface name="org.freedesktop.thumbnails.Thumbnailer1">
+  	<interface name="org.freedesktop.thumbnails.Thumbnailer1">
+		
+	<annotation name="org.gtk.GDBus.C.Name" value="ExportedService" />
+		
     <method name="Queue">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="as" name="uris" direction="in" />
       <arg type="as" name="mime_types" direction="in" />
       <arg type="s" name="flavor" direction="in" />
@@ -12,23 +14,19 @@
     </method>
 
     <method name="Dequeue">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="u" name="handle" direction="in" />
     </method>
 
     <method name="GetSupported">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true" />
       <arg type="as" name="uri_schemes" direction="out" />
       <arg type="as" name="mime_types" direction="out" />
     </method>
 
     <method name="GetSchedulers">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true" />
       <arg type="as" name="schedulers" direction="out" />
     </method>
 
     <method name="GetFlavors">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true" />
       <arg type="as" name="flavors" direction="out" />
     </method>
 
diff --git a/tumblerd/tumbler-service.c b/tumblerd/tumbler-service.c
index d46a2db..e54e99a 100644
--- a/tumblerd/tumbler-service.c
+++ b/tumblerd/tumbler-service.c
@@ -1,7 +1,8 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
  * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
- *
+ * Copyright (c) 2015      Ali Abdallah    <ali at xfce.org>
+ * 
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation; either version 2 of 
@@ -28,20 +29,15 @@
 
 #include <gio/gio.h>
 
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
 #include <tumbler/tumbler.h>
 
 #include <tumblerd/tumbler-component.h>
 #include <tumblerd/tumbler-scheduler.h>
 #include <tumblerd/tumbler-service.h>
-#include <tumblerd/tumbler-service-dbus-bindings.h>
 #include <tumblerd/tumbler-lifo-scheduler.h>
 #include <tumblerd/tumbler-group-scheduler.h>
 #include <tumblerd/tumbler-utils.h>
-
+#include <tumblerd/tumbler-service-gdbus.h>
 
 
 #define THUMBNAILER_PATH    "/org/freedesktop/thumbnails/Thumbnailer1"
@@ -50,15 +46,6 @@
 
 
 
-/* signal identifiers */
-enum
-{
-  SIGNAL_ERROR,
-  SIGNAL_FINISHED,
-  SIGNAL_READY,
-  SIGNAL_STARTED,
-  LAST_SIGNAL,
-};
 
 /* property identifiers */
 enum
@@ -84,6 +71,27 @@ static void tumbler_service_set_property       (GObject            *object,
                                                 guint               prop_id,
                                                 const GValue       *value,
                                                 GParamSpec         *pspec);
+static gboolean tumbler_service_queue_cb        (TumblerExportedService  *skeleton,
+                                                 GDBusMethodInvocation   *invocation,
+                                                 const gchar *const      *uris,
+                                                 const gchar *const      *mime_hints,
+                                                 const gchar             *flavor_name,
+                                                 const gchar             *scheduler_name,
+                                                 guint                    handle_to_dequeue,
+                                                 TumblerService          *service);
+static gboolean tumbler_service_dequeue_cb      (TumblerExportedService  *skeleton,
+                                                 GDBusMethodInvocation   *invocation,
+                                                 guint                     handle,
+                                                 TumblerService          *service);
+static gboolean tumbler_service_get_schedulers_cb(TumblerExportedService  *skeleton,
+                                                  GDBusMethodInvocation   *invocation,
+                                                  TumblerService          *service);
+static gboolean tumbler_service_get_supported_cb(TumblerExportedService  *skeleton,
+                                                 GDBusMethodInvocation   *invocation,
+                                                 TumblerService          *service);
+static gboolean tumbler_service_get_flavors_cb  (TumblerExportedService  *skeleton,
+                                                 GDBusMethodInvocation   *invocation,
+                                                 TumblerService          *service);
 static void tumbler_service_scheduler_error    (TumblerScheduler   *scheduler,
                                                 guint               handle,
                                                 const gchar *const *failed_uris,
@@ -118,14 +126,17 @@ struct _TumblerServiceClass
 
 struct _TumblerService
 {
-  TumblerComponent  __parent__;
+  TumblerComponent       __parent__;
 
-  DBusGConnection  *connection;
-  TumblerRegistry  *registry;
-  TUMBLER_MUTEX     (mutex);
-  GList            *schedulers;
+  GDBusConnection        *connection;
+  TumblerExportedService *skeleton;
+  gboolean                dbus_interface_exported;
+  
+  TumblerRegistry        *registry;
+  TUMBLER_MUTEX          (mutex);
+  GList                  *schedulers;
 
-  GVolumeMonitor   *volume_monitor;
+  GVolumeMonitor         *volume_monitor;
 };
 
 struct _SchedulerIdleInfo
@@ -141,9 +152,6 @@ struct _SchedulerIdleInfo
 
 
 
-static guint tumbler_service_signals[LAST_SIGNAL];
-
-
 
 G_DEFINE_TYPE (TumblerService, tumbler_service, TUMBLER_TYPE_COMPONENT);
 
@@ -161,11 +169,12 @@ tumbler_service_class_init (TumblerServiceClass *klass)
   gobject_class->set_property = tumbler_service_set_property;
 
   g_object_class_install_property (gobject_class, PROP_CONNECTION,
-                                   g_param_spec_pointer ("connection",
-                                                         "connection",
-                                                         "connection",
-                                                         G_PARAM_READWRITE |
-                                                         G_PARAM_CONSTRUCT_ONLY));
+                                   g_param_spec_object ("connection",
+                                                        "connection",
+                                                        "connection",
+                                                        G_TYPE_DBUS_CONNECTION,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
 
   g_object_class_install_property (gobject_class, PROP_REGISTRY,
                                    g_param_spec_object ("registry",
@@ -174,57 +183,6 @@ tumbler_service_class_init (TumblerServiceClass *klass)
                                                         TUMBLER_TYPE_REGISTRY,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT_ONLY));
-
-  tumbler_service_signals[SIGNAL_ERROR] =
-    g_signal_new ("error",
-                  TUMBLER_TYPE_SERVICE,
-                  G_SIGNAL_RUN_LAST,
-                  0,
-                  NULL,
-                  NULL,
-                  tumbler_marshal_VOID__UINT_POINTER_INT_STRING,
-                  G_TYPE_NONE,
-                  4,
-                  G_TYPE_UINT,
-                  G_TYPE_STRV,
-                  G_TYPE_INT,
-                  G_TYPE_STRING);
-
-  tumbler_service_signals[SIGNAL_FINISHED] =
-    g_signal_new ("finished",
-                  TUMBLER_TYPE_SERVICE,
-                  G_SIGNAL_RUN_LAST,
-                  0,
-                  NULL,
-                  NULL,
-                  g_cclosure_marshal_VOID__UINT,
-                  G_TYPE_NONE,
-                  1,
-                  G_TYPE_UINT);
-
-  tumbler_service_signals[SIGNAL_READY] =
-    g_signal_new ("ready",
-                  TUMBLER_TYPE_SERVICE,
-                  G_SIGNAL_RUN_LAST,
-                  0,
-                  NULL,
-                  NULL,
-                  g_cclosure_marshal_VOID__POINTER,
-                  G_TYPE_NONE,
-                  1,
-                  G_TYPE_STRV);
-
-  tumbler_service_signals[SIGNAL_STARTED] =
-    g_signal_new ("started",
-                  TUMBLER_TYPE_SERVICE,
-                  G_SIGNAL_RUN_LAST,
-                  0,
-                  NULL,
-                  NULL,
-                  g_cclosure_marshal_VOID__UINT,
-                  G_TYPE_NONE,
-                  1,
-                  G_TYPE_UINT);
 }
 
 
@@ -281,7 +239,8 @@ tumbler_service_constructed (GObject *object)
 {
   TumblerScheduler *scheduler;
   TumblerService   *service = TUMBLER_SERVICE (object);
-
+  GError           *error = NULL;
+  
   /* chain up to parent classes */
   if (G_OBJECT_CLASS (tumbler_service_parent_class)->constructed != NULL)
     (G_OBJECT_CLASS (tumbler_service_parent_class)->constructed) (object);
@@ -297,13 +256,37 @@ tumbler_service_constructed (GObject *object)
   g_object_unref (scheduler);
 
   /* everything is fine, install the generic thumbnailer D-Bus info */
-  dbus_g_object_type_install_info (G_OBJECT_TYPE (service),
-                                   &dbus_glib_tumbler_service_object_info);
-
-  /* register the service instance as a handler of this interface */
-  dbus_g_connection_register_g_object (service->connection, 
-                                       THUMBNAILER_PATH, 
-                                       G_OBJECT (service));
+  service->skeleton = tumbler_exported_service_skeleton_new();
+  
+  g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON(service->skeleton),
+                                    service->connection,
+                                    THUMBNAILER_PATH,
+                                    &error);
+  if (error != NULL)
+    {
+      g_critical ("error exporting thumbnail service on session bus: %s", error->message);
+      g_error_free (error);
+      service->dbus_interface_exported = FALSE; 
+    }
+  else
+    {
+      service->dbus_interface_exported = TRUE;
+      
+      g_signal_connect (service->skeleton, "handle-queue",
+                        G_CALLBACK(tumbler_service_queue_cb), service);
+      
+      g_signal_connect (service->skeleton, "handle-dequeue",
+                        G_CALLBACK(tumbler_service_dequeue_cb), service);
+      
+      g_signal_connect (service->skeleton, "handle-get-supported",
+                        G_CALLBACK(tumbler_service_get_supported_cb), service);
+      
+      g_signal_connect (service->skeleton, "handle-get-schedulers",
+                        G_CALLBACK(tumbler_service_get_schedulers_cb), service);
+      
+      g_signal_connect (service->skeleton, "handle-get-flavors",
+                        G_CALLBACK(tumbler_service_get_flavors_cb), service);
+    }
 }
 
 
@@ -326,8 +309,20 @@ tumbler_service_finalize (GObject *object)
 
   /* release the reference on the thumbnailer registry */
   g_object_unref (service->registry);
-
-  dbus_g_connection_unref (service->connection);
+  
+  /* Unexport from dbus */
+  if (service->dbus_interface_exported)
+    g_dbus_interface_skeleton_unexport_from_connection 
+      (
+        G_DBUS_INTERFACE_SKELETON (service->skeleton),
+        service->connection
+      );
+
+  /* release the Skeleton object */
+  g_object_unref (service->skeleton);
+  
+  /* release the D-Bus connection object */
+  g_object_unref (service->connection);
 
   tumbler_mutex_free (service->mutex);
 
@@ -347,7 +342,7 @@ tumbler_service_get_property (GObject    *object,
   switch (prop_id)
     {
     case PROP_CONNECTION:
-      g_value_set_pointer (value, service->connection);
+      g_value_set_object (value, service->connection);
       break;
     case PROP_REGISTRY:
       g_value_set_object (value, service->registry);
@@ -371,7 +366,7 @@ tumbler_service_set_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_CONNECTION:
-      service->connection = dbus_g_connection_ref (g_value_get_pointer (value));
+      service->connection = g_object_ref (g_value_get_object (value));
       break;
     case PROP_REGISTRY:
       service->registry = g_value_dup_object (value);
@@ -388,10 +383,7 @@ static gboolean
 tumbler_service_error_idle (gpointer user_data)
 {
   SchedulerIdleInfo *info = user_data;
-  DBusMessageIter    iter;
-  DBusMessageIter    strv_iter;
-  DBusMessage       *message;
-  guint              n;
+  GVariant          *signal_variant;
 
   g_return_val_if_fail (info != NULL, FALSE);
   g_return_val_if_fail (TUMBLER_IS_SCHEDULER (info->scheduler), FALSE);
@@ -400,38 +392,22 @@ tumbler_service_error_idle (gpointer user_data)
   g_return_val_if_fail (info->origin != NULL && *info->origin != '\0', FALSE);
   g_return_val_if_fail (TUMBLER_IS_SERVICE (info->service), FALSE);
 
-  /* create a D-Bus message for the error signal */
-  message = dbus_message_new_signal (THUMBNAILER_PATH, THUMBNAILER_IFACE, "Error");
-
-  /* define the destination (the thumbnailer client) if possible */
-  if (info->origin)
-    dbus_message_set_destination (message, info->origin);
-
-  /* append the request handle */
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &info->handle);
-
-  /* start the URI string array */
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, 
-                                    DBUS_TYPE_STRING_AS_STRING, &strv_iter);
-
-  /* insert all failed URIs into the array */
-  for (n = 0; info->uris[n] != NULL; n++)
-    dbus_message_iter_append_basic (&strv_iter, DBUS_TYPE_STRING, &info->uris[n]);
-
-  /* finish the URI string array */
-  dbus_message_iter_close_container (&iter, &strv_iter);
-
-  /* append the error code and error message */
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &info->error_code);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &info->message);
-
+  /* signal variant */
+  signal_variant = g_variant_ref_sink (g_variant_new ("(u^asis)",
+                                                      info->handle,
+                                                      info->uris,
+                                                      info->error_code,
+                                                      info->message));
   /* send the signal message over D-Bus */
-  dbus_connection_send (dbus_g_connection_get_connection (info->service->connection), 
-                        message, NULL);
+  g_dbus_connection_emit_signal (info->service->connection,
+                                 info->origin, 
+                                 THUMBNAILER_PATH,
+                                 THUMBNAILER_IFACE,
+                                 "Error",
+                                 signal_variant, 
+                                 NULL);
 
-  /* free the allocated D-Bus message */
-  dbus_message_unref (message);
+  g_variant_unref (signal_variant);
 
   scheduler_idle_info_free (info);
 
@@ -476,30 +452,24 @@ static gboolean
 tumbler_service_finished_idle (gpointer user_data)
 {
   SchedulerIdleInfo *info = user_data;
-  DBusMessageIter    iter;
-  DBusMessage       *message;
+  GVariant          *signal_variant;
 
   g_return_val_if_fail (info != NULL, FALSE);
   g_return_val_if_fail (info->origin != NULL && *info->origin != '\0', FALSE);
   g_return_val_if_fail (TUMBLER_IS_SERVICE (info->service), FALSE);
-
-  /* create a D-Bus message for the finished signal */
-  message = dbus_message_new_signal (THUMBNAILER_PATH, THUMBNAILER_IFACE, "Finished");
-
-  /* define the destination (the thumbnailer client) if possible */
-  if (info->origin)
-    dbus_message_set_destination (message, info->origin);
-
-  /* append the request handle */
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &info->handle);
-
+  
+  signal_variant = g_variant_ref_sink (g_variant_new ("(u)",
+                                                      info->handle));
   /* send the signal message over D-Bus */
-  dbus_connection_send (dbus_g_connection_get_connection (info->service->connection), 
-                        message, NULL);
+  g_dbus_connection_emit_signal (info->service->connection,
+                                 info->origin, 
+                                 THUMBNAILER_PATH,
+                                 THUMBNAILER_IFACE,
+                                 "Finished",
+                                 signal_variant, 
+                                 NULL);
 
-  /* free the allocated D-Bus message */
-  dbus_message_unref (message);
+  g_variant_unref (signal_variant);
 
   /* allow the lifecycle manager to shut down the service again (unless there
    * are other requests still being processed) */
@@ -540,10 +510,7 @@ static gboolean
 tumbler_service_ready_idle (gpointer user_data)
 {
   SchedulerIdleInfo *info = user_data;
-  DBusMessageIter    iter;
-  DBusMessageIter    strv_iter;
-  DBusMessage       *message;
-  guint              n;
+  GVariant          *signal_variant;
 
   g_return_val_if_fail (info != NULL, FALSE);
   g_return_val_if_fail (TUMBLER_IS_SCHEDULER (info->scheduler), FALSE);
@@ -551,36 +518,21 @@ tumbler_service_ready_idle (gpointer user_data)
   g_return_val_if_fail (info->origin != NULL && *info->origin != '\0', FALSE);
   g_return_val_if_fail (TUMBLER_IS_SERVICE (info->service), FALSE);
 
-  /* create a D-Bus message for the ready signal */
-  message = dbus_message_new_signal (THUMBNAILER_PATH, THUMBNAILER_IFACE, "Ready");
-
-  /* define the destination (the thumbnailer client) if possible */
-  if (info->origin)
-    dbus_message_set_destination (message, info->origin);
-
-  dbus_message_iter_init_append (message, &iter);
-
-  /* append the request handle */
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &info->handle);
-
-  /* start the URI string array */
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
-                                    DBUS_TYPE_STRING_AS_STRING, &strv_iter);
-
-  /* insert all URIs into the array for which we have thumbnails now */
-  for (n = 0; info->uris[n] != NULL; n++)
-    dbus_message_iter_append_basic (&strv_iter, DBUS_TYPE_STRING, &info->uris[n]);
-
-  /* finish the URI string array */
-  dbus_message_iter_close_container (&iter, &strv_iter);
-
+  signal_variant = g_variant_ref_sink (g_variant_new ("(u^as)",
+                                                      info->handle,
+                                                      info->uris));
+ 
   /* send the signal message over D-Bus */
-  dbus_connection_send (dbus_g_connection_get_connection (info->service->connection), 
-                        message, NULL);
-
-  /* free the allocated D-Bus message */
-  dbus_message_unref (message);
-
+  g_dbus_connection_emit_signal (info->service->connection,
+                                 info->origin, 
+                                 THUMBNAILER_PATH,
+                                 THUMBNAILER_IFACE,
+                                 "Ready",
+                                 signal_variant, 
+                                 NULL);
+  
+  g_variant_unref (signal_variant);
+   
   scheduler_idle_info_free (info);
 
   return FALSE;
@@ -619,32 +571,27 @@ static gboolean
 tumbler_service_started_idle (gpointer user_data)
 {
   SchedulerIdleInfo *info = user_data;
-  DBusMessageIter   iter;
-  DBusMessage      *message;
-
+  GVariant          *signal_variant;
+  
   g_return_val_if_fail (info != NULL, FALSE);
   g_return_val_if_fail (TUMBLER_IS_SCHEDULER (info->scheduler), FALSE);
   g_return_val_if_fail (info->origin != NULL && *info->origin != '\0', FALSE);
   g_return_val_if_fail (TUMBLER_IS_SERVICE (info->service), FALSE);
 
-  /* create a D-Bus message for the started signal */
-  message = dbus_message_new_signal (THUMBNAILER_PATH, THUMBNAILER_IFACE, "Started");
-
-  /* define the destination (the thumbnailer client) if possible */
-  if (info->origin)
-    dbus_message_set_destination (message, info->origin);
-
-  /* append the request handle */
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &info->handle);
-
+  signal_variant = g_variant_ref_sink (g_variant_new ("(u)", info->handle));
+                                                      
+ 
   /* send the signal message over D-Bus */
-  dbus_connection_send (dbus_g_connection_get_connection (info->service->connection), 
-                        message, NULL);
-
-  /* free the allocated D-Bus message */
-  dbus_message_unref (message);
-
+  g_dbus_connection_emit_signal (info->service->connection,
+                                 info->origin, 
+                                 THUMBNAILER_PATH,
+                                 THUMBNAILER_IFACE,
+                                 "Started",
+                                 signal_variant, 
+                                 NULL);
+  
+  g_variant_unref (signal_variant);
+  
   scheduler_idle_info_free (info);
 
   return FALSE;
@@ -717,7 +664,7 @@ scheduler_idle_info_free (SchedulerIdleInfo *info)
 
 
 TumblerService *
-tumbler_service_new (DBusGConnection         *connection,
+tumbler_service_new (GDBusConnection         *connection,
                      TumblerLifecycleManager *lifecycle_manager,
                      TumblerRegistry         *registry)
 {
@@ -730,54 +677,16 @@ tumbler_service_new (DBusGConnection         *connection,
 
 
 
-gboolean
-tumbler_service_start (TumblerService *service,
-                       GError        **error)
-{
-  DBusConnection *connection;
-  gint            result;
-
-  g_return_val_if_fail (TUMBLER_IS_SERVICE (service), FALSE);
-  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
-  tumbler_mutex_lock (service->mutex);
-
-  /* get the native D-Bus connection */
-  connection = dbus_g_connection_get_connection (service->connection);
-
-  /* request ownership for the generic thumbnailer interface */
-  result = dbus_bus_request_name (connection, THUMBNAILER_SERVICE,
-                                  DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL);
-
-  /* check if that failed */
-  if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-    {
-      if (error != NULL)
-        {
-          g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED,
-                       _("Another generic thumbnailer is already running"));
-        }
-
-      tumbler_mutex_unlock (service->mutex);
-
-      return FALSE;
-    }
-
-  tumbler_mutex_unlock (service->mutex);
-
-  return TRUE;
-}
-
-
 
-void
-tumbler_service_queue (TumblerService        *service,
-                       const gchar *const    *uris,
-                       const gchar *const    *mime_hints,
-                       const gchar           *flavor_name,
-                       const gchar           *scheduler_name,
-                       guint                  handle_to_dequeue,
-                       DBusGMethodInvocation *context)
+static gboolean 
+tumbler_service_queue_cb (TumblerExportedService  *skeleton,
+                          GDBusMethodInvocation   *invocation,
+                          const gchar *const      *uris,
+                          const gchar *const      *mime_hints,
+                          const gchar             *flavor_name,
+                          const gchar             *scheduler_name,
+                          guint                    handle_to_dequeue,
+                          TumblerService          *service)
 {
   TumblerSchedulerRequest *scheduler_request;
   TumblerThumbnailFlavor  *flavor;
@@ -787,13 +696,13 @@ tumbler_service_queue (TumblerService        *service,
   TumblerCache            *cache;
   GList                   *iter;
   gchar                   *name;
-  gchar                   *origin;
+  const gchar             *origin;
   guint                    handle;
   guint                    length;
 
-  dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context);
-  dbus_async_return_if_fail (uris != NULL, context);
-  dbus_async_return_if_fail (mime_hints != NULL, context);
+  g_dbus_async_return_val_if_fail (TUMBLER_IS_SERVICE (service), invocation, FALSE);
+  g_dbus_async_return_val_if_fail (uris != NULL, invocation, FALSE);
+  g_dbus_async_return_val_if_fail (mime_hints != NULL, invocation, FALSE);
 
   tumbler_mutex_lock (service->mutex);
 
@@ -816,7 +725,7 @@ tumbler_service_queue (TumblerService        *service,
   thumbnailers = tumbler_registry_get_thumbnailer_array (service->registry, infos,
                                                          length);
 
-  origin = dbus_g_method_get_sender (context);
+  origin = g_dbus_method_invocation_get_sender (invocation);
 
   /* allocate a scheduler request */
   scheduler_request = tumbler_scheduler_request_new (infos, thumbnailers, 
@@ -825,7 +734,6 @@ tumbler_service_queue (TumblerService        *service,
   /* release the file info array */
   tumbler_file_info_array_free (infos);
 
-  g_free (origin);
 
   /* get the request handle */
   handle = scheduler_request->handle;
@@ -885,24 +793,25 @@ tumbler_service_queue (TumblerService        *service,
   tumbler_thumbnailer_array_free (thumbnailers, length);
 
   tumbler_mutex_unlock (service->mutex);
-
-  dbus_g_method_return (context, handle);
-
+  
+  tumbler_exported_service_complete_queue(skeleton, invocation, handle);
+  
   /* try to keep tumbler alive */
   tumbler_component_keep_alive (TUMBLER_COMPONENT (service), NULL);
+    
+  return TRUE;
 }
 
 
 
-void
-tumbler_service_dequeue (TumblerService        *service,
-                         guint                  handle,
-                         DBusGMethodInvocation *context)
+static gboolean 
+tumbler_service_dequeue_cb (TumblerExportedService  *skeleton,
+                            GDBusMethodInvocation   *invocation,
+                            guint                    handle,
+                            TumblerService          *service)
 {
   GList *iter;
 
-  dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context);
-
   tumbler_mutex_lock (service->mutex);
 
   if (handle != 0) 
@@ -918,22 +827,70 @@ tumbler_service_dequeue (TumblerService        *service,
 
   tumbler_mutex_unlock (service->mutex);
 
-  dbus_g_method_return (context);
-
+  tumbler_exported_service_complete_dequeue(skeleton, invocation);
+    
   /* keep tumbler alive */
   tumbler_component_keep_alive (TUMBLER_COMPONENT (service), NULL);
+  
+  return TRUE;
+}
+
+
+
+static gboolean 
+tumbler_service_get_schedulers_cb (TumblerExportedService  *skeleton,
+                                   GDBusMethodInvocation   *invocation,
+                                   TumblerService          *service)
+{
+  gchar **supported_schedulers;
+  GList  *iter;
+  guint   n = 0;
+
+  tumbler_mutex_lock (service->mutex);
+
+  /* allocate an error for the schedulers */
+  supported_schedulers = g_new0 (gchar *, g_list_length (service->schedulers) + 2);
+
+  /* always prepend the "default" scheduler */
+  supported_schedulers[n++] = g_strdup ("default");
+
+  /* append all supported scheduler names */
+  for (iter = service->schedulers; iter != NULL; iter = iter->next)
+    {
+      supported_schedulers[n++] = 
+        tumbler_scheduler_get_name (TUMBLER_SCHEDULER (iter->data));
+    }
+
+  tumbler_mutex_unlock (service->mutex);
+
+  /* NULL-terminate the array */
+  supported_schedulers[n] = NULL;
+
+  /* return the scheduler array to the caller */
+  tumbler_exported_service_complete_get_schedulers (skeleton, 
+                                                    invocation,
+                                                    (const char* const*)supported_schedulers);
+
+  /* free the array */
+  g_strfreev (supported_schedulers);
+
+  /* try to keep tumbler alive */
+  tumbler_component_keep_alive (TUMBLER_COMPONENT (service), NULL);
+  
+  return TRUE;
 }
 
 
 
-void
-tumbler_service_get_supported (TumblerService        *service,
-                               DBusGMethodInvocation *context)
+static gboolean 
+tumbler_service_get_supported_cb (TumblerExportedService  *skeleton,
+                                  GDBusMethodInvocation   *invocation,
+                                  TumblerService          *service)
 {
   const gchar *const *mime_types;
   const gchar *const *uri_schemes;
 
-  dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context);
+  g_dbus_async_return_val_if_fail (TUMBLER_IS_SERVICE (service), invocation, FALSE);
 
   tumbler_mutex_lock (service->mutex);
 
@@ -943,17 +900,20 @@ tumbler_service_get_supported (TumblerService        *service,
   tumbler_mutex_unlock (service->mutex);
 
   /* return the arrays to the caller */
-  dbus_g_method_return (context, uri_schemes, mime_types);
+  tumbler_exported_service_complete_get_supported(skeleton, invocation, uri_schemes, mime_types);
 
   /* try to keep tumbler alive */
   tumbler_component_keep_alive (TUMBLER_COMPONENT (service), NULL);
+  
+  return TRUE;
 }
 
 
 
-void 
-tumbler_service_get_flavors (TumblerService        *service,
-                              DBusGMethodInvocation *context)
+static gboolean 
+tumbler_service_get_flavors_cb  (TumblerExportedService  *skeleton,
+                                 GDBusMethodInvocation   *invocation,
+                                 TumblerService          *service)
 {
   TumblerCache *cache;
   const gchar **flavor_strings;
@@ -971,9 +931,9 @@ tumbler_service_get_flavors (TumblerService        *service,
       for (iter = flavors, n = 0; iter != NULL; iter = iter->next, ++n)
         flavor_strings[n] = tumbler_thumbnail_flavor_get_name (iter->data);
       flavor_strings[n] = NULL;
-    
-      dbus_g_method_return (context, flavor_strings);
-
+   
+      tumbler_exported_service_complete_get_flavors (skeleton, invocation, flavor_strings);
+      
       g_free (flavor_strings);
 
       g_list_foreach (flavors, (GFunc) g_object_unref, NULL);
@@ -985,53 +945,22 @@ tumbler_service_get_flavors (TumblerService        *service,
     {
       flavor_strings = g_new0 (const gchar *, 1);
       flavor_strings[0] = NULL;
-
-      dbus_g_method_return (context, flavor_strings);
+      
+      tumbler_exported_service_complete_get_flavors (skeleton, invocation, flavor_strings);
 
       g_free (flavor_strings);
     }
 
   /* try to keep tumbler alive */
   tumbler_component_keep_alive (TUMBLER_COMPONENT (service), NULL);
-}
-
-
-void
-tumbler_service_get_schedulers (TumblerService        *service,
-                                DBusGMethodInvocation *context)
-{
-  gchar **supported_schedulers;
-  GList  *iter;
-  guint   n = 0;
-
-  dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context);
-
-  tumbler_mutex_lock (service->mutex);
-
-  /* allocate an error for the schedulers */
-  supported_schedulers = g_new0 (gchar *, g_list_length (service->schedulers) + 2);
-
-  /* always prepend the "default" scheduler */
-  supported_schedulers[n++] = g_strdup ("default");
-
-  /* append all supported scheduler names */
-  for (iter = service->schedulers; iter != NULL; iter = iter->next)
-    {
-      supported_schedulers[n++] = 
-        tumbler_scheduler_get_name (TUMBLER_SCHEDULER (iter->data));
-    }
-
-  tumbler_mutex_unlock (service->mutex);
 
-  /* NULL-terminate the array */
-  supported_schedulers[n] = NULL;
+  return TRUE;
+}
 
-  /* return the scheduler array to the caller */
-  dbus_g_method_return (context, supported_schedulers);
 
-  /* free the array */
-  g_strfreev (supported_schedulers);
 
-  /* try to keep tumbler alive */
-  tumbler_component_keep_alive (TUMBLER_COMPONENT (service), NULL);
+gboolean tumbler_service_is_exported (TumblerService *service)
+{
+  g_return_if_fail (TUMBLER_IS_SERVICE(service));
+  return service->dbus_interface_exported;
 }
diff --git a/tumblerd/tumbler-service.h b/tumblerd/tumbler-service.h
index d2d4bed..d2610cb 100644
--- a/tumblerd/tumbler-service.h
+++ b/tumblerd/tumbler-service.h
@@ -1,7 +1,8 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
  * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
- *
+ * Copyright (c) 2015      Ali Abdallah    <ali at xfce.org>
+ * 
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation; either version 2 of 
@@ -40,27 +41,10 @@ typedef struct _TumblerService      TumblerService;
 
 GType           tumbler_service_get_type (void) G_GNUC_CONST;
 
-TumblerService *tumbler_service_new            (DBusGConnection         *connection,
+TumblerService *tumbler_service_new            (GDBusConnection         *connection,
                                                 TumblerLifecycleManager *lifecycle_manager,
                                                 TumblerRegistry         *registry) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-gboolean        tumbler_service_start          (TumblerService          *service,
-                                                GError                 **error);
-void            tumbler_service_queue          (TumblerService          *service,
-                                                const gchar *const      *uris,
-                                                const gchar *const      *mime_hints,
-                                                const gchar             *flavor_name,
-                                                const gchar             *scheduler_name,
-                                                guint                    handle_to_dequeue,
-                                                DBusGMethodInvocation   *context);
-void            tumbler_service_dequeue        (TumblerService           *service,
-                                                guint                     handle,
-                                                DBusGMethodInvocation    *context);
-void            tumbler_service_get_schedulers (TumblerService          *service,
-                                                DBusGMethodInvocation   *context);
-void            tumbler_service_get_supported  (TumblerService          *service,
-                                                DBusGMethodInvocation   *context);
-void            tumbler_service_get_flavors    (TumblerService          *service,
-                                                DBusGMethodInvocation   *context);
+gboolean        tumbler_service_is_exported    (TumblerService *service);
 
 G_END_DECLS;
 
diff --git a/tumblerd/tumbler-utils.h b/tumblerd/tumbler-utils.h
index 6d02d9d..3049afd 100644
--- a/tumblerd/tumbler-utils.h
+++ b/tumblerd/tumbler-utils.h
@@ -41,6 +41,36 @@ G_BEGIN_DECLS
       }                                                                                 \
   }G_STMT_END
 
+#define g_dbus_async_return_if_fail(expr, invocation)                                   \
+  G_STMT_START{                                                                         \
+    if (G_UNLIKELY (!(expr)))                                                           \
+      {                                                                                 \
+        GError *dbus_async_return_if_fail_error = NULL;                                 \
+                                                                                        \
+        g_set_error (&dbus_async_return_if_fail_error, DBUS_GERROR, DBUS_GERROR_FAILED, \
+                     "Assertion \"%s\" failed", #expr);                                 \
+        g_dbus_method_invocation_return_gerror (invocation, dbus_async_return_if_fail_error);\
+        g_clear_error (&dbus_async_return_if_fail_error);                               \
+                                                                                        \
+        return;                                                                         \
+      }                                                                                 \
+  }G_STMT_END
+
+#define g_dbus_async_return_val_if_fail(expr, invocation,val)                           \
+  G_STMT_START{                                                                         \
+    if (G_UNLIKELY (!(expr)))                                                           \
+      {                                                                                 \
+        GError *dbus_async_return_if_fail_error = NULL;                                 \
+                                                                                        \
+        g_set_error (&dbus_async_return_if_fail_error, DBUS_GERROR, DBUS_GERROR_FAILED, \
+                     "Assertion \"%s\" failed", #expr);                                 \
+        g_dbus_method_invocation_return_gerror (invocation, dbus_async_return_if_fail_error);\
+        g_clear_error (&dbus_async_return_if_fail_error);                               \
+                                                                                        \
+        return (val);                                                                   \
+      }                                                                                 \
+  }G_STMT_END
+
 #if GLIB_CHECK_VERSION (2, 32, 0)
 #define TUMBLER_MUTEX(mtx)        GMutex mtx
 #define tumbler_mutex_free(mtx)   g_mutex_clear (&(mtx))

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list