static void rygel_media_object_finalize (GObject* obj) { RygelMediaObject * self; self = RYGEL_MEDIA_OBJECT (obj); self->id = (g_free (self->id), NULL); self->title = (g_free (self->title), NULL); G_OBJECT_CLASS (rygel_media_object_parent_class)->finalize (obj); }
/** * Factory method. * * Create a QueryContainer from a plain-text description string. * * @param definition Plain-text defintion of the query-container * @param name The title of the container. If not supplied, it * will be derived from the plain-text description of * the container * @return A new instance of QueryContainer */ RygelMediaExportQueryContainer * rygel_media_export_query_container_factory_create_from_description (RygelMediaExportQueryContainerFactory *self, const gchar *definition, const gchar *name) { gchar *title; gchar *attribute; gchar *pattern; gchar *upnp_class; gchar *id; RygelMediaExportQueryContainer *container; RygelSearchExpression *expression; g_return_val_if_fail (RYGEL_MEDIA_EXPORT_IS_QUERY_CONTAINER_FACTORY (self), NULL); g_return_val_if_fail (definition != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); title = g_strdup (name); attribute = NULL; pattern = NULL; upnp_class = NULL; id = g_strdup (definition); rygel_media_export_query_container_factory_register_id (self, &id); expression = rygel_media_export_query_container_factory_parse_description (definition, &pattern, &attribute, &upnp_class, &title); if (!pattern || pattern[0] == '\0') { container = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER (rygel_media_export_leaf_query_container_new (expression, id, title)); } else { container = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER (rygel_media_export_node_query_container_new (expression, id, title, pattern, attribute)); } if (upnp_class) { rygel_media_object_set_upnp_class (RYGEL_MEDIA_OBJECT (container), upnp_class); if (!g_strcmp0 (upnp_class, RYGEL_MEDIA_CONTAINER_MUSIC_ALBUM)) { rygel_media_container_set_sort_criteria (RYGEL_MEDIA_CONTAINER (container), RYGEL_MEDIA_CONTAINER_ALBUM_SORT_CRITERIA); } } rygel_search_expression_unref (expression); g_free (id); g_free (upnp_class); g_free (pattern); g_free (attribute); g_free (title); return container; }
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_object_set_mime_type (RYGEL_MEDIA_OBJECT (item), content_type); rygel_media_object_add_uri (RYGEL_MEDIA_OBJECT (item), uri); rygel_simple_container_add_child_item (root_container, item); } 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); }