completed skels
authorJorn Baayen <jorn@openedhand.com>
Thu, 20 Apr 2006 09:51:56 +0000 (09:51 +0000)
committerJorn Baayen <jorn@openedhand.com>
Thu, 20 Apr 2006 09:51:56 +0000 (09:51 +0000)
git-svn-id: https://svn.o-hand.com/repos/gupnp/gssdp@123 d8cb91d7-bff9-0310-92b9-80b65e4482b2

libgssdp/Makefile.am
libgssdp/gssdp-device-private.h
libgssdp/gssdp-device.c
libgssdp/gssdp-marshal.list [new file with mode: 0644]
libgssdp/gssdp-root-device-private.h [new file with mode: 0644]
libgssdp/gssdp-root-device.c [new file with mode: 0644]
libgssdp/gssdp-root-device.h
libgssdp/gssdp-service.c

index c290f21..d32eb41 100644 (file)
@@ -10,13 +10,26 @@ libgssdpinc_HEADERS =       gssdp-device.h           \
                        gssdp-service.h          \
                        gssdp.h
 
-libgssdp_1_0_la_SOURCES = gssdp-device.c        \
-                         gssdp-device-private.h \
-                         gssdp-discoverable.c   \
-                         gssdp-service.c
+gssdp-marshal.c: gssdp-marshal.list
+       $(GLIB_GENMARSHAL) --prefix=gssdp_marshal $(srcdir)/gssdp-marshal.list --header --body > gssdp-marshal.c
+
+gssdp-marshal.h: gssdp-marshal.list
+       $(GLIB_GENMARSHAL) --prefix=gssdp_marshal $(srcdir)/gssdp-marshal.list --header > gssdp-marshal.h
+
+BUILT_SOURCES = gssdp-marshal.c gssdp-marshal.h
+
+libgssdp_1_0_la_SOURCES = gssdp-device.c               \
+                         gssdp-device-private.h        \
+                         gssdp-discoverable.c          \
+                         gssdp-root-device.c           \
+                         gssdp-root-device-private.h   \
+                         gssdp-service.c               \
+                         $(BUILT_SOURCES)
 
 libgssdp_1_0_la_LIBADD = $(LIBGSSDP_LIBS)
 
+EXTRA_DIST = gssdp-marshal.list
+
 CLEANFILES = $(BUILT_SOURCES)
 DISTCLEANFILES = $(BUILT_SOURCES)
 MAINTAINERCLEANFILES = Makefile.in $(BUILT_SOURCES)
index 3e7762f..6a79656 100644 (file)
 G_BEGIN_DECLS
 
 void
-gssdp_device_set_services (GSSDPDevice *divice,
-                           GList       *services);
+gssdp_device_add_service    (GSSDPDevice  *device,
+                             GSSDPService *service);
+
+void
+gssdp_device_remove_service (GSSDPDevice  *device,
+                             GSSDPService *service);
 
 G_END_DECLS
 
index d8d9f3b..c9e0724 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/* XXX connect to "notify::available" and handle actual advertisement */
-
 #include <config.h>
+#include <string.h>
 #include <uuid/uuid.h>
 
 #include "gssdp-device-private.h"
+#include "gssdp-root-device-private.h"
 
 /* Hack around G_DEFINE_TYPE hardcoding the type function name */
 #define gssdp_device_get_type gssdp_device_type
@@ -87,6 +87,46 @@ gssdp_device_get_property (GObject    *object,
 }
 
 static void
