393 lines
10 KiB
HTML
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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Glib::MainLoop - An event source manager
|
|
<A NAME="lbAC"> </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>"default"</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>"Glib::IO->add_watch"</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>"Gtk2->main"</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"> </A>
|
|
<H2>CONSTANTS</H2>
|
|
|
|
|
|
|
|
<TT>"SOURCE_REMOVE"</TT> and <TT>"SOURCE_CONTINUE"</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"> </A>
|
|
<H2>METHODS</H2>
|
|
|
|
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>maincontext thingamabob = Glib::MainContext-><B>new</B></H3>
|
|
|
|
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>mainloop = Glib::MainLoop-><B>new</B> ($context=undef, $is_running=FALSE)</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="1">•<DD>
|
|
<TT>$context</TT> (Glib::MainContext thingamabob)
|
|
<DT id="2">•<DD>
|
|
<TT>$is_running</TT> (boolean)
|
|
</DL>
|
|
<A NAME="lbAH"> </A>
|
|
<H3>integer = Glib::Timeout-><B>add</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="3">•<DD>
|
|
<TT>$interval</TT> (integer) number of milliseconds
|
|
<DT id="4">•<DD>
|
|
<TT>$callback</TT> (subroutine)
|
|
<DT id="5">•<DD>
|
|
<TT>$data</TT> (scalar)
|
|
<DT id="6">•<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>"Glib::Source->remove"</TT>.
|
|
Note that a mainloop must be active for the timeout to execute.
|
|
<A NAME="lbAI"> </A>
|
|
<H3>integer = Glib::Idle-><B>add</B> ($callback, $data=undef, $priority=G_PRIORITY_DEFAULT_IDLE)</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="7">•<DD>
|
|
<TT>$callback</TT> (subroutine)
|
|
<DT id="8">•<DD>
|
|
<TT>$data</TT> (scalar)
|
|
<DT id="9">•<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>"Glib::Source->remove"</TT>.
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>integer = Glib::Timeout-><B>add_seconds</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="10">•<DD>
|
|
<TT>$interval</TT> (integer)
|
|
<DT id="11">•<DD>
|
|
<TT>$callback</TT> (scalar)
|
|
<DT id="12">•<DD>
|
|
<TT>$data</TT> (scalar)
|
|
<DT id="13">•<DD>
|
|
<TT>$priority</TT> (integer)
|
|
</DL>
|
|
<P>
|
|
|
|
Since: glib 2.14
|
|
<A NAME="lbAK"> </A>
|
|
<H3>integer = Glib::IO-><B>add_watch</B> ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="14">•<DD>
|
|
<TT>$fd</TT> (integer) file descriptor, e.g. fileno($filehandle)
|
|
<DT id="15">•<DD>
|
|
<TT>$condition</TT> (Glib::IOCondition)
|
|
<DT id="16">•<DD>
|
|
<TT>$callback</TT> (subroutine)
|
|
<DT id="17">•<DD>
|
|
<TT>$data</TT> (scalar)
|
|
<DT id="18">•<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>"Glib::Source->remove"</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>"fileno"</TT> in perlfunc.
|
|
<A NAME="lbAL"> </A>
|
|
<H3>maincontext thingamabob = $loop-><B>get_context</B></H3>
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H3>maincontext thingamabob = Glib::MainContext-><B>default</B></H3>
|
|
|
|
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H3>boolean = $context-><B>is_owner</B></H3>
|
|
|
|
|
|
|
|
|
|
|
|
Since: glib 2.12
|
|
<A NAME="lbAO"> </A>
|
|
<H3>boolean = $loop-><B>is_running</B></H3>
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAP"> </A>
|
|
<H3>boolean = $context-><B>iteration</B> ($may_block)</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="19">•<DD>
|
|
<TT>$may_block</TT> (boolean)
|
|
</DL>
|
|
<A NAME="lbAQ"> </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"> </A>
|
|
<H3>boolean = $context-><B>pending</B></H3>
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAS"> </A>
|
|
<H3>$loop-><B>quit</B></H3>
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAT"> </A>
|
|
<H3>boolean = Glib::Source-><B>remove</B> ($tag)</H3>
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="20">•<DD>
|
|
<TT>$tag</TT> (integer)
|
|
</DL>
|
|
<P>
|
|
|
|
Remove an event source. <I></I>$tag<I></I> is the number returned by things like
|
|
<TT>"Glib::Timeout->add"</TT>, <TT>"Glib::Idle->add"</TT>, and
|
|
<TT>"Glib::IO->add_watch"</TT>.
|
|
<A NAME="lbAU"> </A>
|
|
<H3>$loop-><B>run</B></H3>
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAV"> </A>
|
|
<H3>integer = Glib::Child-><B>watch_add</B> ($pid, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="21">•<DD>
|
|
<TT>$pid</TT> (integer) child process <FONT SIZE="-1">ID</FONT>
|
|
<DT id="22">•<DD>
|
|
<TT>$callback</TT> (subroutine)
|
|
<DT id="23">•<DD>
|
|
<TT>$data</TT> (scalar)
|
|
<DT id="24">•<DD>
|
|
<TT>$priority</TT> (integer)
|
|
</DL>
|
|
<P>
|
|
|
|
Add a source to the default main context which will call
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
&$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>"Glib::Source->remove"</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"> </A>
|
|
<H2>ENUMS AND FLAGS</H2>
|
|
|
|
|
|
|
|
<A NAME="lbAX"> </A>
|
|
<H3>flags Glib::IOCondition</H3>
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="25">•<DD>
|
|
'in' / 'G_IO_IN'
|
|
<DT id="26">•<DD>
|
|
'out' / 'G_IO_OUT'
|
|
<DT id="27">•<DD>
|
|
'pri' / 'G_IO_PRI'
|
|
<DT id="28">•<DD>
|
|
'err' / 'G_IO_ERR'
|
|
<DT id="29">•<DD>
|
|
'hup' / 'G_IO_HUP'
|
|
<DT id="30">•<DD>
|
|
'nval' / 'G_IO_NVAL'
|
|
</DL>
|
|
<A NAME="lbAY"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
Glib
|
|
<A NAME="lbAZ"> </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"> </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-><B>new</B></A><DD>
|
|
<DT id="36"><A HREF="#lbAG">mainloop = Glib::MainLoop-><B>new</B> ($context=undef, $is_running=FALSE)</A><DD>
|
|
<DT id="37"><A HREF="#lbAH">integer = Glib::Timeout-><B>add</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</A><DD>
|
|
<DT id="38"><A HREF="#lbAI">integer = Glib::Idle-><B>add</B> ($callback, $data=undef, $priority=G_PRIORITY_DEFAULT_IDLE)</A><DD>
|
|
<DT id="39"><A HREF="#lbAJ">integer = Glib::Timeout-><B>add_seconds</B> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</A><DD>
|
|
<DT id="40"><A HREF="#lbAK">integer = Glib::IO-><B>add_watch</B> ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)</A><DD>
|
|
<DT id="41"><A HREF="#lbAL">maincontext thingamabob = $loop-><B>get_context</B></A><DD>
|
|
<DT id="42"><A HREF="#lbAM">maincontext thingamabob = Glib::MainContext-><B>default</B></A><DD>
|
|
<DT id="43"><A HREF="#lbAN">boolean = $context-><B>is_owner</B></A><DD>
|
|
<DT id="44"><A HREF="#lbAO">boolean = $loop-><B>is_running</B></A><DD>
|
|
<DT id="45"><A HREF="#lbAP">boolean = $context-><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-><B>pending</B></A><DD>
|
|
<DT id="48"><A HREF="#lbAS">$loop-><B>quit</B></A><DD>
|
|
<DT id="49"><A HREF="#lbAT">boolean = Glib::Source-><B>remove</B> ($tag)</A><DD>
|
|
<DT id="50"><A HREF="#lbAU">$loop-><B>run</B></A><DD>
|
|
<DT id="51"><A HREF="#lbAV">integer = Glib::Child-><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>
|