rygel r47 - in trunk: . src



Author: zeeshanak
Date: Tue Oct 28 20:59:04 2008
New Revision: 47
URL: http://svn.gnome.org/viewvc/rygel?rev=47&view=rev

Log:
Put the services implementations into separate objects.

Added:
   trunk/src/gupnp-content-directory.c
      - copied, changed from r46, /trunk/src/gupnp-media-server.c
   trunk/src/gupnp-content-directory.h
   trunk/src/gupnp-media-receiver-registrar.c
   trunk/src/gupnp-media-receiver-registrar.h
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/gupnp-media-server.c

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Oct 28 20:59:04 2008
@@ -15,6 +15,10 @@
 gupnp_media_server_SOURCES = main.c \
 			     gupnp-media-server.h \
 			     gupnp-media-server.c \
+			     gupnp-content-directory.h \
+			     gupnp-content-directory.c \
+			     gupnp-media-receiver-registrar.h \
+			     gupnp-media-receiver-registrar.c \
 			     gupnp-media-tracker.h \
 			     gupnp-media-tracker.c
 gupnp_media_server_LDADD = $(LIBGUPNP_LIBS) \

Copied: trunk/src/gupnp-content-directory.c (from r46, /trunk/src/gupnp-media-server.c)
==============================================================================
--- /trunk/src/gupnp-media-server.c	(original)
+++ trunk/src/gupnp-content-directory.c	Tue Oct 28 20:59:04 2008
@@ -28,72 +28,60 @@
 #include <libgupnp/gupnp.h>
 #include <libgupnp-av/gupnp-av.h>
 
-#include "gupnp-media-server.h"
+#include "gupnp-content-directory.h"
 #include "gupnp-media-tracker.h"
 
-#define HOME_DIR_ALIAS "/media"
+G_DEFINE_TYPE (GUPnPContentDirectory,
+               gupnp_content_directory,
+               GUPNP_TYPE_SERVICE);
 
