Re: exception trap in key snooper callback



muppet <scott asofyet org> writes:

The important bit is gperl_run_exception_handlers(); the
rest is painful boilerplate.

Painful being the operative word :-).

I see what you mean about say the ->foreach methods not needing or
wanting exception trapping.  Is there anything beyond the key snooper
which is a main loop callback not using a GClosure thingie?  If there's
a few then maybe an option in GPerlCallback could give the G_EVAL bit.

The only one I can think of offhand is g_child_watch which I had a go at
lately (below, kinda tested a bit; but I got pretty cheesed off that
"GPid" is another absolutely ridiculous "portability" wrapper, and that
any perl level SIGCHLD use will break the watch ...)

--- GMainLoop.xs        16 Sep 2007 00:10:12 +1000      1.24
+++ GMainLoop.xs        17 Jul 2008 15:50:36 +1000      
@@ -136,6 +136,11 @@
        g_source_attach (async_watcher, NULL);
 }
 
+static void
+gperl_child_watch_callback (GPid pid, gint status, gpointer cb)
+{
+       gperl_callback_invoke ((GPerlCallback*)cb, NULL, (int) pid, status);
+}
 
 MODULE = Glib::MainLoop        PACKAGE = Glib  PREFIX = g_
 
@@ -549,3 +554,45 @@
     OUTPUT:
        RETVAL
 
+
+MODULE = Glib::MainLoop        PACKAGE = Glib::Child   PREFIX = g_child_
+
+=for object Glib::MainLoop
+=cut
+
+=for apidoc
+=for arg pid (integer) child process ID
+=for arg callback (subroutine)
+
+Add a source to the default main context to call
+
+    &$callback ($waitstatus, $data)
+
+when child process $pid terminates.  The return value is a source id
+which can be used with C<< Glib::Source->remove >>.  When the callback
+is made the source is removed automatically.
+
+In a non-threaded program Glib implements this source by installing a
+SIGCHLD handler.  Don't change change $SIG{CHLD} from Perl or the
+callback will never run.
+
+=cut
+guint
+g_child_watch_add (class, int pid, SV *callback, SV *data=NULL, gint priority=G_PRIORITY_DEFAULT)
+    PREINIT:
+       GPerlCallback* cb;
+       GType param_types[2];
+    CODE:
+       /* As of Glib 2.16.4 there's no "callback_closure" func in
+          g_child_watch_funcs, and none added there by
+          g_source_set_closure (unlike idle, timeout and io above),
+          so go through the callback style. */
+       param_types[0] = G_TYPE_INT;
+       param_types[1] = G_TYPE_INT;
+       cb = gperl_callback_new (callback, data, 2, param_types, 0);
+       RETVAL = g_child_watch_add_full (priority, (GPid) pid,
+                                        gperl_child_watch_callback,
+                                        cb,
+                       (GDestroyNotify) gperl_callback_destroy);
+    OUTPUT:
+       RETVAL

-- 
I made a Freedom of Information request to the Taxation Office asking
whether they had an open audit file on me.  A week later the reply came:
"We do now."


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