summaryrefslogtreecommitdiff
path: root/src/nautilus-freedesktop-dbus.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2011-12-06 13:56:00 -0600
committerFederico Mena Quintero <federico@gnome.org>2011-12-06 17:47:46 -0600
commit456afcbb6042c8f1ab73f240e5be5eabd681e090 (patch)
tree057a181168948ba84af57fa071fe8e8223d4012b /src/nautilus-freedesktop-dbus.c
parentaa01e30c0d3d585bd808ed1ab53c5ca396371cd1 (diff)
downloadnautilus-456afcbb6042c8f1ab73f240e5be5eabd681e090.tar.gz
DBus boilerplate for handling the org.freedesktop.FileManager1 service
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
Diffstat (limited to 'src/nautilus-freedesktop-dbus.c')
-rw-r--r--src/nautilus-freedesktop-dbus.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/nautilus-freedesktop-dbus.c b/src/nautilus-freedesktop-dbus.c
new file mode 100644
index 000000000..29418ebc3
--- /dev/null
+++ b/src/nautilus-freedesktop-dbus.c
@@ -0,0 +1,115 @@
+/*
+ * nautilus-freedesktop-dbus: Implementation for the org.freedesktop DBus file-management interfaces
+ *
+ * Nautilus 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 the
+ * License, or (at your option) any later version.
+ *
+ * Nautilus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Authors: Akshay Gupta <kitallis@gmail.com>
+ * Federico Mena Quintero <federico@gnome.org>
+ */
+
+#include <config.h>
+
+#include "nautilus-freedesktop-dbus.h"
+#include "nautilus-freedesktop-generated.h"
+
+/* We share the same debug domain as nautilus-dbus-manager */
+#define DEBUG_FLAG NAUTILUS_DEBUG_DBUS
+#include "nautilus-debug.h"
+
+#include "gio/gio.h"
+
+
+/* Id from g_dbus_own_name() */
+static guint owner_id;
+
+/* DBus paraphernalia */
+static GDBusConnection *connection;
+static GDBusObjectManagerServer *object_manager;
+
+/* Our DBus implementation skeleton */
+static NautilusFreedesktopFileManager1 *skeleton;
+
+static void
+bus_acquired_cb (GDBusConnection *conn,
+ const gchar *name,
+ gpointer user_data)
+{
+ DEBUG ("Bus acquired at %s", name);
+
+ connection = g_object_ref (conn);
+ object_manager = g_dbus_object_manager_server_new ("/org/freedesktop/FileManager1");
+
+ skeleton = nautilus_freedesktop_file_manager1_skeleton_new ();
+
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton), connection, "/org/freedesktop/FileManager1", NULL);
+
+ g_dbus_object_manager_server_set_connection (object_manager, connection);
+}
+
+static void
+name_acquired_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ DEBUG ("Acquired the name %s on the session message bus\n", name);
+}
+
+static void
+name_lost_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ DEBUG ("Lost (or failed to acquire) the name %s on the session message bus\n", name);
+}
+
+/* Tries to own the org.freedesktop.FileManager1 service name */
+void
+nautilus_freedesktop_dbus_start (void)
+{
+ if (owner_id != 0)
+ return;
+
+ owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ "org.freedesktop.FileManager1",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ bus_acquired_cb,
+ name_acquired_cb,
+ name_lost_cb,
+ NULL,
+ NULL);
+}
+
+/* Releases the org.freedesktop.FileManager1 service name */
+void
+nautilus_freedesktop_dbus_stop (void)
+{
+ if (owner_id != 0) {
+ g_bus_unown_name (owner_id);
+ owner_id = 0;
+ }
+
+ if (skeleton != NULL) {
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (skeleton));
+ g_object_unref (skeleton);
+ skeleton = NULL;
+ }
+
+ if (object_manager != NULL) {
+ g_object_unref (object_manager);
+ object_manager = NULL;
+ }
+
+ g_clear_object (&connection);
+}