-G_DEFINE_TYPE (GUPnPMediaServer,
-               gupnp_media_server,
-               GUPNP_TYPE_ROOT_DEVICE);
-
-struct _GUPnPMediaServerPrivate {
+struct _GUPnPContentDirectoryPrivate {
         guint32 system_update_id;
 
-        GUPnPService *content_dir;
-        GUPnPService *msr;              /* MS MediaReceiverRegistrar */
-
         GUPnPMediaTracker *tracker;
 };
 
 /* GObject stuff */
 static void
-gupnp_media_server_dispose (GObject *object)
+gupnp_content_directory_dispose (GObject *object)
 {
-        GUPnPMediaServer *server;
+        GUPnPContentDirectory *content_dir;
         GObjectClass *object_class;
 
-        server = GUPNP_MEDIA_SERVER (object);
+        content_dir = GUPNP_CONTENT_DIRECTORY (object);
 
         /* Free GUPnP resources */
-        if (server->priv->tracker) {
-                g_object_unref (server->priv->tracker);
-                server->priv->tracker = NULL;
-        }
-        if (server->priv->content_dir) {
-                g_object_unref (server->priv->content_dir);
-                server->priv->content_dir = NULL;
-        }
-        if (server->priv->msr) {
-                g_object_unref (server->priv->msr);
-                server->priv->msr = NULL;
+        if (content_dir->priv->tracker) {
+                g_object_unref (content_dir->priv->tracker);
+                content_dir->priv->tracker = NULL;
         }
 
         /* Call super */
-        object_class = G_OBJECT_CLASS (gupnp_media_server_parent_class);
+        object_class = G_OBJECT_CLASS (gupnp_content_directory_parent_class);
         object_class->dispose (object);
 }
 
 static void
-gupnp_media_server_init (GUPnPMediaServer *server)
+gupnp_content_directory_init (GUPnPContentDirectory *content_dir)
 {
-         server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server,
-                                                     GUPNP_TYPE_MEDIA_SERVER,
-                                                     GUPnPMediaServerPrivate);
+         content_dir->priv = G_TYPE_INSTANCE_GET_PRIVATE
+                                (content_dir,
+                                 GUPNP_TYPE_CONTENT_DIRECTORY,
+                                 GUPnPContentDirectoryPrivate);
 }
 
 static GObject *
-gupnp_media_server_constructor (GType                  type,
-                                guint                  n_construct_params,
-                                GObjectConstructParam *construct_params)
+gupnp_content_directory_constructor (GType                  type,
+                                     guint                  n_construct_params,
+                                     GObjectConstructParam *construct_params)
 {
         GObject *object;
         GObjectClass *object_class;
-        GUPnPMediaServer *server;
-        GUPnPServiceInfo *service;
+        GUPnPContentDirectory *content_dir;
         GUPnPContext *context;
+        GError *error;
 
-        object_class = G_OBJECT_CLASS (gupnp_media_server_parent_class);
+        object_class = G_OBJECT_CLASS (gupnp_content_directory_parent_class);
         object = object_class->constructor (type,
                                             n_construct_params,
                                             construct_params);
@@ -101,84 +89,51 @@
         if (object == NULL)
                 return NULL;
 
-        server = GUPNP_MEDIA_SERVER (object);
+        content_dir = GUPNP_CONTENT_DIRECTORY (object);
 
-        /* Connect ContentDirectory signals */
-        service = gupnp_device_info_get_service
-                        (GUPNP_DEVICE_INFO (server),
-                         "urn:schemas-upnp-org:service:ContentDirectory");
-        if (service != NULL) {
-                GError *error;
-
-                server->priv->content_dir = GUPNP_SERVICE (service);
-
-                error = NULL;
-                gupnp_service_signals_autoconnect (server->priv->content_dir,
-                                                   server,
-                                                   &error);
-                if (error) {
-                        g_warning ("Error autoconnecting signals: %s",
-                                   error->message);
-                        g_error_free (error);
-                }
+        error = NULL;
+        gupnp_service_signals_autoconnect (GUPNP_SERVICE (content_dir),
+                                           NULL,
+                                           &error);
+        if (error) {
+                g_warning ("Error autoconnecting signals: %s",
+                           error->message);
+                g_error_free (error);
         }
 
-        /* Connect MS MediaReceiverRegistrar signals */
-        service = gupnp_device_info_get_service
-                        (GUPNP_DEVICE_INFO (server),
-                         "urn:microsoft.com:service"
-                         ":X_MS_MediaReceiverRegistrar");
-        if (service != NULL) {
-                GError *error;
-
-                server->priv->msr = GUPNP_SERVICE (service);
-
-                error = NULL;
-                gupnp_service_signals_autoconnect (server->priv->msr,
-                                                   server,
-                                                   &error);
-                if (error) {
-                        g_warning ("Error autoconnecting signals: %s",
-                                   error->message);
-                        g_error_free (error);
-                }
-        }
-
-        context = gupnp_device_info_get_context (GUPNP_DEVICE_INFO (server));
+        context = gupnp_service_info_get_context
+                                (GUPNP_SERVICE_INFO (content_dir));
 
-        server->priv->tracker = gupnp_media_tracker_new ("0", context);
+        content_dir->priv->tracker = gupnp_media_tracker_new ("0", context);
 
         return object;
 }
 
 static void
-gupnp_media_server_class_init (GUPnPMediaServerClass *klass)
+gupnp_content_directory_class_init (GUPnPContentDirectoryClass *klass)
 {
         GObjectClass *object_class;
 
         object_class = G_OBJECT_CLASS (klass);
 
-        object_class->dispose = gupnp_media_server_dispose;
-        object_class->constructor = gupnp_media_server_constructor;
+        object_class->dispose = gupnp_content_directory_dispose;
+        object_class->constructor = gupnp_content_directory_constructor;
 
-        g_type_class_add_private (klass, sizeof (GUPnPMediaServerPrivate));
+        g_type_class_add_private (klass, sizeof (GUPnPContentDirectoryPrivate));
 }
 
 /* Browse action implementation */
 void
-browse_cb (GUPnPService       *service,
-           GUPnPServiceAction *action,
-           gpointer            user_data)
+browse_cb (GUPnPContentDirectory *content_dir,
+           GUPnPServiceAction    *action,
+           gpointer               user_data)
 {
-        GUPnPMediaServer *server;
         char *object_id, *browse_flag;
         gboolean browse_metadata;
         char *result, *sort_criteria, *filter;
         guint32 starting_index, requested_count;
         guint32 num_returned, total_matches, update_id;
 
-        server = GUPNP_MEDIA_SERVER (user_data);
-
         /* Handle incoming arguments */
         gupnp_service_action_get (action,
                                   "ObjectID",
@@ -231,7 +186,7 @@
 
         if (browse_metadata) {
                 result = gupnp_media_tracker_get_metadata
-                                        (server->priv->tracker,
+                                        (content_dir->priv->tracker,
                                          object_id,
                                          filter,
                                          sort_criteria,
@@ -240,7 +195,7 @@
                 num_returned = 1;
                 total_matches = 1;
         } else {
-                result = gupnp_media_tracker_browse (server->priv->tracker,
+                result = gupnp_media_tracker_browse (content_dir->priv->tracker,
                                                      object_id,
                                                      filter,
                                                      starting_index,
@@ -260,7 +215,7 @@
         }
 
         if (update_id == GUPNP_INVALID_UPDATE_ID)
-                update_id = server->priv->system_update_id;
+                update_id = content_dir->priv->system_update_id;
 
         /* Set action return arguments */
         gupnp_service_action_set (action,
@@ -285,69 +240,3 @@
         g_free (object_id);
 }
 
-/* IsAuthorized action implementation (fake) */
-void
-is_authorized_cb (GUPnPService       *service,
-                  GUPnPServiceAction *action,
-                  gpointer            user_data)
-{
-        /* Set action return arguments */
-        gupnp_service_action_set (action,
-                                  "Result",
-                                  G_TYPE_INT,
-                                  1,
-                                  NULL);
-
-        gupnp_service_action_return (action);
-}
-
-/* RegisterDevice action implementation (fake) */
-void
-register_device_cb (GUPnPService       *service,
-                    GUPnPServiceAction *action,
-                    gpointer            user_data)
-{
-        /* Set action return arguments */
-        gupnp_service_action_set (action,
-                                  "RegistrationRespMsg",
-                                  GUPNP_TYPE_BIN_BASE64,
-                                  "WhatisSupposedToBeHere",
-                                  NULL);
-
-        gupnp_service_action_return (action);
-}
-
-/* IsValidated action implementation (fake) */
-void
-is_validated_cb (GUPnPService       *service,
-                 GUPnPServiceAction *action,
-                 gpointer            user_data)
-{
-        /* Set action return arguments */
-        gupnp_service_action_set (action,
-                                  "Result",
-                                  G_TYPE_INT,
-                                  1,
-                                  NULL);
-
-        gupnp_service_action_return (action);
-}
-
-GUPnPMediaServer *
-gupnp_media_server_new (GUPnPContext *context,
-                        xmlDoc       *description_doc,
-                        const char   *relative_location)
-{
-        GUPnPResourceFactory *factory;
-
-        factory = gupnp_resource_factory_get_default ();
-
-        return g_object_new (GUPNP_TYPE_MEDIA_SERVER,
-                             "context", context,
-                             "resource-factory", factory,
-                             "root-device", NULL,
-                             "description-doc", description_doc,
-                             "relative-location", relative_location,
-                             NULL);
-}
-

Added: trunk/src/gupnp-content-directory.h
==============================================================================
--- (empty file)
+++ trunk/src/gupnp-content-directory.h	Tue Oct 28 20:59:04 2008
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
+ * Copyright (C) 2007 OpenedHand Ltd.
+ *
+ * Author: Zeeshan Ali <zeenix gmail com>
+ *         Jorn Baayen <jorn openedhand 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 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.
+ */
+
+#ifndef __GUPNP_CONTENT_DIRECTORY_H__
+#define __GUPNP_CONTENT_DIRECTORY_H__
+
+#include <libgupnp/gupnp.h>
+
+G_BEGIN_DECLS
+
+GType
+gupnp_content_directory_get_type (void) G_GNUC_CONST;
+
+#define GUPNP_TYPE_CONTENT_DIRECTORY \
+                (gupnp_content_directory_get_type ())
+#define GUPNP_CONTENT_DIRECTORY(obj) \
+                (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                 GUPNP_TYPE_CONTENT_DIRECTORY, \
+                 GUPnPContentDirectory))
+#define GUPNP_CONTENT_DIRECTORY_CLASS(obj) \
+                (G_TYPE_CHECK_CLASS_CAST ((obj), \
+                 GUPNP_TYPE_CONTENT_DIRECTORY, \
+                 GUPnPContentDirectoryClass))
+#define GUPNP_IS_CONTENT_DIRECTORY(obj) \
+                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                 GUPNP_TYPE_CONTENT_DIRECTORY))
+#define GUPNP_IS_CONTENT_DIRECTORY_CLASS(obj) \
+                (G_TYPE_CHECK_CLASS_TYPE ((obj), \
+                 GUPNP_TYPE_CONTENT_DIRECTORY))
+#define GUPNP_CONTENT_DIRECTORY_GET_CLASS(obj) \
+                (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                 GUPNP_TYPE_CONTENT_DIRECTORY, \
+                 GUPnPContentDirectoryClass))
+
+typedef struct _GUPnPContentDirectoryPrivate GUPnPContentDirectoryPrivate;
+
+typedef struct {
+        GUPnPService parent;
+
+        GUPnPContentDirectoryPrivate *priv;
+} GUPnPContentDirectory;
+
+typedef struct {
+        GUPnPServiceClass parent_class;
+
+        /* future padding */
+        void (* _gupnp_reserved1) (void);
+        void (* _gupnp_reserved2) (void);
+        void (* _gupnp_reserved3) (void);
+        void (* _gupnp_reserved4) (void);
+} GUPnPContentDirectoryClass;
+
+G_END_DECLS
+
+#endif /* __GUPNP_CONTENT_DIRECTORY_H__ */

Added: trunk/src/gupnp-media-receiver-registrar.c
==============================================================================
--- (empty file)
+++ trunk/src/gupnp-media-receiver-registrar.c	Tue Oct 28 20:59:04 2008
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
+ *
+ * Author: Zeeshan Ali <zeenix 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 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.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ */
+
+#include <string.h>
+#include <libgupnp/gupnp.h>
+#include <libgupnp-av/gupnp-av.h>
+
+#include "gupnp-media-receiver-registrar.h"
+#include "gupnp-media-tracker.h"
+
+G_DEFINE_TYPE (GUPnPMediaReceiverRegistrar,
+               gupnp_media_receiver_registrar,
+               GUPNP_TYPE_SERVICE);
+
+static GObject *
+gupnp_media_receiver_registrar_constructor
+                        (GType                  type,
+                         guint                  n_construct_params,
+                         GObjectConstructParam *construct_params)
+{
+        GObject *object;
+        GObjectClass *object_class;
+        GUPnPService *service;
+        GError *error;
+
+        object_class =
+                G_OBJECT_CLASS (gupnp_media_receiver_registrar_parent_class);
+        object = object_class->constructor (type,
+                                            n_construct_params,
+                                            construct_params);
+
+        if (object == NULL)
+                return NULL;
+
+        service = GUPNP_SERVICE (object);
+
+        error = NULL;
+        gupnp_service_signals_autoconnect (service,
+                                           NULL,
+                                           &error);
+        if (error) {
+                g_warning ("Error autoconnecting signals: %s",
+                           error->message);
+                g_error_free (error);
+        }
+
+        return object;
+}
+
+static void
+gupnp_media_receiver_registrar_init (GUPnPMediaReceiverRegistrar *registrar)
+{
+}
+
+static void
+gupnp_media_receiver_registrar_class_init
+                (GUPnPMediaReceiverRegistrarClass *klass)
+{
+        GObjectClass *object_class;
+
+        object_class = G_OBJECT_CLASS (klass);
+
+        object_class->constructor = gupnp_media_receiver_registrar_constructor;
+}
+
+/* IsAuthorized action implementation (fake) */
+void
+is_authorized_cb (GUPnPMediaReceiverRegistrar *registrar,
+                  GUPnPServiceAction          *action,
+                  gpointer                     user_data)
+{
+        /* Set action return arguments */
+        gupnp_service_action_set (action,
+                                  "Result",
+                                  G_TYPE_INT,
+                                  1,
+                                  NULL);
+
+        gupnp_service_action_return (action);
+}
+
+/* RegisterDevice action implementation (fake) */
+void
+register_device_cb (GUPnPMediaReceiverRegistrar *registrar,
+                    GUPnPServiceAction          *action,
+                    gpointer                     user_data)
+{
+        /* Set action return arguments */
+        gupnp_service_action_set (action,
+                                  "RegistrationRespMsg",
+                                  GUPNP_TYPE_BIN_BASE64,
+                                  "WhatisSupposedToBeHere",
+                                  NULL);
+
+        gupnp_service_action_return (action);
+}
+
+/* IsValidated action implementation (fake) */
+void
+is_validated_cb (GUPnPMediaReceiverRegistrar *registrar,
+                 GUPnPServiceAction          *action,
+                 gpointer                     user_data)
+{
+        /* Set action return arguments */
+        gupnp_service_action_set (action,
+                                  "Result",
+                                  G_TYPE_INT,
+                                  1,
+                                  NULL);
+
+        gupnp_service_action_return (action);
+}
+

Added: trunk/src/gupnp-media-receiver-registrar.h
==============================================================================
--- (empty file)
+++ trunk/src/gupnp-media-receiver-registrar.h	Tue Oct 28 20:59:04 2008
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
+ *
+ * Author: Zeeshan Ali <zeenix 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 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.
+ */
+
+#ifndef __GUPNP_MEDIA_RECEIVER_REGISTRAR_H__
+#define __GUPNP_MEDIA_RECEIVER_REGISTRAR_H__
+
+#include <libgupnp/gupnp.h>
+
+G_BEGIN_DECLS
+
+GType
+gupnp_media_receiver_registrar_get_type (void) G_GNUC_CONST;
+
+#define GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR \
+                (gupnp_media_receiver_registrar_get_type ())
+#define GUPNP_MEDIA_RECEIVER_REGISTRAR(obj) \
+                (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                 GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR, \
+                 GUPnPMediaReceiverRegistrar))
+#define GUPNP_MEDIA_RECEIVER_REGISTRAR_CLASS(obj) \
+                (G_TYPE_CHECK_CLASS_CAST ((obj), \
+                 GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR, \
+                 GUPnPMediaReceiverRegistrarClass))
+#define GUPNP_IS_MEDIA_RECEIVER_REGISTRAR(obj) \
+                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                 GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR))
+#define GUPNP_IS_MEDIA_RECEIVER_REGISTRAR_CLASS(obj) \
+                (G_TYPE_CHECK_CLASS_TYPE ((obj), \
+                 GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR))
+#define GUPNP_MEDIA_RECEIVER_REGISTRAR_GET_CLASS(obj) \
+                (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                 GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR, \
+                 GUPnPMediaReceiverRegistrarClass))
+
+typedef struct _GUPnPMediaReceiverRegistrarPrivate GUPnPMediaReceiverRegistrarPrivate;
+
+typedef struct {
+        GUPnPService parent;
+
+        /* future padding */
+        gpointer _gupnp_reserved;
+} GUPnPMediaReceiverRegistrar;
+
+typedef struct {
+        GUPnPServiceClass parent_class;
+
+        /* future padding */
+        void (* _gupnp_reserved1) (void);
+        void (* _gupnp_reserved2) (void);
+        void (* _gupnp_reserved3) (void);
+        void (* _gupnp_reserved4) (void);
+} GUPnPMediaReceiverRegistrarClass;
+
+G_END_DECLS
+
+#endif /* __GUPNP_MEDIA_RECEIVER_REGISTRAR_H__ */
+

