1Glib::MainLoop(3)     User Contributed Perl Documentation    Glib::MainLoop(3)
2
3
4

NAME

6       Glib::MainLoop -  An event source manager
7

DESCRIPTION

9       Event-driven programs need some sort of loop which watches for events
10       and launches the appropriate actions.  Glib::MainLoop provides this
11       functionality.
12
13       Mainloops have context, provided by the MainContext object.  For the
14       most part you can use the default context (see "default"), but if you
15       want to create a subcontext for a nested loop which doesn't have the
16       same event sources, etc, you can.
17
18       Event sources, attached to main contexts, watch for events to happen,
19       and launch appropriate actions.  Glib provides a few ready-made event
20       sources, the Glib::Timeout, Glib::Idle, and io watch
21       ("Glib::IO->add_watch").
22
23       Under the hood, Gtk+ adds event sources for GdkEvents to dispatch
24       events to your widgets.  In fact, Gtk2 provides an abstraction of
25       Glib::MainLoop (See "Gtk2->main" and friends), so you may rarely have
26       cause to use Glib::MainLoop directly.
27
28       Note: As of version 1.080, the Glib module uses a custom event source
29       to ensure that perl's safe signal handling and the glib polling event
30       loop play nicely together.  It is no longer necessary to install a
31       timeout to ensure that async signals get handled in a timely manner.
32

CONSTANTS

34       "SOURCE_REMOVE" and "SOURCE_CONTINUE" are designed for use as the
35       return values from timeout, idle and I/O watch source functions.  They
36       return true to keep running or false to remove themselves.  These
37       constants can help you get that the right way around.
38
39           Glib::SOURCE_CONTINUE     # true
40           Glib::SOURCE_REMOVE       # false
41

METHODS

43   maincontext thingamabob = Glib::MainContext->new
44   mainloop = Glib::MainLoop->new ($context=undef, $is_running=FALSE)
45       ·   $context (Glib::MainContext thingamabob)
46
47       ·   $is_running (boolean)
48
49   integer = Glib::Timeout->add ($interval, $callback, $data=undef,
50       $priority=G_PRIORITY_DEFAULT)
51       ·   $interval (integer) number of milliseconds
52
53       ·   $callback (subroutine)
54
55       ·   $data (scalar)
56
57       ·   $priority (integer)
58
59       Run $callback every $interval milliseconds until $callback returns
60       false.  Returns a source id which may be used with
61       "Glib::Source->remove".  Note that a mainloop must be active for the
62       timeout to execute.
63
64   integer = Glib::Idle->add ($callback, $data=undef,
65       $priority=G_PRIORITY_DEFAULT_IDLE)
66       ·   $callback (subroutine)
67
68       ·   $data (scalar)
69
70       ·   $priority (integer)
71
72       Run $callback when the mainloop is idle.  If $callback returns false,
73       it will uninstall itself, otherwise, it will run again at the next idle
74       iteration.  Returns a source id which may be used with
75       "Glib::Source->remove".
76
77   integer = Glib::Timeout->add_seconds ($interval, $callback, $data=undef,
78       $priority=G_PRIORITY_DEFAULT)
79       ·   $interval (integer)
80
81       ·   $callback (scalar)
82
83       ·   $data (scalar)
84
85       ·   $priority (integer)
86
87       Since: glib 2.14
88
89   integer = Glib::IO->add_watch ($fd, $condition, $callback, $data=undef,
90       $priority=G_PRIORITY_DEFAULT)
91       ·   $fd (integer) file descriptor, e.g. fileno($filehandle)
92
93       ·   $condition (Glib::IOCondition)
94
95       ·   $callback (subroutine)
96
97       ·   $data (scalar)
98
99       ·   $priority (integer)
100
101       Run $callback when there is an event on $fd that matches $condition.
102       The watch uninstalls itself if $callback returns false.  Returns a
103       source id that may be used with "Glib::Source->remove".
104
105       Glib's IO channels serve the same basic purpose as Perl's file handles,
106       so for the most part you don't see GIOChannels in Perl.  The IO watch
107       integrates IO operations with the main loop, which Perl file handles
108       don't do.  For various reasons, this function requires raw file
109       descriptors, not full file handles.  See "fileno" in perlfunc.
110
111   maincontext thingamabob = $loop->get_context
112   maincontext thingamabob = Glib::MainContext->default
113   boolean = $context->is_owner
114       Since: glib 2.12
115
116   boolean = $loop->is_running
117   boolean = $context->iteration ($may_block)
118       ·   $may_block (boolean)
119
120   integer = Glib::main_depth
121       Find the current main loop recursion level.  This is handy in fringe
122       situations, but those are very rare; see the C API reference for a more
123       in-depth discussion.
124
125       Since: glib 2.4
126
127   boolean = $context->pending
128   $loop->quit
129   boolean = Glib::Source->remove ($tag)
130       ·   $tag (integer)
131
132       Remove an event source.  $tag is the number returned by things like
133       "Glib::Timeout->add", "Glib::Idle->add", and "Glib::IO->add_watch".
134
135   $loop->run
136   integer = Glib::Child->watch_add ($pid, $callback, $data=undef,
137       $priority=G_PRIORITY_DEFAULT)
138       ·   $pid (integer) child process ID
139
140       ·   $callback (subroutine)
141
142       ·   $data (scalar)
143
144       ·   $priority (integer)
145
146       Add a source to the default main context which will call
147
148           &$callback ($pid, $waitstatus, $data)
149
150       when child process $pid terminates.  The return value is a source id
151       which can be used with "Glib::Source->remove".  When the callback is
152       made the source is removed automatically.
153
154       In a non-threaded program Glib implements this source by installing a
155       SIGCHLD handler.  Don't change $SIG{CHLD} in Perl or the callback will
156       never run.
157
158       Since: glib 2.4
159

ENUMS AND FLAGS

161   flags Glib::IOCondition
162       ·   'in' / 'G_IO_IN'
163
164       ·   'out' / 'G_IO_OUT'
165
166       ·   'pri' / 'G_IO_PRI'
167
168       ·   'err' / 'G_IO_ERR'
169
170       ·   'hup' / 'G_IO_HUP'
171
172       ·   'nval' / 'G_IO_NVAL'
173

SEE ALSO

175       Glib
176
178       Copyright (C) 2003-2011 by the gtk2-perl team.
179
180       This software is licensed under the LGPL.  See Glib for a full notice.
181
182
183
184perl v5.32.0                      2020-07-28                 Glib::MainLoop(3)
Impressum