[gnome-online-miners] src: Added wrappers over dleyna-server D-Bus API



commit 76555f99e44d52898172eb2ba9b48a8334ae8aed
Author: Pranav Kant <pranav913 gmail com>
Date:   Thu Jun 19 23:48:51 2014 +0530

    src: Added wrappers over dleyna-server D-Bus API
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728912

 src/Makefile.am                |    4 +
 src/gom-dlna-server.c          |  320 ++++++++++++++++++++++++++++++++++++++++
 src/gom-dlna-server.h          |   91 ++++++++++++
 src/gom-dlna-servers-manager.c |  287 +++++++++++++++++++++++++++++++++++
 src/gom-dlna-servers-manager.h |   78 ++++++++++
 5 files changed, 780 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 915bb5b..8612023 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -149,6 +149,10 @@ gom_media_server_miner_SOURCES = \
     gom-media-server-miner-main.c \
     gom-media-server-miner.c \
     gom-media-server-miner.h \
+    gom-dlna-server.c \
+    gom-dlna-server.h \
+    gom-dlna-servers-manager.c \
+    gom-dlna-servers-manager.h \
     $(NULL)
 
 gom_media_server_miner_CPPFLAGS = \
diff --git a/src/gom-dlna-server.c b/src/gom-dlna-server.c
new file mode 100644
index 0000000..d13bf68
--- /dev/null
+++ b/src/gom-dlna-server.c
@@ -0,0 +1,320 @@
+/*
+ * GNOME Online Miners - crawls through your online content
+ * Copyright (c) 2014 Pranav Kant
+ *
+ * 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 Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Author: Pranav Kant <pranav913 gmail com>
+ *
+ */
+
+#include "config.h"
+
+#include "gom-dleyna-server-media-device.h"
+#include "gom-upnp-media-container2.h"
+#include "gom-dlna-server.h"
+
+struct _GomDlnaServerPrivate
+{
+  DleynaServerMediaDevice *device;
+  UpnpMediaContainer2 *container;
+  GBusType bus_type;
+  GDBusProxyFlags flags;
+  gchar *object_path;
+  gchar *well_known_name;
+};
+
+
+enum{
+  PROP_0,
+  PROP_BUS_TYPE,
+  PROP_FLAGS,
+  PROP_OBJECT_PATH,
+  PROP_WELL_KNOWN_NAME,
+};
+
+static void gom_dlna_server_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GomDlnaServer, gom_dlna_server, G_TYPE_OBJECT,
+                         G_ADD_PRIVATE (GomDlnaServer)
+                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+                                                gom_dlna_server_initable_iface_init));
+
+
+static void
+gom_dlna_server_dispose (GObject *object)
+{
+  GomDlnaServer *self = GOM_DLNA_SERVER (object);
+  GomDlnaServerPrivate *priv = self->priv;
+
+  g_clear_object (&priv->device);
+  g_clear_object (&priv->container);
+
+  G_OBJECT_CLASS (gom_dlna_server_parent_class)->dispose (object);
+}
+
+
+static void
+gom_dlna_server_finalize (GObject *object)
+{
+  GomDlnaServer *self = GOM_DLNA_SERVER (object);
+  GomDlnaServerPrivate *priv = self->priv;
+
+  g_free (priv->well_known_name);
+  g_free (priv->object_path);
+
+  G_OBJECT_CLASS (gom_dlna_server_parent_class)->finalize (object);
+}
+
+
+static void
+gom_dlna_server_get_property (GObject *object,
+                              guint prop_id,
+                              GValue *value,
+                              GParamSpec *pspec)
+{
+  GomDlnaServer *self = GOM_DLNA_SERVER (object);
+
+  switch (prop_id)
+    {
+    case PROP_OBJECT_PATH:
+      g_value_set_string (value, gom_dlna_server_get_object_path (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+gom_dlna_server_set_property (GObject *object,
+                              guint prop_id,
+                              const GValue *value,
+                              GParamSpec *pspec)
+{
+  GomDlnaServer *self = GOM_DLNA_SERVER (object);
+  GomDlnaServerPrivate *priv = self->priv;
+
+  switch (prop_id)
+    {
+    case PROP_BUS_TYPE:
+      priv->bus_type = g_value_get_enum (value);
+      break;
+
+    case PROP_FLAGS:
+      priv->flags = g_value_get_flags (value);
+      break;
+
+    case PROP_OBJECT_PATH:
+      priv->object_path = g_value_dup_string (value);
+      break;
+
+    case PROP_WELL_KNOWN_NAME:
+      priv->well_known_name = g_value_dup_string (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+gom_dlna_server_init (GomDlnaServer *self)
+{
+  self->priv = gom_dlna_server_get_instance_private (self);
+}
+
+
+static void
+gom_dlna_server_class_init (GomDlnaServerClass *class)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+
+  gobject_class->dispose = gom_dlna_server_dispose;
+  gobject_class->finalize = gom_dlna_server_finalize;
+  gobject_class->set_property = gom_dlna_server_set_property;
+  gobject_class->get_property = gom_dlna_server_get_property;
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_BUS_TYPE,
+                                   g_param_spec_enum ("bus-type",
+                                                      "Bus Type",
+                                                      "The bus to connect to, defaults to the session one",
+                                                      G_TYPE_BUS_TYPE,
+                                                      G_BUS_TYPE_SESSION,
+                                                      G_PARAM_WRITABLE |
+                                                      G_PARAM_CONSTRUCT_ONLY |
+                                                      G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_FLAGS,
+                                   g_param_spec_flags ("flags",
+                                                       "Flags",
+                                                       "Proxy flags",
+                                                       G_TYPE_DBUS_PROXY_FLAGS,
+                                                       G_DBUS_PROXY_FLAGS_NONE,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT_ONLY |
+                                                       G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_OBJECT_PATH,
+                                   g_param_spec_string ("object-path",
+                                                        "Object Path",
+                                                        "The object path the proxy is for",
+                                                        NULL,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
+
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_WELL_KNOWN_NAME,
+                                   g_param_spec_string ("well-known-name",
+                                                        "Well-Known Name",
+                                                        "The well-known name of the service",
+                                                        NULL,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
+
+}
+
+
+GomDlnaServer *
+gom_dlna_server_new_for_bus (GBusType bus_type,
+                             GDBusProxyFlags flags,
+                             const gchar *well_known_name,
+                             const gchar *object_path,
+                             GCancellable *cancellable,
+                             GError **error)
+{
+  return g_initable_new (GOM_TYPE_DLNA_SERVER,
+                         cancellable,
+                         error,
+                         "bus-type", bus_type,
+                         "flags", flags,
+                         "object-path", object_path,
+                         "well-known-name", well_known_name,
+                         NULL);
+}
+
+
+static gboolean
+gom_dlna_server_initable_init (GInitable *initable,
+                               GCancellable *cancellable,
+                               GError **error)
+{
+  GomDlnaServer *self = GOM_DLNA_SERVER (initable);
+  GomDlnaServerPrivate *priv = self->priv;
+  gboolean ret_val = TRUE;
+
+  priv->device =
+    dleyna_server_media_device_proxy_new_for_bus_sync (priv->bus_type,
+                                                       G_DBUS_PROXY_FLAGS_NONE,
+                                                       priv->well_known_name,
+                                                       priv->object_path,
+                                                       NULL,
+                                                       error);
+  if (*error != NULL)
+    {
+      ret_val = FALSE;
+      goto out;
+    }
+
+  priv->container =
+    upnp_media_container2_proxy_new_for_bus_sync (priv->bus_type,
+                                                  G_DBUS_PROXY_FLAGS_NONE,
+                                                  priv->well_known_name,
+                                                  priv->object_path,
+                                                  NULL,
+                                                  error);
+  if (*error != NULL)
+    {
+      ret_val = FALSE;
+      goto out;
+    }
+
+ out:
+  return ret_val;
+}
+
+
+static void
+gom_dlna_server_initable_iface_init (GInitableIface *iface)
+{
+  iface->init = gom_dlna_server_initable_init;
+}
+
+
+const gchar *
+gom_dlna_server_get_object_path (GomDlnaServer *self)
+{
+  return self->priv->object_path;
+}
+
+
+const gchar *
+gom_dlna_server_get_friendly_name (GomDlnaServer *self)
+{
+  GomDlnaServerPrivate *priv = self->priv;
+
+  return dleyna_server_media_device_get_friendly_name (priv->device);
+}
+
+
+GVariant *
+gom_dlna_server_search_objects (GomDlnaServer *self, GError **error)
+{
+  GomDlnaServerPrivate *priv = self->priv;
+  GVariant *out = NULL;
+  gchar *query = g_strdup_printf ("Type = \"image.photo\"");
+  const gchar const *filter[] = {"DisplayName", "URLs", "Path", "MIMEType"};
+
+  upnp_media_container2_call_search_objects_sync (priv->container,
+                                                  query,
+                                                  0,
+                                                  0,
+                                                  filter,
+                                                  &out,
+                                                  NULL,
+                                                  error);
+
+
+  g_free (query);
+  return out;
+}
+
+
+const gchar *
+gom_dlna_server_get_udn (GomDlnaServer *self)
+{
+  GomDlnaServerPrivate *priv = self->priv;
+
+  return dleyna_server_media_device_get_udn (priv->device);
+}
+
+
+gboolean
+gom_dlna_server_get_searchable (GomDlnaServer *self)
+{
+  GomDlnaServerPrivate *priv = self->priv;
+  return upnp_media_container2_get_searchable (priv->container);
+}
diff --git a/src/gom-dlna-server.h b/src/gom-dlna-server.h
new file mode 100644
index 0000000..2cda7da
--- /dev/null
+++ b/src/gom-dlna-server.h
@@ -0,0 +1,91 @@
+/*
+ * GNOME Online Miners - crawls through your online content
+ * Copyright (c) 2014 Pranav Kant
+ *
+ * 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 Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Author: Pranav Kant <pranav913 gmail com>
+ *
+ */
+
+#ifndef GOM_DLNA_SERVER_H
+#define GOM_DLNA_SERVER_H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define GOM_TYPE_DLNA_SERVER (gom_dlna_server_get_type ())
+
+#define GOM_DLNA_SERVER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   GOM_TYPE_DLNA_SERVER, GomDlnaServer))
+
+#define GOM_DLNA_SERVER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   GOM_TYPE_DLNA_SERVER, GomDlnaServerClass))
+
+#define GOM_IS_DLNA_SERVER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   GOM_TYPE_DLNA_SERVER))
+
+#define GOM_IS_DLNA_SERVER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   GOM_TYPE_DLNA_SERVER))
+
+#define GOM_DLNA_SERVER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   GOM_TYPE_DLNA_SERVER, GomDlnaServerClass))
+
+typedef struct _GomDlnaServer        GomDlnaServer;
+typedef struct _GomDlnaServerClass   GomDlnaServerClass;
+typedef struct _GomDlnaServerPrivate GomDlnaServerPrivate;
+
+struct _GomDlnaServer
+{
+  GObject parent_instance;
+  GomDlnaServerPrivate *priv;
+};
+
+struct _GomDlnaServerClass
+{
+  GObjectClass parent_class;
+};
+
+GType                 gom_dlna_server_get_type                  (void) G_GNUC_CONST;
+
+GomDlnaServer        *gom_dlna_server_new_from_object_path      (const gchar *object_path);
+
+GomDlnaServer        *gom_dlna_server_new_for_bus               (GBusType bus_type,
+                                                                 GDBusProxyFlags flags,
+                                                                 const gchar *well_known_name,
+                                                                 const gchar *object_path,
+                                                                 GCancellable *cancellable,
+                                                                 GError **error);
+
+const gchar          *gom_dlna_server_get_object_path           (GomDlnaServer  *server);
+
+gboolean              gom_dlna_server_get_searchable            (GomDlnaServer  *server);
+
+GVariant             *gom_dlna_server_search_objects            (GomDlnaServer  *device, GError **error);
+
+const gchar          *gom_dlna_server_get_friendly_name         (GomDlnaServer  *self);
+
+const gchar          *gom_dlna_server_get_udn                   (GomDlnaServer  *self);
+
+G_END_DECLS
+
+#endif /* GOM_DLNA_SERVER_H */
diff --git a/src/gom-dlna-servers-manager.c b/src/gom-dlna-servers-manager.c
new file mode 100644
index 0000000..77f61f3
--- /dev/null
+++ b/src/gom-dlna-servers-manager.c
@@ -0,0 +1,287 @@
+/*
+ * GNOME Online Miners - crawls through your online content
+ * Copyright (c) 2014 Pranav Kant
+ *
+ * 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 Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Author: Pranav Kant <pranav913 gmail com>
+ *
+ */
+
+#include "config.h"
+
+#include <gio/gio.h>
+
+#include "gom-dleyna-server-manager.h"
+#include "gom-dlna-servers-manager.h"
+#include "gom-dlna-server.h"
+
+struct _GomDlnaServersManagerPrivate
+{
+  DleynaServerManager *proxy;
+  GHashTable *servers;
+  GHashTable *udn_to_server;
+  GError *error;
+};
+
+enum
+{
+  SERVER_FOUND,
+  SERVER_LOST,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (GomDlnaServersManager, gom_dlna_servers_manager, G_TYPE_OBJECT)
+
+
+static GObject *gom_dlna_servers_manager_singleton = NULL;
+
+
+static void
+gom_dlna_servers_manager_dispose (GObject *object)
+{
+  GomDlnaServersManager *self = GOM_DLNA_SERVERS_MANAGER (object);
+  GomDlnaServersManagerPrivate *priv = self->priv;
+
+  g_clear_object (&priv->proxy);
+  g_clear_pointer (&priv->servers, g_hash_table_unref);
+  g_clear_pointer (&priv->udn_to_server, g_hash_table_unref);
+  g_clear_error (&priv->error);
+
+  G_OBJECT_CLASS (gom_dlna_servers_manager_parent_class)->dispose (object);
+}
+
+static void
+gom_dlna_servers_manager_server_found_cb (GomDlnaServersManager *self,
+                                          const gchar           *object_path,
+                                          gpointer              *data)
+{
+  GomDlnaServersManagerPrivate *priv = self->priv;
+  GError *error = NULL;
+  GomDlnaServer *server;
+  const gchar *udn;
+
+  server = gom_dlna_server_new_for_bus (G_BUS_TYPE_SESSION,
+                                        G_DBUS_PROXY_FLAGS_NONE,
+                                        "com.intel.dleyna-server",
+                                        object_path,
+                                        NULL, /* GCancellable */
+                                        &error);
+
+  if (error != NULL)
+    {
+      g_warning ("Error initializing new Server : %s",
+                 error->message);
+      g_error_free (error);
+      return;
+    }
+
+  udn = gom_dlna_server_get_udn (server);
+  g_hash_table_insert (priv->servers, (gpointer) object_path, server);
+  g_hash_table_insert (priv->udn_to_server, (gpointer) udn, server);
+  g_signal_emit (self, signals[SERVER_FOUND], 0, server);
+}
+
+
+static void
+gom_dlna_servers_manager_server_lost_cb (GomDlnaServersManager *self,
+                                         const gchar           *object_path,
+                                         gpointer              *data)
+{
+  GomDlnaServersManagerPrivate *priv = self->priv;
+  GomDlnaServer *server;
+  const gchar *udn;
+
+  server = GOM_DLNA_SERVER (g_hash_table_lookup (priv->servers, object_path));
+  g_return_if_fail (server != NULL);
+
+  udn = gom_dlna_server_get_udn (server);
+  /* By using g_hash_table_steal instead of remove, we delay deallocation
+     of 'server' until all of its associations from all
+     hashtables are removed. */
+  g_hash_table_steal (priv->udn_to_server, udn);
+  g_hash_table_steal (priv->servers, object_path);
+
+  g_signal_emit (self, signals[SERVER_LOST], 0, server);
+  /* Server is deallocated now after destroying all its associations
+     from all hashtables */
+  g_object_unref (server);
+}
+
+
+static void
+gom_dlna_servers_manager_proxy_get_servers_cb (GObject      *source_object,
+                                               GAsyncResult *res,
+                                               gpointer      user_data)
+{
+  GomDlnaServersManager *self = user_data;
+  GomDlnaServersManagerPrivate *priv = self->priv;
+  gchar **object_paths = NULL;
+  GError *error = NULL;
+  guint i;
+
+  dleyna_server_manager_call_get_servers_finish (priv->proxy, &object_paths, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to Call GetServers : %s",
+                 error->message);
+      g_error_free (error);
+      g_propagate_error (&priv->error, error);
+      goto out;
+    }
+
+  for (i = 0; object_paths[i] != NULL; i++)
+    gom_dlna_servers_manager_server_found_cb (self, object_paths[i], NULL);
+
+ out:
+  g_strfreev (object_paths);
+  g_object_unref (self);
+}
+
+
+static void
+gom_dlna_servers_manager_proxy_new_cb (GObject      *source_object,
+                                       GAsyncResult *res,
+                                       gpointer      user_data)
+{
+  GomDlnaServersManager *self = user_data;
+  GomDlnaServersManagerPrivate *priv = self->priv;
+  GError *error = NULL;
+
+  priv->proxy = dleyna_server_manager_proxy_new_for_bus_finish (res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to connect to the dlnaservers.Manager DBus object: %s",
+                 error->message);
+      g_error_free (error);
+      g_propagate_error (&priv->error, error);
+      goto out;
+    }
+
+  g_debug ("%s DLNA Servers Manager initialized", G_STRFUNC);
+
+  g_signal_connect_swapped (priv->proxy,
+                            "found-server",
+                            G_CALLBACK (gom_dlna_servers_manager_server_found_cb),
+                            self);
+
+  g_signal_connect_swapped (priv->proxy,
+                            "lost-server",
+                            G_CALLBACK (gom_dlna_servers_manager_server_lost_cb),
+                            self);
+
+  dleyna_server_manager_call_get_servers (priv->proxy, NULL,
+                                          gom_dlna_servers_manager_proxy_get_servers_cb,
+                                          g_object_ref (self));
+
+ out:
+  g_object_unref (self);
+}
+
+
+static GObject *
+gom_dlna_servers_manager_constructor (GType                  type,
+                                      guint                  n_construct_params,
+                                      GObjectConstructParam *construct_params)
+{
+  if (gom_dlna_servers_manager_singleton == NULL)
+    {
+      gom_dlna_servers_manager_singleton
+        = G_OBJECT_CLASS (gom_dlna_servers_manager_parent_class)->constructor (type,
+                                                                               n_construct_params,
+                                                                               construct_params);
+      g_object_add_weak_pointer (gom_dlna_servers_manager_singleton,
+                                 (gpointer) &gom_dlna_servers_manager_singleton);
+      return gom_dlna_servers_manager_singleton;
+    }
+
+  return g_object_ref (gom_dlna_servers_manager_singleton);
+}
+
+
+static void
+gom_dlna_servers_manager_init (GomDlnaServersManager *self)
+{
+  GomDlnaServersManagerPrivate *priv;
+
+  self->priv = priv = gom_dlna_servers_manager_get_instance_private (self);
+
+  dleyna_server_manager_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+                                           G_DBUS_PROXY_FLAGS_NONE,
+                                           "com.intel.dleyna-server",
+                                           "/com/intel/dLeynaServer",
+                                           NULL,
+                                           gom_dlna_servers_manager_proxy_new_cb,
+                                           g_object_ref (self));
+
+  priv->servers = g_hash_table_new (g_str_hash, g_str_equal);
+  priv->udn_to_server = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+
+static void
+gom_dlna_servers_manager_class_init (GomDlnaServersManagerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->constructor = gom_dlna_servers_manager_constructor;
+  object_class->dispose = gom_dlna_servers_manager_dispose;
+
+  signals[SERVER_FOUND] = g_signal_new ("server-found",
+                                        G_TYPE_FROM_CLASS (class),
+                                        G_SIGNAL_RUN_LAST,
+                                        0,
+                                        NULL,
+                                        NULL,
+                                        g_cclosure_marshal_VOID__OBJECT,
+                                        G_TYPE_NONE,
+                                        1,
+                                        GOM_TYPE_DLNA_SERVER);
+
+  signals[SERVER_LOST] = g_signal_new ("server-lost",
+                                       G_TYPE_FROM_CLASS (class),
+                                       G_SIGNAL_RUN_LAST,
+                                       0,
+                                       NULL,
+                                       NULL,
+                                       g_cclosure_marshal_VOID__OBJECT,
+                                       G_TYPE_NONE,
+                                       1,
+                                       GOM_TYPE_DLNA_SERVER);
+}
+
+
+GomDlnaServer *
+gom_dlna_servers_manager_get_server (GomDlnaServersManager *self,
+                                     const gchar           *udn)
+{
+  GomDlnaServersManagerPrivate *priv = self->priv;
+  GomDlnaServer *server;
+
+  server = GOM_DLNA_SERVER (g_hash_table_lookup (priv->udn_to_server, udn));
+
+  return server != NULL ? g_object_ref (server) : NULL;
+}
+
+
+GomDlnaServersManager *
+gom_dlna_servers_manager_dup_singleton (void)
+{
+  return g_object_new (GOM_TYPE_DLNA_SERVERS_MANAGER, NULL);
+}
diff --git a/src/gom-dlna-servers-manager.h b/src/gom-dlna-servers-manager.h
new file mode 100644
index 0000000..241b01e
--- /dev/null
+++ b/src/gom-dlna-servers-manager.h
@@ -0,0 +1,78 @@
+/*
+ * GNOME Online Miners - crawls through your online content
+ * Copyright (c) 2014 Pranav Kant
+ *
+ * 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 Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Author: Pranav Kant <pranav913 gmail com>
+ *
+ */
+
+#ifndef GOM_DLNA_SERVERS_MANAGER_H
+#define GOM_DLNA_SERVERS_MANAGER_H
+
+#include <glib-object.h>
+#include "gom-dlna-server.h"
+
+G_BEGIN_DECLS
+
+#define GOM_TYPE_DLNA_SERVERS_MANAGER (gom_dlna_servers_manager_get_type ())
+
+#define GOM_DLNA_SERVERS_MANAGER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   GOM_TYPE_DLNA_SERVERS_MANAGER, GomDlnaServersManager))
+
+#define GOM_DLNA_SERVERS_MANAGER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   GOM_TYPE_DLNA_SERVERS_MANAGER, GomDlnaServersManagerClass))
+
+#define GOM_IS_DLNA_SERVERS_MANAGER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   GOM_TYPE_DLNA_SERVERS_MANAGER))
+
+#define GOM_IS_DLNA_SERVERS_MANAGER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   GOM_TYPE_DLNA_SERVERS_MANAGER))
+
+#define GOM_DLNA_SERVERS_MANAGER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   GOM_TYPE_DLNA_SERVERS_MANAGER, GomDlnaServersManagerClass))
+
+typedef struct _GomDlnaServersManager        GomDlnaServersManager;
+typedef struct _GomDlnaServersManagerClass   GomDlnaServersManagerClass;
+typedef struct _GomDlnaServersManagerPrivate GomDlnaServersManagerPrivate;
+
+struct _GomDlnaServersManager
+{
+  GObject parent_instance;
+  GomDlnaServersManagerPrivate *priv;
+};
+
+struct _GomDlnaServersManagerClass
+{
+  GObjectClass parent_class;
+};
+
+GType                    gom_dlna_servers_manager_get_type           (void) G_GNUC_CONST;
+
+GomDlnaServersManager   *gom_dlna_servers_manager_dup_singleton      (void);
+
+GomDlnaServer           *gom_dlna_servers_manager_get_server         (GomDlnaServersManager *self,
+                                                                      const gchar *udn);
+
+G_END_DECLS
+
+#endif /* GOM_DLNA_SERVERS_MANAGER_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]