Modified: trunk/src/gupnp-media-server.c
==============================================================================
--- trunk/src/gupnp-media-server.c	(original)
+++ trunk/src/gupnp-media-server.c	Tue Oct 28 20:59:04 2008
@@ -29,21 +29,24 @@
 #include <libgupnp-av/gupnp-av.h>
 
 #include "gupnp-media-server.h"
-#include "gupnp-media-tracker.h"
+#include "gupnp-content-directory.h"
+#include "gupnp-media-receiver-registrar.h"
 
-#define HOME_DIR_ALIAS "/media"
+#define CONTENT_DIR "urn:schemas-upnp-org:service:ContentDirectory"
+#define CONTENT_DIR_V1 CONTENT_DIR ":1"
+#define CONTENT_DIR_V2 CONTENT_DIR ":2"
+#define MEDIA_RECEIVER_REGISTRAR "urn:microsoft.com:service" \
+                                 ":X_MS_MediaReceiverRegistrar"
+#define MEDIA_RECEIVER_REGISTRAR_V1 MEDIA_RECEIVER_REGISTRAR ":1"
+#define MEDIA_RECEIVER_REGISTRAR_V2 MEDIA_RECEIVER_REGISTRAR ":2"
 
 G_DEFINE_TYPE (GUPnPMediaServer,
                gupnp_media_server,
                GUPNP_TYPE_ROOT_DEVICE);
 
 struct _GUPnPMediaServerPrivate {
-        guint32 system_update_id;
-
-        GUPnPService *content_dir;
+        GUPnPService *content_dir;      /* ContentDirectory */
         GUPnPService *msr;              /* MS MediaReceiverRegistrar */
-
-        GUPnPMediaTracker *tracker;
 };
 
 /* GObject stuff */
