[rygel-gst-0-10-plugins] RygelMediaExportRecursiveFileMonitor: Cleanup



commit 55bae3944864b4517d999a3f0192fe896f528377
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Feb 1 10:52:57 2013 +0100

    RygelMediaExportRecursiveFileMonitor: Cleanup

 .../rygel-media-export-recursive-file-monitor.c    |  583 +++++++++-----------
 .../rygel-media-export-recursive-file-monitor.h    |   10 -
 2 files changed, 254 insertions(+), 339 deletions(-)
---
diff --git a/src/media-export/rygel-media-export-recursive-file-monitor.c b/src/media-export/rygel-media-export-recursive-file-monitor.c
index 830c5ef..e972e00 100644
--- a/src/media-export/rygel-media-export-recursive-file-monitor.c
+++ b/src/media-export/rygel-media-export-recursive-file-monitor.c
@@ -30,73 +30,40 @@ typedef struct _RygelMediaExportRecursiveFileMonitorAddData RygelMediaExportRecu
 
 
 struct _RygelMediaExportRecursiveFileMonitorPrivate {
-	GCancellable *cancellable;
-	GeeHashMap *monitors;
-	gboolean monitor_changes;
+  GCancellable *cancellable;
+  GeeHashMap *monitors;
+  gboolean monitor_changes;
 };
 
 struct _RygelMediaExportRecursiveFileMonitorAddData {
-	int _state_;
-	GObject *_source_object_;
-	GAsyncResult *_res_;
-	GSimpleAsyncResult *_async_result;
-	RygelMediaExportRecursiveFileMonitor *self;
-	GFile *file;
-	gboolean _tmp0_;
-	gboolean _tmp1_;
-	GeeHashMap *_tmp2_;
-	GFile *_tmp3_;
-	gboolean _tmp4_;
-	gboolean _tmp5_;
-	GFile *_tmp6_;
-	GFileInfo *_tmp7_;
-	GFileInfo *info;
-	GFileInfo *_tmp8_;
-	GFileType _tmp9_;
-	GFile *_tmp10_;
-	GCancellable *_tmp11_;
-	GFileMonitor *_tmp12_;
-	GFileMonitor *file_monitor;
-	GeeHashMap *_tmp13_;
-	GFile *_tmp14_;
-	GFileMonitor *_tmp15_;
-	GFileMonitor *_tmp16_;
-	GError *err;
-	const gchar *_tmp17_;
-	GFile *_tmp18_;
-	gchar *_tmp19_;
-	gchar *_tmp20_;
-	GError  *_inner_error_;
+  RygelMediaExportRecursiveFileMonitor *self;
+  GSimpleAsyncResult *async_result;
 };
 
 
 #define RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_MEDIA_EXPORT_TYPE_RECURSIVE_FILE_MONITOR, RygelMediaExportRecursiveFileMonitorPrivate))
 
-static void _rygel_media_export_recursive_file_monitor_cancel_g_cancellable_cancelled (GCancellable *_sender, gpointer self);
-static void _rygel_media_export_recursive_file_monitor_on_monitor_changed_g_file_monitor_changed (GFileMonitor *_sender, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer self);
-static void rygel_media_export_recursive_file_monitor_add_data_free (gpointer _data);
-static gboolean rygel_media_export_recursive_file_monitor_add_co (RygelMediaExportRecursiveFileMonitorAddData *_data_);
-static void rygel_media_export_recursive_file_monitor_add_ready (GObject *source_object, GAsyncResult *_res_, gpointer _user_data_);
+static void rygel_media_export_recursive_file_monitor_on_monitor_changed (GFileMonitor *file_monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data);
+static void rygel_media_export_recursive_file_monitor_add_data_complete_and_free (RygelMediaExportRecursiveFileMonitorAddData *data);
+static void rygel_media_export_recursive_file_monitor_add_on_query_info (GObject *source_object, GAsyncResult *async_result, gpointer user_data);
 static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT_ENUM (GClosure  *closure, GValue  *return_value, guint n_param_values, const GValue  *param_values, gpointer invocation_hint, gpointer marshal_data);
 static void rygel_media_export_recursive_file_monitor_finalize (GObject *obj);
