tizen 2.3.1 release
[external/gupnp.git] / libgupnp / gupnp-device-proxy.c
1 /*
2  * Copyright (C) 2006, 2007 OpenedHand Ltd.
3  *
4  * Author: Jorn Baayen <jorn@openedhand.com>
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 /**
23  * SECTION:gupnp-device-proxy
24  * @short_description: Proxy class for remote devices.
25  *
26  * #GUPnPDeviceProxy allows for retrieving proxies for a device's subdevices
27  * and services. #GUPnPDeviceProxy implements the #GUPnPDeviceInfo interface.
28  */
29
30 #include <string.h>
31
32 #include "gupnp-device-proxy.h"
33 #include "gupnp-device-info-private.h"
34 #include "gupnp-resource-factory-private.h"
35 #include "xml-util.h"
36
37 G_DEFINE_TYPE (GUPnPDeviceProxy,
38                gupnp_device_proxy,
39                GUPNP_TYPE_DEVICE_INFO);
40
41 static GUPnPDeviceInfo *
42 gupnp_device_proxy_get_device (GUPnPDeviceInfo *info,
43                                xmlNode         *element)
44 {
45         GUPnPDeviceProxy     *device;
46         GUPnPResourceFactory *factory;
47         GUPnPContext         *context;
48         GUPnPXMLDoc          *doc;
49         const char           *location;
50         const SoupURI        *url_base;
51
52         factory = gupnp_device_info_get_resource_factory (info);
53         context = gupnp_device_info_get_context (info);
54         doc = _gupnp_device_info_get_document (info);
55         location = gupnp_device_info_get_location (info);
56         url_base = gupnp_device_info_get_url_base (info);
57
58         device = gupnp_resource_factory_create_device_proxy (factory,
59                                                              context,
60                                                              doc,
61                                                              element,
62                                                              NULL,
63                                                              location,
64                                                              url_base);
65
66         return GUPNP_DEVICE_INFO (device);
67 }
68
69 static GUPnPServiceInfo *
70 gupnp_device_proxy_get_service (GUPnPDeviceInfo *info,
71                                 xmlNode         *element)
72 {
73         GUPnPResourceFactory *factory;
74         GUPnPServiceProxy    *service;
75         GUPnPContext         *context;
76         GUPnPXMLDoc          *doc;
77         const char           *location, *udn;
78         const SoupURI        *url_base;
79
80         factory = gupnp_device_info_get_resource_factory (info);
81         context = gupnp_device_info_get_context (info);
82         doc = _gupnp_device_info_get_document (info);
83         udn = gupnp_device_info_get_udn (info);
84         location = gupnp_device_info_get_location (info);
85         url_base = gupnp_device_info_get_url_base (info);
86
87         service = gupnp_resource_factory_create_service_proxy (factory,
88                                                                context,
89                                                                doc,
90                                                                element,
91                                                                udn,
92                                                                NULL,
93                                                                location,
94                                                                url_base);
95
96         return GUPNP_SERVICE_INFO (service);
97 }
98
99 static void
100 gupnp_device_proxy_init (GUPnPDeviceProxy *proxy)
101 {
102 }
103
104 static void
105 gupnp_device_proxy_class_init (GUPnPDeviceProxyClass *klass)
106 {
107         GUPnPDeviceInfoClass *info_class;
108
109         info_class = GUPNP_DEVICE_INFO_CLASS (klass);
110
111         info_class->get_device  = gupnp_device_proxy_get_device;
112         info_class->get_service = gupnp_device_proxy_get_service;
113 }
114