packaging: add gobject introspection and vala bindings
[profile/ivi/GUPnP-DLNA.git] / libgupnp-dlna / gupnp-dlna-information.c
1 /*
2  * Copyright (C) 2012 Intel Corporation.
3  *
4  * Authors: Krzesimir Nowak <krnowak@openismus.com>
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., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 /**
23  * SECTION:gupnp-dlna-information
24  * @short_description: Base class for storing various types of
25  * metadata informations.
26  *
27  * Subclasses of #GUPnPDLNAInformation should override all virtual
28  * functions provided by this class. The overrides should return a
29  * subclasses of specific information base classes.
30  *
31  * When instantiating a subclass of #GUPnPDLNAInformation make sure
32  * that "uri" with a URI to media file is passed to g_object_new().
33  */
34
35 #include "gupnp-dlna-information.h"
36
37 G_DEFINE_ABSTRACT_TYPE (GUPnPDLNAInformation,
38                         gupnp_dlna_information,
39                         G_TYPE_OBJECT)
40
41 struct _GUPnPDLNAInformationPrivate {
42         gchar* uri;
43         gboolean got_audio_info;
44         gboolean got_container_info;
45         gboolean got_image_info;
46         gboolean got_video_info;
47         GUPnPDLNAAudioInformation *audio_info;
48         GUPnPDLNAContainerInformation *container_info;
49         GUPnPDLNAImageInformation *image_info;
50         GUPnPDLNAVideoInformation *video_info;
51 };
52
53 enum {
54         PROP_0,
55
56         PROP_URI,
57         PROP_AUDIO_INFO,
58         PROP_CONTAINER_INFO,
59         PROP_IMAGE_INFO,
60         PROP_VIDEO_INFO
61 };
62
63 static const gchar *
64 gupnp_dlna_information_get_profile_name_default (GUPnPDLNAInformation *info G_GNUC_UNUSED)
65 {
66         return NULL;
67 }
68
69 static void
70 gupnp_dlna_information_dispose (GObject *object)
71 {
72         GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
73         GUPnPDLNAInformationPrivate *priv = info->priv;
74
75         g_clear_object (&priv->audio_info);
76         g_clear_object (&priv->container_info);
77         g_clear_object (&priv->image_info);
78         g_clear_object (&priv->video_info);
79         G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->dispose (object);
80 }
81
82 static void
83 gupnp_dlna_information_finalize (GObject *object)
84 {
85         GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
86
87         g_free (info->priv->uri);
88         G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->finalize (object);
89 }
90
91 static void
92 gupnp_dlna_information_set_property (GObject      *object,
93                                      guint         property_id,
94                                      const GValue *value,
95                                      GParamSpec   *pspec)
96 {
97         GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
98         GUPnPDLNAInformationPrivate *priv = info->priv;
99
100         switch (property_id) {
101         case PROP_URI:
102                 g_free (priv->uri);
103                 priv->uri = g_value_dup_string (value);
104                 break;
105
106         default:
107                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108                 break;
109         }
110 }
111
112 static void
113 gupnp_dlna_information_get_property (GObject    *object,
114                                      guint       property_id,
115                                      GValue     *value,
116                                      GParamSpec *pspec)
117 {
118         GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
119         GUPnPDLNAInformationPrivate *priv = info->priv;
120
121         switch (property_id) {
122         case PROP_URI:
123                 g_value_set_string (value, priv->uri);
124
125                 break;
126         case PROP_AUDIO_INFO:
127                 g_value_set_object
128                           (value,
129                            gupnp_dlna_information_get_audio_information (info));
130
131                 break;
132         case PROP_CONTAINER_INFO:
133                 g_value_set_object
134                       (value,
135                        gupnp_dlna_information_get_container_information (info));
136
137                 break;
138         case PROP_IMAGE_INFO:
139                 g_value_set_object
140                           (value,
141                            gupnp_dlna_information_get_image_information (info));
142
143                 break;
144         case PROP_VIDEO_INFO:
145                 g_value_set_object
146                           (value,
147                            gupnp_dlna_information_get_video_information (info));
148
149                 break;
150         default:
151                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
152
153                 break;
154         }
155 }
156
157 static void
158 gupnp_dlna_information_class_init (GUPnPDLNAInformationClass *info_class)
159 {
160         GObjectClass *object_class = G_OBJECT_CLASS (info_class);
161         GParamSpec *pspec;
162
163         object_class->dispose = gupnp_dlna_information_dispose;
164         object_class->finalize = gupnp_dlna_information_finalize;
165         object_class->set_property = gupnp_dlna_information_set_property;
166         object_class->get_property = gupnp_dlna_information_get_property;
167         info_class->get_container_information = NULL;
168         info_class->get_image_information = NULL;
169         info_class->get_video_information = NULL;
170         info_class->get_audio_information = NULL;
171         info_class->get_profile_name = gupnp_dlna_information_get_profile_name_default;
172
173         /**
174          * GUPnPDLNAInformation:uri:
175          *
176          * URI of file which metadata this object stores.
177          */
178         pspec = g_param_spec_string ("uri",
179                                      "uri",
180                                      "URI of file which metadata this object "
181                                      "stores",
182                                      NULL,
183                                      G_PARAM_READWRITE |
184                                      G_PARAM_CONSTRUCT_ONLY);
185         g_object_class_install_property (object_class, PROP_URI, pspec);
186
187         /**
188          * GUPnPDLNAInformation:audio-information:
189          *
190          * Audio information of a file.
191          */
192         pspec = g_param_spec_object ("audio-information",
193                                      "Audio information",
194                                      "Audio information of a file",
195                                      GUPNP_TYPE_DLNA_AUDIO_INFORMATION,
196                                      G_PARAM_READABLE);
197         g_object_class_install_property (object_class, PROP_AUDIO_INFO, pspec);
198
199         /**
200          * GUPnPDLNAInformation:container-information:
201          *
202          * Container information of a file.
203          */
204         pspec = g_param_spec_object ("container-information",
205                                      "Container information",
206                                      "Container information of a file",
207                                      GUPNP_TYPE_DLNA_CONTAINER_INFORMATION,
208                                      G_PARAM_READABLE);
209         g_object_class_install_property (object_class,
210                                          PROP_CONTAINER_INFO,
211                                          pspec);
212
213         /**
214          * GUPnPDLNAInformation:image-information:
215          *
216          * Image information of a file.
217          */
218         pspec = g_param_spec_object ("image-information",
219                                      "Image information",
220                                      "Image information of a file",
221                                      GUPNP_TYPE_DLNA_IMAGE_INFORMATION,
222                                      G_PARAM_READABLE);
223         g_object_class_install_property (object_class, PROP_IMAGE_INFO, pspec);
224
225         /**
226          * GUPnPDLNAInformation:video-information:
227          *
228          * Video information of a file.
229          */
230         pspec = g_param_spec_object ("video-information",
231                                      "Video information",
232                                      "Video information of a file",
233                                      GUPNP_TYPE_DLNA_VIDEO_INFORMATION,
234                                      G_PARAM_READABLE);
235         g_object_class_install_property (object_class, PROP_VIDEO_INFO, pspec);
236
237         g_type_class_add_private (info_class,
238                                   sizeof (GUPnPDLNAInformationPrivate));
239 }
240
241 static void
242 gupnp_dlna_information_init (GUPnPDLNAInformation *info)
243 {
244         GUPnPDLNAInformationPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE
245                                         (info,
246                                          GUPNP_TYPE_DLNA_INFORMATION,
247                                          GUPnPDLNAInformationPrivate);
248
249         priv->uri = NULL;
250         priv->got_audio_info = FALSE;
251         priv->got_container_info = FALSE;
252         priv->got_image_info = FALSE;
253         priv->got_video_info = FALSE;
254         priv->audio_info = NULL;
255         priv->container_info = NULL;
256         priv->image_info = NULL;
257         priv->video_info = NULL;
258         info->priv = priv;
259 }
260
261 /**
262  * gupnp_dlna_information_get_audio_information:
263  * @info: A #GUPnPDLNAInformation object.
264  *
265  * Get an audio information of media file if applicable (e.g. for
266  * video and audio files).
267  *
268  * Returns: (transfer none): A #GUPnPDLNAAudioInformation object or %NULL.
269  */
270 GUPnPDLNAAudioInformation *
271 gupnp_dlna_information_get_audio_information (GUPnPDLNAInformation *info)
272 {
273         GUPnPDLNAInformationPrivate *priv;
274
275         g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
276
277         priv = info->priv;
278         if (!priv->got_audio_info) {
279                 GUPnPDLNAInformationClass *info_class;
280
281                 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
282
283                 g_return_val_if_fail
284                                   (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
285                                    NULL);
286                 g_return_val_if_fail (info_class->get_audio_information != NULL,
287                                       NULL);
288
289                 priv->audio_info = info_class->get_audio_information (info);
290                 priv->got_audio_info = TRUE;
291         }
292
293         return priv->audio_info;
294 }
295
296 /**
297  * gupnp_dlna_information_get_container_information:
298  * @info: A #GUPnPDLNAInformation object.
299  *
300  * Get an container information of media file if applicable (e.g. for
301  * video and audio files).
302  *
303  * Returns: (transfer none): A #GUPnPDLNAContainerInformation object or %NULL.
304  */
305 GUPnPDLNAContainerInformation *
306 gupnp_dlna_information_get_container_information (GUPnPDLNAInformation *info)
307 {
308         GUPnPDLNAInformationPrivate *priv;
309
310         g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
311
312         priv = info->priv;
313         if (!priv->got_container_info) {
314                 GUPnPDLNAInformationClass *info_class;
315
316                 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
317
318                 g_return_val_if_fail
319                                   (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
320                                    NULL);
321                 g_return_val_if_fail
322                                  (info_class->get_container_information != NULL,
323                                   NULL);
324
325                 priv->container_info =
326                                    info_class->get_container_information (info);
327                 priv->got_container_info = TRUE;
328         }
329
330         return priv->container_info;
331 }
332
333 /**
334  * gupnp_dlna_information_get_image_information:
335  * @info: A #GUPnPDLNAInformation object.
336  *
337  * Get an container information of media file if applicable (e.g. for
338  * image files).
339  *
340  * Returns: (transfer none): A #GUPnPDLNAImageInformation object or %NULL.
341  */
342 GUPnPDLNAImageInformation *
343 gupnp_dlna_information_get_image_information (GUPnPDLNAInformation *info)
344 {
345         GUPnPDLNAInformationPrivate *priv;
346
347         g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
348
349         priv = info->priv;
350         if (!priv->got_image_info) {
351                 GUPnPDLNAInformationClass *info_class;
352
353                 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
354
355                 g_return_val_if_fail
356                                   (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
357                                    NULL);
358                 g_return_val_if_fail (info_class->get_image_information != NULL,
359                                       NULL);
360
361                 priv->image_info = info_class->get_image_information (info);
362                 priv->got_image_info = TRUE;
363         }
364
365         return priv->image_info;
366 }
367
368 /**
369  * gupnp_dlna_information_get_video_information:
370  * @info: A #GUPnPDLNAInformation object.
371  *
372  * Get an container information of media file if applicable (e.g. for
373  * video files).
374  *
375  * Returns: (transfer none): A #GUPnPDLNAVideoInformation object or %NULL.
376  */
377 GUPnPDLNAVideoInformation *
378 gupnp_dlna_information_get_video_information (GUPnPDLNAInformation *info)
379 {
380         GUPnPDLNAInformationPrivate *priv;
381
382         g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
383
384         priv = info->priv;
385         if (!priv->got_video_info) {
386                 GUPnPDLNAInformationClass *info_class;
387
388                 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
389
390                 g_return_val_if_fail
391                                   (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
392                                    NULL);
393                 g_return_val_if_fail (info_class->get_video_information != NULL,
394                                       NULL);
395
396                 priv->video_info = info_class->get_video_information (info);
397                 priv->got_video_info = TRUE;
398         }
399
400         return priv->video_info;
401 }
402
403 /**
404  * gupnp_dlna_information_get_profile_name:
405  * @info: A #GUPnPDLNAInformation object.
406  *
407  * Returns: (transfer none): The name of a DLNA profile or %NULL.
408  */
409 const gchar *
410 gupnp_dlna_information_get_profile_name (GUPnPDLNAInformation *info)
411 {
412         g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
413
414         return GUPNP_DLNA_INFORMATION_GET_CLASS (info)->get_profile_name (info);
415 }
416
417
418 /**
419  * gupnp_dlna_information_get_uri:
420  * @info: A #GUPnPDLNAInformation object.
421  *
422  * Returns: (transfer none): An URI of a file.
423  */
424 const gchar *
425 gupnp_dlna_information_get_uri (GUPnPDLNAInformation *info)
426 {
427         g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
428
429         return info->priv->uri;
430 }