[maemo-commits] [maemo-commits] r16022 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Sep 4 20:22:30 EEST 2008
- Previous message: [maemo-commits] r16021 - projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins
- Next message: [maemo-commits] r16023 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-09-04 20:22:22 +0300 (Thu, 04 Sep 2008) New Revision: 16022 Added: projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.xml Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog projects/haf/branches/hildon-thumbnail/daemonize/daemon/ projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am Log: 2008-09-04 Philip Van Hoof <philip at codeminded.be> * daemon/plugin-runner.c * daemon/plugin-runner.xml * daemon/Makefile.am: Added a tool to run a GModule plugin as a standalone specialized thumbnailer. Sample usage: libexec/hildon-thumbnailerd & libexec/hildon-thumbnailer-run-plugin-as-standalone gdkpixbuf Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-04 16:49:45 UTC (rev 16021) +++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-04 17:22:22 UTC (rev 16022) @@ -1,5 +1,19 @@ 2008-09-04 Philip Van Hoof <philip at codeminded.be> + * daemon/plugin-runner.c + * daemon/plugin-runner.xml + * daemon/Makefile.am: Added a tool to run a GModule plugin as a + standalone specialized thumbnailer. + + Sample usage: + + libexec/hildon-thumbnailerd & + libexec/hildon-thumbnailer-run-plugin-as-standalone gdkpixbuf + + To run the libhildon-thumbnailer-gdkpixbuf.so module as standalone + +2008-09-04 Philip Van Hoof <philip at codeminded.be> + * daemon/hildon-thumbnail-daemon.c * daemon/plugins/gdkpixbuf-plugin.c * daemon/plugins/default.c Property changes on: projects/haf/branches/hildon-thumbnail/daemonize/daemon ___________________________________________________________________ Name: svn:ignore - Makefile.in hildon-thumbnailerd .libs .deps org.freedesktop.thumbnailer.service Makefile *-glue.h *-marshal.c *-marshal.h + hildon-thumbnailer-run-plugin-as-standalone Makefile.in hildon-thumbnailerd .libs .deps org.freedesktop.thumbnailer.service Makefile *-glue.h *-marshal.c *-marshal.h Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am 2008-09-04 16:49:45 UTC (rev 16021) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am 2008-09-04 17:22:22 UTC (rev 16022) @@ -6,6 +6,7 @@ $(GMODULE_CFLAGS) \ $(GIO_CFLAGS) \ $(GDK_PIXBUF_CFLAGS) \ + $(DBUS_CFLAGS) \ -DPLUGINS_DIR=\""$(libdir)/hildon-thumbnailer/plugins"\" @@ -13,20 +14,26 @@ libshared_la_SOURCES = md5.c md5.h utils.h utils.c pixbuf-io-loader.c -libexec_PROGRAMS = hildon-thumbnailerd +libexec_PROGRAMS = hildon-thumbnailerd hildon-thumbnailer-run-plugin-as-standalone -include_HEADERS = hildon-thumbnail-plugin.h +plugin_stuff = hildon-thumbnail-plugin.h hildon-thumbnail-plugin.c - thumbnailer-marshal.h: thumbnailer-marshal.list $(GLIB_GENMARSHAL) $< --prefix=thumbnailer_marshal --header > $@ thumbnailer-marshal.c: thumbnailer-marshal.list $(GLIB_GENMARSHAL) $< --prefix=thumbnailer_marshal --body > $@ +hildon_thumbnailer_run_plugin_as_standalone_SOURCES = \ + plugin-runner.c \ + $(plugin_stuff) \ + plugin-runner-glue.h + +hildon_thumbnailer_run_plugin_as_standalone_LDADD = \ + $(DBUS_LIBS) $(GLIB_LIBS) $(GMODULE_LIBS) $(GIO_LIBS) + hildon_thumbnailerd_SOURCES = \ - $(include_HEADERS) \ - hildon-thumbnail-plugin.c \ + $(plugin_stuff) \ hildon-thumbnail-daemon.c \ thumbnailer.c \ thumbnailer.h \ @@ -34,6 +41,8 @@ thumbnailer-marshal.h \ manager.c \ manager.h \ + manager-glue.h \ + thumbnailer-glue.h \ dbus-utils.h \ dbus-utils.c @@ -54,7 +63,7 @@ %-glue.h: $(top_srcdir)/daemon/%.xml $(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=$(subst -,_,$*) $^ -BUILT_SOURCES = manager-glue.h thumbnailer-glue.h \ +BUILT_SOURCES = manager-glue.h thumbnailer-glue.h plugin-runner-glue.h \ thumbnailer-marshal.c thumbnailer-marshal.h configdir = $(datadir)/hildon-thumbnail config_DATA = manager.xml thumbnailer.xml Added: projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c 2008-09-04 16:49:45 UTC (rev 16021) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c 2008-09-04 17:22:22 UTC (rev 16022) @@ -0,0 +1,272 @@ +#include <glib.h> +#include <gio/gio.h> +#include <dbus/dbus-glib-bindings.h> + +#include "hildon-thumbnail-plugin.h" + +#define DAEMON_SERVICE "org.freedesktop.Thumbnailer" +#define DAEMON_PATH "/org/freedesktop/Thumbnailer" +#define DAEMON_INTERFACE "org.freedesktop.Thumbnailer" + +#define MANAGER_SERVICE "org.freedesktop.Thumbnailer" +#define MANAGER_PATH "/org/freedesktop/Thumbnailer/Manager" +#define MANAGER_INTERFACE "org.freedesktop.Thumbnailer.Manager" + +#define TYPE_DAEMON (daemon_get_type()) +#define DAEMON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_DAEMON, Daemon)) +#define DAEMON_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TYPE_DAEMON, DaemonClass)) +#define DAEMON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_DAEMON, DaemonClass)) + +typedef struct Daemon Daemon; +typedef struct DaemonClass DaemonClass; + +struct Daemon { + GObject parent; +}; + +struct DaemonClass { + GObjectClass parent; +}; + +typedef struct { + DBusGConnection *connection; + GModule *module; +} DaemonPrivate; + +enum { + PROP_0, + PROP_CONNECTION, + PROP_MODULE +}; + +G_DEFINE_TYPE (Daemon, daemon, G_TYPE_OBJECT) + +#define DAEMON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_DAEMON, DaemonPrivate)) + +#define plugin_runner_create daemon_create + +void +daemon_create (Daemon *object, GStrv uris, DBusGMethodInvocation *context) +{ + DaemonPrivate *priv = DAEMON_GET_PRIVATE (object); + GError *error = NULL; + hildon_thumbnail_plugin_do_create (priv->module, uris, &error); + if (error) + dbus_g_method_return_error (context, error); + else + dbus_g_method_return (context); +} + +#include "plugin-runner-glue.h" + + +static void +daemon_set_connection (Daemon *object, DBusGConnection *connection) +{ + DaemonPrivate *priv = DAEMON_GET_PRIVATE (object); + priv->connection = connection; +} + +static void +daemon_set_module (Daemon *object, GModule *module) +{ + DaemonPrivate *priv = DAEMON_GET_PRIVATE (object); + priv->module = module; +} + + +static void +daemon_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONNECTION: + daemon_set_connection (DAEMON (object), + g_value_get_pointer (value)); + break; + case PROP_MODULE: + daemon_set_module (DAEMON (object), + g_value_get_pointer (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + + +static void +daemon_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + DaemonPrivate *priv; + + priv = DAEMON_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_CONNECTION: + g_value_set_pointer (value, priv->connection); + break; + case PROP_MODULE: + g_value_set_pointer (value, priv->module); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +daemon_finalize (GObject *object) +{ + G_OBJECT_CLASS (daemon_parent_class)->finalize (object); +} + +static void +daemon_class_init (DaemonClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = daemon_finalize; + object_class->set_property = daemon_set_property; + object_class->get_property = daemon_get_property; + + + g_object_class_install_property (object_class, + PROP_CONNECTION, + g_param_spec_pointer ("connection", + "DBus connection", + "DBus connection", + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + + g_object_class_install_property (object_class, + PROP_MODULE, + g_param_spec_pointer ("module", + "Module to proxy to", + "Module to proxy to", + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_type_class_add_private (object_class, sizeof (DaemonPrivate)); +} + +static void +daemon_init (Daemon *object) +{ +} + +// these two are a little hack that will be fixed when that silly manager thing +// is better specified + +typedef struct { + Thumbnailer parent; + DBusGProxy *manager_proxy; +} SomeInfo; + +void +thumbnailer_register_plugin (Thumbnailer *object, const gchar *mime_type, GModule *plugin) +{ + GError *error = NULL; + SomeInfo *info = (SomeInfo *) object; + DBusGProxy *manager_proxy = info->manager_proxy; + + dbus_g_proxy_call (manager_proxy, "Register", + &error, G_TYPE_STRING, + mime_type, + G_TYPE_INVALID, + G_TYPE_INVALID); + + if (error) { + g_critical ("Failed to init: %s\n", error->message); + g_error_free (error); + } +} + +void +thumbnailer_unregister_plugin (Thumbnailer *object, GModule *plugin) +{ +} + +static void +daemon_start (Daemon *object) +{ + GError *error = NULL; + DaemonPrivate *priv = DAEMON_GET_PRIVATE (object); + SomeInfo *info = g_slice_new (SomeInfo); + + info->manager_proxy = dbus_g_proxy_new_for_name (priv->connection, + MANAGER_SERVICE, + MANAGER_PATH, + MANAGER_INTERFACE); + + hildon_thumbnail_plugin_do_init (priv->module, (Thumbnailer *) info, &error); + + if (error) { + g_critical ("Failed to init: %s\n", error->message); + g_error_free (error); + } + + g_object_unref (info->manager_proxy); + g_slice_free (SomeInfo, info); +} + + +int +main (int argc, char **argv) +{ + DBusGConnection *connection; + DBusGProxy *proxy; + GError *error = NULL; + guint result; + GMainLoop *main_loop; + GObject *object; + GModule *module; + + g_type_init (); + + if (!g_thread_supported ()) + g_thread_init (NULL); + + if (argc != 2) { + g_print ("Usage: %s MODULE\n", argv[0]); + return 0; + } + + module = hildon_thumbnail_plugin_load (argv[1]); + + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + + proxy = dbus_g_proxy_new_for_name (connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); + + org_freedesktop_DBus_request_name (proxy, DAEMON_SERVICE, + DBUS_NAME_FLAG_DO_NOT_QUEUE, + &result, error); + + object = g_object_new (TYPE_DAEMON, + "connection", connection, + "module", module, + NULL); + + daemon_start (DAEMON (object)); + + dbus_g_object_type_install_info (G_OBJECT_TYPE (object), + &dbus_glib_plugin_runner_object_info); + + dbus_g_connection_register_g_object (connection, + DAEMON_PATH, + object); + + + main_loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (main_loop); + + g_main_loop_unref (main_loop); + + return 0; +} Added: projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.xml =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.xml 2008-09-04 16:49:45 UTC (rev 16021) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.xml 2008-09-04 17:22:22 UTC (rev 16022) @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<node name="/"> + <interface name="org.freedesktop.Thumbnailer"> + <method name="Create"> + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> + <arg type="as" name="uris" direction="in" /> + </method> + </interface> +</node>
- Previous message: [maemo-commits] r16021 - projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins
- Next message: [maemo-commits] r16023 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]