[rygel-gst-0-10-plugins] Cleanup RygelMediaExportPhotoItem



commit df398964c2715c438c4c68aa87e5273d220fd7f5
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Jan 30 11:53:00 2013 +0100

    Cleanup RygelMediaExportPhotoItem

 src/media-export/rygel-media-export-photo-item.c |  183 ++++++++--------------
 src/media-export/rygel-media-export-video-item.c |   15 --
 2 files changed, 63 insertions(+), 135 deletions(-)
---
diff --git a/src/media-export/rygel-media-export-photo-item.c b/src/media-export/rygel-media-export-photo-item.c
index c112954..3a6ca81 100644
--- a/src/media-export/rygel-media-export-photo-item.c
+++ b/src/media-export/rygel-media-export-photo-item.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Jens Georg <jensg openismus com>
  *
@@ -23,141 +23,84 @@
 #include "rygel-media-export-photo-item.h"
 #include "rygel-media-export-media-cache.h"
 
-static void rygel_media_export_photo_item_rygel_updatable_object_interface_init (RygelUpdatableObjectIface * iface);
+static void rygel_media_export_photo_item_rygel_updatable_object_interface_init (RygelUpdatableObjectIface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (RygelMediaExportPhotoItem, rygel_media_export_photo_item, RYGEL_TYPE_PHOTO_ITEM,
   G_IMPLEMENT_INTERFACE (RYGEL_TYPE_UPDATABLE_OBJECT, rygel_media_export_photo_item_rygel_updatable_object_interface_init))
 
-typedef struct _RygelMediaExportPhotoItemCommitData RygelMediaExportPhotoItemCommitData;
-
-struct _RygelMediaExportPhotoItemCommitData {
-	int _state_;
-	GObject* _source_object_;
-	GAsyncResult* _res_;
-	GSimpleAsyncResult* _async_result;
-	RygelMediaExportPhotoItem* self;
-	RygelMediaExportMediaCache* _tmp0_;
-	RygelMediaExportMediaCache* cache;
-	RygelMediaExportMediaCache* _tmp1_;
-	GError * _inner_error_;
-};
-
-RygelMediaExportPhotoItem* rygel_media_export_photo_item_construct (GType object_type, const gchar* id, RygelMediaContainer* parent, const gchar* title, const gchar* upnp_class);
-static void rygel_media_export_photo_item_real_commit_data_free (gpointer _data);
-static void rygel_media_export_photo_item_real_commit (RygelUpdatableObject* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
-static gboolean rygel_media_export_photo_item_real_commit_co (RygelMediaExportPhotoItemCommitData* _data_);
-GType rygel_media_export_media_cache_get_type (void) G_GNUC_CONST;
-RygelMediaExportMediaCache* rygel_media_export_media_cache_get_default (GError** error);
-void rygel_media_export_media_cache_save_item (RygelMediaExportMediaCache* self, RygelMediaItem* item, GError** error);
-
-
-RygelMediaExportPhotoItem* rygel_media_export_photo_item_construct (GType object_type, const gchar* id, RygelMediaContainer* parent, const gchar* title, const gchar* upnp_class) {
-	RygelMediaExportPhotoItem * self = NULL;
-	const gchar* _tmp0_;
-	RygelMediaContainer* _tmp1_;
-	const gchar* _tmp2_;
-	const gchar* _tmp3_;
-	g_return_val_if_fail (id != NULL, NULL);
-	g_return_val_if_fail (parent != NULL, NULL);
-	g_return_val_if_fail (title != NULL, NULL);
-	g_return_val_if_fail (upnp_class != NULL, NULL);
-	_tmp0_ = id;
-	_tmp1_ = parent;
-	_tmp2_ = title;
-	_tmp3_ = upnp_class;
-	self = (RygelMediaExportPhotoItem*) rygel_photo_item_construct (object_type, _tmp0_, _tmp1_, _tmp2_, _tmp3_);
-	return self;
-}
+RygelMediaExportPhotoItem *rygel_media_export_photo_item_construct (GType object_type, const gchar *id, RygelMediaContainer *parent, const gchar *title, const gchar *upnp_class);
+static void rygel_media_export_photo_item_real_commit (RygelUpdatableObject *base, GAsyncReadyCallback callback, gpointer user_data);
 
+/* TODO: Remove the construct function? */
+RygelMediaExportPhotoItem*
+rygel_media_export_photo_item_construct (GType object_type, const gchar *id, RygelMediaContainer *parent, const gchar *title, const gchar *upnp_class) {
+  g_return_val_if_fail (id, NULL);
+  g_return_val_if_fail (parent, NULL);
+  g_return_val_if_fail (title, NULL);
+  g_return_val_if_fail (upnp_class, NULL);
 
-RygelMediaExportPhotoItem* rygel_media_export_photo_item_new (const gchar* id, RygelMediaContainer* parent, const gchar* title, const gchar* upnp_class) {
-	return rygel_media_export_photo_item_construct (RYGEL_MEDIA_EXPORT_TYPE_PHOTO_ITEM, id, parent, title, upnp_class);
+  return RYGEL_MEDIA_EXPORT_PHOTO_ITEM (rygel_photo_item_construct (object_type, id, parent, title, upnp_class));
 }
 
-
-static void rygel_media_export_photo_item_real_commit_data_free (gpointer _data) {
-	RygelMediaExportPhotoItemCommitData* _data_;
-	_data_ = _data;
-	g_object_unref (_data_->self);
-	g_slice_free (RygelMediaExportPhotoItemCommitData, _data_);
+RygelMediaExportPhotoItem*
+rygel_media_export_photo_item_new (const gchar *id, RygelMediaContainer *parent, const gchar *title, const gchar *upnp_class) {
+  return rygel_media_export_photo_item_construct (RYGEL_MEDIA_EXPORT_TYPE_PHOTO_ITEM, id, parent, title, upnp_class);
 }
 
-static void rygel_media_export_photo_item_real_commit (RygelUpdatableObject* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
-	RygelMediaExportPhotoItem * self;
-	RygelMediaExportPhotoItemCommitData* _data_;
-	RygelMediaExportPhotoItem* _tmp0_;
-	self = (RygelMediaExportPhotoItem*) base;
-	_data_ = g_slice_new0 (RygelMediaExportPhotoItemCommitData);
-	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_media_export_photo_item_real_commit);
-	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_media_export_photo_item_real_commit_data_free);
-	_tmp0_ = g_object_ref (self);
-	_data_->self = _tmp0_;
-	rygel_media_export_photo_item_real_commit_co (_data_);
+static void rygel_media_export_photo_item_real_commit (RygelUpdatableObject *base, GAsyncReadyCallback callback, gpointer user_data) {
+  RygelMediaExportPhotoItem *self = RYGEL_MEDIA_EXPORT_PHOTO_ITEM (base);
+
+  g_return_if_fail (self);
+  g_return_if_fail (callback);
+
+  /* Setup the async result.
+   */
+  GSimpleAsyncResult *async_result =
+    g_simple_async_result_new (G_OBJECT (self), callback, user_data,
+      rygel_media_export_photo_item_real_commit);
+
+  /* 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);
+  }
+
+  /* Set any error in the async result, if necessary.
+   */
+  if (error) {
+    g_simple_async_result_set_from_error (async_result, error);
+    g_error_free (error);
+  }
+
+  /* Let the caller know that the async operation is finished,
+   * and that its result is now available.
+   */
+  g_simple_async_result_complete (async_result);
+
+  /* Free our data structure. */
+  g_object_unref (async_result);
+  g_object_unref (cache);
 }
 
-
-static void rygel_media_export_photo_item_real_commit_finish (RygelUpdatableObject* base G_GNUC_UNUSED, GAsyncResult* _res_, GError** error) {
-  g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error);
+static void
+rygel_media_export_photo_item_real_commit_finish (RygelUpdatableObject *base G_GNUC_UNUSED, GAsyncResult *result, GError* *error) {
+  g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
 }
 
-
-static gboolean rygel_media_export_photo_item_real_commit_co (RygelMediaExportPhotoItemCommitData* _data_) {
-	switch (_data_->_state_) {
-		case 0:
-		goto _state_0;
-		default:
-		g_assert_not_reached ();
-	}
-	_state_0:
-	_data_->_tmp0_ = NULL;
-	_data_->_tmp0_ = rygel_media_export_media_cache_get_default (&_data_->_inner_error_);
-	_data_->cache = _data_->_tmp0_;
-	if (_data_->_inner_error_ != NULL) {
-		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
-		g_error_free (_data_->_inner_error_);
-		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_->_tmp1_ = _data_->cache;
-	rygel_media_export_media_cache_save_item (_data_->_tmp1_, (RygelMediaItem*) _data_->self, &_data_->_inner_error_);
-	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_->cache);
-		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_->cache);
-	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;
+static void rygel_media_export_photo_item_class_init (RygelMediaExportPhotoItemClass *klass) {
+  rygel_media_export_photo_item_parent_class = g_type_class_peek_parent (klass);
 }
 
-
-static void rygel_media_export_photo_item_class_init (RygelMediaExportPhotoItemClass * klass) {
-	rygel_media_export_photo_item_parent_class = g_type_class_peek_parent (klass);
+static void
+rygel_media_export_photo_item_rygel_updatable_object_interface_init (RygelUpdatableObjectIface *iface) {
+  iface->commit = rygel_media_export_photo_item_real_commit;
+  iface->commit_finish = rygel_media_export_photo_item_real_commit_finish;
 }
 
-
-static void rygel_media_export_photo_item_rygel_updatable_object_interface_init (RygelUpdatableObjectIface * iface) {
-	iface->commit = rygel_media_export_photo_item_real_commit;
-	iface->commit_finish = rygel_media_export_photo_item_real_commit_finish;
-}
-
-
-static void rygel_media_export_photo_item_init (RygelMediaExportPhotoItem * self G_GNUC_UNUSED) {
+static void
+rygel_media_export_photo_item_init (RygelMediaExportPhotoItem *self G_GNUC_UNUSED) {
 }
diff --git a/src/media-export/rygel-media-export-video-item.c b/src/media-export/rygel-media-export-video-item.c
index 83e443c..f2939f3 100644
--- a/src/media-export/rygel-media-export-video-item.c
+++ b/src/media-export/rygel-media-export-video-item.c
@@ -30,21 +30,6 @@ G_DEFINE_TYPE_WITH_CODE (RygelMediaExportVideoItem, rygel_media_export_video_ite
   G_IMPLEMENT_INTERFACE (RYGEL_TYPE_TRACKABLE_ITEM, rygel_media_export_video_item_rygel_trackable_item_interface_init)
   G_IMPLEMENT_INTERFACE (RYGEL_TYPE_UPDATABLE_OBJECT, rygel_media_export_video_item_rygel_updatable_object_interface_init))
 
-typedef struct _RygelMediaExportVideoItemCommitData RygelMediaExportVideoItemCommitData;
-
-struct _RygelMediaExportVideoItemCommitData {
-  int _state_;
-  GObject *_source_object_;
-  GAsyncResult *result;
-  GSimpleAsyncResult *_async_result;
-  RygelMediaExportVideoItem *self;
-  RygelMediaExportMediaCache *_tmp0_;
-  RygelMediaExportMediaCache *cache;
-  RygelMediaExportMediaCache *_tmp1_;
-  GError *_inner_error_;
-};
-
-
 static void rygel_media_export_video_item_real_commit (RygelUpdatableObject *base, GAsyncReadyCallback _callback_, gpointer _user_data_);
 
 /* TODO: Remove the construct function? */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]