1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Implementing Server Plugins: Simple Example: librygel-server Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="librygel-server Reference Manual">
<link rel="up" href="implementing-server-plugins.html" title="Implementing Rygel Server Plugins">
<link rel="prev" href="implementing-server-plugins.html" title="Implementing Rygel Server Plugins">
<link rel="next" href="implementing-server-plugins-full-example.html" title="Implementing Server Plugins: Full Example">
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="implementing-server-plugins.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="implementing-server-plugins.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="implementing-server-plugins-full-example.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="implementing-server-plugins-simple-example"></a>Implementing Server Plugins: Simple Example</h2></div></div></div>
<p>
This example source code shows how to implement a Rygel Server plugin.</p>
<p>This example implements a root <a class="link" href="RygelMediaContainer.html" title="RygelMediaContainer">RygelMediaContainer</a> by
deriving from <a class="link" href="RygelSimpleContainer.html" title="RygelSimpleContainer">RygelSimpleContainer</a> and adding some
hard-coded items. A real Rygel server plugin's root container, or its child items, would typically
populate themselves dynamically. For instance, they might add and remove items based on some source
such as a file system or database. See, for instance, the
<a class="ulink" href="http://git.gnome.org/browse/rygel/tree/src/plugins/tracker" target="_top">Rygel Tracker Plugin</a> or the
<a class="ulink" href="http://git.gnome.org/browse/rygel/tree/src/plugins/media-export" target="_top">Rygel MediaExport Plugin</a> plugins,
implemented in Vala.
</p>
<pre class="programlisting">
/*
* Copyright (C) 2012 Intel Corporation
*
* This file is part of Rygel.
*
* Rygel is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Rygel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __RYGEL_EXAMPLE_SERVER_PLUGIN_H__
#define __RYGEL_EXAMPLE_SERVER_PLUGIN_H__
#include <glib.h>
#include <glib-object.h>
#include <rygel-server.h>
G_BEGIN_DECLS
#define RYGEL_EXAMPLE_TYPE_SERVER_PLUGIN (rygel_example_server_plugin_get_type ())
#define RYGEL_EXAMPLE_SERVER_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_EXAMPLE_TYPE_SERVER_PLUGIN, RygelExampleServerPlugin))
#define RYGEL_EXAMPLE_SERVER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_EXAMPLE_TYPE_SERVER_PLUGIN, RygelExampleServerPluginClass))
#define RYGEL_EXAMPLE_IS_SERVER_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_EXAMPLE_TYPE_SERVER_PLUGIN))
#define RYGEL_EXAMPLE_IS_SERVER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_EXAMPLE_TYPE_SERVER_PLUGIN))
#define RYGEL_EXAMPLE_SERVER_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_EXAMPLE_TYPE_SERVER_PLUGIN, RygelExampleServerPluginClass))
typedef struct _RygelExampleServerPlugin RygelExampleServerPlugin;
typedef struct _RygelExampleServerPluginClass RygelExampleServerPluginClass;
typedef struct _RygelExampleServerPluginPrivate RygelExampleServerPluginPrivate;
struct _RygelExampleServerPlugin {
RygelMediaServerPlugin parent_instance;
RygelExampleServerPluginPrivate * priv;
};
struct _RygelExampleServerPluginClass {
RygelMediaServerPluginClass parent_class;
};
GType rygel_example_server_plugin_get_type (void) G_GNUC_CONST;
RygelExampleServerPlugin* rygel_example_server_plugin_new (void);
void module_init (RygelPluginLoader* loader);
G_END_DECLS
#endif /* __RYGEL_EXAMPLE_SERVER_PLUGIN_H__ */
</pre>
<pre class="programlisting">
/*
* Copyright (C) 2012 Intel Corporation
*
* This file is part of Rygel.
*
* Rygel is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Rygel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "example-server-plugin.h"
#include "example-root-container.h"
#define RYGEL_EXAMPLE_SERVER_PLUGIN_NAME "ExampleServerPluginC"
enum {
RYGEL_EXAMPLE_SERVER_PLUGIN_DUMMY_PROPERTY
};
#define RYGEL_EXAMPLE_SERVER_PLUGIN_TITLE "Example Server Plugin C"
#define RYGEL_EXAMPLE_SERVER_PLUGIN_DESCRIPTION "An example Rygel server plugin implemented in C."
G_DEFINE_TYPE (RygelExampleServerPlugin, rygel_example_server_plugin, RYGEL_TYPE_MEDIA_SERVER_PLUGIN)
void
module_init (RygelPluginLoader* loader) {
RygelExampleServerPlugin* plugin;
g_return_if_fail (loader != NULL);
if (rygel_plugin_loader_plugin_disabled (loader, RYGEL_EXAMPLE_SERVER_PLUGIN_NAME)) {
g_message ("Plugin '%s' disabled by user. Ignoring.",
RYGEL_EXAMPLE_SERVER_PLUGIN_NAME);
return;
}
plugin = rygel_example_server_plugin_new ();
rygel_plugin_loader_add_plugin (loader, RYGEL_PLUGIN (plugin));
g_object_unref (plugin);
}
static RygelExampleServerPlugin*
rygel_example_server_plugin_construct (GType object_type) {
RygelExampleServerPlugin *self;
RygelExampleRootContainer *root_container;
root_container =
rygel_example_root_container_new (RYGEL_EXAMPLE_SERVER_PLUGIN_TITLE);
self = (RygelExampleServerPlugin*) rygel_media_server_plugin_construct (object_type,
(RygelMediaContainer*) root_container, RYGEL_EXAMPLE_SERVER_PLUGIN_NAME,
RYGEL_EXAMPLE_SERVER_PLUGIN_DESCRIPTION, RYGEL_PLUGIN_CAPABILITIES_NONE);
g_object_unref (root_container);
return self;
}
RygelExampleServerPlugin*
rygel_example_server_plugin_new (void) {
return rygel_example_server_plugin_construct (RYGEL_EXAMPLE_TYPE_SERVER_PLUGIN);
}
static void
rygel_example_server_plugin_class_init (RygelExampleServerPluginClass *klass) {
}
static void
rygel_example_server_plugin_init (RygelExampleServerPlugin *self) {
}
</pre>
<pre class="programlisting">
/*
* Copyright (C) 2012 Intel Corporation
*
* This file is part of Rygel.
*
* Rygel is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Rygel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __RYGEL_EXAMPLE_ROOT_CONTAINER_H__
#define __RYGEL_EXAMPLE_ROOT_CONTAINER_H__
#include <glib.h>
#include <glib-object.h>
#include <rygel-server.h>
G_BEGIN_DECLS
#define RYGEL_EXAMPLE_TYPE_ROOT_CONTAINER (rygel_example_root_container_get_type ())
#define RYGEL_EXAMPLE_ROOT_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_EXAMPLE_TYPE_ROOT_CONTAINER, RygelExampleRootContainer))
#define RYGEL_EXAMPLE_ROOT_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_EXAMPLE_TYPE_ROOT_CONTAINER, RygelExampleRootContainerClass))
#define RYGEL_EXAMPLE_IS_ROOT_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_EXAMPLE_TYPE_ROOT_CONTAINER))
#define RYGEL_EXAMPLE_IS_ROOT_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_EXAMPLE_TYPE_ROOT_CONTAINER))
#define RYGEL_EXAMPLE_ROOT_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_EXAMPLE_TYPE_ROOT_CONTAINER, RygelExampleRootContainerClass))
typedef struct _RygelExampleRootContainer RygelExampleRootContainer;
typedef struct _RygelExampleRootContainerClass RygelExampleRootContainerClass;
typedef struct _RygelExampleRootContainerPrivate RygelExampleRootContainerPrivate;
struct _RygelExampleRootContainer {
RygelSimpleContainer parent_instance;
RygelExampleRootContainerPrivate * priv;
};
struct _RygelExampleRootContainerClass {
RygelSimpleContainerClass parent_class;
};
RygelExampleRootContainer* rygel_example_root_container_new (const gchar* title);
GType rygel_example_root_container_get_type (void);
G_END_DECLS
#endif /* __RYGEL_EXAMPLE_ROOT_CONTAINER_H__ */
</pre>
<pre class="programlisting">
/*
* Copyright (C) 2012 Intel Corporation
*
* This file is part of Rygel.
*
* Rygel is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Rygel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "example-root-container.h"
/**
* Our derived MediaContainer.
* In this example, we just derive from the SimpleContainer,
* but a real-world server plugin might need something more sophisticated.
*/
enum {
RYGEL_EXAMPLE_ROOT_CONTAINER_DUMMY_PROPERTY
};
G_DEFINE_TYPE (RygelExampleRootContainer, rygel_example_root_container, RYGEL_TYPE_SIMPLE_CONTAINER)
RygelExampleRootContainer* rygel_example_root_container_new (const gchar *title);
static RygelExampleRootContainer*
rygel_example_root_container_construct (GType object_type, const gchar *title) {
RygelExampleRootContainer *self;
RygelMediaItem *item;
g_return_val_if_fail (title != NULL, NULL);
self = (RygelExampleRootContainer*) rygel_simple_container_construct_root (object_type, title);
item = rygel_music_item_new ("test 1", (RygelMediaContainer*) self, "Test 1", RYGEL_MUSIC_ITEM_UPNP_CLASS);
rygel_media_object_add_uri (RYGEL_MEDIA_OBJECT (item), "file:///home/murrayc/Music/Madness/05_Baggy_Trousers.mp3");
rygel_media_file_item_set_mime_type (item, "audio/mpeg");
rygel_simple_container_add_child_item ((RygelSimpleContainer*) self, item);
rygel_media_file_item_add_engine_resources (item, NULL, NULL);
g_object_unref (item);
item = rygel_music_item_new ("test 2", (RygelMediaContainer*) self, "Test 1", RYGEL_MUSIC_ITEM_UPNP_CLASS);
rygel_media_object_add_uri (RYGEL_MEDIA_OBJECT (item), "file:///home/murrayc/Music/08%20Busload%20of%20Faith.mp3");
rygel_media_file_item_set_mime_type (item, "audio/mpeg");
rygel_simple_container_add_child_item ((RygelSimpleContainer*) self, item);
rygel_media_file_item_add_engine_resources (item, NULL, NULL);
g_object_unref (item);
return self;
}
RygelExampleRootContainer*
rygel_example_root_container_new (const gchar *title) {
return rygel_example_root_container_construct (RYGEL_EXAMPLE_TYPE_ROOT_CONTAINER, title);
}
static void
rygel_example_root_container_class_init (RygelExampleRootContainerClass *klass) {
}
static void
rygel_example_root_container_init (RygelExampleRootContainer *self) {
}
</pre>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.27</div>
</body>
</html>
|