@@ -56,10 +59,6 @@
         server = GUPNP_MEDIA_SERVER (object);
 
         /* Free GUPnP resources */
-        if (server->priv->tracker) {
-                g_object_unref (server->priv->tracker);
-                server->priv->tracker = NULL;
-        }
         if (server->priv->content_dir) {
                 g_object_unref (server->priv->content_dir);
                 server->priv->content_dir = NULL;
@@ -90,8 +89,9 @@
         GObject *object;
         GObjectClass *object_class;
         GUPnPMediaServer *server;
+        GUPnPDeviceInfo  *info;
         GUPnPServiceInfo *service;
-        GUPnPContext *context;
+        GUPnPResourceFactory *factory;
 
         object_class = G_OBJECT_CLASS (gupnp_media_server_parent_class);
         object = object_class->constructor (type,
@@ -102,51 +102,36 @@
                 return NULL;
 
         server = GUPNP_MEDIA_SERVER (object);
+        info = GUPNP_DEVICE_INFO (server);
 
-        /* Connect ContentDirectory signals */
-        service = gupnp_device_info_get_service
-                        (GUPNP_DEVICE_INFO (server),
-                         "urn:schemas-upnp-org:service:ContentDirectory");
-        if (service != NULL) {
-                GError *error;
-
-                server->priv->content_dir = GUPNP_SERVICE (service);
-
-                error = NULL;
-                gupnp_service_signals_autoconnect (server->priv->content_dir,
-                                                   server,
-                                                   &error);
-                if (error) {
-                        g_warning ("Error autoconnecting signals: %s",
-                                   error->message);
-                        g_error_free (error);
-                }
-        }
+        factory = gupnp_device_info_get_resource_factory (info);
 
-        /* Connect MS MediaReceiverRegistrar signals */
-        service = gupnp_device_info_get_service
-                        (GUPNP_DEVICE_INFO (server),
-                         "urn:microsoft.com:service"
-                         ":X_MS_MediaReceiverRegistrar");
-        if (service != NULL) {
-                GError *error;
-
-                server->priv->msr = GUPNP_SERVICE (service);
-
-                error = NULL;
-                gupnp_service_signals_autoconnect (server->priv->msr,
-                                                   server,
-                                                   &error);
-                if (error) {
-                        g_warning ("Error autoconnecting signals: %s",
-                                   error->message);
-                        g_error_free (error);
-                }
-        }
-
-        context = gupnp_device_info_get_context (GUPNP_DEVICE_INFO (server));
-
-        server->priv->tracker = gupnp_media_tracker_new ("0", context);
+        /* Register GUPnPContentDirectory and GUPnPMediaReceiverRegistrar */
+        gupnp_resource_factory_register_resource_type
+                                (factory,
+                                 CONTENT_DIR_V1,
+                                 GUPNP_TYPE_CONTENT_DIRECTORY);
+        gupnp_resource_factory_register_resource_type
+                                (factory,
+                                 CONTENT_DIR_V2,
+                                 GUPNP_TYPE_CONTENT_DIRECTORY);
+
+        gupnp_resource_factory_register_resource_type
+                                (factory,
+                                 MEDIA_RECEIVER_REGISTRAR_V1,
+                                 GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR);
+        gupnp_resource_factory_register_resource_type
+                                (factory,
+                                 MEDIA_RECEIVER_REGISTRAR_V2,
+                                 GUPNP_TYPE_MEDIA_RECEIVER_REGISTRAR);
+
+        /* Now create the sevice objects */
+        service = gupnp_device_info_get_service (info, CONTENT_DIR);
+        server->priv->content_dir = GUPNP_SERVICE (service);
+
+        service =
+                gupnp_device_info_get_service (info, MEDIA_RECEIVER_REGISTRAR);
+        server->priv->msr = GUPNP_SERVICE (service);
 
         return object;
 }
@@ -164,175 +149,6 @@
         g_type_class_add_private (klass, sizeof (GUPnPMediaServerPrivate));
 }
 
