[nautilus/wip/ernestask/tasks: 26/33] Add task-private utilities
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/ernestask/tasks: 26/33] Add task-private utilities
- Date: Mon, 7 Aug 2017 10:28:15 +0000 (UTC)
commit a301f754032fa39c9f3a4845a63422ede5cb1c49
Author: Ernestas Kulik <ernestask gnome org>
Date: Mon Jul 3 14:56:20 2017 +0300
Add task-private utilities
src/meson.build | 4 +-
src/nautilus-task-private.c | 97 +++++++++++++++++++++++++++++++++++++++++++
src/nautilus-task-private.h | 10 ++++
3 files changed, 110 insertions(+), 1 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index ec814f6..17db6f0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -282,7 +282,9 @@ libnautilus_sources = [
# 'tasks/nautilus-info-attribute-task.c',
# 'tasks/nautilus-info-attribute-task.h'
'nautilus-task-batch.c',
- 'nautilus-task-batch.h'
+ 'nautilus-task-batch.h',
+ 'nautilus-task-private.c',
+ 'nautilus-task-private.h'
]
nautilus_deps = [glib,
diff --git a/src/nautilus-task-private.c b/src/nautilus-task-private.c
new file mode 100644
index 0000000..62272fd
--- /dev/null
+++ b/src/nautilus-task-private.c
@@ -0,0 +1,97 @@
+#include "nautilus-task-private.h"
+
+#include <glib-object.h>
+#include <gobject/gvaluecollector.h>
+
+typedef struct
+{
+ GValue instance_and_params[3];
+ guint signal_id;
+ int n_values;
+} EmissionData;
+
+static void
+emission_data_free (EmissionData *data)
+{
+ for (int i = 0; i < data->n_values; i++)
+ {
+ g_value_unset (&data->instance_and_params[i]);
+ }
+
+ g_free (data);
+}
+
+static gboolean
+emit_signal (gpointer data)
+{
+ EmissionData *emission_data;
+
+ emission_data = data;
+
+ g_signal_emitv (emission_data->instance_and_params,
+ emission_data->signal_id,
+ 0, NULL);
+
+ g_clear_pointer (&emission_data, emission_data_free);
+
+ return FALSE;
+}
+
+void
+nautilus_emit_signal_in_main_context (gpointer instance,
+ guint signal_id,
+ ...)
+{
+ va_list ap;
+ EmissionData *emission_data;
+ GSignalQuery query;
+ g_autofree gchar *error = NULL;
+
+ emission_data = g_new0 (EmissionData, 1);
+
+ va_start (ap, signal_id);
+
+ g_value_init (&emission_data->instance_and_params[0],
+ G_TYPE_FROM_INSTANCE (instance));
+ g_value_set_instance (&emission_data->instance_and_params[0], instance);
+
+ emission_data->signal_id = signal_id;
+
+ g_signal_query (signal_id, &query);
+
+ if (query.signal_id == 0)
+ {
+ g_clear_pointer (&emission_data, emission_data_free);
+
+ va_end (ap);
+
+ return;
+ }
+
+ for (int i = 0; i < query.n_params; i++)
+ {
+ G_VALUE_COLLECT_INIT (&emission_data->instance_and_params[i + 1],
+ query.param_types[i],
+ ap, 0, &error);
+
+ if (error != NULL)
+ {
+ break;
+ }
+
+ emission_data->n_values++;
+ }
+
+ if (error != NULL)
+ {
+ g_clear_pointer (&emission_data, emission_data_free);
+
+ va_end (ap);
+
+ return;
+ }
+
+ g_main_context_invoke (NULL, emit_signal, emission_data);
+
+ va_end (ap);
+}
diff --git a/src/nautilus-task-private.h b/src/nautilus-task-private.h
new file mode 100644
index 0000000..f57b4d8
--- /dev/null
+++ b/src/nautilus-task-private.h
@@ -0,0 +1,10 @@
+#ifndef NAUTILUS_TASK_PRIVATE_H
+#define NAUTILUS_TASK_PRIVATE_H
+
+#include <glib.h>
+
+void nautilus_emit_signal_in_main_context (gpointer instance,
+ guint signal_id,
+ ...);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]