[rygel-grilo] Start client side library



commit 5a168ccb924616f3f6658927057b0cc6eee7ae59
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Mon Apr 12 13:43:41 2010 +0200

    Start client side library
    
    Start to implement client api.

 lib/Makefile.am            |    1 +
 lib/media-server2-client.h |   81 +++++++++++++++++++++++++++++++++++++
 lib/media-server2-server.h |    2 +-
 lib/media-server2.c        |   94 ++++++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am            |   14 ++++++-
 src/rygel-grilo.c          |    2 +-
 src/test-client.c          |   11 +++++
 7 files changed, 202 insertions(+), 3 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 4fd7cbd..6a3d6b5 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -35,6 +35,7 @@ libmediaserver2_la_SOURCES =		\
 	media-server2-server-private.h	\
 	media-server2-server.h		\
 	media-server2-client-glue.h	\
+	media-server2-client.h		\
 	media-server2.c
 
 MAINTAINERCLEANFILES =	\
diff --git a/lib/media-server2-client.h b/lib/media-server2-client.h
new file mode 100644
index 0000000..40ce3fd
--- /dev/null
+++ b/lib/media-server2-client.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * Authors: Juan A. Suarez Romero <jasuarez igalia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef _MEDIA_SERVER2_CLIENT_H_
+#define _MEDIA_SERVER2_CLIENT_H_
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "media-server2-common.h"
+
+#define MS2_TYPE_CLIENT                         \
+  (ms2_client_get_type ())
+
+#define MS2_CLIENT(obj)                         \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj),           \
+                               MS2_TYPE_CLIENT, \
+                               MS2Client))
+
+#define MS2_IS_CLIENT(obj)                              \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj),                   \
+                               MS2_TYPE_CLIENT))
+
+#define MS2_CLIENT_CLASS(klass)                 \
+  (G_TYPE_CHECK_CLASS_CAST((klass),             \
+                           MS2_TYPE_CLIENT,     \
+                           MS2ClientClass))
+
+#define MS2_IS_CLIENT_CLASS(klass)              \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),             \
+                           MS2_TYPE_CLIENT))
+
+#define MS2_CLIENT_GET_CLASS(obj)               \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj),            \
+                              MS2_TYPE_CLIENT,  \
+                              MS2ClientClass))
+
+typedef struct _MS2Client        MS2Client;
+typedef struct _MS2ClientPrivate MS2ClientPrivate;
+
+struct _MS2Client {
+
+  GObject parent;
+
+  /*< private >*/
+  MS2ClientPrivate *priv;
+};
+
+typedef struct _MS2ClientClass MS2ClientClass;
+
+struct _MS2ClientClass {
+
+  GObjectClass parent_class;
+};
+
+GType ms2_client_get_type (void);
+
+gchar **ms2_client_get_providers (void);
+
+MS2Client *ms2_client_new (const gchar *provider);
+
+#endif /* _MEDIA_SERVER2_CLIENT_H_ */
diff --git a/lib/media-server2-server.h b/lib/media-server2-server.h
index 1a7dc05..f97e480 100644
--- a/lib/media-server2-server.h
+++ b/lib/media-server2-server.h
@@ -26,7 +26,7 @@
 #include <glib.h>
 #include <glib-object.h>
 
-#include "media-server2-common.h"
+#include <media-server2-common.h>
 
 #define MS2_TYPE_SERVER                         \
   (ms2_server_get_type ())
diff --git a/lib/media-server2.c b/lib/media-server2.c
index 1d33989..a1481a3 100644
--- a/lib/media-server2.c
+++ b/lib/media-server2.c
@@ -22,11 +22,15 @@
 
 #include <dbus/dbus-glib-bindings.h>
 #include <dbus/dbus-glib.h>
+#include <string.h>
 
 #include "media-server2-server-private.h"
 #include "media-server2-server-glue.h"
 #include "media-server2-server.h"
 
+#include "media-server2-client-glue.h"
+#include "media-server2-client.h"
+
 #define ENTRY_POINT_IFACE "/org/gnome/UPnP/MediaServer2/"
 #define ENTRY_POINT_NAME  "org.gnome.UPnP.MediaServer2."
 
@@ -36,6 +40,9 @@
 #define MS2_SERVER_GET_PRIVATE(o)                                    \
   G_TYPE_INSTANCE_GET_PRIVATE((o), MS2_TYPE_SERVER, MS2ServerPrivate)
 
+#define MS2_CLIENT_GET_PRIVATE(o)                                    \
+  G_TYPE_INSTANCE_GET_PRIVATE((o), MS2_TYPE_CLIENT, MS2ClientPrivate)
+
 /*
  * Private MS2Server structure
  *   data: holds stuff for owner
@@ -48,7 +55,12 @@ struct _MS2ServerPrivate {
   GetPropertiesFunc get_properties;
 };
 
+struct _MS2ClientPrivate {
+  gpointer *reserved;
+};
+
 G_DEFINE_TYPE (MS2Server, ms2_server, G_TYPE_OBJECT);
+G_DEFINE_TYPE (MS2Client, ms2_client, G_TYPE_OBJECT);
 
 /* Registers the MS2Server object in dbus */
 static gboolean