+static void rygel_media_export_recursive_file_monitor_on_cancelled (GCancellable *cancellable G_GNUC_UNUSED, gpointer user_data);
 
 
-static void _rygel_media_export_recursive_file_monitor_cancel_g_cancellable_cancelled (GCancellable *_sender G_GNUC_UNUSED, gpointer self) {
-	rygel_media_export_recursive_file_monitor_cancel (self);
-}
-
-static void rygel_media_export_recursive_file_monitor_on_config_changed (RygelConfiguration* config, const gchar* section, const gchar* key, gpointer user_data) {
-  RygelMediaExportRecursiveFileMonitor* self = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR (self);
+static void
+rygel_media_export_recursive_file_monitor_on_config_changed (RygelConfiguration *config, const gchar *section, const gchar *key, gpointer user_data) {
+  RygelMediaExportRecursiveFileMonitor *self = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR (self);
 
-	g_return_if_fail (self);
-	g_return_if_fail (config);
-	g_return_if_fail (section);
-	g_return_if_fail (key);
+  g_return_if_fail (self);
+  g_return_if_fail (config);
+  g_return_if_fail (section);
+  g_return_if_fail (key);
   
-	if ((g_strcmp0 (section, RYGEL_MEDIA_EXPORT_PLUGIN_NAME) != 0) ||
-	  (g_strcmp0 (key, "monitor-changes") != 0)) {
-		return;
-	}
+  if ((g_strcmp0 (section, RYGEL_MEDIA_EXPORT_PLUGIN_NAME) != 0) ||
+    (g_strcmp0 (key, "monitor-changes") != 0)) {
+    return;
+  }
 
   self->priv->monitor_changes = rygel_configuration_get_bool (config,
     RYGEL_MEDIA_EXPORT_PLUGIN_NAME,
@@ -104,12 +71,12 @@ static void rygel_media_export_recursive_file_monitor_on_config_changed (RygelCo
 }
 
 
-static
-RygelMediaExportRecursiveFileMonitor *rygel_media_export_recursive_file_monitor_construct (GType object_type, GCancellable *cancellable) {
-	RygelMediaExportRecursiveFileMonitor *self;
-	RygelMetaConfig *config;
-	
-	self = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR (g_object_new (object_type, NULL));
+static RygelMediaExportRecursiveFileMonitor*
+rygel_media_export_recursive_file_monitor_construct (GType object_type, GCancellable *cancellable) {
+  RygelMediaExportRecursiveFileMonitor *self;
+  RygelMetaConfig *config;
+  
+  self = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR (g_object_new (object_type, NULL));
   self->priv->monitor_changes = TRUE;
   
   config = rygel_meta_config_get_default ();
@@ -117,13 +84,13 @@ RygelMediaExportRecursiveFileMonitor *rygel_media_export_recursive_file_monitor_
   g_signal_connect_object (RYGEL_CONFIGURATION (config), "setting-changed",
     (GCallback)rygel_media_export_recursive_file_monitor_on_config_changed,
     self, 0);
-	rygel_media_export_recursive_file_monitor_on_config_changed (RYGEL_CONFIGURATION (config),
-	  RYGEL_MEDIA_EXPORT_PLUGIN_NAME, "monitor-changes", self);
+  rygel_media_export_recursive_file_monitor_on_config_changed (RYGEL_CONFIGURATION (config),
+    RYGEL_MEDIA_EXPORT_PLUGIN_NAME, "monitor-changes", self);
 
   if(!rygel_configuration_get_bool (RYGEL_CONFIGURATION (config),
     "MediaExport", "monitor-changes", NULL)) {
-		g_message ("rygel-media-export-recursive-file-monitor.c: %s",
-		  _("Will not monitor file changes"));
+    g_message ("rygel-media-export-recursive-file-monitor.c: %s",
+      _("Will not monitor file changes"));
   }
   
   self->priv->monitors = gee_hash_map_new (G_TYPE_FILE,
@@ -140,308 +107,266 @@ RygelMediaExportRecursiveFileMonitor *rygel_media_export_recursive_file_monitor_
     g_object_ref (self->priv->cancellable);
     
     g_signal_connect_object (self->priv->cancellable, "cancelled",
-      (GCallback) _rygel_media_export_recursive_file_monitor_cancel_g_cancellable_cancelled,
+      (GCallback) rygel_media_export_recursive_file_monitor_on_cancelled,
       self, 0);
   }
 
-	return self;
+  return self;
 }
 
 
-RygelMediaExportRecursiveFileMonitor *rygel_media_export_recursive_file_monitor_new (GCancellable *cancellable) {
-	return rygel_media_export_recursive_file_monitor_construct (RYGEL_MEDIA_EXPORT_TYPE_RECURSIVE_FILE_MONITOR, cancellable);
+RygelMediaExportRecursiveFileMonitor*
+rygel_media_export_recursive_file_monitor_new (GCancellable *cancellable) {
+  return rygel_media_export_recursive_file_monitor_construct (RYGEL_MEDIA_EXPORT_TYPE_RECURSIVE_FILE_MONITOR, cancellable);
 }
 
 
-static void _rygel_media_export_recursive_file_monitor_on_monitor_changed_g_file_monitor_changed (GFileMonitor *_sender G_GNUC_UNUSED, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer self) {
-	rygel_media_export_recursive_file_monitor_on_monitor_changed (self, file, other_file, event_type);
-}
+static void
+rygel_media_export_recursive_file_monitor_on_monitor_changed (GFileMonitor *file_monitor G_GNUC_UNUSED, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) {
+  RygelMediaExportRecursiveFileMonitor *self = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR (user_data);
 
+  g_return_if_fail (self);
+  g_return_if_fail (file);
 
-void rygel_media_export_recursive_file_monitor_on_monitor_changed (RygelMediaExportRecursiveFileMonitor *self, GFile *file, GFile *other_file, GFileMonitorEvent event_type) {
-	GFile *_tmp0_;
-	GFile *_tmp1_;
-	GFileMonitorEvent _tmp2_;
-	GFileMonitorEvent _tmp3_;
-	g_return_if_fail (self);
-	g_return_if_fail (file);
-	_tmp0_ = file;
-	_tmp1_ = other_file;
-	_tmp2_ = event_type;
-	g_signal_emit_by_name (self, "changed", _tmp0_, _tmp1_, _tmp2_);
-	_tmp3_ = event_type;
-	switch (_tmp3_) {
-		case G_FILE_MONITOR_EVENT_CREATED:
-		{
-			GFile *_tmp4_;
-			_tmp4_ = file;
-			rygel_media_export_recursive_file_monitor_add (self, _tmp4_, NULL, NULL);
-			break;
-		}
-		case G_FILE_MONITOR_EVENT_DELETED:
-		{
-			GeeHashMap *_tmp5_;
-			GFile *_tmp6_;
-			gpointer _tmp7_ = NULL;
-			GFileMonitor *file_monitor;
-			GFileMonitor *_tmp8_;
-			_tmp5_ = self->priv->monitors;
-			_tmp6_ = file;
-			_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp5_, _tmp6_);
-			file_monitor = (GFileMonitor*) _tmp7_;
-			_tmp8_ = file_monitor;
-			if (_tmp8_) {
-				GFile *_tmp9_;
-				gchar *_tmp10_ = NULL;
-				gchar *_tmp11_;
-				GeeHashMap *_tmp12_;
-				GFile *_tmp13_;
-				GFileMonitor *_tmp14_;
-				GFileMonitor *_tmp15_;
-				guint _tmp16_ = 0U;
-				_tmp9_ = file;
-				_tmp10_ = g_file_get_uri (_tmp9_);
-				_tmp11_ = _tmp10_;
-				g_debug ("rygel-media-export-recursive-file-monitor.vala:64: Folder %s gone; rem" \
-"oving watch", _tmp11_);
-				g_free (_tmp11_);
-				_tmp12_ = self->priv->monitors;
-				_tmp13_ = file;
-				gee_abstract_map_unset ((GeeAbstractMap*) _tmp12_, _tmp13_, NULL);
-				_tmp14_ = file_monitor;
-				g_file_monitor_cancel (_tmp14_);
-				_tmp15_ = file_monitor;
-				g_signal_parse_name ("changed", g_file_monitor_get_type (), &_tmp16_, NULL, FALSE);
-				g_signal_handlers_disconnect_matched (_tmp15_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp16_, 0, NULL, (GCallback) _rygel_media_export_recursive_file_monitor_on_monitor_changed_g_file_monitor_changed, self);
-			}
-			g_object_unref (file_monitor);
-			break;
-		}
-		default:
-		{
-			break;
-		}
-	}
+  if (self->priv->monitor_changes) {
+    g_signal_emit_by_name (self, "changed", file, other_file, event_type);
+  }
+
+  switch (event_type) {
+    case G_FILE_MONITOR_EVENT_CREATED:
+    {
+      rygel_media_export_recursive_file_monitor_add (self, file, NULL, NULL);
+      break;
+    }
+    case G_FILE_MONITOR_EVENT_DELETED:
+    {
+      GFileMonitor *file_monitor = G_FILE_MONITOR (gee_abstract_map_get ((GeeAbstractMap*) self->priv->monitors, file));
+      if (file_monitor) {
+        gchar *uri = g_file_get_uri (file);
+        g_debug ("rygel-media-export-recursive-file-monitor.vala:64: Folder %s gone. Removing watch", uri);
+        g_free (uri);
+
+        gee_abstract_map_unset ((GeeAbstractMap*) self->priv->monitors, file, NULL);
+        g_file_monitor_cancel (file_monitor);
+
+        guint signal_id = 0U;
+        g_signal_parse_name ("changed", g_file_monitor_get_type (), &signal_id, NULL, FALSE);
+        g_signal_handlers_disconnect_matched (file_monitor,
+          G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+          signal_id, 0, NULL,
+          (GCallback) rygel_media_export_recursive_file_monitor_on_monitor_changed, self);
+
+       g_object_unref (file_monitor);
+      }
+
+      break;
+    }
+    default:
+    {
+      break;
+    }
+  }
 }
 
+static void
+rygel_media_export_recursive_file_monitor_add_data_complete_and_free (RygelMediaExportRecursiveFileMonitorAddData *data) {
+  g_simple_async_result_complete (data->async_result);
+  g_object_unref (data->async_result);
 
-static void rygel_media_export_recursive_file_monitor_add_data_free (gpointer _data) {
-	RygelMediaExportRecursiveFileMonitorAddData *_data_;
-	_data_ = _data;
-	g_object_unref (_data_->file);
-	g_object_unref (_data_->self);
-	g_slice_free (RygelMediaExportRecursiveFileMonitorAddData, _data_);
+  g_object_unref (data->self);
+  g_slice_free (RygelMediaExportRecursiveFileMonitorAddData, data);
 }
 
 
-void rygel_media_export_recursive_file_monitor_add (RygelMediaExportRecursiveFileMonitor *self, GFile *file, GAsyncReadyCallback _callback_, gpointer _user_data_) {
-	RygelMediaExportRecursiveFileMonitorAddData *_data_;
-	RygelMediaExportRecursiveFileMonitor *_tmp0_;
-	GFile *_tmp1_;
-	GFile *_tmp2_;
-	_data_ = g_slice_new0 (RygelMediaExportRecursiveFileMonitorAddData);
-	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_media_export_recursive_file_monitor_add);
-	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_media_export_recursive_file_monitor_add_data_free);
-	_tmp0_ = g_object_ref (self);
-	_data_->self = _tmp0_;
-	_tmp1_ = file;
-	_tmp2_ = g_object_ref (_tmp1_);
-	g_object_unref (_data_->file);
-	_data_->file = _tmp2_;
-	rygel_media_export_recursive_file_monitor_add_co (_data_);
-}
+void rygel_media_export_recursive_file_monitor_add (RygelMediaExportRecursiveFileMonitor *self, GFile *file, GAsyncReadyCallback callback, gpointer user_data) {
+  RygelMediaExportRecursiveFileMonitorAddData *data;
+
+  g_return_if_fail (self);
+  g_return_if_fail (file);
+  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_recursive_file_monitor_add);
+
+  /* Do the work that could take a while.
+   */
+  if (gee_abstract_map_has_key ((GeeAbstractMap*) self->priv->monitors, file)) {
+    /* Let the caller know that the async operation is finished,
+     * and that its result is now available.
+     */
+    g_simple_async_result_complete (async_result);
+    g_object_unref (async_result);
+    return;
+  }
 
+  /* Call another async function, whose callback will complete our async result,
+   * passing a data instance to hold our self and async result.
+   */
+  data = g_slice_new0 (RygelMediaExportRecursiveFileMonitorAddData);
+  data->self = self;
+  g_object_ref (data->self);
+  data->async_result = async_result;
+  g_file_query_info_async (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
+      G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, rygel_media_export_recursive_file_monitor_add_on_query_info, data);
+}
 
-void rygel_media_export_recursive_file_monitor_add_finish (RygelMediaExportRecursiveFileMonitor *self G_GNUC_UNUSED, GAsyncResult *_res_ G_GNUC_UNUSED) {
+void
+rygel_media_export_recursive_file_monitor_add_finish (RygelMediaExportRecursiveFileMonitor *self G_GNUC_UNUSED, GAsyncResult *res G_GNUC_UNUSED) {
 }
 
 
-static void rygel_media_export_recursive_file_monitor_add_ready (GObject *source_object, GAsyncResult *_res_, gpointer _user_data_) {
-	RygelMediaExportRecursiveFileMonitorAddData *_data_;
-	_data_ = _user_data_;
-	_data_->_source_object_ = source_object;
-	_data_->_res_ = _res_;
-	rygel_media_export_recursive_file_monitor_add_co (_data_);
-}
+static void
+rygel_media_export_recursive_file_monitor_add_on_query_info (GObject *source_object, GAsyncResult *async_result, gpointer user_data) {
+  RygelMediaExportRecursiveFileMonitorAddData *data = (RygelMediaExportRecursiveFileMonitorAddData*)user_data;
+  GFile *file = G_FILE (source_object);
+  GFileInfo *info;
+
+  g_return_if_fail (data);
+  g_return_if_fail (async_result);
+  g_return_if_fail (file);
+
+  /* async_result is the result of our query.
+   * data->async_result is the result, in progress, of our own operation.
+   */
+
+  GError *error = NULL;
+  info = g_file_query_info_finish (file, async_result, &error);
+  g_return_if_fail (info);
+  if (error) {
+    gchar *uri = g_file_get_uri (file);
+    g_warning ( _("Failed to get file info for %s"), uri);
+    g_free (uri);
+
+    /* Set the error in the async result.
+     */
+    g_simple_async_result_set_from_error (data->async_result, error);
+    g_error_free (error);
+  }
 
+  if (!info || error) {
+    /* Let the caller know that the async operation is finished,
+     * and that its result is now available.
+     */
+    rygel_media_export_recursive_file_monitor_add_data_complete_and_free (data);
+    return;
+  }
 
-static gboolean rygel_media_export_recursive_file_monitor_add_co (RygelMediaExportRecursiveFileMonitorAddData *_data_) {
-	switch (_data_->_state_) {
-		case 0:
-		goto _state_0;
-		case 1:
-		goto _state_1;
-		default:
-		g_assert_not_reached ();
-	}
-	_state_0:
-	_data_->_tmp1_ = _data_->self->priv->monitor_changes;
-	if (!_data_->_tmp1_) {
-		_data_->_tmp0_ = TRUE;
-	} else {
-		_data_->_tmp2_ = _data_->self->priv->monitors;
-		_data_->_tmp3_ = _data_->file;
-		_data_->_tmp4_ = FALSE;
-		_data_->_tmp4_ = gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp2_, _data_->_tmp3_);
-		_data_->_tmp0_ = _data_->_tmp4_;
-	}
-	_data_->_tmp5_ = _data_->_tmp0_;
-	if (_data_->_tmp5_) {
-		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_->_tmp6_ = _data_->file;
-		_data_->_state_ = 1;
-		g_file_query_info_async (_data_->_tmp6_, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, rygel_media_export_recursive_file_monitor_add_ready, _data_);
-		return FALSE;
-		_state_1:
-		_data_->_tmp7_ = NULL;
-		_data_->_tmp7_ = g_file_query_info_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error_);
-		_data_->info = _data_->_tmp7_;
-		if (_data_->_inner_error_) {
-			goto __catch45_g_error;
-		}
-		_data_->_tmp8_ = _data_->info;
-		_data_->_tmp9_ = 0;
-		_data_->_tmp9_ = g_file_info_get_file_type (_data_->_tmp8_);
-		if (_data_->_tmp9_ == G_FILE_TYPE_DIRECTORY) {
-			_data_->_tmp10_ = _data_->file;
-			_data_->_tmp11_ = _data_->self->priv->cancellable;
-			_data_->_tmp12_ = NULL;
-			_data_->_tmp12_ = g_file_monitor_directory (_data_->_tmp10_, G_FILE_MONITOR_NONE, _data_->_tmp11_, &_data_->_inner_error_);
-			_data_->file_monitor = _data_->_tmp12_;
-			if (_data_->_inner_error_) {
-				g_object_unref (_data_->info);
-				goto __catch45_g_error;
-			}
-			_data_->_tmp13_ = _data_->self->priv->monitors;
-			_data_->_tmp14_ = _data_->file;
-			_data_->_tmp15_ = _data_->file_monitor;
-			gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp13_, _data_->_tmp14_, _data_->_tmp15_);
-			_data_->_tmp16_ = _data_->file_monitor;
-			g_signal_connect_object (_data_->_tmp16_, "changed", (GCallback) _rygel_media_export_recursive_file_monitor_on_monitor_changed_g_file_monitor_changed, _data_->self, 0);
-			g_object_unref (_data_->file_monitor);
-		}
-		g_object_unref (_data_->info);
-	}
-	goto __finally45;
-	__catch45_g_error:
-	{
-		_data_->err = _data_->_inner_error_;
-		_data_->_inner_error_ = NULL;
-		_data_->_tmp17_ = NULL;
-		_data_->_tmp17_ = _ ("Failed to get file info for %s");
-		_data_->_tmp18_ = _data_->file;
-		_data_->_tmp19_ = NULL;
-		_data_->_tmp19_ = g_file_get_uri (_data_->_tmp18_);
-		_data_->_tmp20_ = _data_->_tmp19_;
-		g_warning (_data_->_tmp17_, _data_->_tmp20_);
-		g_free (_data_->_tmp20_);
-		g_error_free (_data_->err);
-	}
-	__finally45:
-	if (_data_->_inner_error_) {
-		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
-		g_clear_error (&_data_->_inner_error_);
-		return FALSE;
-	}
-	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;
-}
+  if (g_file_info_get_file_type (info) !=  G_FILE_TYPE_DIRECTORY) {
+    /* Let the caller know that the async operation is finished,
+     * and that its result is now available.
+     */
+    rygel_media_export_recursive_file_monitor_add_data_complete_and_free (data);
+    return;
+  }
+
+  error = NULL;
+  GFileMonitor *file_monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, data->self->priv->cancellable, &error);
+  if (error) {
+    gchar *uri = g_file_get_uri (file);
+    g_warning ( _ ("Failed to get file info for %s"), uri);
+    g_free (uri);
+
+    /* Set the error in the async result.
+     */
+    g_simple_async_result_set_from_error (data->async_result, error);
+    g_error_free (error);
+  }
 
+  if (file_monitor) {
+    gee_abstract_map_set ((GeeAbstractMap*) data->self->priv->monitors, file, file_monitor);
+    g_signal_connect_object (file_monitor, "changed", (GCallback) rygel_media_export_recursive_file_monitor_on_monitor_changed, data->self, 0);
+  }
 
-void rygel_media_export_recursive_file_monitor_cancel (RygelMediaExportRecursiveFileMonitor *self) {
-	GeeHashMap *_tmp11_;
-	g_return_if_fail (self);
-	{
-		GeeHashMap *_tmp0_;
-		GeeCollection *_tmp1_;
-		GeeCollection *_tmp2_;
-		GeeCollection *_tmp3_;
-		GeeIterator *_tmp4_ = NULL;
-		GeeIterator *_tmp5_;
-		GeeIterator *_monitor_it;
-		_tmp0_ = self->priv->monitors;
-		_tmp1_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp0_);
-		_tmp2_ = _tmp1_;
-		_tmp3_ = _tmp2_;
-		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
-		_tmp5_ = _tmp4_;
-		g_object_unref (_tmp3_);
-		_monitor_it = _tmp5_;
-		while (TRUE) {
-			GeeIterator *_tmp6_;
-			gboolean _tmp7_ = FALSE;
-			GeeIterator *_tmp8_;
-			gpointer _tmp9_ = NULL;
-			GFileMonitor *monitor;
-			GFileMonitor *_tmp10_;
-			_tmp6_ = _monitor_it;
-			_tmp7_ = gee_iterator_next (_tmp6_);
-			if (!_tmp7_) {
-				break;
-			}
-			_tmp8_ = _monitor_it;
-			_tmp9_ = gee_iterator_get (_tmp8_);
-			monitor = (GFileMonitor*) _tmp9_;
-			_tmp10_ = monitor;
-			g_file_monitor_cancel (_tmp10_);
-			g_object_unref (monitor);
-		}
-		g_object_unref (_monitor_it);
-	}
-	_tmp11_ = self->priv->monitors;
-	gee_abstract_map_clear ((GeeAbstractMap*) _tmp11_);
+  /* Let the caller know that the async operation is finished,
+   * and that its result is now available.
+   */
+  rygel_media_export_recursive_file_monitor_add_data_complete_and_free (data);
 }
 
 
