Initial commit
[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 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 #include "gupnp-dlna-information.h"
23
24 G_DEFINE_TYPE (GUPnPDLNAInformation, gupnp_dlna_information, G_TYPE_OBJECT)
25
26 #define GET_PRIVATE(o) \
27   (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
28                                 GUPNP_TYPE_DLNA_INFORMATION, \
29                                 GUPnPDLNAInformationPrivate))
30
31 typedef struct _GUPnPDLNAInformationPrivate GUPnPDLNAInformationPrivate;
32
33 struct _GUPnPDLNAInformationPrivate {
34         GstDiscovererInformation *info;
35         gchar                    *name;
36         gchar                    *mime;
37 };
38
39 enum {
40         PROP_0,
41         PROP_DLNA_NAME,
42         PROP_DLNA_MIME,
43         PROP_DISCOVERER_INFO,
44 };
45
46 static void
47 gupnp_dlna_information_get_property (GObject    *object,
48                                      guint       property_id,
49                                      GValue     *value,
50                                      GParamSpec *pspec)
51 {
52         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
53         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
54
55         switch (property_id) {
56                 case PROP_DLNA_NAME:
57                         g_value_set_string (value, priv->name);
58                         break;
59
60                 case PROP_DLNA_MIME:
61                         g_value_set_string (value, priv->mime);
62                         break;
63
64                 case PROP_DISCOVERER_INFO:
65                         g_value_set_boxed (value, priv->info);
66                         break;
67
68                 default:
69                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
70                                                            property_id,
71                                                            pspec);
72                         break;
73         }
74 }
75
76 static void
77 gupnp_dlna_information_set_property (GObject      *object,
78                                      guint         property_id,
79                                      const GValue *value,
80                                      GParamSpec   *pspec)
81 {
82         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
83         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
84
85         switch (property_id) {
86                 case PROP_DLNA_NAME:
87                         g_free (priv->name);
88                         priv->name = g_value_dup_string (value);
89                         break;
90
91                 case PROP_DLNA_MIME:
92                         g_free (priv->mime);
93                         priv->mime = g_value_dup_string (value);
94                         break;
95
96                 case PROP_DISCOVERER_INFO:
97                         if (priv->info)
98                                 gst_discoverer_information_free (priv->info);
99                         priv->info = g_value_dup_boxed (value);
100                         break;
101
102                 default:
103                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
104                                                            property_id,
105                                                            pspec);
106                         break;
107   }
108 }
109
110
111 static void
112 gupnp_dlna_information_finalize (GObject *object)
113 {
114         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
115         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
116
117         g_free (priv->name);
118         g_free (priv->mime);
119         if (priv->info)
120                 gst_discoverer_information_free (priv->info);
121
122         G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->finalize (object);
123 }
124
125 static void
126 gupnp_dlna_information_class_init (GUPnPDLNAInformationClass *klass)
127 {
128         GObjectClass *object_class = G_OBJECT_CLASS (klass);
129         GParamSpec *pspec;
130
131         g_type_class_add_private (klass, sizeof (GUPnPDLNAInformation));
132
133         object_class->get_property = gupnp_dlna_information_get_property;
134         object_class->set_property = gupnp_dlna_information_set_property;
135         object_class->finalize = gupnp_dlna_information_finalize;
136
137         pspec = g_param_spec_string ("name",
138                                      "DLNA profile name",
139                                      "The name of the DLNA profile"
140                                      "corresponding to the strream",
141                                      NULL,
142                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
143         g_object_class_install_property (object_class, PROP_DLNA_NAME, pspec);
144
145         pspec = g_param_spec_string ("mime",
146                                      "DLNA profile MIME type corresponding"
147                                      "to the stream",
148                                      "The MIME type of the DLNA profile",
149                                      NULL,
150                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
151         g_object_class_install_property (object_class, PROP_DLNA_NAME, pspec);
152
153         pspec = g_param_spec_boxed ("info",
154                                     "Stream metadata",
155                                     "Metadata of the stream in an"
156                                     "GstDiscovererInformation structure",
157                                     GST_TYPE_DISCOVERER_INFORMATION,
158                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
159         g_object_class_install_property (object_class,
160                                          PROP_DISCOVERER_INFO,
161                                          pspec);
162 }
163
164 static void
165 gupnp_dlna_information_init (GUPnPDLNAInformation *self)
166 {
167         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
168
169         priv->name = NULL;
170         priv->mime = NULL;
171         priv->info = NULL;
172 }
173
174 GUPnPDLNAInformation*
175 gupnp_dlna_information_new (gchar                    *name,
176                             gchar                    *mime,
177                             GstDiscovererInformation *info)
178 {
179         return g_object_new (GUPNP_TYPE_DLNA_INFORMATION,
180                              "name", name,
181                              "mime", mime,
182                              "info", info,
183                              NULL);
184 }
185
186 gchar *
187 gupnp_dlna_information_get_name (GUPnPDLNAInformation *self)
188 {
189         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
190         return priv->name;
191 }
192
193 gchar *
194 gupnp_dlna_information_get_mime (GUPnPDLNAInformation *self)
195 {
196         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
197         return priv->mime;
198 }
199
200 GstDiscovererInformation *
201 gupnp_dlna_information_get_info (GUPnPDLNAInformation *self)
202 {
203         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
204         return priv->info;
205 }