@@ -107,6 +119,13 @@ ms2_server_class_init (MS2ServerClass *klass)
                                    &dbus_glib_ms2_server_object_info);
 }
 
+/* Class init function */
+static void
+ms2_client_class_init (MS2ClientClass *klass)
+{
+  g_type_class_add_private (klass, sizeof (MS2ClientPrivate));
+}
+
 /* Object init function */
 static void
 ms2_server_init (MS2Server *server)
@@ -114,6 +133,13 @@ ms2_server_init (MS2Server *server)
   server->priv = MS2_SERVER_GET_PRIVATE (server);
 }
 
+/* Object init function */
+static void
+ms2_client_init (MS2Client *client)
+{
+  client->priv = MS2_CLIENT_GET_PRIVATE (client);
+}
+
 /* Free gvalue */
 static void
 free_value (GValue *value)
@@ -983,3 +1009,71 @@ ms2_server_set_urls (GHashTable *properties,
                          ptrarray_to_value (url_array));
   }
 }
+
+gchar **
+ms2_client_get_providers ()
+{
+  DBusGConnection *connection;
+  DBusGProxy *gproxy;
+  GError *error = NULL;
+  GPtrArray *providers;
+  gchar **dbus_names;
+  gchar **list_providers;
+  gchar **p;
+  gint i;
+  gint prefix_size = strlen (ENTRY_POINT_NAME);
+
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (!connection) {
+    g_printerr ("Could not connect to session bus, %s\n", error->message);
+    g_clear_error (&error);
+    return FALSE;
+  }
+
+  gproxy = dbus_g_proxy_new_for_name (connection,
+                                      DBUS_SERVICE_DBUS,
+                                      DBUS_PATH_DBUS,
+                                      DBUS_INTERFACE_DBUS);
+
+  org_freedesktop_DBus_list_names (gproxy, &dbus_names, &error);
+  g_object_unref (gproxy);
+
+  if (error) {
+    g_printerr ("Could not get list of dbus names, %s\n", error->message);
+    g_clear_error (&error);
+    return FALSE;
+  }
+
+  if (!dbus_names) {
+    return FALSE;
+  }
+
+  providers = g_ptr_array_new ();
+  for (p = dbus_names; *p; p++) {
+    if (g_str_has_prefix (*p, ENTRY_POINT_NAME)) {
+      g_ptr_array_add (providers, *p);
+    }
+  }
+
+
+  list_providers = g_new (gchar *, providers->len + 1);
+  for (i = 0; i < providers->len; i++) {
+    list_providers[i] = g_strdup (g_ptr_array_index (providers, i) + prefix_size);
+  }
+
+  list_providers[i] = NULL;
+
+  g_strfreev (dbus_names);
+  g_ptr_array_free (providers, TRUE);
+
+  return list_providers;
+}
+
+MS2Client *ms2_client_new (const gchar *provider)
+{
+  MS2Client *client;
+
+  client = g_object_new (MS2_TYPE_CLIENT, NULL);
+
+  return client;
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index d9afcd1..c3fb32c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,7 +14,7 @@ rygel-grilo-%-glue.h: $(top_srcdir)/data/%2.xml
 	--prefix=rygel_grilo_$(subst -,_,$*)	\
 	$^
 
-bin_PROGRAMS = rygel-grilo
+bin_PROGRAMS = rygel-grilo test-client
 
 rygel_grilo_SOURCES =	\
 	rygel-grilo.c
@@ -29,6 +29,18 @@ rygel_grilo_LDADD =	\
 	@DEPS_LIBS@	\
 	$(top_builddir)/lib/libmediaserver2.la
 
+test_client_SOURCES =	\
+	test-client.c
+
+test_client_CFLAGS =		\
+	-DPREFIX=$(prefix)	\
+	-I$(top_srcdir)/lib
+
+test_client_LDADD =	\
+	-ldl -lpthread	\
+	@DEPS_LIBS@	\
+	$(top_builddir)/lib/libmediaserver2.la
+
 MAINTAINERCLEANFILES =	\
 	*.in
 
diff --git a/src/rygel-grilo.c b/src/rygel-grilo.c
index f60d487..35683c9 100644
--- a/src/rygel-grilo.c
+++ b/src/rygel-grilo.c
@@ -25,7 +25,7 @@
 #include <grilo.h>
 #include <stdio.h>
 
-#include "media-server2-server.h"
+#include <media-server2-server.h>
 
 #define ID_PREFIX_AUDIO     "gra://"
 #define ID_PREFIX_CONTAINER "grc://"
diff --git a/src/test-client.c b/src/test-client.c
new file mode 100644
index 0000000..5ce1dd3
--- /dev/null
+++ b/src/test-client.c
@@ -0,0 +1,11 @@
+#include <media-server2-client.h>
+#include <glib.h>
+
+int main (int argc, char **argv)
+{
+  gchar **providers;
+
+  g_type_init ();
+
+  providers = ms2_client_get_providers ();
+}



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