.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Glib::MainLoop 3pm" .TH Glib::MainLoop 3pm "2014-08-29" "perl v5.20.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Glib::MainLoop \- An event source manager .SH "DESCRIPTION" .IX Header "DESCRIPTION" Event-driven programs need some sort of loop which watches for events and launches the appropriate actions. Glib::MainLoop provides this functionality. .PP Mainloops have context, provided by the MainContext object. For the most part you can use the default context (see \f(CW\*(C`default\*(C'\fR), but if you want to create a subcontext for a nested loop which doesn't have the same event sources, etc, you can. .PP 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 (\f(CW\*(C`Glib::IO\->add_watch\*(C'\fR). .PP 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 \&\f(CW\*(C`Gtk2\->main\*(C'\fR and friends), so you may rarely have cause to use Glib::MainLoop directly. .PP 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. .SH "CONSTANTS" .IX Header "CONSTANTS" \&\f(CW\*(C`SOURCE_REMOVE\*(C'\fR and \f(CW\*(C`SOURCE_CONTINUE\*(C'\fR 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. .PP .Vb 2 \& Glib::SOURCE_CONTINUE # true \& Glib::SOURCE_REMOVE # false .Ve .SH "METHODS" .IX Header "METHODS" .SS "maincontext thingamabob = Glib::MainContext\->\fBnew\fP" .IX Subsection "maincontext thingamabob = Glib::MainContext->new" .ie n .SS "mainloop = Glib::MainLoop\->\fBnew\fP ($context=undef, $is_running=FALSE)" .el .SS "mainloop = Glib::MainLoop\->\fBnew\fP ($context=undef, \f(CW$is_running\fP=FALSE)" .IX Subsection "mainloop = Glib::MainLoop->new ($context=undef, $is_running=FALSE)" .IP "\(bu" 4 \&\f(CW$context\fR (Glib::MainContext thingamabob) .IP "\(bu" 4 \&\f(CW$is_running\fR (boolean) .ie n .SS "integer = Glib::Timeout\->\fBadd\fP ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .el .SS "integer = Glib::Timeout\->\fBadd\fP ($interval, \f(CW$callback\fP, \f(CW$data\fP=undef, \f(CW$priority\fP=G_PRIORITY_DEFAULT)" .IX Subsection "integer = Glib::Timeout->add ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .IP "\(bu" 4 \&\f(CW$interval\fR (integer) number of milliseconds .IP "\(bu" 4 \&\f(CW$callback\fR (subroutine) .IP "\(bu" 4 \&\f(CW$data\fR (scalar) .IP "\(bu" 4 \&\f(CW$priority\fR (integer) .PP Run \fI\f(CI$callback\fI\fR every \fI\f(CI$interval\fI\fR milliseconds until \fI\f(CI$callback\fI\fR returns false. Returns a source id which may be used with \f(CW\*(C`Glib::Source\->remove\*(C'\fR. Note that a mainloop must be active for the timeout to execute. .ie n .SS "integer = Glib::Idle\->\fBadd\fP ($callback, $data=undef, $priority=G_PRIORITY_DEFAULT_IDLE)" .el .SS "integer = Glib::Idle\->\fBadd\fP ($callback, \f(CW$data\fP=undef, \f(CW$priority\fP=G_PRIORITY_DEFAULT_IDLE)" .IX Subsection "integer = Glib::Idle->add ($callback, $data=undef, $priority=G_PRIORITY_DEFAULT_IDLE)" .IP "\(bu" 4 \&\f(CW$callback\fR (subroutine) .IP "\(bu" 4 \&\f(CW$data\fR (scalar) .IP "\(bu" 4 \&\f(CW$priority\fR (integer) .PP Run \fI\f(CI$callback\fI\fR when the mainloop is idle. If \fI\f(CI$callback\fI\fR 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 \&\f(CW\*(C`Glib::Source\->remove\*(C'\fR. .ie n .SS "integer = Glib::Timeout\->\fBadd_seconds\fP ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .el .SS "integer = Glib::Timeout\->\fBadd_seconds\fP ($interval, \f(CW$callback\fP, \f(CW$data\fP=undef, \f(CW$priority\fP=G_PRIORITY_DEFAULT)" .IX Subsection "integer = Glib::Timeout->add_seconds ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .IP "\(bu" 4 \&\f(CW$interval\fR (integer) .IP "\(bu" 4 \&\f(CW$callback\fR (scalar) .IP "\(bu" 4 \&\f(CW$data\fR (scalar) .IP "\(bu" 4 \&\f(CW$priority\fR (integer) .PP Since: glib 2.14 .ie n .SS "integer = Glib::IO\->\fBadd_watch\fP ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .el .SS "integer = Glib::IO\->\fBadd_watch\fP ($fd, \f(CW$condition\fP, \f(CW$callback\fP, \f(CW$data\fP=undef, \f(CW$priority\fP=G_PRIORITY_DEFAULT)" .IX Subsection "integer = Glib::IO->add_watch ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .IP "\(bu" 4 \&\f(CW$fd\fR (integer) file descriptor, e.g. fileno($filehandle) .IP "\(bu" 4 \&\f(CW$condition\fR (Glib::IOCondition) .IP "\(bu" 4 \&\f(CW$callback\fR (subroutine) .IP "\(bu" 4 \&\f(CW$data\fR (scalar) .IP "\(bu" 4 \&\f(CW$priority\fR (integer) .PP Run \fI\f(CI$callback\fI\fR when there is an event on \fI\f(CI$fd\fI\fR that matches \fI\f(CI$condition\fI\fR. The watch uninstalls itself if \fI\f(CI$callback\fI\fR returns false. Returns a source id that may be used with \f(CW\*(C`Glib::Source\->remove\*(C'\fR. .PP Glib's \s-1IO\s0 channels serve the same basic purpose as Perl's file handles, so for the most part you don't see GIOChannels in Perl. The \s-1IO\s0 watch integrates \&\s-1IO\s0 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 \f(CW\*(C`fileno\*(C'\fR in perlfunc. .ie n .SS "maincontext thingamabob = $loop\->\fBget_context\fP" .el .SS "maincontext thingamabob = \f(CW$loop\fP\->\fBget_context\fP" .IX Subsection "maincontext thingamabob = $loop->get_context" .SS "maincontext thingamabob = Glib::MainContext\->\fBdefault\fP" .IX Subsection "maincontext thingamabob = Glib::MainContext->default" .ie n .SS "boolean = $context\->\fBis_owner\fP" .el .SS "boolean = \f(CW$context\fP\->\fBis_owner\fP" .IX Subsection "boolean = $context->is_owner" Since: glib 2.12 .ie n .SS "boolean = $loop\->\fBis_running\fP" .el .SS "boolean = \f(CW$loop\fP\->\fBis_running\fP" .IX Subsection "boolean = $loop->is_running" .ie n .SS "boolean = $context\->\fBiteration\fP ($may_block)" .el .SS "boolean = \f(CW$context\fP\->\fBiteration\fP ($may_block)" .IX Subsection "boolean = $context->iteration ($may_block)" .IP "\(bu" 4 \&\f(CW$may_block\fR (boolean) .SS "integer = Glib::main_depth" .IX Subsection "integer = Glib::main_depth" Find the current main loop recursion level. This is handy in fringe situations, but those are very rare; see the C \s-1API\s0 reference for a more in-depth discussion. .PP Since: glib 2.4 .ie n .SS "boolean = $context\->\fBpending\fP" .el .SS "boolean = \f(CW$context\fP\->\fBpending\fP" .IX Subsection "boolean = $context->pending" .ie n .SS "$loop\->\fBquit\fP" .el .SS "\f(CW$loop\fP\->\fBquit\fP" .IX Subsection "$loop->quit" .SS "boolean = Glib::Source\->\fBremove\fP ($tag)" .IX Subsection "boolean = Glib::Source->remove ($tag)" .IP "\(bu" 4 \&\f(CW$tag\fR (integer) .PP Remove an event source. \fI\f(CI$tag\fI\fR is the number returned by things like \&\f(CW\*(C`Glib::Timeout\->add\*(C'\fR, \f(CW\*(C`Glib::Idle\->add\*(C'\fR, and \&\f(CW\*(C`Glib::IO\->add_watch\*(C'\fR. .ie n .SS "$loop\->\fBrun\fP" .el .SS "\f(CW$loop\fP\->\fBrun\fP" .IX Subsection "$loop->run" .ie n .SS "integer = Glib::Child\->\fBwatch_add\fP ($pid, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .el .SS "integer = Glib::Child\->\fBwatch_add\fP ($pid, \f(CW$callback\fP, \f(CW$data\fP=undef, \f(CW$priority\fP=G_PRIORITY_DEFAULT)" .IX Subsection "integer = Glib::Child->watch_add ($pid, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)" .IP "\(bu" 4 \&\f(CW$pid\fR (integer) child process \s-1ID\s0 .IP "\(bu" 4 \&\f(CW$callback\fR (subroutine) .IP "\(bu" 4 \&\f(CW$data\fR (scalar) .IP "\(bu" 4 \&\f(CW$priority\fR (integer) .PP Add a source to the default main context which will call .PP .Vb 1 \& &$callback ($pid, $waitstatus, $data) .Ve .PP when child process \f(CW$pid\fR terminates. The return value is a source id which can be used with \f(CW\*(C`Glib::Source\->remove\*(C'\fR. When the callback is made the source is removed automatically. .PP In a non-threaded program Glib implements this source by installing a \&\s-1SIGCHLD\s0 handler. Don't change \f(CW$SIG\fR{\s-1CHLD\s0} in Perl or the callback will never run. .PP Since: glib 2.4 .SH "ENUMS AND FLAGS" .IX Header "ENUMS AND FLAGS" .SS "flags Glib::IOCondition" .IX Subsection "flags Glib::IOCondition" .IP "\(bu" 4 \&'in' / 'G_IO_IN' .IP "\(bu" 4 \&'out' / 'G_IO_OUT' .IP "\(bu" 4 \&'pri' / 'G_IO_PRI' .IP "\(bu" 4 \&'err' / 'G_IO_ERR' .IP "\(bu" 4 \&'hup' / 'G_IO_HUP' .IP "\(bu" 4 \&'nval' / 'G_IO_NVAL' .SH "SEE ALSO" .IX Header "SEE ALSO" Glib .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2003\-2011 by the gtk2\-perl team. .PP This software is licensed under the \s-1LGPL. \s0 See Glib for a full notice.