man-pages/man3/Glib::MainLoop.3pm.html
2021-03-31 01:06:50 +01:00

393 lines
10 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Glib::MainLoop</TITLE>
</HEAD><BODY>
<H1>Glib::MainLoop</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2020-02-18<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Glib::MainLoop - An event source manager
<A NAME="lbAC">&nbsp;</A>
<H2>DESCRIPTION</H2>
Event-driven programs need some sort of loop which watches for events and
launches the appropriate actions. Glib::MainLoop provides this functionality.
<P>
Mainloops have context, provided by the MainContext object. For the most part
you can use the default context (see <TT>&quot;default&quot;</TT>), but if you want to create a
subcontext for a nested loop which doesn't have the same event sources, etc,
you can.
<P>
Event sources, attached to main contexts, watch for events to happen, and
launch appropriate actions. Glib provides a few ready-made event sources,
the Glib::Timeout, Glib::Idle, and io watch (<TT>&quot;Glib::IO-&gt;add_watch&quot;</TT>).
<P>
Under the hood, Gtk+ adds event sources for GdkEvents to dispatch events to
your widgets. In fact, Gtk2 provides an abstraction of Glib::MainLoop (See
<TT>&quot;Gtk2-&gt;main&quot;</TT> and friends), so you may rarely have cause to use
Glib::MainLoop directly.
<P>
Note: As of version 1.080, the Glib module uses a custom event source to
ensure that perl's safe signal handling and the glib polling event loop
play nicely together. It is no longer necessary to install a timeout to
ensure that async signals get handled in a timely manner.
<A NAME="lbAD">&nbsp;</A>
<H2>CONSTANTS</H2>
<TT>&quot;SOURCE_REMOVE&quot;</TT> and <TT>&quot;SOURCE_CONTINUE&quot;</TT> are designed for use as the
return values from timeout, idle and I/O watch source functions. They
return true to keep running or false to remove themselves. These
constants can help you get that the right way around.
<P>
<PRE>
Glib::SOURCE_CONTINUE # true
Glib::SOURCE_REMOVE # false
</PRE>
<A NAME="lbAE">&nbsp;</A>
<H2>METHODS</H2>
<A NAME="lbAF">&nbsp;</A>
<H3>maincontext thingamabob = Glib::MainContext-&gt;<B>new</B></H3>
<A NAME="lbAG">&nbsp;</A>
<H3>mainloop = Glib::MainLoop-&gt;<B>new</B> ($context=undef, $is_running=FALSE)</H3>
<DL COMPACT>
<DT id="1">&bull;<DD>
<TT>$context</TT> (Glib::MainContext thingamabob)
<DT id="2">&bull;<DD>
<TT>$is_running</TT> (boolean)
</DL>
<A NAME="lbAH">&nbsp;</A>
<H3>integer = Glib::Timeout-&gt;<B>add</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
<DL COMPACT>
<DT id="3">&bull;<DD>
<TT>$interval</TT> (integer) number of milliseconds
<DT id="4">&bull;<DD>
<TT>$callback</TT> (subroutine)
<DT id="5">&bull;<DD>
<TT>$data</TT> (scalar)
<DT id="6">&bull;<DD>
<TT>$priority</TT> (integer)
</DL>
<P>
Run <I></I>$callback<I></I> every <I></I>$interval<I></I> milliseconds until <I></I>$callback<I></I> returns
false. Returns a source id which may be used with <TT>&quot;Glib::Source-&gt;remove&quot;</TT>.
Note that a mainloop must be active for the timeout to execute.
<A NAME="lbAI">&nbsp;</A>
<H3>integer = Glib::Idle-&gt;<B>add</B> ($callback, $data=undef, $priority=G_PRIORITY_DEFAULT_IDLE)</H3>
<DL COMPACT>
<DT id="7">&bull;<DD>
<TT>$callback</TT> (subroutine)
<DT id="8">&bull;<DD>
<TT>$data</TT> (scalar)
<DT id="9">&bull;<DD>
<TT>$priority</TT> (integer)
</DL>
<P>
Run <I></I>$callback<I></I> when the mainloop is idle. If <I></I>$callback<I></I> returns false,
it will uninstall itself, otherwise, it will run again at the next idle
iteration. Returns a source id which may be used with
<TT>&quot;Glib::Source-&gt;remove&quot;</TT>.
<A NAME="lbAJ">&nbsp;</A>
<H3>integer = Glib::Timeout-&gt;<B>add_seconds</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
<DL COMPACT>
<DT id="10">&bull;<DD>
<TT>$interval</TT> (integer)
<DT id="11">&bull;<DD>
<TT>$callback</TT> (scalar)
<DT id="12">&bull;<DD>
<TT>$data</TT> (scalar)
<DT id="13">&bull;<DD>
<TT>$priority</TT> (integer)
</DL>
<P>
Since: glib 2.14
<A NAME="lbAK">&nbsp;</A>
<H3>integer = Glib::IO-&gt;<B>add_watch</B> ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
<DL COMPACT>
<DT id="14">&bull;<DD>
<TT>$fd</TT> (integer) file descriptor, e.g. fileno($filehandle)
<DT id="15">&bull;<DD>
<TT>$condition</TT> (Glib::IOCondition)
<DT id="16">&bull;<DD>
<TT>$callback</TT> (subroutine)
<DT id="17">&bull;<DD>
<TT>$data</TT> (scalar)
<DT id="18">&bull;<DD>
<TT>$priority</TT> (integer)
</DL>
<P>
Run <I></I>$callback<I></I> when there is an event on <I></I>$fd<I></I> that matches <I></I>$condition<I></I>.
The watch uninstalls itself if <I></I>$callback<I></I> returns false.
Returns a source id that may be used with <TT>&quot;Glib::Source-&gt;remove&quot;</TT>.
<P>
Glib's <FONT SIZE="-1">IO</FONT> channels serve the same basic purpose as Perl's file handles, so
for the most part you don't see GIOChannels in Perl. The <FONT SIZE="-1">IO</FONT> watch integrates
<FONT SIZE="-1">IO</FONT> operations with the main loop, which Perl file handles don't do. For
various reasons, this function requires raw file descriptors, not full
file handles. See <TT>&quot;fileno&quot;</TT> in perlfunc.
<A NAME="lbAL">&nbsp;</A>
<H3>maincontext thingamabob = $loop-&gt;<B>get_context</B></H3>
<A NAME="lbAM">&nbsp;</A>
<H3>maincontext thingamabob = Glib::MainContext-&gt;<B>default</B></H3>
<A NAME="lbAN">&nbsp;</A>
<H3>boolean = $context-&gt;<B>is_owner</B></H3>
Since: glib 2.12
<A NAME="lbAO">&nbsp;</A>
<H3>boolean = $loop-&gt;<B>is_running</B></H3>
<A NAME="lbAP">&nbsp;</A>
<H3>boolean = $context-&gt;<B>iteration</B> ($may_block)</H3>
<DL COMPACT>
<DT id="19">&bull;<DD>
<TT>$may_block</TT> (boolean)
</DL>
<A NAME="lbAQ">&nbsp;</A>
<H3>integer = Glib::main_depth</H3>
Find the current main loop recursion level. This is handy in fringe
situations, but those are very rare; see the C <FONT SIZE="-1">API</FONT> reference for a more
in-depth discussion.
<P>
Since: glib 2.4
<A NAME="lbAR">&nbsp;</A>
<H3>boolean = $context-&gt;<B>pending</B></H3>
<A NAME="lbAS">&nbsp;</A>
<H3>$loop-&gt;<B>quit</B></H3>
<A NAME="lbAT">&nbsp;</A>
<H3>boolean = Glib::Source-&gt;<B>remove</B> ($tag)</H3>
<DL COMPACT>
<DT id="20">&bull;<DD>
<TT>$tag</TT> (integer)
</DL>
<P>
Remove an event source. <I></I>$tag<I></I> is the number returned by things like
<TT>&quot;Glib::Timeout-&gt;add&quot;</TT>, <TT>&quot;Glib::Idle-&gt;add&quot;</TT>, and
<TT>&quot;Glib::IO-&gt;add_watch&quot;</TT>.
<A NAME="lbAU">&nbsp;</A>
<H3>$loop-&gt;<B>run</B></H3>
<A NAME="lbAV">&nbsp;</A>
<H3>integer = Glib::Child-&gt;<B>watch_add</B> ($pid, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
<DL COMPACT>
<DT id="21">&bull;<DD>
<TT>$pid</TT> (integer) child process <FONT SIZE="-1">ID</FONT>
<DT id="22">&bull;<DD>
<TT>$callback</TT> (subroutine)
<DT id="23">&bull;<DD>
<TT>$data</TT> (scalar)
<DT id="24">&bull;<DD>
<TT>$priority</TT> (integer)
</DL>
<P>
Add a source to the default main context which will call
<P>
<PRE>
&amp;$callback ($pid, $waitstatus, $data)
</PRE>
<P>
when child process <TT>$pid</TT> terminates. The return value is a source id
which can be used with <TT>&quot;Glib::Source-&gt;remove&quot;</TT>. When the callback
is made the source is removed automatically.
<P>
In a non-threaded program Glib implements this source by installing a
<FONT SIZE="-1">SIGCHLD</FONT> handler. Don't change <TT>$SIG</TT>{<FONT SIZE="-1">CHLD</FONT>} in Perl or the callback will
never run.
<P>
Since: glib 2.4
<A NAME="lbAW">&nbsp;</A>
<H2>ENUMS AND FLAGS</H2>
<A NAME="lbAX">&nbsp;</A>
<H3>flags Glib::IOCondition</H3>
<DL COMPACT>
<DT id="25">&bull;<DD>
'in' / 'G_IO_IN'
<DT id="26">&bull;<DD>
'out' / 'G_IO_OUT'
<DT id="27">&bull;<DD>
'pri' / 'G_IO_PRI'
<DT id="28">&bull;<DD>
'err' / 'G_IO_ERR'
<DT id="29">&bull;<DD>
'hup' / 'G_IO_HUP'
<DT id="30">&bull;<DD>
'nval' / 'G_IO_NVAL'
</DL>
<A NAME="lbAY">&nbsp;</A>
<H2>SEE ALSO</H2>
Glib
<A NAME="lbAZ">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright (C) 2003-2011 by the gtk2-perl team.
<P>
This software is licensed under the <FONT SIZE="-1">LGPL.</FONT> See Glib for a full notice.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="31"><A HREF="#lbAB">NAME</A><DD>
<DT id="32"><A HREF="#lbAC">DESCRIPTION</A><DD>
<DT id="33"><A HREF="#lbAD">CONSTANTS</A><DD>
<DT id="34"><A HREF="#lbAE">METHODS</A><DD>
<DL>
<DT id="35"><A HREF="#lbAF">maincontext thingamabob = Glib::MainContext-&gt;<B>new</B></A><DD>
<DT id="36"><A HREF="#lbAG">mainloop = Glib::MainLoop-&gt;<B>new</B> ($context=undef, $is_running=FALSE)</A><DD>
<DT id="37"><A HREF="#lbAH">integer = Glib::Timeout-&gt;<B>add</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</A><DD>
<DT id="38"><A HREF="#lbAI">integer = Glib::Idle-&gt;<B>add</B> ($callback, $data=undef, $priority=G_PRIORITY_DEFAULT_IDLE)</A><DD>
<DT id="39"><A HREF="#lbAJ">integer = Glib::Timeout-&gt;<B>add_seconds</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</A><DD>
<DT id="40"><A HREF="#lbAK">integer = Glib::IO-&gt;<B>add_watch</B> ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</A><DD>
<DT id="41"><A HREF="#lbAL">maincontext thingamabob = $loop-&gt;<B>get_context</B></A><DD>
<DT id="42"><A HREF="#lbAM">maincontext thingamabob = Glib::MainContext-&gt;<B>default</B></A><DD>
<DT id="43"><A HREF="#lbAN">boolean = $context-&gt;<B>is_owner</B></A><DD>
<DT id="44"><A HREF="#lbAO">boolean = $loop-&gt;<B>is_running</B></A><DD>
<DT id="45"><A HREF="#lbAP">boolean = $context-&gt;<B>iteration</B> ($may_block)</A><DD>
<DT id="46"><A HREF="#lbAQ">integer = Glib::main_depth</A><DD>
<DT id="47"><A HREF="#lbAR">boolean = $context-&gt;<B>pending</B></A><DD>
<DT id="48"><A HREF="#lbAS">$loop-&gt;<B>quit</B></A><DD>
<DT id="49"><A HREF="#lbAT">boolean = Glib::Source-&gt;<B>remove</B> ($tag)</A><DD>
<DT id="50"><A HREF="#lbAU">$loop-&gt;<B>run</B></A><DD>
<DT id="51"><A HREF="#lbAV">integer = Glib::Child-&gt;<B>watch_add</B> ($pid, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</A><DD>
</DL>
<DT id="52"><A HREF="#lbAW">ENUMS AND FLAGS</A><DD>
<DL>
<DT id="53"><A HREF="#lbAX">flags Glib::IOCondition</A><DD>
</DL>
<DT id="54"><A HREF="#lbAY">SEE ALSO</A><DD>
<DT id="55"><A HREF="#lbAZ">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:44 GMT, March 31, 2021
</BODY>
</HTML>