+gssdp_device_dispose (GObject *object)
+{
+        GSSDPDevice *device, *parent;
+        GObjectClass *object_class;
+
+        device = GSSDP_DEVICE (object);
+
+        parent = gssdp_discoverable_get_parent (GSSDP_DISCOVERABLE (device));
+        if (parent) {
+                gssdp_root_device_remove_device (GSSDP_ROOT_DEVICE (parent),
+                                                 device);
+        }
+
+        object_class = G_OBJECT_CLASS (gssdp_device_parent_class);
+        object_class->dispose (object);
+}
+
+static void
+gssdp_device_notify (GObject    *object,
+                     GParamSpec *param_spec)
+{
+        GSSDPDevice *device;
+
+        device = GSSDP_DEVICE (object);
+        
+        if (strcmp (param_spec->name, "parent") == 0) {
+                GSSDPDevice *parent;
+
+                parent = gssdp_discoverable_get_parent
+                                        (GSSDP_DISCOVERABLE (device));
+                if (parent) {
+                        gssdp_root_device_add_device
+                                        (GSSDP_ROOT_DEVICE (parent), device);
+                }
+        } else if (strcmp (param_spec->name, "available") == 0) {
+                /* XXX */
+        }
+}
+
+static void
 gssdp_device_class_init (GSSDPDeviceClass *klass)
 {
         GObjectClass *object_class;
@@ -94,6 +134,8 @@ gssdp_device_class_init (GSSDPDeviceClass *klass)
        object_class = G_OBJECT_CLASS (klass);
 
        object_class->get_property = gssdp_device_get_property;
+       object_class->dispose      = gssdp_device_dispose;
+       object_class->notify       = gssdp_device_notify;
 
         g_type_class_add_private (klass, sizeof (GSSDPDevicePrivate));
 
@@ -156,15 +198,33 @@ gssdp_device_get_uuid (GSSDPDevice *device)
 }
 
 /**
- * Sets the list of contained services of @device to @services
+ * Adds @service to the list of services contained in @device
+ **/
+void
+gssdp_device_add_service (GSSDPDevice  *device,
+                          GSSDPService *service)
+{
+        g_return_if_fail (GSSDP_IS_DEVICE (device));
+        g_return_if_fail (GSSDP_IS_SERVICE (service));
+
+        device->priv->services = g_list_append (device->priv->services,
+                                                service);
+
+        g_object_notify (G_OBJECT (device), "services");
+}
+
+/**
+ * Removes @service from the list of services contained in @device
  **/
 void
-gssdp_device_set_services (GSSDPDevice *device,
-                           GList       *services)
+gssdp_device_remove_service (GSSDPDevice  *device,
+                             GSSDPService *service)
 {
         g_return_if_fail (GSSDP_IS_DEVICE (device));
+        g_return_if_fail (GSSDP_IS_SERVICE (service));
 
-        device->priv->services = services;
+        device->priv->services = g_list_remove (device->priv->services,
+                                                service);
 
         g_object_notify (G_OBJECT (device), "services");
 }
