[kdbus] Do not set body message if signature field is empty
[platform/upstream/glib.git] / gobject / gsourceclosure.c
index 644a1e0..b74bdb6 100644 (file)
@@ -12,9 +12,7 @@
  * 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -25,6 +23,9 @@
 #include "gmarshal.h"
 #include "gvalue.h"
 #include "gvaluetypes.h"
+#ifdef G_OS_UNIX
+#include "glib-unix.h"
+#endif
 
 G_DEFINE_BOXED_TYPE (GIOChannel, g_io_channel, g_io_channel_ref, g_io_channel_unref)
 
@@ -102,6 +103,72 @@ io_watch_closure_callback (GIOChannel   *channel,
 }
 
 static gboolean
+g_child_watch_closure_callback (GPid     pid,
+                                gint     status,
+                                gpointer data)
+{
+  GClosure *closure = data;
+
+  GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
+  GValue result_value = G_VALUE_INIT;
+  gboolean result;
+
+  g_value_init (&result_value, G_TYPE_BOOLEAN);
+
+#ifdef G_OS_UNIX
+  g_value_init (&params[0], G_TYPE_ULONG);
+  g_value_set_ulong (&params[0], pid);
+#endif
+#ifdef G_OS_WIN32
+  g_value_init (&params[0], G_TYPE_POINTER);
+  g_value_set_pointer (&params[0], pid);
+#endif
+
+  g_value_init (&params[1], G_TYPE_INT);
+  g_value_set_int (&params[1], status);
+
+  g_closure_invoke (closure, &result_value, 2, params, NULL);
+
+  result = g_value_get_boolean (&result_value);
+  g_value_unset (&result_value);
+  g_value_unset (&params[0]);
+  g_value_unset (&params[1]);
+
+  return result;
+}
+
+#ifdef G_OS_UNIX
+static gboolean
+g_unix_fd_source_closure_callback (int           fd,
+                                   GIOCondition  condition,
+                                   gpointer      data)
+{
+  GClosure *closure = data;
+
+  GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
+  GValue result_value = G_VALUE_INIT;
+  gboolean result;
+
+  g_value_init (&result_value, G_TYPE_BOOLEAN);
+
+  g_value_init (&params[0], G_TYPE_INT);
+  g_value_set_int (&params[0], fd);
+
+  g_value_init (&params[1], G_TYPE_IO_CONDITION);
+  g_value_set_flags (&params[1], condition);
+
+  g_closure_invoke (closure, &result_value, 2, params, NULL);
+
+  result = g_value_get_boolean (&result_value);
+  g_value_unset (&result_value);
+  g_value_unset (&params[0]);
+  g_value_unset (&params[1]);
+
+  return result;
+}
+#endif
+
+static gboolean
 source_closure_callback (gpointer data)
 {
   GClosure *closure = data;
@@ -129,10 +196,19 @@ closure_callback_get (gpointer     cb_data,
   if (!closure_callback)
     {
       if (source->source_funcs == &g_io_watch_funcs)
-       closure_callback = (GSourceFunc)io_watch_closure_callback;
+        closure_callback = (GSourceFunc)io_watch_closure_callback;
+      else if (source->source_funcs == &g_child_watch_funcs)
+        closure_callback = (GSourceFunc)g_child_watch_closure_callback;
+#ifdef G_OS_UNIX
+      else if (source->source_funcs == &g_unix_fd_source_funcs)
+        closure_callback = (GSourceFunc)g_unix_fd_source_closure_callback;
+#endif
       else if (source->source_funcs == &g_timeout_funcs ||
-              source->source_funcs == &g_idle_funcs)
-       closure_callback = source_closure_callback;
+#ifdef G_OS_UNIX
+               source->source_funcs == &g_unix_signal_funcs ||
+#endif
+               source->source_funcs == &g_idle_funcs)
+        closure_callback = source_closure_callback;
     }
 
   *func = closure_callback;
@@ -145,6 +221,13 @@ static GSourceCallbackFuncs closure_callback_funcs = {
   closure_callback_get
 };
 
+static void
+closure_invalidated (gpointer  user_data,
+                     GClosure *closure)
+{
+  g_source_destroy (user_data);
+}
+
 /**
  * g_source_set_closure:
  * @source: the source
@@ -164,6 +247,11 @@ g_source_set_closure (GSource  *source,
   g_return_if_fail (closure != NULL);
 
   if (!source->source_funcs->closure_callback &&
+#ifdef G_OS_UNIX
+      source->source_funcs != &g_unix_fd_source_funcs &&
+      source->source_funcs != &g_unix_signal_funcs &&
+#endif
+      source->source_funcs != &g_child_watch_funcs &&
       source->source_funcs != &g_io_watch_funcs &&
       source->source_funcs != &g_timeout_funcs &&
       source->source_funcs != &g_idle_funcs)
@@ -176,19 +264,21 @@ g_source_set_closure (GSource  *source,
   g_closure_sink (closure);
   g_source_set_callback_indirect (source, closure, &closure_callback_funcs);
 
+  g_closure_add_invalidate_notifier (closure, source, closure_invalidated);
+
   if (G_CLOSURE_NEEDS_MARSHAL (closure))
     {
       GClosureMarshal marshal = (GClosureMarshal)source->source_funcs->closure_marshal;
-      if (!marshal)
-       {
-         if (source->source_funcs == &g_idle_funcs ||
-             source->source_funcs == &g_timeout_funcs)
-           marshal = source_closure_marshal_BOOLEAN__VOID;
-         else if (source->source_funcs == &g_io_watch_funcs)
-           marshal = g_cclosure_marshal_BOOLEAN__FLAGS;
-       }
       if (marshal)
        g_closure_set_marshal (closure, marshal);
+      else if (source->source_funcs == &g_idle_funcs ||
+#ifdef G_OS_UNIX
+               source->source_funcs == &g_unix_signal_funcs ||
+#endif
+               source->source_funcs == &g_timeout_funcs)
+       g_closure_set_marshal (closure, source_closure_marshal_BOOLEAN__VOID);
+      else
+        g_closure_set_marshal (closure, g_cclosure_marshal_generic);
     }
 }