summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2015-02-18 13:55:38 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2015-02-18 13:56:14 +0100
commitb49c3076c06c32250f28ea4080811759de1119f5 (patch)
tree683aa365b5ef3bfcdae0adcb1eaae7354d6d2b76
parentf8f1d4b846942eb66427f7735ac47a902cc5290a (diff)
Add ufo_signal_emit for threadsafe signal emission
-rw-r--r--ufo/CMakeLists.txt2
-rw-r--r--ufo/ufo-misc.c62
-rw-r--r--ufo/ufo-misc.h39
-rw-r--r--ufo/ufo.h1
4 files changed, 104 insertions, 0 deletions
diff --git a/ufo/CMakeLists.txt b/ufo/CMakeLists.txt
index 07ab549..a0d5458 100644
--- a/ufo/CMakeLists.txt
+++ b/ufo/CMakeLists.txt
@@ -22,6 +22,7 @@ set(ufocore_SRCS
ufo-local-scheduler.c
ufo-messenger-iface.c
ufo-method-iface.c
+ ufo-misc.c
ufo-node.c
ufo-output-task.c
ufo-plugin-manager.c
@@ -60,6 +61,7 @@ set(ufocore_HDRS
ufo-local-scheduler.h
ufo-messenger-iface.h
ufo-method-iface.h
+ ufo-misc.h
ufo-node.h
ufo-output-task.h
ufo-plugin-manager.h
diff --git a/ufo/ufo-misc.c b/ufo/ufo-misc.c
new file mode 100644
index 0000000..f7b8d82
--- /dev/null
+++ b/ufo/ufo-misc.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2011-2015 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#ifdef WITH_PYTHON
+#include <Python.h>
+#endif
+
+#include <ufo/ufo.h>
+
+/**
+ * ufo_signal_emit:
+ * @instance: (type GObject.Object): the instance the signal is being emitted on.
+ * @signal_id: the signal id
+ * @detail: the detail
+ * @...: parameters to be passed to the signal, followed by a
+ * location for the return value. If the return type of the signal
+ * is #G_TYPE_NONE, the return value location can be omitted.
+ *
+ * Emits a signal just like g_signal_emit(). In case ufo-core is compiled with
+ * Python-support, the GIL will be locked before signalling.
+ *
+ * Note that g_signal_emit() resets the return value to the default
+ * if no handlers are connected, in contrast to g_signal_emitv().
+ */
+void
+ufo_signal_emit (gpointer instance,
+ guint signal_id,
+ GQuark detail,
+ ...)
+{
+ va_list var_args;
+
+#ifdef WITH_PYTHON
+ PyGILState_STATE state = PyGILState_Ensure ();
+#endif
+
+ va_start (var_args, detail);
+ g_signal_emit_valist (instance, signal_id, detail, var_args);
+ va_end (var_args);
+
+#ifdef WITH_PYTHON
+ PyGILState_Release (state);
+#endif
+}
diff --git a/ufo/ufo-misc.h b/ufo/ufo-misc.h
new file mode 100644
index 0000000..5b70f4c
--- /dev/null
+++ b/ufo/ufo-misc.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2011-2015 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UFO_MISC_H
+#define UFO_MISC_H
+
+#if !defined (__UFO_H_INSIDE__) && !defined (UFO_COMPILATION)
+#error "Only <ufo/ufo.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+void ufo_signal_emit (gpointer instance,
+ guint signal_id,
+ GQuark detail,
+ ...);
+
+
+G_END_DECLS
+
+#endif
diff --git a/ufo/ufo.h b/ufo/ufo.h
index 59306f8..f757541 100644
--- a/ufo/ufo.h
+++ b/ufo/ufo.h
@@ -48,6 +48,7 @@
#include <ufo/ufo-two-way-queue.h>
#include <ufo/ufo-basic-ops.h>
#include <ufo/ufo-messenger-iface.h>
+#include <ufo/ufo-misc.h>
#include <ufo/ufo-processor.h>
#include <ufo/ufo-method-iface.h>
#include <ufo/ufo-transform-iface.h>