diff --git a/libgssdp/gssdp-marshal.list b/libgssdp/gssdp-marshal.list
new file mode 100644 (file)
index 0000000..68d59ac
--- /dev/null
@@ -0,0 +1,2 @@
+VOID:STRING,STRING,STRING
+VOID:STRING,STRING
diff --git a/libgssdp/gssdp-root-device-private.h b/libgssdp/gssdp-root-device-private.h
new file mode 100644 (file)
index 0000000..9aaff04
--- /dev/null
@@ -0,0 +1,39 @@
+/* 
+ * (C) 2006 OpenedHand Ltd.
+ *
+ * Author: Jorn Baayen <jorn@openedhand.com>
+ *
+ * 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.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gssdp-root-device.h"
+
+#ifndef __GSSDP_ROOT_DEVICE_PRIVATE_H__
+#define __GSSDP_ROOT_DEVICE_PRIVANE_H__
+
+G_BEGIN_DECLS
+
+void
+gssdp_root_device_add_device    (GSSDPRootDevice *root_device,
+                                 GSSDPDevice     *device);
+
+void
+gssdp_root_device_remove_device (GSSDPRootDevice *root_device,
+                                 GSSDPDevice     *device);
+
+G_END_DECLS
+
+#endif /* __GSSDP_ROOT_DEVICE_PRIVATE_H__ */
diff --git a/libgssdp/gssdp-root-device.c b/libgssdp/gssdp-root-device.c
new file mode 100644 (file)
index 0000000..c6b543d
--- /dev/null
@@ -0,0 +1,392 @@
+/* 
+ * (C) 2006 OpenedHand Ltd.
+ *
+ * Author: Jorn Baayen <jorn@openedhand.com>
+ *
+ * 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.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+#include "gssdp-root-device-private.h"
+#include "gssdp-marshal.h"
+
+/* Hack around G_DEFINE_TYPE hardcoding the type function name */
+#define gssdp_root_device_get_type gssdp_root_device_type
+
+G_DEFINE_TYPE (GSSDPRootDevice,
+               gssdp_root_device,
+               GSSDP_TYPE_DEVICE);
+
+#undef gssdp_root_device_get_type
+
+struct _GSSDPRootDevicePrivate {
+        char  *location;
+
+        char  *server_id;
+        
+        GList *devices;
+};
+
+enum {
+        PROP_0,
+        PROP_LOCATION,
+        PROP_SERVER_ID,
+        PROP_DEVICES
+};
+
+enum {
+        DISCOVERABLE_AVAILABLE,
+        DISCOVERABLE_UNAVAILABLE,
+        LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+/* Function prototypes */
+static void
+gssdp_root_device_set_location (GSSDPRootDevice *root_device,
+                                const char      *location);
+
+static void
+gssdp_root_device_init (GSSDPRootDevice *root_device)
+{
+        struct utsname sysinfo;
+
+        root_device->priv = G_TYPE_INSTANCE_GET_PRIVATE
+                                        (root_device,
+                                         GSSDP_TYPE_ROOT_DEVICE,
+                                         GSSDPRootDevicePrivate);
+
+        /* Generate default server ID XXX */
+        uname (&sysinfo);
+        
+        root_device->priv->server_id =
+                g_strdup_printf ("%s/%s UPnP/1.0 GSSDP/%s",
+                                 sysinfo.sysname,
+                                 sysinfo.version,
+                                 VERSION);
+}
+
+static void
+gssdp_root_device_get_property (GObject    *object,
+                                guint       property_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+        GSSDPRootDevice *root_device;
+
+        root_device = GSSDP_ROOT_DEVICE (object);
+
+        switch (property_id) {
+        case PROP_LOCATION:
+                g_value_set_string
+                        (value,
+                         gssdp_root_device_get_location (root_device));
+                break;
+        case PROP_SERVER_ID:
+                g_value_set_string
+                        (value,
+                         gssdp_root_device_get_server_id (root_device));
+                break;
+        case PROP_DEVICES:
+                g_value_set_pointer
+                        (value,
+                         (gpointer)
+                          gssdp_root_device_get_devices (root_device));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+gssdp_root_device_set_property (GObject      *object,
+                                guint         property_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+        GSSDPRootDevice *root_device;
+
+        root_device = GSSDP_ROOT_DEVICE (object);
+
+        switch (property_id) {
+        case PROP_LOCATION:
+                gssdp_root_device_set_location (root_device,
+                                                g_value_get_string (value));
+                break;
+        case PROP_SERVER_ID:
+                gssdp_root_device_set_server_id (root_device,
+                                                 g_value_get_string (value));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+gssdp_root_device_notify (GObject    *object,
+                          GParamSpec *param_spec)
+{
+        if (strcmp (param_spec->name, "available") == 0) {
+                /* XXX */
+        }
+}
+
+static void
+gssdp_root_device_finalize (GObject *object)
+{
+        GSSDPRootDevice *root_device;
+        GObjectClass *object_class;
+
+        root_device = GSSDP_ROOT_DEVICE (object);
+
+        g_free (root_device->priv->location);
+        g_free (root_device->priv->server_id);
+
+        object_class = G_OBJECT_CLASS (gssdp_root_device_parent_class);
+        object_class->finalize (object);
+}
+
+static void
+gssdp_root_device_class_init (GSSDPRootDeviceClass *klass)
+{
+        GObjectClass *object_class;
+
+       object_class = G_OBJECT_CLASS (klass);
+
+       object_class->set_property = gssdp_root_device_set_property;
+       object_class->get_property = gssdp_root_device_get_property;
+       object_class->finalize     = gssdp_root_device_finalize;
+       object_class->notify       = gssdp_root_device_notify;
+
+        g_type_class_add_private (klass, sizeof (GSSDPRootDevicePrivate));
+
+        g_object_class_install_property
+                (object_class,
+                 PROP_LOCATION,
+                 g_param_spec_string
+                         ("location",
+                          "Location",
+                          "The device information URL.",
+                          NULL,
+                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+                          G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
+                          G_PARAM_STATIC_BLURB));
+
+        g_object_class_install_property
+                (object_class,
+                 PROP_SERVER_ID,
+                 g_param_spec_string
+                         ("server-id",
+                          "Server ID",
+                          "The server identifier.",
+                          NULL,
+                          G_PARAM_READWRITE |
+                          G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
+                          G_PARAM_STATIC_BLURB));
+
+        g_object_class_install_property
+                (object_class,
+                 PROP_DEVICES,
+                 g_param_spec_pointer
+                         ("devices",
+                          "Devices",
+                          "The list of contained devices.",
+                          G_PARAM_READABLE |
+                          G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
+                          G_PARAM_STATIC_BLURB));
+
+        signals[DISCOVERABLE_AVAILABLE] =
+                g_signal_new ("discoverable-available",
+                              GSSDP_TYPE_ROOT_DEVICE,
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (GSSDPRootDeviceClass,
+                                               discoverable_available),
+                              NULL, NULL,
+                              gssdp_marshal_VOID__STRING_STRING_STRING,
+                              G_TYPE_NONE,
+                              3,
+                              G_TYPE_STRING,
+                              G_TYPE_STRING,
+                              G_TYPE_STRING);
+
+        signals[DISCOVERABLE_UNAVAILABLE] =
+                g_signal_new ("discoverable-unavailable",
+                              GSSDP_TYPE_ROOT_DEVICE,
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (GSSDPRootDeviceClass,
+                                               discoverable_unavailable),
+                              NULL, NULL,
+                              gssdp_marshal_VOID__STRING_STRING,
+                              G_TYPE_NONE,
+                              2,
+                              G_TYPE_STRING,
+                              G_TYPE_STRING);
+}
+
+/**
+ * gssdp_device_new
+ * @type: A string identifying the type of the device
+ * @version: A #gushort identifying the version of the device type
+ * @location: The device information URL
+ *
+ * Return value: A new #GSSDPRootDevice object.
+ **/
+GSSDPRootDevice *
+gssdp_root_device_new (const char *type,
+                       gushort     version,
+                       const char *location)
+{
+        return g_object_new (GSSDP_TYPE_ROOT_DEVICE,
+                             "type",     type,
+                             "version",  version,
+                             "location", location,
+                             NULL);
+}
+
+/**
+ * Sets the location URL of @root_device to @location.
+ **/
+static void
+gssdp_root_device_set_location (GSSDPRootDevice *root_device,
+                                const char      *location)
+{
+        root_device->priv->location = g_strdup (location);
+
+        g_object_notify (G_OBJECT (root_device), "location");
+}
+
+/**
+ * gssdp_root_device_get_location
+ * @root_device: A #GSSDPRootDevice
+ *
+ * Return value: The device information URL.
+ **/
+const char *
+gssdp_root_device_get_location (GSSDPRootDevice *root_device)
+{
+        g_return_val_if_fail (GSSDP_IS_ROOT_DEVICE (root_device), NULL);
+
+        return root_device->priv->location;
+}
+
+/**
+ * gssdp_root_device_set_server_id
+ * @root_device: A #GSSDPRootDevice
+ * @server_id: The server ID
+ *
+ * Sets the server ID of @root_device to @service_id.
+ **/
+void
+gssdp_root_device_set_server_id (GSSDPRootDevice *root_device,
+                                 const char      *server_id)
+{
+        g_return_if_fail (GSSDP_IS_ROOT_DEVICE (root_device));
+
+        if (root_device->priv->server_id) {
+                g_free (root_device->priv->server_id);
+                root_device->priv->server_id = NULL;
+        }
+
+        if (server_id)
+                root_device->priv->server_id = g_strdup (server_id);
+
+        g_object_notify (G_OBJECT (root_device), "server-id");
+}
+
+/**
+ * gssdp_root_device_get_server_id
+ * @root_device: A #GSSDPRootDevice
+ *
+ * Return value: The server ID.
+ **/
+const char *
+gssdp_root_device_get_server_id (GSSDPRootDevice *root_device)
+{
+        g_return_val_if_fail (GSSDP_IS_ROOT_DEVICE (root_device), NULL);
+
+        return root_device->priv->server_id;
+}
+
+/**
+ * Adds @device to the list of devices contained in @root_device
+ **/
+void
+gssdp_root_device_add_device (GSSDPRootDevice *root_device,
+                              GSSDPDevice     *device)
+{
+        g_return_if_fail (GSSDP_IS_ROOT_DEVICE (root_device));
+        g_return_if_fail (GSSDP_IS_DEVICE (device));
+        g_return_if_fail (!GSSDP_IS_ROOT_DEVICE (device));
+
+        root_device->priv->devices = g_list_append (root_device->priv->devices,
+                                                    device);
+
+        g_object_notify (G_OBJECT (root_device), "devices");
+}
+
+/**
+ * Removes @device from the list of devices contained in @root_device
+ **/
+void
+gssdp_root_device_remove_device (GSSDPRootDevice *root_device,
+                                 GSSDPDevice     *device)
+{
+        g_return_if_fail (GSSDP_IS_ROOT_DEVICE (root_device));
+        g_return_if_fail (GSSDP_IS_DEVICE (device));
+        g_return_if_fail (!GSSDP_IS_ROOT_DEVICE (device));
+
+        root_device->priv->devices = g_list_remove (root_device->priv->devices,
+                                                    device);
+
+        g_object_notify (G_OBJECT (root_device), "devices");
+}
+
+/**
+ * gssdp_device_get_devices
+ * @root_device: A #GSSDPRootDevice
+ *
+ * Return value: A #GList of devices contained in @root_device.
+ **/
+const GList *
+gssdp_root_device_get_devices (GSSDPRootDevice *root_device)
+{
+        g_return_val_if_fail (GSSDP_IS_ROOT_DEVICE (root_device), NULL);
+        
+        return root_device->priv->devices;
+}
+
+/**
+ * gssdp_root_device_discover
+ * @root_device: A #GSSDPRootDevice
+ * @target: The discovery target
+ *
+ * Sends a discovery request for @target.
+ **/
+void
+gssdp_root_device_discover (GSSDPRootDevice *root_device,
+                            const char      *target)
+{
+        g_return_if_fail (GSSDP_IS_ROOT_DEVICE (root_device));
+        g_return_if_fail (target != NULL);
+
+        /* XXX */
+}
index 690adb5..71696c0 100644 (file)
@@ -83,20 +83,21 @@ gssdp_root_device_new           (const char      *type,
                                  const char      *location);
 
 const char *
-gssdp_root_device_get_location  (GSSDPRootDevice *device);
+gssdp_root_device_get_location  (GSSDPRootDevice *root_device);
 
 void
-gssdp_root_device_set_server_id (GSSDPRootDevice *device,
+gssdp_root_device_set_server_id (GSSDPRootDevice *root_device,
                                  const char      *server_id);
 
 const char *
-gssdp_root_device_get_server_id (GSSDPRootDevice *device);
+gssdp_root_device_get_server_id (GSSDPRootDevice *root_device);
 
 const GList *
-gssdp_root_device_get_devices   (GSSDPRootDevice *device);
+gssdp_root_device_get_devices   (GSSDPRootDevice *root_device);
 
 void
-gssdp_root_device_discover      (const char      *target);
+gssdp_root_device_discover      (GSSDPRootDevice *root_device,
+                                 const char      *target);
 
 G_END_DECLS
 
index 5e696f1..1a29eb3 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/* XXX connect to "notify::available" and handle actual advertisement */
-
 #include <config.h>
+#include <string.h>
 
 #include "gssdp-service.h"
+#include "gssdp-device-private.h"
 
 /* Hack around G_DEFINE_TYPE hardcoding the type function name */
 #define gssdp_service_get_type gssdp_service_type
@@ -47,12 +47,52 @@ gssdp_service_init (GSSDPService *service)
 }
 
 static void
+gssdp_service_dispose (GObject *object)
+{
+        GSSDPService *service;
+        GSSDPDevice *parent;
+        GObjectClass *object_class;
+
+        service = GSSDP_SERVICE (object);
+
+        parent = gssdp_discoverable_get_parent (GSSDP_DISCOVERABLE (service));
+        if (parent)
+                gssdp_device_remove_service (parent, service);
+
+        object_class = G_OBJECT_CLASS (gssdp_service_parent_class);
+        object_class->dispose (object);
+}
+
+static void
+gssdp_service_notify (GObject    *object,
+                      GParamSpec *param_spec)
+{
+        GSSDPService *service;
+
+        service = GSSDP_SERVICE (object);
+        
+        if (strcmp (param_spec->name, "parent") == 0) {
+                GSSDPDevice *parent;
+
+                parent = gssdp_discoverable_get_parent
+                                        (GSSDP_DISCOVERABLE (service));
+                if (parent)
+                        gssdp_device_add_service (parent, service);
+        } else if (strcmp (param_spec->name, "available") == 0) {
+                /* XXX */
+        }
+}
+
+static void
 gssdp_service_class_init (GSSDPServiceClass *klass)
 {
         GObjectClass *object_class;
 
        object_class = G_OBJECT_CLASS (klass);
 
+        object_class->dispose = gssdp_service_dispose;
+        object_class->notify  = gssdp_service_notify;
+
         g_type_class_add_private (klass, sizeof (GSSDPServicePrivate));
 }