Add support for Linux Block devices
authorDavid Zeuthen <davidz@redhat.com>
Thu, 2 Sep 2010 19:55:31 +0000 (15:55 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Thu, 2 Sep 2010 19:55:31 +0000 (15:55 -0400)
Well, it's more like the skeleton.

Signed-off-by: David Zeuthen <davidz@redhat.com>
src/Makefile.am
src/linuxblock.c [new file with mode: 0644]
src/linuxblock.h [new file with mode: 0644]
src/main.c
src/types.h [new file with mode: 0644]

index 9e0d915..c1c4d2c 100644 (file)
@@ -26,7 +26,8 @@ libexec_PROGRAMS = udisks-daemon
 udisks_daemon_SOURCES =                                                \
                                        main.c                          \
        gposixsignal.h                  gposixsignal.c                  \
-       $(BUILT_SOURCES)                                                \
+       types.h                                                         \
+       linuxblock.h                    linuxblock.c                    \
        $(NULL)
 
 udisks_daemon_CPPFLAGS =                               \
diff --git a/src/linuxblock.c b/src/linuxblock.c
new file mode 100644 (file)
index 0000000..bf7588e
--- /dev/null
@@ -0,0 +1,81 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2007-2010 David Zeuthen <zeuthen@gmail.com>
+ *
+ * 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 the License, or
+ * (at your option) any later version.
+ *
+ * This program 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "config.h"
+
+#include "linuxblock.h"
+
+#include <gudev/gudev.h>
+
+typedef struct
+{
+  GUdevClient *gudev_client;
+} LinuxBlockProvider;
+
+static LinuxBlockProvider *_g_provider = NULL;
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_uevent (GUdevClient  *client,
+           const gchar  *action,
+           GUdevDevice  *device,
+           gpointer      user_data)
+{
+  //LinuxBlockProvider *provider = user_data;
+
+  g_print ("%s:%s: entering\n", G_STRLOC, G_STRFUNC);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+/* called when the system bus connection has been acquired but before the well-known
+ * org.freedesktop.UDisks name is claimed
+ */
+void
+linux_block_init (GDBusObjectManager *manager)
+{
+  const gchar *subsystems[] = {"block", NULL};
+  LinuxBlockProvider *provider;
+
+  g_print ("%s:%s: entering\n", G_STRLOC, G_STRFUNC);
+
+  _g_provider = provider = g_new0 (LinuxBlockProvider, 1);
+
+  /* get ourselves an udev client */
+  provider->gudev_client = g_udev_client_new (subsystems);
+  g_signal_connect (provider->gudev_client,
+                    "uevent",
+                    G_CALLBACK (on_uevent),
+                    provider);
+}
+
+/* called on shutdown */
+void
+linux_block_shutdown (void)
+{
+  LinuxBlockProvider *provider = _g_provider;
+
+  g_print ("%s:%s: entering\n", G_STRLOC, G_STRFUNC);
+
+  g_object_unref (provider->gudev_client);
+  g_free (provider);
+}
+
diff --git a/src/linuxblock.h b/src/linuxblock.h
new file mode 100644 (file)
index 0000000..560c763
--- /dev/null
@@ -0,0 +1,29 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2007-2010 David Zeuthen <zeuthen@gmail.com>
+ *
+ * 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 the License, or
+ * (at your option) any later version.
+ *
+ * This program 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __LINUX_BLOCK_H__
+#define __LINUX_BLOCK_H__
+
+#include "types.h"
+
+void linux_block_init (GDBusObjectManager *manager);
+void linux_block_shutdown (void);
+
+#endif /* __LINUX_BLOCK_H__ */
index 0108e84..f4400a4 100644 (file)
@@ -24,7 +24,8 @@
 
 #include "gposixsignal.h"
 
-#include <udisks/udisks.h>
+#include "types.h"
+#include "linuxblock.h"
 
 /* ---------------------------------------------------------------------------------------------------- */
 
@@ -37,6 +38,8 @@ static GOptionEntry opt_entries[] = {
   {NULL }
 };
 
+static GDBusObjectManager *object_manager = NULL;
+
 static void
 on_bus_acquired (GDBusConnection *connection,
                  const gchar     *name,
@@ -44,6 +47,10 @@ on_bus_acquired (GDBusConnection *connection,
 {
   g_print ("Connected to the system bus\n");
 
+  object_manager = g_dbus_object_manager_new (connection, "/org/freedesktop/UDisks");
+
+  linux_block_init (object_manager);
+
   UDisksBlockDevice *b;
   b = udisks_block_device_stub_new ();
   g_dbus_interface_register_object (G_DBUS_INTERFACE (b),
@@ -151,8 +158,11 @@ main (int    argc,
 
   g_print ("Shutting down\n");
  out:
+  linux_block_shutdown ();
   if (sigint_id > 0)
     g_source_remove (sigint_id);
+  if (object_manager != NULL)
+    g_object_unref (object_manager);
   if (name_owner_id != 0)
     g_bus_unown_name (name_owner_id);
   if (loop != NULL)
diff --git a/src/types.h b/src/types.h
new file mode 100644 (file)
index 0000000..234fe34
--- /dev/null
@@ -0,0 +1,28 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2007-2010 David Zeuthen <zeuthen@gmail.com>
+ *
+ * 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 the License, or
+ * (at your option) any later version.
+ *
+ * This program 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+#include <gio/gio.h>
+#include <udisks/udisks.h>
+#include <gdbusobjectmanager.h>
+
+#endif