TMDBMovie: Added tmdb movie service
authorSimón Pena <spenap@gmail.com>
Sun, 30 May 2010 14:23:25 +0000 (16:23 +0200)
committerSimón Pena <spenap@gmail.com>
Sun, 30 May 2010 20:06:28 +0000 (22:06 +0200)
A new service is added so that the TMDBMovie info gets exposed via
DBus and the peer doesn't need to fully retrieve all the results,
but the one it needs.

src/mvs-tmdb-movie-service.c [new file with mode: 0644]
src/mvs-tmdb-movie-service.h [new file with mode: 0644]
src/mvs-tmdb-movie.xml [new file with mode: 0644]

diff --git a/src/mvs-tmdb-movie-service.c b/src/mvs-tmdb-movie-service.c
new file mode 100644 (file)
index 0000000..788eb18
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * mvs-tmdb-movie-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-tmdb-movie-service.h"
+
+#define TMDB_MOVIE_SERVICE_OBJECT_PATH "/TMDBMovie"
+#define TMDB_MOVIE_SERVICE_NAME "com.simonpena.maevies.tmdbmovie"
+
+G_DEFINE_TYPE (MvsTMDBMovieService, mvs_tmdb_movie_service, G_TYPE_OBJECT)
+
+enum {
+        PROP_0,
+        PROP_DBUSGCONN,
+};
+
+#define GET_PRIVATE(o) \
+        (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_TMDB_MOVIE_SERVICE, MvsTMDBMovieServicePrivate))
+
+struct _MvsTMDBMovieServicePrivate {
+        MvsTmdbMovie *movie;
+        DBusGConnection *connection;
+};
+
+gboolean
+mvs_tmdb_movie_service_get_title (MvsTMDBMovieService *self, gchar **title,
+                                  GError **error)
+{
+        *title = g_strdup (mvs_tmdb_movie_get_name (self->priv->movie));
+        return *title != NULL;
+}
+
+#include "mvs-tmdb-movie-service-glue.h"
+
+static void
+setup_dbus (MvsTMDBMovieService *self)
+{
+        DBusGProxy *proxy;
+        guint request_name_result;
+        GError *error = NULL;
+
+        g_message ("Registering DBUS " TMDB_MOVIE_SERVICE_OBJECT_PATH " " TMDB_MOVIE_SERVICE_NAME);
+
+        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,
+                                                TMDB_MOVIE_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,
+                                             TMDB_MOVIE_SERVICE_OBJECT_PATH,
+                                             G_OBJECT (self));
+
+        g_object_unref (proxy);
+}
+
+static void
+mvs_tmdb_movie_service_set_property (GObject *object, guint property_id,
+                                  const GValue *value, GParamSpec *pspec)
+{
+        MvsTMDBMovieService *self = MVS_TMDB_MOVIE_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_tmdb_movie_service_finalize (GObject *object)
+{
+        MvsTMDBMovieService *self = MVS_TMDB_MOVIE_SERVICE (object);
+
+        if (self->priv->connection) {
+                dbus_g_connection_unref (self->priv->connection);
+        }
+        g_object_unref (self->priv->movie);
+        G_OBJECT_CLASS (mvs_tmdb_movie_service_parent_class)->finalize (object);
+}
+
+static void
+mvs_tmdb_movie_service_class_init (MvsTMDBMovieServiceClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        g_type_class_add_private (klass, sizeof (MvsTMDBMovieServicePrivate));
+
+        object_class->set_property = mvs_tmdb_movie_service_set_property;
+        object_class->finalize = mvs_tmdb_movie_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_TMDB_MOVIE_SERVICE,
+                                          &dbus_glib_mvs_tmdb_movie_service_object_info);
+}
+
+static void
+mvs_tmdb_movie_service_init (MvsTMDBMovieService *self)
+{
+        self->priv = GET_PRIVATE (self);
+        self->priv->movie = NULL;
+        self->priv->connection = NULL;
+}
+
+MvsTMDBMovieService*
+mvs_tmdb_movie_service_new (DBusGConnection *connection, MvsTmdbMovie *movie)
+{
+        MvsTMDBMovieService *instance = g_object_new (MVS_TYPE_TMDB_MOVIE_SERVICE,
+                             "connection", connection, NULL);
+        instance->priv->movie = movie;
+        return instance;
+}
diff --git a/src/mvs-tmdb-movie-service.h b/src/mvs-tmdb-movie-service.h
new file mode 100644 (file)
index 0000000..b296a83
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * mvs-tmdb-movie-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_TMDB_MOVIE_SERVICE
+#define _MVS_TMDB_MOVIE_SERVICE
+
+#include <glib-object.h>
+#include "mvs-tmdb-movie.h"
+
+G_BEGIN_DECLS
+
+#define MVS_TYPE_TMDB_MOVIE_SERVICE mvs_tmdb_movie_service_get_type()
+#define MVS_TMDB_MOVIE_SERVICE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), MVS_TYPE_TMDB_MOVIE_SERVICE, MvsTMDBMovieService))
+#define MVS_TMDB_MOVIE_SERVICE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), MVS_TYPE_TMDB_MOVIE_SERVICE, MvsTMDBMovieServiceClass))
+#define MVS_IS_TMDB_MOVIE_SERVICE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MVS_TYPE_TMDB_MOVIE_SERVICE))
+#define MVS_IS_TMDB_MOVIE_SERVICE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), MVS_TYPE_TMDB_MOVIE_SERVICE))
+#define MVS_TMDB_MOVIE_SERVICE_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), MVS_TYPE_TMDB_MOVIE_SERVICE, MvsTMDBMovieServiceClass))
+
+typedef struct _MvsTMDBMovieServicePrivate MvsTMDBMovieServicePrivate;
+
+typedef struct {
+        GObject parent;
+
+        /* <private> */
+        MvsTMDBMovieServicePrivate *priv;
+} MvsTMDBMovieService;
+
+typedef struct {
+        GObjectClass parent_class;
+} MvsTMDBMovieServiceClass;
+
+GType mvs_tmdb_movie_service_get_type (void);
+MvsTMDBMovieService* mvs_tmdb_movie_service_new (DBusGConnection *connection,
+                MvsTmdbMovie *movie);
+
+G_END_DECLS
+
+#endif /* _MVS_TMDB_MOVIE_SERVICE */
diff --git a/src/mvs-tmdb-movie.xml b/src/mvs-tmdb-movie.xml
new file mode 100644 (file)
index 0000000..72b74b2
--- /dev/null
@@ -0,0 +1,11 @@
+<?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.movie">
+               <method name="GetTitle">
+                       <arg type="s" name="Title" direction="out" />
+               </method>
+       </interface>
+</node>
\ No newline at end of file