doc: Update NEWS for 0.4.1
[gupnp:gupnp-dlna.git] / libgupnp-dlna / gupnp-dlna-information.c
1 /*
2  * Copyright (C) 2010 Nokia Corporation.
3  *
4  * Authors: Arun Raghavan <arun.raghavan@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser 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 #include "gupnp-dlna-information.h"
23
24 /**
25  * SECTION:gupnp-dlna-information
26  * @short_description: Object containing metadata information returned by the
27  * #GUPNPDLNADiscoverer API
28  *
29  * The GUPnPDLNAInformation object holds metadata information discovered by the
30  * GUPnPDiscoverer API. The DLNA profile name and MIME type have their own
31  * fields, and other metadata is held in a GstDiscovererInformation structure.
32  * All fields are read-only.
33  */
34
35 G_DEFINE_TYPE (GUPnPDLNAInformation, gupnp_dlna_information, G_TYPE_OBJECT)
36
37 #define GET_PRIVATE(o) \
38   (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
39                                 GUPNP_TYPE_DLNA_INFORMATION, \
40                                 GUPnPDLNAInformationPrivate))
41
42 typedef struct _GUPnPDLNAInformationPrivate GUPnPDLNAInformationPrivate;
43
44 struct _GUPnPDLNAInformationPrivate {
45         GstDiscovererInformation *info;
46         gchar                    *name;
47         gchar                    *mime;
48 };
49
50 enum {
51         PROP_0,
52         PROP_DLNA_NAME,
53         PROP_DLNA_MIME,
54         PROP_DISCOVERER_INFO,
55 };
56
57 static void
58 gupnp_dlna_information_get_property (GObject    *object,
59                                      guint       property_id,
60                                      GValue     *value,
61                                      GParamSpec *pspec)
62 {
63         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
64         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
65
66         switch (property_id) {
67                 case PROP_DLNA_NAME:
68                         g_value_set_string (value, priv->name);
69                         break;
70
71                 case PROP_DLNA_MIME:
72                         g_value_set_string (value, priv->mime);
73                         break;
74
75                 case PROP_DISCOVERER_INFO:
76                         g_value_set_boxed (value, priv->info);
77                         break;
78
79                 default:
80                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
81                                                            property_id,
82                                                            pspec);
83                         break;
84         }
85 }
86
87 static void
88 gupnp_dlna_information_set_property (GObject      *object,
89                                      guint         property_id,
90                                      const GValue *value,
91                                      GParamSpec   *pspec)
92 {
93         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
94         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
95
96         switch (property_id) {
97                 case PROP_DLNA_NAME:
98                         g_free (priv->name);
99                         priv->name = g_value_dup_string (value);
100                         break;
101
102                 case PROP_DLNA_MIME:
103                         g_free (priv->mime);
104                         priv->mime = g_value_dup_string (value);
105                         break;
106
107                 case PROP_DISCOVERER_INFO:
108                         if (priv->info)
109                                 gst_discoverer_information_free (priv->info);
110                         priv->info = g_value_dup_boxed (value);
111                         break;
112
113                 default:
114                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
115                                                            property_id,
116                                                            pspec);
117                         break;
118   }
119 }
120
121
122 static void
123 gupnp_dlna_information_finalize (GObject *object)
124 {
125         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
126         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
127
128         g_free (priv->name);
129         g_free (priv->mime);
130         if (priv->info)
131                 gst_discoverer_information_free (priv->info);
132
133         G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->finalize (object);
134 }
135
136 static void
137 gupnp_dlna_information_class_init (GUPnPDLNAInformationClass *klass)
138 {
139         GObjectClass *object_class = G_OBJECT_CLASS (klass);
140         GParamSpec *pspec;
141
142         g_type_class_add_private (klass, sizeof (GUPnPDLNAInformationPrivate));
143
144         object_class->get_property = gupnp_dlna_information_get_property;
145         object_class->set_property = gupnp_dlna_information_set_property;
146         object_class->finalize = gupnp_dlna_information_finalize;
147
148         pspec = g_param_spec_string ("name",
149                                      "DLNA profile name",
150                                      "The name of the DLNA profile "
151                                      "corresponding to the strream",
152                                      NULL,
153                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
154         g_object_class_install_property (object_class, PROP_DLNA_NAME, pspec);
155
156         pspec = g_param_spec_string ("mime",
157                                      "DLNA profile MIME type corresponding "
158                                      "to the stream",
159                                      "The DLNA MIME type of the stream",
160                                      NULL,
161                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
162         g_object_class_install_property (object_class, PROP_DLNA_MIME, pspec);
163
164         pspec = g_param_spec_boxed ("info",
165                                     "Stream metadata",
166                                     "Metadata of the stream in a "
167                                     "GstDiscovererInformation structure",
168                                     GST_TYPE_DISCOVERER_INFORMATION,
169                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
170         g_object_class_install_property (object_class,
171                                          PROP_DISCOVERER_INFO,
172                                          pspec);
173 }
174
175 static void
176 gupnp_dlna_information_init (GUPnPDLNAInformation *self)
177 {
178         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
179
180         priv->name = NULL;
181         priv->mime = NULL;
182         priv->info = NULL;
183 }
184
185 /**
186  * gupnp_dlna_information_new:
187  * @name: DLNA media profile name corresponding to the media
188  * @mime: DLNA MIME type for the media
189  * @info: #GstDiscovererInformation type with additional metadata about the
190  *        stream
191  *
192  * Creates a new #GUPnPDLNAInformation object with the given properties.
193  *
194  * Returns: A newly created #GUPnPDLNAInformation object.
195  */
196 GUPnPDLNAInformation*
197 gupnp_dlna_information_new (gchar                    *name,
198                             gchar                    *mime,
199                             GstDiscovererInformation *info)
200 {
201         return g_object_new (GUPNP_TYPE_DLNA_INFORMATION,
202                              "name", name,
203                              "mime", mime,
204                              "info", info,
205                              NULL);
206 }
207
208 /**
209  * gupnp_dlna_information_get_name:
210  * @self: The #GUPnPDLNAInformation object
211  *
212  * Returns: the DLNA profile name of the stream represented by @self. Do not
213  *          free this string.
214  */
215 const gchar *
216 gupnp_dlna_information_get_name (GUPnPDLNAInformation *self)
217 {
218         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
219         return priv->name;
220 }
221
222 /**
223  * gupnp_dlna_information_get_mime:
224  * @self: The #GUPnPDLNAInformation object
225  *
226  * Returns: the DLNA MIME type of the stream represented by @self. Do not
227  *          free this string.
228  */
229 const gchar *
230 gupnp_dlna_information_get_mime (GUPnPDLNAInformation *self)
231 {
232         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
233         return priv->mime;
234 }
235
236 /**
237  * gupnp_dlna_information_get_info:
238  * @self: The #GUPnPDLNAInformation object
239  *
240  * Returns: additional stream metadata for @self in the form of a
241  *          #GstDiscovererInformation structure. Do not free this structure.
242  */
243 const GstDiscovererInformation *
244 gupnp_dlna_information_get_info (GUPnPDLNAInformation *self)
245 {
246         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
247         return priv->info;
248 }