-static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT_ENUM (GClosure  *closure, GValue  *return_value G_GNUC_UNUSED, guint n_param_values, const GValue  *param_values, gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data) {
-	typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT_ENUM) (gpointer data1, gpointer arg_1, gpointer arg_2, gint arg_3, gpointer data2);
-	register GMarshalFunc_VOID__OBJECT_OBJECT_ENUM callback;
-	register GCClosure  *cc;
-	register gpointer data1;
-	register gpointer data2;
-	cc = (GCClosure *) closure;
-	g_return_if_fail (n_param_values == 4);
-	if (G_CCLOSURE_SWAP_DATA (closure)) {
-		data1 = closure->data;
-		data2 = param_values->data[0].v_pointer;
-	} else {
-		data1 = param_values->data[0].v_pointer;
-		data2 = closure->data;
-	}
-	callback = (GMarshalFunc_VOID__OBJECT_OBJECT_ENUM) (marshal_data ? marshal_data : cc->callback);
-	callback (data1, g_value_get_object (param_values + 1), g_value_get_object (param_values + 2), g_value_get_enum (param_values + 3), data2);
+
+static void
+rygel_media_export_recursive_file_monitor_on_cancelled (GCancellable *cancellable G_GNUC_UNUSED, gpointer user_data) {
+  RygelMediaExportRecursiveFileMonitor *self = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR (user_data);
+  GeeCollection * values;
+  GeeIterator *iter;
+  g_return_if_fail (self);
+
+  values = gee_abstract_map_get_values ((GeeAbstractMap*) self->priv->monitors);
+  iter = gee_iterable_iterator ((GeeIterable*) values);
+  g_object_unref (values);
+
+  while (TRUE) {
+    if (!gee_iterator_next (iter))
+      break;
+
+    GFileMonitor *monitor = G_FILE_MONITOR (gee_iterator_get (iter));
+    if (!monitor)
+      continue;
+
+    g_file_monitor_cancel (monitor);
+    g_object_unref (monitor);
+  }
+
+  g_object_unref (iter);
+
+  gee_abstract_map_clear ((GeeAbstractMap*) self->priv->monitors);
 }
 
