home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / perl5 / Glib / MainLoop.pod < prev    next >
Encoding:
Text File  |  2007-03-05  |  4.9 KB  |  271 lines

  1. =head1 NAME
  2.  
  3. Glib::MainLoop -  An event source manager
  4.  
  5. =for position DESCRIPTION
  6.  
  7. =head1 DESCRIPTION
  8.  
  9. Event-driven programs need some sort of loop which watches for events and
  10. launches the appropriate actions.  Glib::MainLoop provides this functionality.
  11.  
  12. Mainloops have context, provided by the MainContext object.  For the most part
  13. you can use the default context (see C<default>), but if you want to create a
  14. subcontext for a nested loop which doesn't have the same event sources, etc,
  15. you can.
  16.  
  17. Event sources, attached to main contexts, watch for events to happen, and
  18. launch appropriate actions.  Glib provides a few ready-made event sources,
  19. the Glib::Timeout, Glib::Idle, and io watch (C<< Glib::IO->add_watch >>).
  20.  
  21. Under the hood, Gtk+ adds event sources for GdkEvents to dispatch events to
  22. your widgets.  In fact, Gtk2 provides an abstraction of Glib::MainLoop (See
  23. C<< Gtk2->main >> and friends), so you may rarely have cause to use
  24. Glib::MainLoop directly.
  25.  
  26. Note: As of version 1.080, the Glib module uses a custom event source to
  27. ensure that perl's safe signal handling and the glib polling event loop
  28. play nicely together.  It is no longer necessary to install a timeout to
  29. ensure that async signals get handled in a timely manner.
  30.  
  31. =cut
  32.  
  33.  
  34.  
  35. =for object Glib::MainLoop
  36. =cut
  37.  
  38. =for object Glib::MainLoop An event source manager
  39. =cut
  40.  
  41. =for object Glib::MainLoop
  42. =cut
  43.  
  44. =for object Glib::MainLoop
  45. =cut
  46.  
  47. =for object Glib::MainLoop
  48. =cut
  49.  
  50. =for object Glib::MainLoop
  51. =cut
  52.  
  53.  
  54.  
  55.  
  56. =head1 METHODS
  57.  
  58. =head2 maincontext thingamabob = Glib::MainContext-E<gt>B<new> 
  59.  
  60. =over
  61.  
  62. =back
  63.  
  64. =head2 mainloop = Glib::MainLoop-E<gt>B<new> ($context=undef, $is_running=FALSE)
  65.  
  66. =over
  67.  
  68. =over
  69.  
  70. =item * $context (Glib::MainContext thingamabob) 
  71.  
  72. =item * $is_running (boolean) 
  73.  
  74. =back
  75.  
  76. =back
  77.  
  78. =head2 integer = Glib::Timeout-E<gt>B<add> ($interval, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)
  79.  
  80. =over
  81.  
  82. =over
  83.  
  84. =item * $interval (integer) number of milliseconds
  85.  
  86. =item * $callback (subroutine) 
  87.  
  88. =item * $data (scalar) 
  89.  
  90. =item * $priority (integer) 
  91.  
  92. =back
  93.  
  94.  
  95. Run I<$callback> every I<$interval> milliseconds until I<$callback> returns
  96. false.  Returns a source id which may be used with C<< Glib::Source->remove >>.
  97. Note that a mainloop must be active for the timeout to execute.
  98.  
  99.  
  100. =back
  101.  
  102. =head2 integer = Glib::Idle-E<gt>B<add> ($callback, $data=undef, $priority=G_PRIORITY_DEFAULT_IDLE)
  103.  
  104. =over
  105.  
  106. =over
  107.  
  108. =item * $callback (subroutine) 
  109.  
  110. =item * $data (scalar) 
  111.  
  112. =item * $priority (integer) 
  113.  
  114. =back
  115.  
  116.  
  117. Run I<$callback> when the mainloop is idle.  If I<$callback> returns false,
  118. it will uninstall itself, otherwise, it will run again at the next idle
  119. iteration.  Returns a source id which may be used with
  120. C<< Glib::Source->remove >>.
  121.  
  122.  
  123. =back
  124.  
  125. =head2 integer = Glib::IO-E<gt>B<add_watch> ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT)
  126.  
  127. =over
  128.  
  129. =over
  130.  
  131. =item * $fd (Glib::IO) file number, e.g. fileno($filehandle)
  132.  
  133. =item * $condition (Glib::IOCondition) 
  134.  
  135. =item * $callback (subroutine) 
  136.  
  137. =item * $data (scalar) 
  138.  
  139. =item * $priority (integer) 
  140.  
  141. =back
  142.  
  143.  
  144. Run I<$callback> when there is an event on I<$fd> that matches I<$condition>.
  145. The watch uninstalls itself if I<$callback> returns false.
  146. Returns a source id that may be used with C<< Glib::Source->remove >>.
  147.  
  148. Glib's IO channels serve the same basic purpose as Perl's file handles, so
  149. for the most part you don't see GIOChannels in Perl.  The IO watch integrates
  150. IO operations with the main loop, which Perl file handles don't do.  For
  151. various reasons, this function requires raw file descriptors, not full
  152. file handles.  See C<fileno> in L<perlfunc>.
  153.  
  154.  
  155. =back
  156.  
  157. =head2 maincontext thingamabob = $loop-E<gt>B<get_context> 
  158.  
  159. =over
  160.  
  161. =back
  162.  
  163. =head2 maincontext thingamabob = Glib::MainContext-E<gt>B<default> 
  164.  
  165. =over
  166.  
  167. =back
  168.  
  169. =head2 boolean = $loop-E<gt>B<is_running> 
  170.  
  171. =over
  172.  
  173. =back
  174.  
  175. =head2 boolean = $context-E<gt>B<iteration> ($may_block)
  176.  
  177. =over
  178.  
  179. =over
  180.  
  181. =item * $may_block (boolean) 
  182.  
  183. =back
  184.  
  185. =back
  186.  
  187. =head2 integer = Glib::main_depth 
  188.  
  189. =over
  190.  
  191. Find the current main loop recursion level.  This is handy in fringe
  192. situations, but those are very rare; see the C API reference for a more
  193. in-depth discussion.
  194.  
  195. =back
  196.  
  197. =head2 boolean = $context-E<gt>B<pending> 
  198.  
  199. =over
  200.  
  201. =back
  202.  
  203. =head2 $loop-E<gt>B<quit> 
  204.  
  205. =over
  206.  
  207. =back
  208.  
  209. =head2 boolean = Glib::Source-E<gt>B<remove> ($tag)
  210.  
  211. =over
  212.  
  213. =over
  214.  
  215. =item * $tag (integer) 
  216.  
  217. =back
  218.  
  219.  
  220. Remove an event source.  I<$tag> is the number returned by things like
  221. C<< Glib::Timeout->add >>, C<< Glib::Idle->add >>, and
  222. C<< Glib::IO->add_watch >>.
  223.  
  224.  
  225. =back
  226.  
  227. =head2 $loop-E<gt>B<run> 
  228.  
  229. =over
  230.  
  231. =back
  232.  
  233.  
  234. =head1 ENUMS AND FLAGS
  235.  
  236. =head2 flags Glib::IOCondition
  237.  
  238.  
  239.  
  240. =over
  241.  
  242. =item * 'in' / 'G_IO_IN'
  243.  
  244. =item * 'out' / 'G_IO_OUT'
  245.  
  246. =item * 'pri' / 'G_IO_PRI'
  247.  
  248. =item * 'err' / 'G_IO_ERR'
  249.  
  250. =item * 'hup' / 'G_IO_HUP'
  251.  
  252. =item * 'nval' / 'G_IO_NVAL'
  253.  
  254. =back
  255.  
  256.  
  257.  
  258. =head1 SEE ALSO
  259.  
  260. L<Glib>
  261.  
  262. =head1 COPYRIGHT
  263.  
  264. Copyright (C) 2003-2006 by the gtk2-perl team.
  265.  
  266. This software is licensed under the LGPL.  See L<Glib> for a full notice.
  267.  
  268.  
  269. =cut
  270.  
  271.