minfo-dataprovider: Added dataprovider service
authorSimón Pena <spenap@gmail.com>
Sat, 29 May 2010 21:36:39 +0000 (23:36 +0200)
committerSimón Pena <spenap@gmail.com>
Sun, 30 May 2010 20:06:28 +0000 (22:06 +0200)
A dataprovider service is added so that it expose the Query
method via DBus

* The interface XML file is created
* The Makefile is updated to generate the glue header from the XML
* The gobject for the service is created

src/Makefile.am
src/mvs-minfo-provider-service.c [new file with mode: 0644]
src/mvs-minfo-provider-service.h [new file with mode: 0644]
src/mvs-minfo-provider.xml [new file with mode: 0644]

index 6d62d5a..f096e03 100644 (file)
@@ -13,4 +13,10 @@ MAINTAINERCLEANFILES =       \
        *.in \
        *~
 
+mvs-minfo-provider-service-glue.h: mvs-minfo-provider.xml
+       dbus-binding-tool --mode=glib-server --prefix=mvs_minfo_provider_service $< > $@
+
 DISTCLEANFILES = $(MAINTAINERCLEANFILES)
+
+BUILT_SOURCES =                        \
+       mvs-minfo-provider-service-glue.h
\ No newline at end of file
diff --git a/src/mvs-minfo-provider-service.c b/src/mvs-minfo-provider-service.c
new file mode 100644 (file)
index 0000000..f35150a
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * mvs-minfo-provider-service.c
+ *
+ * This file is part of maevies
+ * Copyright (C) 2010 Simón Pena <spenap@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 3 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.
+ *
+ */
+
+#include <dbus/dbus-glib-bindings.h>
+
+#include "mvs-minfo-provider-service.h"
+#include "mvs-minfo-provider.h"
+
+#define MINFO_PROVIDER_SERVICE_OBJECT_PATH "/MInfoProvider"
+#define MINFO_PROVIDER_SERVICE_NAME "com.simonpena.maevies.minfoprovider"
+
+G_DEFINE_TYPE (MvsMInfoProviderService, mvs_minfo_provider_service, G_TYPE_OBJECT)
+
+enum {
+        PROP_0,
+        PROP_DBUSGCONN,
+};
+
+enum {
+        RESPONSE_RECEIVED,
+        LAST_SIGNAL
+};
+
+static guint
+mvs_minfo_provider_service_signals[LAST_SIGNAL] = { 0 };
+
+#define GET_PRIVATE(o) \
+        (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_MINFO_PROVIDER_SERVICE, MvsMInfoProviderServicePrivate))
+
+struct _MvsMInfoProviderServicePrivate {
+        MvsMInfoProvider *minfo_provider;
+        DBusGConnection *connection;
+};
+
+gboolean
+mvs_minfo_provider_service_query (MvsMInfoProviderService *self,
+                                  MvsService service,
+                                  const gchar *query,
+                                  GError **error)
+{
+        return mvs_minfo_provider_query (self->priv->minfo_provider,
+                        service, query);
+}
+
+#include "mvs-minfo-provider-service-glue.h"
+
+static void
+response_received_cb (MvsMInfoProvider *provider, gpointer response,
+                      gpointer user_data)
+{
+        MvsMInfoProviderService *self = MVS_MINFO_PROVIDER_SERVICE (user_data);
+        g_signal_emit (self, mvs_minfo_provider_service_signals[RESPONSE_RECEIVED], 0);
+}
+
+static void
+setup_dbus (MvsMInfoProviderService *self)
+{
+        DBusGProxy *proxy;
+        guint request_name_result;
+        GError *error = NULL;
+
+        proxy = dbus_g_proxy_new_for_name (self->priv->connection,
+                                           DBUS_SERVICE_DBUS,
+                                           DBUS_PATH_DBUS,
+                                           DBUS_INTERFACE_DBUS);
+
+        if (!org_freedesktop_DBus_request_name (proxy,
+                                                MINFO_PROVIDER_SERVICE_NAME,
+                                                0, &request_name_result,
+                                                &error)) {
+                g_warning ("Unable to register service: %s", error->message);
+                g_error_free (error);
+        }
+
+        dbus_g_connection_register_g_object (self->priv->connection,
+                                             MINFO_PROVIDER_SERVICE_OBJECT_PATH,
+                                             G_OBJECT (self));
+
+        g_object_unref (proxy);
+}
+
+static void
+mvs_minfo_provider_service_set_property (GObject *object, guint property_id,
+                                  const GValue *value, GParamSpec *pspec)
+{
+        MvsMInfoProviderService *self = MVS_MINFO_PROVIDER_SERVICE (object);
+
+        switch (property_id) {
+        case PROP_DBUSGCONN:
+                if (!self->priv->connection) {
+                        DBusGConnection *tmp = g_value_get_pointer (value);
+                        if (tmp) {
+                                self->priv->connection =
+                                        dbus_g_connection_ref (tmp);
+                                setup_dbus (self);
+                        }
+                }
+                g_assert (self->priv->connection);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        }
+}
+
+static void
+mvs_minfo_provider_service_finalize (GObject *object)
+{
+        MvsMInfoProviderService *self = MVS_MINFO_PROVIDER_SERVICE (object);
+
+        if (self->priv->connection) {
+                dbus_g_connection_unref (self->priv->connection);
+        }
+        g_object_unref (self->priv->minfo_provider);
+        G_OBJECT_CLASS (mvs_minfo_provider_service_parent_class)->finalize (object);
+}
+
+static void
+mvs_minfo_provider_service_class_init (MvsMInfoProviderServiceClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        g_type_class_add_private (klass, sizeof (MvsMInfoProviderServicePrivate));
+
+        object_class->set_property = mvs_minfo_provider_service_set_property;
+        object_class->finalize = mvs_minfo_provider_service_finalize;
+
+        g_object_class_install_property
+                (object_class, PROP_DBUSGCONN,
+                 g_param_spec_pointer ("connection", "DBusGConnection",
+                                       "DBus GConnection",
+                                       G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+         dbus_g_object_type_install_info (MVS_TYPE_MINFO_PROVIDER_SERVICE,
+                                          &dbus_glib_mvs_minfo_provider_service_object_info);
+
+         mvs_minfo_provider_service_signals[RESPONSE_RECEIVED] =
+                         g_signal_new ("response-received",
+                         G_TYPE_FROM_CLASS (klass),
+                         G_SIGNAL_RUN_LAST,
+                         0,
+                         NULL,
+                         NULL,
+                         g_cclosure_marshal_VOID__VOID,
+                         G_TYPE_NONE,
+                         0,
+                         NULL);
+}
+
+static void
+mvs_minfo_provider_service_init (MvsMInfoProviderService *self)
+{
+        self->priv = GET_PRIVATE (self);
+        self->priv->minfo_provider = mvs_minfo_provider_new ();
+        self->priv->connection = NULL;
+
+        g_signal_connect (self->priv->minfo_provider, "response-received",
+                          G_CALLBACK (response_received_cb), self);
+}
+
+MvsMInfoProviderService*
+mvs_minfo_provider_service_new (DBusGConnection *connection)
+{
+        return g_object_new (MVS_TYPE_MINFO_PROVIDER_SERVICE,
+                             "connection", connection, NULL);
+}
diff --git a/src/mvs-minfo-provider-service.h b/src/mvs-minfo-provider-service.h
new file mode 100644 (file)
index 0000000..1a3d89f
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * mvs-minfo-provider-service.h
+ *
+ * This file is part of maevies
+ * Copyright (C) 2010 Simón Pena <spenap@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 3 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.
+ *
+ */
+
+#ifndef _MVS_MINFO_PROVIDER_SERVICE
+#define _MVS_MINFO_PROVIDER_SERVICE
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MVS_TYPE_MINFO_PROVIDER_SERVICE mvs_minfo_provider_service_get_type()
+#define MVS_MINFO_PROVIDER_SERVICE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), MVS_TYPE_MINFO_PROVIDER_SERVICE, MvsMInfoProviderService))
+#define MVS_MINFO_PROVIDER_SERVICE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), MVS_TYPE_MINFO_PROVIDER_SERVICE, MvsMInfoProviderServiceClass))
+#define MVS_IS_MINFO_PROVIDER_SERVICE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MVS_TYPE_MINFO_PROVIDER_SERVICE))
+#define MVS_IS_MINFO_PROVIDER_SERVICE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), MVS_TYPE_MINFO_PROVIDER_SERVICE))
+#define MVS_MINFO_PROVIDER_SERVICE_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), MVS_TYPE_MINFO_PROVIDER_SERVICE, MvsMInfoProviderServiceClass))
+
+typedef struct _MvsMInfoProviderServicePrivate MvsMInfoProviderServicePrivate;
+
+typedef struct {
+        GObject parent;
+
+        /* <private> */
+        MvsMInfoProviderServicePrivate *priv;
+} MvsMInfoProviderService;
+
+typedef struct {
+        GObjectClass parent_class;
+} MvsMInfoProviderServiceClass;
+
+GType mvs_minfo_provider_service_get_type (void);
+MvsMInfoProviderService* mvs_minfo_provider_service_new (DBusGConnection *connection);
+
+G_END_DECLS
+
+#endif /* _MVS_MINFO_PROVIDER_SERVICE */
diff --git a/src/mvs-minfo-provider.xml b/src/mvs-minfo-provider.xml
new file mode 100644 (file)
index 0000000..df1123f
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE node PUBLIC
+         "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
+         "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
+<node name="/">
+       <interface name="com.simonpena.maevies.minfoprovider">
+               <method name="Query">
+                       <arg type="i" name="SearchService" />
+                       <arg type="s" name="SearchTerms" />
+               </method>
+               <signal name="ResponseReceived">
+                       <arg type="as" name="Results" />
+               </signal>
+       </interface>
+</node>
\ No newline at end of file