+static void
+g_cclosure_user_marshal_VOID__OBJECT_OBJECT_ENUM (GClosure  *closure, GValue *return_value G_GNUC_UNUSED, guint n_param_values, const GValue *param_values, gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data) {
+  typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT_ENUM) (gpointer data1, gpointer arg_1, gpointer arg_2, gint arg_3, gpointer data2);
+  register GMarshalFunc_VOID__OBJECT_OBJECT_ENUM callback;
+  register GCClosure  *cc;
+  register gpointer data1;
+  register gpointer data2;
+
+  cc = (GCClosure *) closure;
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure)) {
+    data1 = closure->data;
+    data2 = param_values->data[0].v_pointer;
+  } else {
+    data1 = param_values->data[0].v_pointer;
+    data2 = closure->data;
+  }
 
-static void rygel_media_export_recursive_file_monitor_class_init (RygelMediaExportRecursiveFileMonitorClass  *klass) {
-	g_type_class_add_private (klass, sizeof (RygelMediaExportRecursiveFileMonitorPrivate));
-	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_recursive_file_monitor_finalize;
-	g_signal_new ("changed", RYGEL_MEDIA_EXPORT_TYPE_RECURSIVE_FILE_MONITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT_ENUM, G_TYPE_NONE, 3, G_TYPE_FILE, G_TYPE_FILE, g_file_monitor_event_get_type ());
+  callback = (GMarshalFunc_VOID__OBJECT_OBJECT_ENUM) (marshal_data ? marshal_data : cc->callback);
+  callback (data1, g_value_get_object (param_values + 1), g_value_get_object (param_values + 2), g_value_get_enum (param_values + 3), data2);
 }
 
