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
|
<!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 Servers: 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-servers.html" title="Implementing Servers">
<link rel="prev" href="implementing-servers.html" title="Implementing Servers">
<link rel="next" href="implementing-server-plugins.html" title="Implementing Rygel Server Plugins">
<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-servers.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="implementing-servers.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="implementing-server-plugins.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-servers-simple-example"></a>Implementing Servers: Simple Example</h2></div></div></div>
<p>
This example program shows how to fill a container with media items and then instantiate a server to serve
them.
</p>
<pre class="programlisting">
/*
* Copyright (C) 2012 Openismus GmbH.
* Copyright (C) 2012 Intel Corporation.
*
* Author: Jens Georg <jensg@openismus.com>
*
* 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
*/
/*
* Demo application for librygel-server.
*
* Creates a stand-alone UPnP server that exposes the contents of the current
* folder or the folder passed as argument.
*
* Usage:
* standalone-server [<folder>]
*
* The server listens on wlan0 and eth0 by default.
*/
#include <gio/gio.h>
#include <rygel-server.h>
#include <rygel-core.h>
int main (int argc, char *argv[])
{
RygelMediaServer *server;
RygelSimpleContainer *root_container;
char *path;
GFile *source_dir;
GFileEnumerator *enumerator;
GFileInfo *info;
int i;
GMainLoop *loop;
GError *error = NULL;
g_type_init ();
rygel_media_engine_init (&error);
if (error != NULL) {
g_print ("Could not initialize media engine: %s\n",
error->message);
g_error_free (error);
return EXIT_FAILURE;
}
g_set_application_name ("Standalone-Server");
root_container = rygel_simple_container_new_root ("Sample implementation");
if (argc >= 2) {
path = g_strdup (argv[1]);
} else {
path = g_get_current_dir ();
}
source_dir = g_file_new_for_commandline_arg (path);
g_free (path);
enumerator = g_file_enumerate_children (source_dir,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
info = g_file_enumerator_next_file (enumerator, NULL, NULL);
i = 0;
while (info != NULL) {
GFile *file;
const char *display_name, *content_type;
char *uri, *id;
RygelMediaItem *item = NULL;
GError *error = NULL;
display_name = g_file_info_get_display_name (info);
content_type = g_file_info_get_content_type (info);
file = g_file_get_child_for_display_name (source_dir, display_name, &error);
if (error != NULL) {
g_critical ("Failed to get child: %s", error->message);
return 127;
}
uri = g_file_get_uri (file);
g_object_unref (file);
id = g_strdup_printf ("%06d", i);
if (g_str_has_prefix (content_type, "audio/")) {
item = rygel_audio_item_new (id,
root_container,
display_name,
RYGEL_AUDIO_ITEM_UPNP_CLASS);
} else if (g_str_has_prefix (content_type, "video/")) {
item = rygel_video_item_new (id,
root_container,
display_name,
RYGEL_VIDEO_ITEM_UPNP_CLASS);
} else if (g_str_has_prefix (content_type, "image/")) {
item = rygel_image_item_new (id,
root_container,
display_name,
RYGEL_IMAGE_ITEM_UPNP_CLASS);
}
g_free (id);
if (item != NULL) {
GeeArrayList* uris;
rygel_media_file_item_set_mime_type (RYGEL_MEDIA_FILE_ITEM (item),
content_type);
rygel_media_object_add_uri (RYGEL_MEDIA_OBJECT (item), uri);
rygel_simple_container_add_child_item (root_container, item);
rygel_media_file_item_add_engine_resources (item, NULL, NULL);
}
i++;
info = g_file_enumerator_next_file (enumerator, NULL, NULL);
}
server = rygel_media_server_new ("LibRygel sample server",
root_container,
RYGEL_PLUGIN_CAPABILITIES_NONE);
rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (server), "eth0");
rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (server), "wlan0");
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
}
</pre>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.27</div>
</body>
</html>
|