2 * Copyright (C) 2007 OpenedHand Ltd.
4 * Author: Jorn Baayen <jorn@openedhand.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * SECTION:gupnp-device
24 * @short_description: Class for device implementations.
26 * #GUPnPDevice allows for retrieving a device's subdevices
27 * and services. #GUPnPDevice implements the #GUPnPDeviceInfo
33 #include "gupnp-device.h"
34 #include "gupnp-service.h"
35 #include "gupnp-root-device.h"
36 #include "gupnp-resource-factory-private.h"
39 G_DEFINE_TYPE (GUPnPDevice,
41 GUPNP_TYPE_DEVICE_INFO);
43 struct _GUPnPDevicePrivate {
44 GUPnPRootDevice *root_device;
52 static GUPnPDeviceInfo *
53 gupnp_device_get_device (GUPnPDeviceInfo *info,
57 GUPnPResourceFactory *factory;
58 GUPnPContext *context;
59 GUPnPDevice *root_device;
61 const SoupURI *url_base;
63 device = GUPNP_DEVICE (info);
65 root_device = GUPNP_IS_ROOT_DEVICE (device) ? device :
66 GUPNP_DEVICE (device->priv->root_device);
67 if (root_device == NULL) {
68 g_warning ("Root device not found.");
73 factory = gupnp_device_info_get_resource_factory (info);
74 context = gupnp_device_info_get_context (info);
75 location = gupnp_device_info_get_location (info);
76 url_base = gupnp_device_info_get_url_base (info);
78 device = gupnp_resource_factory_create_device (factory,
86 return GUPNP_DEVICE_INFO (device);
89 static GUPnPServiceInfo *
90 gupnp_device_get_service (GUPnPDeviceInfo *info,
94 GUPnPService *service;
95 GUPnPResourceFactory *factory;
96 GUPnPContext *context;
97 GUPnPDevice *root_device;
98 const char *location, *udn;
99 const SoupURI *url_base;
101 device = GUPNP_DEVICE (info);
103 root_device = GUPNP_IS_ROOT_DEVICE (device) ? device :
104 GUPNP_DEVICE (device->priv->root_device);
105 if (root_device == NULL) {
106 g_warning ("Root device not found.");
111 factory = gupnp_device_info_get_resource_factory (info);
112 context = gupnp_device_info_get_context (info);
113 udn = gupnp_device_info_get_udn (info);
114 location = gupnp_device_info_get_location (info);
115 url_base = gupnp_device_info_get_url_base (info);
117 service = gupnp_resource_factory_create_service (factory,
125 return GUPNP_SERVICE_INFO (service);
129 gupnp_device_set_property (GObject *object,
136 device = GUPNP_DEVICE (object);
138 switch (property_id) {
139 case PROP_ROOT_DEVICE:
140 device->priv->root_device = g_value_get_object (value);
142 /* This can be NULL in which case *this* is the root device */
143 if (device->priv->root_device) {
144 GUPnPRootDevice **dev = &(device->priv->root_device);
146 g_object_add_weak_pointer
147 (G_OBJECT (device->priv->root_device),
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
159 gupnp_device_get_property (GObject *object,
166 device = GUPNP_DEVICE (object);
168 switch (property_id) {
169 case PROP_ROOT_DEVICE:
170 g_value_set_object (value, device->priv->root_device);
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
179 gupnp_device_dispose (GObject *object)
182 GObjectClass *object_class;
184 device = GUPNP_DEVICE (object);
186 if (device->priv->root_device) {
187 GUPnPRootDevice **dev = &(device->priv->root_device);
189 g_object_remove_weak_pointer
190 (G_OBJECT (device->priv->root_device),
193 device->priv->root_device = NULL;
197 object_class = G_OBJECT_CLASS (gupnp_device_parent_class);
198 object_class->dispose (object);
202 gupnp_device_init (GUPnPDevice *device)
204 device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device,
210 gupnp_device_class_init (GUPnPDeviceClass *klass)
212 GObjectClass *object_class;
213 GUPnPDeviceInfoClass *info_class;
215 object_class = G_OBJECT_CLASS (klass);
217 object_class->set_property = gupnp_device_set_property;
218 object_class->get_property = gupnp_device_get_property;
219 object_class->dispose = gupnp_device_dispose;
221 info_class = GUPNP_DEVICE_INFO_CLASS (klass);
223 info_class->get_device = gupnp_device_get_device;
224 info_class->get_service = gupnp_device_get_service;
226 g_type_class_add_private (klass, sizeof (GUPnPDevicePrivate));
229 * GUPnPDevice:root-device:
231 * The containing #GUPnPRootDevice, or NULL if this is the root
234 g_object_class_install_property
237 g_param_spec_object ("root-device",
239 "The GUPnPRootDevice",
240 GUPNP_TYPE_ROOT_DEVICE,
242 G_PARAM_CONSTRUCT_ONLY |
243 G_PARAM_STATIC_NAME |
244 G_PARAM_STATIC_NICK |
245 G_PARAM_STATIC_BLURB));