+static void
+rygel_media_export_recursive_file_monitor_class_init (RygelMediaExportRecursiveFileMonitorClass  *klass) {
+  g_type_class_add_private (klass, sizeof (RygelMediaExportRecursiveFileMonitorPrivate));
+
+  G_OBJECT_CLASS (klass)->finalize = rygel_media_export_recursive_file_monitor_finalize;
+
+  g_signal_new ("changed", RYGEL_MEDIA_EXPORT_TYPE_RECURSIVE_FILE_MONITOR,
+    G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT_ENUM,
+    G_TYPE_NONE, 3, G_TYPE_FILE, G_TYPE_FILE, g_file_monitor_event_get_type ());
+}
 
-static void rygel_media_export_recursive_file_monitor_init (RygelMediaExportRecursiveFileMonitor  *self) {
-	self->priv = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR_GET_PRIVATE (self);
+static void
+rygel_media_export_recursive_file_monitor_init (RygelMediaExportRecursiveFileMonitor  *self) {
+  self->priv = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR_GET_PRIVATE (self);
 }
 
+static void
+rygel_media_export_recursive_file_monitor_finalize (GObject *obj) {
+  RygelMediaExportRecursiveFileMonitor  *self = RYGEL_MEDIA_EXPORT_RECURSIVE_FILE_MONITOR (obj);
+
+  g_return_if_fail (self);
+
+  if (self->priv->cancellable)
+    g_object_unref (self->priv->cancellable);
+
+  /* TODO: Empty this properly? */
+  if (self->priv->monitors)
+    g_object_unref (self->priv->monitors);
 
-static void rygel_media_export_recursive_file_monitor_finalize (GObject *obj) {
-	RygelMediaExportRecursiveFileMonitor  *self;
-	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_MEDIA_EXPORT_TYPE_RECURSIVE_FILE_MONITOR, RygelMediaExportRecursiveFileMonitor);
-	g_object_unref (self->priv->cancellable);
-	g_object_unref (self->priv->monitors);
-	G_OBJECT_CLASS (rygel_media_export_recursive_file_monitor_parent_class)->finalize (obj);
+  G_OBJECT_CLASS (rygel_media_export_recursive_file_monitor_parent_class)->finalize (obj);
 }
diff --git a/src/media-export/rygel-media-export-recursive-file-monitor.h b/src/media-export/rygel-media-export-recursive-file-monitor.h
index 2e3358c..2451041 100644
--- a/src/media-export/rygel-media-export-recursive-file-monitor.h
+++ b/src/media-export/rygel-media-export-recursive-file-monitor.h
@@ -59,16 +59,6 @@ RygelMediaExportRecursiveFileMonitor *
 rygel_media_export_recursive_file_monitor_new (GCancellable *cancellable);
 
 void
-rygel_media_export_recursive_file_monitor_cancel (RygelMediaExportRecursiveFileMonitor *self);
-
-/* TODO: This does not look like public API to me. */
-void
-rygel_media_export_recursive_file_monitor_on_monitor_changed (RygelMediaExportRecursiveFileMonitor *self,
-							      GFile                                *file,
-							      GFile                                *other_file,
-							      GFileMonitorEvent                     event_type);
-
-void
 rygel_media_export_recursive_file_monitor_add (RygelMediaExportRecursiveFileMonitor *self,
 					       GFile                                *file,
 					       GAsyncReadyCallback                   callback,



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