-/* Browse action implementation */
-void
-browse_cb (GUPnPService       *service,
-           GUPnPServiceAction *action,
-           gpointer            user_data)
-{
-        GUPnPMediaServer *server;
-        char *object_id, *browse_flag;
-        gboolean browse_metadata;
-        char *result, *sort_criteria, *filter;
-        guint32 starting_index, requested_count;
-        guint32 num_returned, total_matches, update_id;
-
-        server = GUPNP_MEDIA_SERVER (user_data);
-
-        /* Handle incoming arguments */
-        gupnp_service_action_get (action,
-                                  "ObjectID",
-                                        G_TYPE_STRING,
-                                        &object_id,
-                                  "BrowseFlag",
-                                        G_TYPE_STRING,
-                                        &browse_flag,
-                                  "Filter",
-                                        G_TYPE_STRING,
-                                        &filter,
-                                  "StartingIndex",
-                                        G_TYPE_UINT,
-                                        &starting_index,
-                                  "RequestedCount",
-                                        G_TYPE_UINT,
-                                        &requested_count,
-                                  "SortCriteria",
-                                        G_TYPE_STRING,
-                                        &sort_criteria,
-                                  NULL);
-
-        /* BrowseFlag */
-        if (browse_flag && !strcmp (browse_flag, "BrowseDirectChildren")) {
-                browse_metadata = FALSE;
-        } else if (browse_flag && !strcmp (browse_flag, "BrowseMetadata")) {
-                browse_metadata = TRUE;
-        } else {
-                gupnp_service_action_return_error
-                        (action, GUPNP_CONTROL_ERROR_INVALID_ARGS, NULL);
-
-                goto OUT;
-        }
-
-        /* ObjectID */
-        if (!object_id) {
-                /* Stupid Xbox */
-                gupnp_service_action_get (action,
-                                          "ContainerID",
-                                          G_TYPE_STRING,
-                                          &object_id,
-                                          NULL);
-                if (!object_id) {
-                        gupnp_service_action_return_error
-                                (action, 701, "No such object");
-
-                        goto OUT;
-                }
-        }
-
-        if (browse_metadata) {
-                result = gupnp_media_tracker_get_metadata
-                                        (server->priv->tracker,
-                                         object_id,
-                                         filter,
-                                         sort_criteria,
-                                         &update_id);
-
-                num_returned = 1;
-                total_matches = 1;
-        } else {
-                result = gupnp_media_tracker_browse (server->priv->tracker,
-                                                     object_id,
-                                                     filter,
-                                                     starting_index,
-                                                     requested_count,
-                                                     sort_criteria,
-                                                     &num_returned,
-                                                     &total_matches,
-                                                     &update_id);
-        }
-
-        if (result == NULL) {
-                gupnp_service_action_return_error (action,
-                                                   701,
-                                                   "No such object");
-
-                goto OUT;
-        }
-
-        if (update_id == GUPNP_INVALID_UPDATE_ID)
-                update_id = server->priv->system_update_id;
-
-        /* Set action return arguments */
-        gupnp_service_action_set (action,
-                                  "Result",
-                                        G_TYPE_STRING,
-                                        result,
-                                  "NumberReturned",
-                                        G_TYPE_UINT,
-                                        num_returned,
-                                  "TotalMatches",
-                                        G_TYPE_UINT,
-                                        total_matches,
-                                  "UpdateID",
-                                        G_TYPE_UINT,
-                                        update_id,
-                                  NULL);
-
-        gupnp_service_action_return (action);
-
-        g_free (result);
-OUT:
-        g_free (object_id);
-}
-
-/* IsAuthorized action implementation (fake) */
-void
-is_authorized_cb (GUPnPService       *service,
-                  GUPnPServiceAction *action,
-                  gpointer            user_data)
-{
-        /* Set action return arguments */
-        gupnp_service_action_set (action,
-                                  "Result",
-                                  G_TYPE_INT,
-                                  1,
-                                  NULL);
-
-        gupnp_service_action_return (action);
-}
-
-/* RegisterDevice action implementation (fake) */
-void
-register_device_cb (GUPnPService       *service,
-                    GUPnPServiceAction *action,
-                    gpointer            user_data)
-{
-        /* Set action return arguments */
-        gupnp_service_action_set (action,
-                                  "RegistrationRespMsg",
-                                  GUPNP_TYPE_BIN_BASE64,
-                                  "WhatisSupposedToBeHere",
-                                  NULL);
-
-        gupnp_service_action_return (action);
-}
-
-/* IsValidated action implementation (fake) */
-void
-is_validated_cb (GUPnPService       *service,
-                 GUPnPServiceAction *action,
-                 gpointer            user_data)
-{
-        /* Set action return arguments */
-        gupnp_service_action_set (action,
-                                  "Result",
-                                  G_TYPE_INT,
-                                  1,
-                                  NULL);
-
-        gupnp_service_action_return (action);
-}
-
 GUPnPMediaServer *
 gupnp_media_server_new (GUPnPContext *context,
                         xmlDoc       *description_doc,



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