[rygel-gst-0-10-plugins] Clean NodeQueryContainer up and fix the "three calls to count_children" issue.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-gst-0-10-plugins] Clean NodeQueryContainer up and fix the "three calls to count_children" issue.
- Date: Thu, 24 Jan 2013 12:32:22 +0000 (UTC)
commit e3fc669b409ce2d0d886a200fa489e5677f1130e
Author: Krzesimir Nowak <krnowak openismus com>
Date: Thu Jan 24 13:20:44 2013 +0100
Clean NodeQueryContainer up and fix the "three calls to count_children" issue.
src/media-export/rygel-media-export-db-container.c | 42 +-
src/media-export/rygel-media-export-db-container.h | 5 +
.../rygel-media-export-leaf-query-container.c | 18 +-
.../rygel-media-export-node-query-container.c | 654 ++++++++------------
.../rygel-media-export-node-query-container.h | 8 +-
.../rygel-media-export-query-container.c | 34 -
.../rygel-media-export-query-container.h | 6 -
7 files changed, 302 insertions(+), 465 deletions(-)
---
diff --git a/src/media-export/rygel-media-export-db-container.c b/src/media-export/rygel-media-export-db-container.c
index 37e21f4..8c553c7 100644
--- a/src/media-export/rygel-media-export-db-container.c
+++ b/src/media-export/rygel-media-export-db-container.c
@@ -57,25 +57,20 @@ enum {
RYGEL_MEDIA_EXPORT_DB_CONTAINER_MEDIA_DB
};
-static void
-rygel_media_export_db_container_count_children (RygelMediaExportDBContainer* self) {
+static gint
+rygel_media_export_db_container_real_count_children (RygelMediaExportDBContainer* self) {
+ const gchar *id = rygel_media_object_get_id (RYGEL_MEDIA_OBJECT (self));
GError *inner_error = NULL;
- gint count;
- const gchar *id;
-
- g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_DB_CONTAINER (self));
-
- id = rygel_media_object_get_id (RYGEL_MEDIA_OBJECT (self));
- count = rygel_media_export_media_cache_get_child_count (self->priv->media_db,
- id,
- &inner_error);
+ gint count = rygel_media_export_media_cache_get_child_count (self->priv->media_db,
+ id,
+ &inner_error);
if (inner_error) {
g_debug ("Could not get child count from database: %s", inner_error->message);
count = 0;
g_error_free (inner_error);
}
- rygel_media_container_set_child_count (RYGEL_MEDIA_CONTAINER (self), count);
+ return count;
}
static void
@@ -102,6 +97,8 @@ rygel_media_export_db_container_constructed (GObject *object)
NULL,
NULL);
+ G_OBJECT_CLASS (rygel_media_export_db_container_parent_class)->constructed (object);
+
rygel_searchable_container_set_search_classes (RYGEL_SEARCHABLE_CONTAINER (self),
classes);
g_object_unref (classes);
@@ -111,7 +108,8 @@ rygel_media_export_db_container_constructed (GObject *object)
G_CALLBACK (on_media_container_updated),
self,
0);
- rygel_media_export_db_container_count_children (self);
+ rygel_media_container_set_child_count (RYGEL_MEDIA_CONTAINER (self),
+ rygel_media_export_db_container_count_children (self));
}
RygelMediaExportDBContainer *
@@ -451,6 +449,7 @@ rygel_media_export_db_container_class_init (RygelMediaExportDBContainerClass *db
GObjectClass *object_class = G_OBJECT_CLASS (db_container_class);
RygelMediaContainerClass *media_container_class = RYGEL_MEDIA_CONTAINER_CLASS (db_container_class);
+ db_container_class->count_children = rygel_media_export_db_container_real_count_children;
media_container_class->get_children = rygel_media_export_db_container_real_get_children;
media_container_class->get_children_finish = rygel_media_export_db_container_real_get_children_finish;
media_container_class->find_object = rygel_media_export_db_container_real_find_object;
@@ -500,9 +499,22 @@ rygel_media_export_db_container_init (RygelMediaExportDBContainer *self) {
}
RygelMediaExportMediaCache *
-rygel_media_export_db_container_get_media_db (RygelMediaExportDBContainer *self)
-{
+rygel_media_export_db_container_get_media_db (RygelMediaExportDBContainer *self) {
g_return_val_if_fail (RYGEL_MEDIA_EXPORT_IS_DB_CONTAINER (self), NULL);
return self->priv->media_db;
}
+
+gint
+rygel_media_export_db_container_count_children (RygelMediaExportDBContainer *self) {
+ RygelMediaExportDBContainerClass *db_container_class;
+
+ g_return_val_if_fail (RYGEL_MEDIA_EXPORT_IS_DB_CONTAINER (self), 0);
+
+ db_container_class = RYGEL_MEDIA_EXPORT_DB_CONTAINER_GET_CLASS (self);
+
+ g_return_val_if_fail (db_container_class != NULL, 0);
+ g_return_val_if_fail (db_container_class->count_children != NULL, 0);
+
+ return db_container_class->count_children (self);
+}
diff --git a/src/media-export/rygel-media-export-db-container.h b/src/media-export/rygel-media-export-db-container.h
index b7f06ca..26b5953 100644
--- a/src/media-export/rygel-media-export-db-container.h
+++ b/src/media-export/rygel-media-export-db-container.h
@@ -47,6 +47,8 @@ struct _RygelMediaExportDBContainer {
struct _RygelMediaExportDBContainerClass {
RygelMediaContainerClass parent_class;
+
+ gint (* count_children) (RygelMediaExportDBContainer *container);
};
GType
@@ -59,6 +61,9 @@ rygel_media_export_db_container_new (const gchar *id,
RygelMediaExportMediaCache *
rygel_media_export_db_container_get_media_db (RygelMediaExportDBContainer *self);
+gint
+rygel_media_export_db_container_count_children (RygelMediaExportDBContainer *self);
+
G_END_DECLS
#endif /* __RYGEL_0_10_PLUGINS_MEDIA_EXPORT_DB_CONTAINER_H__ */
diff --git a/src/media-export/rygel-media-export-leaf-query-container.c b/src/media-export/rygel-media-export-leaf-query-container.c
index 14bcd37..a418a3b 100644
--- a/src/media-export/rygel-media-export-leaf-query-container.c
+++ b/src/media-export/rygel-media-export-leaf-query-container.c
@@ -108,20 +108,18 @@ rygel_media_export_leaf_query_container_real_get_children_finish (RygelMediaCont
}
static gint
-rygel_media_export_leaf_query_container_real_count_children (RygelMediaExportQueryContainer *base,
- GError **error) {
- GError *inner_error = NULL;
- RygelMediaExportDBContainer *db_container = RYGEL_MEDIA_EXPORT_DB_CONTAINER (base);
+rygel_media_export_leaf_query_container_real_count_children (RygelMediaExportDBContainer *base) {
+ GError *error = NULL;
RygelMediaExportQueryContainer *query_container = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER (base);
- RygelMediaExportMediaCache *cache = rygel_media_export_db_container_get_media_db (db_container);
+ RygelMediaExportMediaCache *cache = rygel_media_export_db_container_get_media_db (base);
RygelSearchExpression *expression = rygel_media_export_query_container_get_expression (query_container);
gint result = (gint) rygel_media_export_media_cache_get_object_count_by_search_expression (cache,
expression,
NULL,
- &inner_error);
+ &error);
- if (inner_error) {
- g_propagate_error (error, inner_error);
+ if (error) {
+ g_error_free (error);
return 0;
}
@@ -131,11 +129,11 @@ rygel_media_export_leaf_query_container_real_count_children (RygelMediaExportQue
static void
rygel_media_export_leaf_query_container_class_init (RygelMediaExportLeafQueryContainerClass *leaf_class) {
RygelMediaContainerClass *container_class = RYGEL_MEDIA_CONTAINER_CLASS (leaf_class);
- RygelMediaExportQueryContainerClass *query_class = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_CLASS (leaf_class);
+ RygelMediaExportDBContainerClass *db_container_class = RYGEL_MEDIA_EXPORT_DB_CONTAINER_CLASS (leaf_class);
container_class->get_children = rygel_media_export_leaf_query_container_real_get_children;
container_class->get_children_finish = rygel_media_export_leaf_query_container_real_get_children_finish;
- query_class->count_children = rygel_media_export_leaf_query_container_real_count_children;
+ db_container_class->count_children = rygel_media_export_leaf_query_container_real_count_children;
}
static void
diff --git a/src/media-export/rygel-media-export-node-query-container.c b/src/media-export/rygel-media-export-node-query-container.c
index d1f372a..66f72d5 100644
--- a/src/media-export/rygel-media-export-node-query-container.c
+++ b/src/media-export/rygel-media-export-node-query-container.c
@@ -22,8 +22,8 @@
#include "rygel-media-export-query-container-factory.h"
G_DEFINE_TYPE (RygelMediaExportNodeQueryContainer,
- rygel_media_export_node_query_container,
- RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER)
+ rygel_media_export_node_query_container,
+ RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER)
typedef struct _RygelMediaExportNodeQueryContainerGetChildrenData RygelMediaExportNodeQueryContainerGetChildrenData;
@@ -32,433 +32,295 @@ struct _RygelMediaExportNodeQueryContainerPrivate {
gchar *attribute;
};
-struct _RygelMediaExportNodeQueryContainerGetChildrenData {
- int _state_;
- GObject* _source_object_;
- GAsyncResult* _res_;
- GSimpleAsyncResult* _async_result;
- RygelMediaExportNodeQueryContainer* self;
- guint offset;
- guint max_count;
- gchar* sort_criteria;
- GCancellable* cancellable;
- RygelMediaObjects* result;
- RygelMediaObjects* _tmp0_;
- RygelMediaObjects* children;
- RygelMediaExportMediaCache* _tmp1_;
- const gchar* _tmp2_;
- RygelSearchExpression* _tmp3_;
- guint _tmp4_;
- guint _tmp5_;
- GeeList* _tmp6_;
- GeeList* data;
- GeeList* _tmp7_;
- GeeList* _meta_data_list;
- GeeList* _tmp8_;
- gint _tmp9_;
- gint _tmp10_;
- gint _meta_data_size;
- gint _meta_data_index;
- gint _tmp11_;
- gint _tmp12_;
- gint _tmp13_;
- GeeList* _tmp14_;
- gint _tmp15_;
- gpointer _tmp16_;
- gchar* meta_data;
- const gchar* _tmp17_;
- gchar* _tmp18_;
- gchar* new_id;
- const gchar* _tmp19_;
- const gchar* _tmp20_;
- gchar* _tmp21_;
- RygelMediaExportQueryContainerFactory* _tmp22_;
- RygelMediaExportQueryContainerFactory* factory;
- RygelMediaExportQueryContainerFactory* _tmp23_;
- RygelMediaExportMediaCache* _tmp24_;
- const gchar* _tmp25_;
- const gchar* _tmp26_;
- RygelMediaExportQueryContainer* _tmp27_;
- RygelMediaExportQueryContainer* container;
- RygelMediaExportQueryContainer* _tmp28_;
- RygelMediaExportQueryContainer* _tmp29_;
- GError * _inner_error_;
-};
-
-
#define RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), \
- RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, \
- RygelMediaExportNodeQueryContainerPrivate))
+ RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, \
+ RygelMediaExportNodeQueryContainerPrivate))
enum {
RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_DUMMY_PROPERTY,
RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_TEMPLATE,
RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_ATTRIBUTE
};
-static void rygel_media_export_node_query_container_real_get_children_data_free (gpointer _data);
-static void rygel_media_export_node_query_container_real_get_children (RygelMediaContainer* base, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
-static gboolean rygel_media_export_node_query_container_real_get_children_co (RygelMediaExportNodeQueryContainerGetChildrenData* _data_);
-static gint rygel_media_export_node_query_container_real_count_children (RygelMediaExportQueryContainer* base, GError** error);
-static void rygel_media_export_node_query_container_finalize (GObject* obj);
-
-static
-RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_construct (GType object_type, RygelSearchExpression* expression, const gchar* id, const gchar* name, const gchar* template, const gchar* attribute) {
- RygelMediaExportNodeQueryContainer * self = NULL;
- RygelSearchExpression* _tmp1_;
- const gchar* _tmp2_;
- const gchar* _tmp3_;
- const gchar* _tmp4_;
- gchar* _tmp5_;
- const gchar* _tmp6_;
- gchar* _tmp7_;
- GError * _inner_error_ = NULL;
- g_return_val_if_fail (expression != NULL, NULL);
- g_return_val_if_fail (id != NULL, NULL);
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (template != NULL, NULL);
- g_return_val_if_fail (attribute != NULL, NULL);
- _tmp1_ = expression;
- _tmp2_ = id;
- _tmp3_ = name;
- self = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (g_object_new (object_type,
- "expression", _tmp1_,
- "id", _tmp2_,
- "title", _tmp3_,
- "parent", NULL,
- "child-count", 0,
- NULL));
- _tmp4_ = template;
- _tmp5_ = g_strdup (_tmp4_);
- g_free (self->priv->template);
- self->priv->template = _tmp5_;
- _tmp6_ = attribute;
- _tmp7_ = g_strdup (_tmp6_);
- g_free (self->priv->attribute);
- self->priv->attribute = _tmp7_;
- {
- gint _tmp8_ = 0;
- gint _tmp9_;
- _tmp8_ = rygel_media_export_query_container_count_children ((RygelMediaExportQueryContainer*) self, &_inner_error_);
- _tmp9_ = _tmp8_;
- if (_inner_error_ != NULL) {
- goto __catch41_g_error;
- }
- rygel_media_container_set_child_count ((RygelMediaContainer*) self, _tmp9_);
- }
- goto __finally41;
- __catch41_g_error:
- {
- GError* _error_ = NULL;
- _error_ = _inner_error_;
- _inner_error_ = NULL;
- g_error_free (_error_);
- }
- __finally41:
- if (_inner_error_ != NULL) {
- g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
- g_clear_error (&_inner_error_);
- return NULL;
- }
- return self;
-}
+RygelMediaExportNodeQueryContainer *
+rygel_media_export_node_query_container_new (RygelSearchExpression *expression,
+ const gchar *id,
+ const gchar *name,
+ const gchar *template,
+ const gchar *attribute) {
+ g_return_val_if_fail (RYGEL_IS_SEARCH_EXPRESSION (expression), NULL);
+ g_return_val_if_fail (id != NULL, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (template != NULL, NULL);
+ g_return_val_if_fail (attribute != NULL, NULL);
-RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_new (RygelSearchExpression* expression, const gchar* id, const gchar* name, const gchar* template, const gchar* attribute) {
- return rygel_media_export_node_query_container_construct (RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, expression, id, name, template, attribute);
+ return RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (g_object_new (RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER,
+ "expression", expression,
+ "id", id,
+ "title", name,
+ "parent", NULL,
+ "child-count", 0,
+ "template", template,
+ "attribute", attribute,
+ NULL));
}
+static gchar*
+string_replace (const gchar *self,
+ const gchar *old,
+ const gchar *replacement,
+ GError **error) {
+ gchar* result;
+ gchar *escaped;
+ GError *inner_error;
+ GRegex *regex;
+
+ g_return_val_if_fail (self != NULL, NULL);
+ g_return_val_if_fail (old != NULL, NULL);
+ g_return_val_if_fail (replacement != NULL, NULL);
+
+ result = NULL;
+ escaped = g_regex_escape_string (old, -1);
+ inner_error = NULL;
+ regex = g_regex_new (escaped, 0, 0, &inner_error);
+ g_free (escaped);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ } else {
+ result = g_regex_replace_literal (regex, self, -1, 0, replacement, 0, &inner_error);
-static void rygel_media_export_node_query_container_real_get_children_data_free (gpointer _data) {
- RygelMediaExportNodeQueryContainerGetChildrenData* _data_;
- _data_ = _data;
- g_free (_data_->sort_criteria);
- g_object_unref (_data_->cancellable);
- g_object_unref (_data_->result);
- g_object_unref (_data_->self);
- g_slice_free (RygelMediaExportNodeQueryContainerGetChildrenData, _data_);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ }
+ g_regex_unref (regex);
+ }
+
+ return result;
}
-static void rygel_media_export_node_query_container_real_get_children (RygelMediaContainer* base, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
- RygelMediaExportNodeQueryContainer * self;
- RygelMediaExportNodeQueryContainerGetChildrenData* _data_;
- RygelMediaExportNodeQueryContainer* _tmp0_;
- guint _tmp1_;
- guint _tmp2_;
- const gchar* _tmp3_;
- gchar* _tmp4_;
- GCancellable* _tmp5_;
- GCancellable* _tmp6_;
- self = (RygelMediaExportNodeQueryContainer*) base;
- _data_ = g_slice_new0 (RygelMediaExportNodeQueryContainerGetChildrenData);
- _data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_media_export_node_query_container_real_get_children);
- g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_media_export_node_query_container_real_get_children_data_free);
- _tmp0_ = g_object_ref (self);
- _data_->self = _tmp0_;
- _tmp1_ = offset;
- _data_->offset = _tmp1_;
- _tmp2_ = max_count;
- _data_->max_count = _tmp2_;
- _tmp3_ = sort_criteria;
- _tmp4_ = g_strdup (_tmp3_);
- g_free (_data_->sort_criteria);
- _data_->sort_criteria = _tmp4_;
- _tmp5_ = cancellable;
- _tmp6_ = g_object_ref (_tmp5_);
- g_object_unref (_data_->cancellable);
- _data_->cancellable = _tmp6_;
- rygel_media_export_node_query_container_real_get_children_co (_data_);
+static void
+rygel_media_export_node_query_container_real_get_children (RygelMediaContainer *base,
+ guint offset,
+ guint max_count,
+ const gchar *sort_criteria G_GNUC_UNUSED,
+ GCancellable *cancellable G_GNUC_UNUSED,
+ GAsyncReadyCallback callback,
+ gpointer user_data) {
+ RygelMediaExportNodeQueryContainer *self = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (base);
+ RygelMediaExportNodeQueryContainerPrivate *priv = self->priv;
+ RygelMediaExportMediaCache *cache = rygel_media_export_db_container_get_media_db (RYGEL_MEDIA_EXPORT_DB_CONTAINER (base));
+ RygelSearchExpression *expression = rygel_media_export_query_container_get_expression (RYGEL_MEDIA_EXPORT_QUERY_CONTAINER (base));
+ GError *error = NULL;
+ GeeList *data = rygel_media_export_media_cache_get_object_attribute_by_search_expression (cache,
+ priv->attribute,
+ expression,
+ (glong) offset,
+ max_count,
+ &error);
+ GSimpleAsyncResult *simple;
+
+ if (error) {
+ simple = g_simple_async_result_new_take_error (G_OBJECT (base),
+ callback,
+ user_data,
+ error);
+ } else {
+ RygelMediaObjects *objects = rygel_media_objects_new ();
+ gint collection_size = gee_collection_get_size (GEE_COLLECTION (data));
+ RygelMediaExportQueryContainerFactory *factory = rygel_media_export_query_container_factory_get_default ();
+ gint iter;
+
+ for (iter = 0; iter < collection_size; ++iter) {
+ gchar *meta_data = gee_list_get (data, iter);
+ gchar *tmp_id = g_uri_escape_string (meta_data, "", TRUE);
+ gchar *new_id = string_replace (priv->template, "%s", tmp_id, &error);
+
+ if (error) {
+ g_warning ("Failed to replace a %%s placeholder in template (%s) with an id (%s): %s",
+ priv->template,
+ tmp_id,
+ error->message);
+ g_error_free (error);
+ error = NULL;
+ } else {
+ RygelMediaExportQueryContainer *container = rygel_media_export_query_container_factory_create_from_description (factory,
+ cache,
+ new_id,
+ meta_data);
+ RygelMediaObject *object = RYGEL_MEDIA_OBJECT (container);
+
+ rygel_media_object_set_parent (object, base);
+ gee_abstract_collection_add (GEE_ABSTRACT_COLLECTION (objects), object);
+ g_object_unref (container);
+ g_free (new_id);
+ }
+ g_free (tmp_id);
+ g_free (meta_data);
+ }
+ g_object_unref (factory);
+ g_object_unref (data);
+
+ simple = g_simple_async_result_new (G_OBJECT (base),
+ callback,
+ user_data,
+ rygel_media_export_node_query_container_real_get_children);
+ g_simple_async_result_set_op_res_gpointer (simple,
+ objects,
+ g_object_unref);
+ }
+ g_simple_async_result_complete_in_idle (simple);
+ g_object_unref (simple);
}
-static RygelMediaObjects* rygel_media_export_node_query_container_real_get_children_finish (RygelMediaContainer* base G_GNUC_UNUSED, GAsyncResult* _res_, GError** error) {
- RygelMediaObjects* result;
- RygelMediaExportNodeQueryContainerGetChildrenData* _data_;
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
- return NULL;
- }
- _data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
- result = _data_->result;
- _data_->result = NULL;
- return result;
+static RygelMediaObjects *
+rygel_media_export_node_query_container_real_get_children_finish (RygelMediaContainer *base G_GNUC_UNUSED,
+ GAsyncResult *res,
+ GError **error) {
+ RygelMediaObjects* result;
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
+
+ if (g_simple_async_result_propagate_error (simple, error)) {
+ return NULL;
+ }
+ result = RYGEL_MEDIA_OBJECTS (g_simple_async_result_get_op_res_gpointer (simple));
+
+ if (result) {
+ g_object_ref (result);
+ }
+
+ return result;
}
+static gint
+rygel_media_export_node_query_container_real_count_children (RygelMediaExportDBContainer *base) {
+ RygelMediaExportNodeQueryContainer *self = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (base);
+ RygelMediaExportNodeQueryContainerPrivate *priv = self->priv;
+ RygelMediaExportQueryContainer *query_container = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER (base);
+ RygelSearchExpression *expression = rygel_media_export_query_container_get_expression (query_container);
+ RygelMediaExportMediaCache *cache = rygel_media_export_db_container_get_media_db (base);
+ GError *error = NULL;
+ GeeList *data = rygel_media_export_media_cache_get_object_attribute_by_search_expression (cache,
+ priv->attribute,
+ expression,
+ 0,
+ -1,
+ &error);
+ gint count;
-static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
- gchar* result = NULL;
- GError * _inner_error_ = NULL;
- g_return_val_if_fail (self != NULL, NULL);
- g_return_val_if_fail (old != NULL, NULL);
- g_return_val_if_fail (replacement != NULL, NULL);
- {
- const gchar* _tmp0_;
- gchar* _tmp1_ = NULL;
- gchar* _tmp2_;
- GRegex* _tmp3_;
- GRegex* _tmp4_;
- GRegex* regex;
- GRegex* _tmp5_;
- const gchar* _tmp6_;
- gchar* _tmp7_ = NULL;
- gchar* _tmp8_;
- _tmp0_ = old;
- _tmp1_ = g_regex_escape_string (_tmp0_, -1);
- _tmp2_ = _tmp1_;
- _tmp3_ = g_regex_new (_tmp2_, 0, 0, &_inner_error_);
- _tmp4_ = _tmp3_;
- g_free (_tmp2_);
- regex = _tmp4_;
- if (_inner_error_ != NULL) {
- if (_inner_error_->domain == G_REGEX_ERROR) {
- goto __catch42_g_regex_error;
- }
- g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
- g_clear_error (&_inner_error_);
- return NULL;
- }
- _tmp5_ = regex;
- _tmp6_ = replacement;
- _tmp7_ = g_regex_replace_literal (_tmp5_, self, (gssize) (-1), 0, _tmp6_, 0, &_inner_error_);
- _tmp8_ = _tmp7_;
- if (_inner_error_ != NULL) {
- g_regex_unref (regex);
- if (_inner_error_->domain == G_REGEX_ERROR) {
- goto __catch42_g_regex_error;
- }
- g_regex_unref (regex);
- g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
- g_clear_error (&_inner_error_);
- return NULL;
- }
- result = _tmp8_;
- g_regex_unref (regex);
- return result;
- }
- goto __finally42;
- __catch42_g_regex_error:
- {
- GError* e = NULL;
- e = _inner_error_;
- _inner_error_ = NULL;
- g_assert_not_reached ();
- g_error_free (e);
- }
- __finally42:
- if (_inner_error_ != NULL) {
- g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
- g_clear_error (&_inner_error_);
- return NULL;
- }
+ if (error) {
+ g_error_free (error);
+ return 0;
+ }
+
+ count = gee_collection_get_size (GEE_COLLECTION (data));
+ g_object_unref (data);
+
+ return count;
}
+static void
+rygel_media_export_node_query_container_finalize (GObject *object) {
+ RygelMediaExportNodeQueryContainer *self = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (object);
+ RygelMediaExportNodeQueryContainerPrivate *priv = self->priv;
+
+ g_free (priv->template);
+ g_free (priv->attribute);
-static gboolean rygel_media_export_node_query_container_real_get_children_co (RygelMediaExportNodeQueryContainerGetChildrenData* _data_) {
- switch (_data_->_state_) {
- case 0:
- goto _state_0;
- default:
- g_assert_not_reached ();
- }
- _state_0:
- _data_->_tmp0_ = rygel_media_objects_new ();
- _data_->children = _data_->_tmp0_;
- _data_->_tmp1_ = rygel_media_export_db_container_get_media_db (RYGEL_MEDIA_EXPORT_DB_CONTAINER (_data_->self));
- _data_->_tmp2_ = _data_->self->priv->attribute;
- _data_->_tmp3_ = rygel_media_export_query_container_get_expression ((RygelMediaExportQueryContainer*) _data_->self);
- _data_->_tmp4_ = _data_->offset;
- _data_->_tmp5_ = _data_->max_count;
- _data_->_tmp6_ = NULL;
- _data_->_tmp6_ = rygel_media_export_media_cache_get_object_attribute_by_search_expression (_data_->_tmp1_, _data_->_tmp2_, _data_->_tmp3_, (glong) _data_->_tmp4_, _data_->_tmp5_, &_data_->_inner_error_);
- _data_->data = _data_->_tmp6_;
- if (_data_->_inner_error_ != NULL) {
- g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
- g_error_free (_data_->_inner_error_);
- g_object_unref (_data_->children);
- if (_data_->_state_ == 0) {
- g_simple_async_result_complete_in_idle (_data_->_async_result);
- } else {
- g_simple_async_result_complete (_data_->_async_result);
- }
- g_object_unref (_data_->_async_result);
- return FALSE;
- }
- {
- _data_->_tmp7_ = g_object_ref (_data_->data);
- _data_->_meta_data_list = _data_->_tmp7_;
- _data_->_tmp8_ = _data_->_meta_data_list;
- _data_->_tmp9_ = gee_collection_get_size ((GeeCollection*) _data_->_tmp8_);
- _data_->_tmp10_ = _data_->_tmp9_;
- _data_->_meta_data_size = _data_->_tmp10_;
- _data_->_meta_data_index = -1;
- while (TRUE) {
- _data_->_tmp11_ = _data_->_meta_data_index;
- _data_->_meta_data_index = _data_->_tmp11_ + 1;
- _data_->_tmp12_ = _data_->_meta_data_index;
- _data_->_tmp13_ = _data_->_meta_data_size;
- if (!(_data_->_tmp12_ < _data_->_tmp13_)) {
- break;
- }
- _data_->_tmp14_ = _data_->_meta_data_list;
- _data_->_tmp15_ = _data_->_meta_data_index;
- _data_->_tmp16_ = NULL;
- _data_->_tmp16_ = gee_list_get (_data_->_tmp14_, _data_->_tmp15_);
- _data_->meta_data = (gchar*) _data_->_tmp16_;
- _data_->_tmp17_ = _data_->meta_data;
- _data_->_tmp18_ = NULL;
- _data_->_tmp18_ = g_uri_escape_string (_data_->_tmp17_, "", TRUE);
- _data_->new_id = _data_->_tmp18_;
- _data_->_tmp19_ = _data_->self->priv->template;
- _data_->_tmp20_ = _data_->new_id;
- _data_->_tmp21_ = NULL;
- _data_->_tmp21_ = string_replace (_data_->_tmp19_, "%s", _data_->_tmp20_);
- g_free (_data_->new_id);
- _data_->new_id = _data_->_tmp21_;
- _data_->_tmp22_ = NULL;
- _data_->_tmp22_ = rygel_media_export_query_container_factory_get_default ();
- _data_->factory = _data_->_tmp22_;
- _data_->_tmp23_ = _data_->factory;
- _data_->_tmp24_ = rygel_media_export_db_container_get_media_db (RYGEL_MEDIA_EXPORT_DB_CONTAINER (_data_->self));
- _data_->_tmp25_ = _data_->new_id;
- _data_->_tmp26_ = _data_->meta_data;
- _data_->_tmp27_ = NULL;
- _data_->_tmp27_ = rygel_media_export_query_container_factory_create_from_description (_data_->_tmp23_, _data_->_tmp24_, _data_->_tmp25_, _data_->_tmp26_);
- _data_->container = _data_->_tmp27_;
- _data_->_tmp28_ = _data_->container;
- rygel_media_object_set_parent ((RygelMediaObject*) _data_->_tmp28_, (RygelMediaContainer*) _data_->self);
- _data_->_tmp29_ = _data_->container;
- gee_abstract_collection_add ((GeeAbstractCollection*) _data_->children, (RygelMediaObject*) _data_->_tmp29_);
- g_object_unref (_data_->container);
- g_object_unref (_data_->factory);
- g_free (_data_->new_id);
- g_free (_data_->meta_data);
- }
- g_object_unref (_data_->_meta_data_list);
- }
- _data_->result = _data_->children;
- g_object_unref (_data_->data);
- if (_data_->_state_ == 0) {
- g_simple_async_result_complete_in_idle (_data_->_async_result);
- } else {
- g_simple_async_result_complete (_data_->_async_result);
- }
- g_object_unref (_data_->_async_result);
- return FALSE;
- g_object_unref (_data_->data);
- g_object_unref (_data_->children);
- if (_data_->_state_ == 0) {
- g_simple_async_result_complete_in_idle (_data_->_async_result);
- } else {
- g_simple_async_result_complete (_data_->_async_result);
- }
- g_object_unref (_data_->_async_result);
- return FALSE;
+ G_OBJECT_CLASS (rygel_media_export_node_query_container_parent_class)->finalize (object);
}
+static void
+rygel_media_export_node_query_container_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec) {
+ RygelMediaExportNodeQueryContainer *self = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (object);
+ RygelMediaExportNodeQueryContainerPrivate *priv = self->priv;
-static gint rygel_media_export_node_query_container_real_count_children (RygelMediaExportQueryContainer* base, GError** error) {
- RygelMediaExportNodeQueryContainer * self;
- gint result = 0;
- gboolean _tmp0_ = FALSE;
- const gchar* _tmp1_;
- gboolean _tmp3_;
- RygelMediaExportMediaCache* _tmp4_;
- const gchar* _tmp5_;
- RygelSearchExpression* _tmp6_;
- GeeList* _tmp7_ = NULL;
- GeeList* data;
- GeeList* _tmp8_;
- gint _tmp9_;
- gint _tmp10_;
- GError * _inner_error_ = NULL;
- self = (RygelMediaExportNodeQueryContainer*) base;
- _tmp1_ = self->priv->attribute;
- if (_tmp1_ == NULL) {
- _tmp0_ = TRUE;
- } else {
- RygelSearchExpression* _tmp2_;
- _tmp2_ = rygel_media_export_query_container_get_expression ((RygelMediaExportQueryContainer*) self);
- _tmp0_ = _tmp2_ == NULL;
- }
- _tmp3_ = _tmp0_;
- if (_tmp3_) {
- result = 0;
- return result;
- }
- _tmp4_ = rygel_media_export_db_container_get_media_db (RYGEL_MEDIA_EXPORT_DB_CONTAINER (self));
- _tmp5_ = self->priv->attribute;
- _tmp6_ = rygel_media_export_query_container_get_expression ((RygelMediaExportQueryContainer*) self);
- _tmp7_ = rygel_media_export_media_cache_get_object_attribute_by_search_expression (_tmp4_, _tmp5_, _tmp6_, (glong) 0, (guint) (-1), &_inner_error_);
- data = _tmp7_;
- if (_inner_error_ != NULL) {
- g_propagate_error (error, _inner_error_);
- return 0;
- }
- _tmp8_ = data;
- _tmp9_ = gee_collection_get_size ((GeeCollection*) _tmp8_);
- _tmp10_ = _tmp9_;
- result = _tmp10_;
- g_object_unref (data);
- return result;
+ switch (property_id) {
+ case RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_TEMPLATE:
+ g_value_set_string (value, priv->template);
+ break;
+
+ case RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_ATTRIBUTE:
+ g_value_set_string (value, priv->attribute);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
}
+static void
+rygel_media_export_node_query_container_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec) {
+ RygelMediaExportNodeQueryContainer *self = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (object);
+ RygelMediaExportNodeQueryContainerPrivate *priv = self->priv;
+
+ switch (property_id) {
+ case RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_TEMPLATE:
+ /* construct-only property */
+ priv->template = g_value_dup_string (value);
+ break;
-static void rygel_media_export_node_query_container_class_init (RygelMediaExportNodeQueryContainerClass * klass) {
- g_type_class_add_private (klass, sizeof (RygelMediaExportNodeQueryContainerPrivate));
- RYGEL_MEDIA_CONTAINER_CLASS (klass)->get_children = rygel_media_export_node_query_container_real_get_children;
- RYGEL_MEDIA_CONTAINER_CLASS (klass)->get_children_finish = rygel_media_export_node_query_container_real_get_children_finish;
- RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_CLASS (klass)->count_children = rygel_media_export_node_query_container_real_count_children;
- G_OBJECT_CLASS (klass)->finalize = rygel_media_export_node_query_container_finalize;
+ case RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_ATTRIBUTE:
+ /* construct-only property */
+ priv->attribute = g_value_dup_string (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
}
+static void
+rygel_media_export_node_query_container_class_init (RygelMediaExportNodeQueryContainerClass *node_query_container_class) {
+ GObjectClass *object_class = G_OBJECT_CLASS (node_query_container_class);
+ RygelMediaContainerClass *container_class = RYGEL_MEDIA_CONTAINER_CLASS (node_query_container_class);
+ RygelMediaExportDBContainerClass *db_container_class = RYGEL_MEDIA_EXPORT_DB_CONTAINER_CLASS (node_query_container_class);
+
+ container_class->get_children = rygel_media_export_node_query_container_real_get_children;
+ container_class->get_children_finish = rygel_media_export_node_query_container_real_get_children_finish;
+ db_container_class->count_children = rygel_media_export_node_query_container_real_count_children;
+ object_class->finalize = rygel_media_export_node_query_container_finalize;
+ object_class->get_property = rygel_media_export_node_query_container_get_property;
+ object_class->set_property = rygel_media_export_node_query_container_set_property;
+
+ g_object_class_install_property (object_class,
+ RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_TEMPLATE,
+ g_param_spec_string ("template",
+ "template",
+ "template",
+ NULL,
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_ATTRIBUTE,
+ g_param_spec_string ("attribute",
+ "attribute",
+ "attribute",
+ NULL,
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
-static void rygel_media_export_node_query_container_init (RygelMediaExportNodeQueryContainer * self) {
- self->priv = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_GET_PRIVATE (self);
+ g_type_class_add_private (node_query_container_class,
+ sizeof (RygelMediaExportNodeQueryContainerPrivate));
}
-static void rygel_media_export_node_query_container_finalize (GObject* obj) {
- RygelMediaExportNodeQueryContainer * self;
- self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, RygelMediaExportNodeQueryContainer);
- g_free (self->priv->template);
- g_free (self->priv->attribute);
- G_OBJECT_CLASS (rygel_media_export_node_query_container_parent_class)->finalize (obj);
+static void rygel_media_export_node_query_container_init (RygelMediaExportNodeQueryContainer *self) {
+ self->priv = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_GET_PRIVATE (self);
}
diff --git a/src/media-export/rygel-media-export-node-query-container.h b/src/media-export/rygel-media-export-node-query-container.h
index 4ba219f..9e2d8c0 100644
--- a/src/media-export/rygel-media-export-node-query-container.h
+++ b/src/media-export/rygel-media-export-node-query-container.h
@@ -53,10 +53,10 @@ rygel_media_export_node_query_container_get_type (void) G_GNUC_CONST;
RygelMediaExportNodeQueryContainer *
rygel_media_export_node_query_container_new (RygelSearchExpression *expression,
- const gchar *id,
- const gchar *name,
- const gchar *template,
- const gchar *attribute);
+ const gchar *id,
+ const gchar *name,
+ const gchar *template,
+ const gchar *attribute);
G_END_DECLS
diff --git a/src/media-export/rygel-media-export-query-container.c b/src/media-export/rygel-media-export-query-container.c
index 7ca5064..4c3a0a1 100644
--- a/src/media-export/rygel-media-export-query-container.c
+++ b/src/media-export/rygel-media-export-query-container.c
@@ -53,22 +53,6 @@ enum {
};
static void
-rygel_media_export_query_container_constructed (GObject *object)
-{
- RygelMediaExportQueryContainer *self = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER (object);
- gint child_count;
- GError *error = NULL;
-
- G_OBJECT_CLASS (rygel_media_export_query_container_parent_class)->constructed (object);
- child_count = rygel_media_export_query_container_count_children (self, &error);
- if (error) {
- g_error_free (error);
- child_count = 0;
- }
- rygel_media_container_set_child_count (RYGEL_MEDIA_CONTAINER (self), child_count);
-}
-
-static void
rygel_media_export_query_container_real_search_data_free (gpointer user_data) {
RygelMediaExportQueryContainerSearchData *data = (RygelMediaExportQueryContainerSearchData *) user_data;
@@ -170,22 +154,6 @@ rygel_media_export_query_container_real_search_finish (RygelSearchableContainer
return result;
}
-static gint
-rygel_media_export_query_container_real_count_children (RygelMediaExportQueryContainer* self, GError** error G_GNUC_UNUSED) {
- g_critical ("Type `%s' does not implement abstract method `rygel_media_export_query_container_count_children'",
- g_type_name (G_TYPE_FROM_INSTANCE (self)));
- return 0;
-}
-
-
-gint
-rygel_media_export_query_container_count_children (RygelMediaExportQueryContainer* self,
- GError** error) {
- g_return_val_if_fail (RYGEL_MEDIA_EXPORT_IS_QUERY_CONTAINER (self), 0);
-
- return RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_GET_CLASS (self)->count_children (self, error);
-}
-
static void rygel_media_export_query_container_dispose (GObject *object) {
RygelMediaExportQueryContainer *self = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER (object);
RygelMediaExportQueryContainerPrivate *priv = self->priv;
@@ -243,9 +211,7 @@ static void
rygel_media_export_query_container_class_init (RygelMediaExportQueryContainerClass *query_container_class) {
GObjectClass *object_class = G_OBJECT_CLASS (query_container_class);
- query_container_class->count_children = rygel_media_export_query_container_real_count_children;
object_class->dispose = rygel_media_export_query_container_dispose;
- object_class->constructed = rygel_media_export_query_container_constructed;
object_class->set_property = rygel_media_export_query_container_set_property;
object_class->get_property = rygel_media_export_query_container_get_property;
diff --git a/src/media-export/rygel-media-export-query-container.h b/src/media-export/rygel-media-export-query-container.h
index 410c802..bf1134b 100644
--- a/src/media-export/rygel-media-export-query-container.h
+++ b/src/media-export/rygel-media-export-query-container.h
@@ -49,17 +49,11 @@ struct _RygelMediaExportQueryContainer {
struct _RygelMediaExportQueryContainerClass {
RygelMediaExportDBContainerClass parent_class;
- gint (* count_children) (RygelMediaExportQueryContainer *self,
- GError **error);
};
GType
rygel_media_export_query_container_get_type (void) G_GNUC_CONST;
-gint
-rygel_media_export_query_container_count_children (RygelMediaExportQueryContainer *self,
- GError **error);
-
RygelSearchExpression *
rygel_media_export_query_container_get_expression (RygelMediaExportQueryContainer *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]