[rygel-gst-0-10-plugins] Make singleton getters non-throwing.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-gst-0-10-plugins] Make singleton getters non-throwing.
- Date: Tue, 5 Feb 2013 15:21:30 +0000 (UTC)
commit 69e34fbd3219e57db6def1f4bc37d2ed178cc9c5
Author: Krzesimir Nowak <krnowak openismus com>
Date: Tue Feb 5 15:54:55 2013 +0100
Make singleton getters non-throwing.
We make sure that singletons are created when creating a plugin instance.
src/media-export/rygel-media-export-db-container.c | 2 +-
.../rygel-media-export-dummy-container.c | 20 +++++------
src/media-export/rygel-media-export-harvester.c | 20 ++--------
.../rygel-media-export-harvesting-task.c | 7 +---
src/media-export/rygel-media-export-media-cache.c | 17 +++++++--
src/media-export/rygel-media-export-media-cache.h | 5 ++-
src/media-export/rygel-media-export-music-item.c | 9 ++---
src/media-export/rygel-media-export-photo-item.c | 9 ++---
src/media-export/rygel-media-export-plugin.c | 37 +++++++++++++------
src/media-export/rygel-media-export-plugin.h | 2 +-
.../rygel-media-export-root-container.c | 22 ++++++++++--
.../rygel-media-export-root-container.h | 3 ++
src/media-export/rygel-media-export-video-item.c | 9 ++---
13 files changed, 89 insertions(+), 73 deletions(-)
---
diff --git a/src/media-export/rygel-media-export-db-container.c b/src/media-export/rygel-media-export-db-container.c
index 7b0899f..d141c95 100644
--- a/src/media-export/rygel-media-export-db-container.c
+++ b/src/media-export/rygel-media-export-db-container.c
@@ -88,7 +88,7 @@ on_media_container_updated (RygelMediaContainer *sender G_GNUC_UNUSED,
static void
rygel_media_export_db_container_constructed (GObject *object)
{
- RygelMediaExportMediaCache *cache = rygel_media_export_media_cache_get_default (NULL);
+ RygelMediaExportMediaCache *cache = rygel_media_export_media_cache_get_default ();
RygelMediaExportDBContainer *self = RYGEL_MEDIA_EXPORT_DB_CONTAINER (object);
GeeArrayList *classes = gee_array_list_new (G_TYPE_STRING,
(GBoxedCopyFunc) g_strdup,
diff --git a/src/media-export/rygel-media-export-dummy-container.c b/src/media-export/rygel-media-export-dummy-container.c
index 29bda96..284e273 100644
--- a/src/media-export/rygel-media-export-dummy-container.c
+++ b/src/media-export/rygel-media-export-dummy-container.c
@@ -52,6 +52,7 @@ rygel_media_export_dummy_container_new (GFile *file,
GError *inner_error;
GeeList *children_list;
gint child_count;
+ GeeArrayList *child_ids;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (RYGEL_IS_MEDIA_CONTAINER (parent), NULL);
@@ -60,17 +61,11 @@ rygel_media_export_dummy_container_new (GFile *file,
basename = g_file_get_basename (file);
inner_error = NULL;
- media_db = rygel_media_export_media_cache_get_default (&inner_error);
- if (!inner_error) {
- GeeArrayList *child_ids = rygel_media_export_media_cache_get_child_ids (media_db,
- id,
- &inner_error);
- g_object_unref (media_db);
- if (!inner_error) {
- children_list = GEE_LIST (child_ids);
- child_count = gee_collection_get_size (GEE_COLLECTION (child_ids));
- }
- }
+ media_db = rygel_media_export_media_cache_get_default ();
+ child_ids = rygel_media_export_media_cache_get_child_ids (media_db,
+ id,
+ &inner_error);
+ g_object_unref (media_db);
if (inner_error)
{
children_list = GEE_LIST (gee_array_list_new (G_TYPE_STRING,
@@ -81,6 +76,9 @@ rygel_media_export_dummy_container_new (GFile *file,
NULL));
child_count = 0;
g_error_free (inner_error);
+ } else {
+ children_list = GEE_LIST (child_ids);
+ child_count = gee_collection_get_size (GEE_COLLECTION (child_ids));
}
self = RYGEL_MEDIA_EXPORT_DUMMY_CONTAINER (g_object_new (RYGEL_MEDIA_EXPORT_TYPE_DUMMY_CONTAINER,
diff --git a/src/media-export/rygel-media-export-harvester.c b/src/media-export/rygel-media-export-harvester.c
index bf803a6..e29d158 100644
--- a/src/media-export/rygel-media-export-harvester.c
+++ b/src/media-export/rygel-media-export-harvester.c
@@ -100,15 +100,7 @@ rygel_media_export_harvester_on_file_added (RygelMediaExportHarvester *self,
uri = g_file_get_uri (file);
g_debug ("Filesystem events settled for %s, scheduling extractionâ", uri);
g_free (uri);
- cache = rygel_media_export_media_cache_get_default (&error);
-
- if (error) {
- g_warning (_("Failed to access media cache: %s"), error->message);
- g_error_free (error);
- error = NULL;
-
- return;
- }
+ cache = rygel_media_export_media_cache_get_default ();
priv = self->priv;
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -250,7 +242,7 @@ rygel_media_export_harvester_on_changes_done (RygelMediaExportHarvester *self,
static void
rygel_media_export_harvester_on_file_removed (RygelMediaExportHarvester *self,
GFile *file,
- GError **error) {
+ GError **error G_GNUC_UNUSED) {
RygelMediaExportMediaCache *cache;
GError *inner_error;
GeeAbstractMap *abstract_grace_timers;
@@ -261,12 +253,7 @@ rygel_media_export_harvester_on_file_removed (RygelMediaExportHarvester *self,
g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_HARVESTER (self));
g_return_if_fail (G_IS_FILE (file));
- inner_error = NULL;
- cache = rygel_media_export_media_cache_get_default (&inner_error);
- if (inner_error != NULL) {
- g_propagate_error (error, inner_error);
- return;
- }
+ cache = rygel_media_export_media_cache_get_default ();
abstract_grace_timers = GEE_ABSTRACT_MAP (self->priv->extraction_grace_timers);
if (gee_abstract_map_has_key (abstract_grace_timers, file)) {
g_source_remove ((guint) ((guintptr) gee_abstract_map_get (abstract_grace_timers, file)));
@@ -274,6 +261,7 @@ rygel_media_export_harvester_on_file_removed (RygelMediaExportHarvester *self,
}
rygel_media_export_harvester_cancel (self, file);
id = rygel_media_export_media_cache_get_id (file);
+ inner_error = NULL;
object = rygel_media_export_media_cache_get_object (cache, id, &inner_error);
if (inner_error) {
diff --git a/src/media-export/rygel-media-export-harvesting-task.c b/src/media-export/rygel-media-export-harvesting-task.c
index 2bea7cf..bdca24e 100644
--- a/src/media-export/rygel-media-export-harvesting-task.c
+++ b/src/media-export/rygel-media-export-harvesting-task.c
@@ -861,15 +861,10 @@ static void
rygel_media_export_harvesting_task_constructed (GObject *object) {
RygelMediaExportHarvestingTask *self = RYGEL_MEDIA_EXPORT_HARVESTING_TASK (object);
RygelMediaExportHarvestingTaskPrivate *priv = self->priv;
- GError *inner_error = NULL;
G_OBJECT_CLASS (rygel_media_export_harvesting_task_parent_class)->constructed (object);
- priv->cache = rygel_media_export_media_cache_get_default (&inner_error);
- /* No error should happen now, because harvesting task is created
- * long after media cache is gotten for the first time. If it erred,
- * then no tasks would be created. */
- g_assert_no_error (inner_error);
+ priv->cache = rygel_media_export_media_cache_get_default ();
g_signal_connect_object (priv->extractor,
"extraction-done",
diff --git a/src/media-export/rygel-media-export-media-cache.c b/src/media-export/rygel-media-export-media-cache.c
index b730e13..036dd6d 100644
--- a/src/media-export/rygel-media-export-media-cache.c
+++ b/src/media-export/rygel-media-export-media-cache.c
@@ -190,20 +190,29 @@ rygel_media_export_media_cache_get_id (GFile *file) {
return result;
}
-RygelMediaExportMediaCache *
-rygel_media_export_media_cache_get_default (GError **error) {
+gboolean
+rygel_media_export_media_cache_ensure_exists (GError **error) {
if (!rygel_media_export_media_cache_instance) {
GError *inner_error = NULL;
RygelMediaExportMediaCache* cache = rygel_media_export_media_cache_new (&inner_error);
if (inner_error) {
g_propagate_error (error, inner_error);
- return NULL;
+ return FALSE;
}
rygel_media_export_media_cache_instance = cache;
}
- return g_object_ref (rygel_media_export_media_cache_instance);
+ return TRUE;
+}
+
+RygelMediaExportMediaCache *
+rygel_media_export_media_cache_get_default (void) {
+ if (rygel_media_export_media_cache_instance) {
+ return g_object_ref (rygel_media_export_media_cache_instance);
+ }
+
+ return NULL;
}
void
diff --git a/src/media-export/rygel-media-export-media-cache.h b/src/media-export/rygel-media-export-media-cache.h
index af0d310..109d063 100644
--- a/src/media-export/rygel-media-export-media-cache.h
+++ b/src/media-export/rygel-media-export-media-cache.h
@@ -59,8 +59,11 @@ rygel_media_export_media_cache_new (GError **error);
gchar *
rygel_media_export_media_cache_get_id (GFile *file);
+gboolean
+rygel_media_export_media_cache_ensure_exists (GError **error);
+
RygelMediaExportMediaCache *
-rygel_media_export_media_cache_get_default (GError **error);
+rygel_media_export_media_cache_get_default (void);
void
rygel_media_export_media_cache_remove_by_id (RygelMediaExportMediaCache *self,
diff --git a/src/media-export/rygel-media-export-music-item.c b/src/media-export/rygel-media-export-music-item.c
index 601b6d5..3b974b5 100644
--- a/src/media-export/rygel-media-export-music-item.c
+++ b/src/media-export/rygel-media-export-music-item.c
@@ -62,12 +62,9 @@ rygel_media_export_music_item_real_commit (RygelUpdatableObject *base, GAsyncRea
/* Do the work that could take a while.
*/
GError *error = NULL;
- RygelMediaExportMediaCache *cache =
- rygel_media_export_media_cache_get_default (&error);
- if (!error) {
- rygel_media_export_media_cache_save_item (cache,
- RYGEL_MEDIA_ITEM (self), &error);
- }
+ RygelMediaExportMediaCache *cache = rygel_media_export_media_cache_get_default ();
+
+ rygel_media_export_media_cache_save_item (cache, RYGEL_MEDIA_ITEM (self), &error);
/* Set any error in the async result, if necessary.
*/
diff --git a/src/media-export/rygel-media-export-photo-item.c b/src/media-export/rygel-media-export-photo-item.c
index 3a6ca81..cf56fc4 100644
--- a/src/media-export/rygel-media-export-photo-item.c
+++ b/src/media-export/rygel-media-export-photo-item.c
@@ -62,12 +62,9 @@ static void rygel_media_export_photo_item_real_commit (RygelUpdatableObject *bas
/* Do the work that could take a while.
*/
GError *error = NULL;
- RygelMediaExportMediaCache *cache =
- rygel_media_export_media_cache_get_default (&error);
- if (!error) {
- rygel_media_export_media_cache_save_item (cache,
- RYGEL_MEDIA_ITEM (self), &error);
- }
+ RygelMediaExportMediaCache *cache = rygel_media_export_media_cache_get_default ();
+
+ rygel_media_export_media_cache_save_item (cache, RYGEL_MEDIA_ITEM (self), &error);
/* Set any error in the async result, if necessary.
*/
diff --git a/src/media-export/rygel-media-export-plugin.c b/src/media-export/rygel-media-export-plugin.c
index 8ecd060..14911a2 100644
--- a/src/media-export/rygel-media-export-plugin.c
+++ b/src/media-export/rygel-media-export-plugin.c
@@ -25,37 +25,50 @@
G_DEFINE_TYPE (RygelMediaExportPlugin, rygel_media_export_plugin, RYGEL_TYPE_MEDIA_SERVER_PLUGIN)
-RygelMediaExportPlugin *rygel_media_export_plugin_construct (GType object_type);
-
/**
* Simple plugin which exposes the media contents of a directory via UPnP.
*
*/
void module_init (RygelPluginLoader *loader) {
- RygelMediaExportPlugin *plugin = NULL;
+ RygelMediaExportPlugin *plugin;
+ GError *error;
if (rygel_plugin_loader_plugin_disabled (loader, RYGEL_MEDIA_EXPORT_PLUGIN_NAME)) {
g_message ("rygel-media-export-plugin.c: Plugin '%s' disabled by user. Ignoring.", RYGEL_MEDIA_EXPORT_PLUGIN_NAME);
return;
}
+ error = NULL;
/* Instantiate the plugin object */
- plugin = rygel_media_export_plugin_new ();
+ plugin = rygel_media_export_plugin_new (&error);
+
+ if (error) {
+ g_warning ("Failed to initialize plugin '" RYGEL_MEDIA_EXPORT_PLUGIN_NAME "': %s. Ignoring...",
+ error->message);
+ g_error_free (error);
+ return;
+ }
rygel_plugin_loader_add_plugin (loader, RYGEL_PLUGIN (plugin));
}
RygelMediaExportPlugin*
-rygel_media_export_plugin_construct (GType object_type) {
- RygelMediaContainer *root = rygel_media_export_root_container_get_instance ();
- return RYGEL_MEDIA_EXPORT_PLUGIN (rygel_media_server_plugin_construct (object_type,
- root, RYGEL_MEDIA_EXPORT_PLUGIN_NAME, NULL, RYGEL_PLUGIN_CAPABILITIES_UPLOAD));
-}
+rygel_media_export_plugin_new (GError **error) {
+ RygelMediaContainer *root;
+ GError *inner_error = NULL;
-RygelMediaExportPlugin*
-rygel_media_export_plugin_new () {
- return rygel_media_export_plugin_construct (RYGEL_MEDIA_EXPORT_TYPE_PLUGIN);
+ rygel_media_export_root_container_ensure_exists (&inner_error);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return NULL;
+ }
+ root = rygel_media_export_root_container_get_instance ();
+ return RYGEL_MEDIA_EXPORT_PLUGIN (rygel_media_server_plugin_construct (RYGEL_MEDIA_EXPORT_TYPE_PLUGIN,
+ root,
+ RYGEL_MEDIA_EXPORT_PLUGIN_NAME,
+ NULL,
+ RYGEL_PLUGIN_CAPABILITIES_UPLOAD));
}
static void
diff --git a/src/media-export/rygel-media-export-plugin.h b/src/media-export/rygel-media-export-plugin.h
index b00a45a..4de606f 100644
--- a/src/media-export/rygel-media-export-plugin.h
+++ b/src/media-export/rygel-media-export-plugin.h
@@ -55,7 +55,7 @@ GType
rygel_media_export_plugin_get_type (void) G_GNUC_CONST;
RygelMediaExportPlugin *
-rygel_media_export_plugin_new ();
+rygel_media_export_plugin_new (GError **error);
void
module_init (RygelPluginLoader *loader);
diff --git a/src/media-export/rygel-media-export-root-container.c b/src/media-export/rygel-media-export-root-container.c
index 3c9f60a..3705d21 100644
--- a/src/media-export/rygel-media-export-root-container.c
+++ b/src/media-export/rygel-media-export-root-container.c
@@ -95,13 +95,29 @@ rygel_media_export_root_container_new (void) {
NULL));
}
-RygelMediaContainer *
-rygel_media_export_root_container_get_instance (void) {
+gboolean
+rygel_media_export_root_container_ensure_exists (GError **error) {
if (!rygel_media_export_root_container_instance) {
+ GError *inner_error = NULL;
+
+ rygel_media_export_media_cache_ensure_exists (&inner_error);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ }
rygel_media_export_root_container_instance = RYGEL_MEDIA_CONTAINER (rygel_media_export_root_container_new ());
}
- return rygel_media_export_root_container_instance;
+ return TRUE;
+}
+
+RygelMediaContainer *
+rygel_media_export_root_container_get_instance (void) {
+ if (rygel_media_export_root_container_instance) {
+ return g_object_ref (rygel_media_export_root_container_instance);
+ }
+
+ return NULL;
}
RygelMediaContainer *
diff --git a/src/media-export/rygel-media-export-root-container.h b/src/media-export/rygel-media-export-root-container.h
index 7e4a949..3e765b8 100644
--- a/src/media-export/rygel-media-export-root-container.h
+++ b/src/media-export/rygel-media-export-root-container.h
@@ -54,6 +54,9 @@ struct _RygelMediaExportRootContainerClass {
GType
rygel_media_export_root_container_get_type (void) G_GNUC_CONST;
+gboolean
+rygel_media_export_root_container_ensure_exists (GError **error);
+
RygelMediaContainer *
rygel_media_export_root_container_get_instance (void);
diff --git a/src/media-export/rygel-media-export-video-item.c b/src/media-export/rygel-media-export-video-item.c
index f2939f3..a60ea23 100644
--- a/src/media-export/rygel-media-export-video-item.c
+++ b/src/media-export/rygel-media-export-video-item.c
@@ -63,12 +63,9 @@ static void rygel_media_export_video_item_real_commit (RygelUpdatableObject *bas
/* Do the work that could take a while.
*/
GError *error = NULL;
- RygelMediaExportMediaCache *cache =
- rygel_media_export_media_cache_get_default (&error);
- if (!error) {
- rygel_media_export_media_cache_save_item (cache,
- RYGEL_MEDIA_ITEM (self), &error);
- }
+ RygelMediaExportMediaCache *cache = rygel_media_export_media_cache_get_default ();
+
+ rygel_media_export_media_cache_save_item (cache, RYGEL_MEDIA_ITEM (self), &error);
/* Set any error in the async result, if necessary.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]