<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.ev.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'ev.watcher-callbacks.php',
    1 => 'Watcher callbacks',
    2 => 'Watcher callbacks',
  ),
  'up' => 
  array (
    0 => 'book.ev.php',
    1 => 'Ev',
  ),
  'prev' => 
  array (
    0 => 'ev.watchers.php',
    1 => 'Watchers',
  ),
  'next' => 
  array (
    0 => 'ev.periodic-modes.php',
    1 => 'Periodic watcher operation modes',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ev/watcher-callbacks.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="ev.watcher-callbacks" class="chapter">
 <h1 class="title">Watcher callbacks</h1>

 <p class="simpara">
  All watchers can be active(waiting for events) or inactive(paused). Only
  active watchers will have their callbacks invoked. All callbacks will be
  called with at least two arguments:
  <code class="parameter">watcher</code>
  - the watcher, and
  <code class="parameter">revents</code>
  a bitmask of received events.
 </p>
 <p class="simpara">
  Watcher callbacks are passed to the watcher constructors (the classes derived
  from
  <span class="classname"><a href="class.evwatcher.php" class="classname">EvWatcher</a></span>
  -
  <span class="methodname"><a href="evcheck.construct.php" class="methodname">EvCheck::__construct()</a></span>,
  <span class="methodname"><a href="evchild.construct.php" class="methodname">EvChild::__construct()</a></span>
  etc.). A watcher callback should match the following prototype:
 </p>
 <div class="methodsynopsis dc-description"><span class="methodname"><strong>callback</strong></span>(<span class="methodparam">
   
   <span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$watcher</code>
   <span class="initializer"> = NULL</span>
  </span>, <span class="methodparam">
   
   <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$revents</code>
   <span class="initializer"> = NULL</span>
  </span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

 <dl>
  
   <dt>
    <code class="parameter">watcher</code>
   </dt>
   <dd>
    <span class="simpara">
     The watcher instance(of a class extending
     <span class="classname"><a href="class.evwatcher.php" class="classname">EvWatcher</a></span>
     ).
    </span>
   </dd>
  
  
   <dt>
    <code class="parameter">revents</code>
   </dt>
   <dd>
    <span class="simpara">
     <a href="class.ev.php#ev.constants.watcher-revents" class="link">Watcher received events</a>.
    </span>
   </dd>
  
 </dl>
 <p class="simpara">
  Each watcher type has its associated bit in
  <code class="parameter">revents</code>,
  so one can use the same callback for multiple watchers. The event mask is
  named after the type, i.e.
  <span class="classname"><a href="class.evchild.php" class="classname">EvChild</a></span>
  (or
  <span class="methodname"><a href="evloop.child.php" class="methodname">EvLoop::child()</a></span>)
  sets
  <strong><code><a href="class.ev.php#ev.constants.child">EV::CHILD</a></code></strong>,
  <span class="classname"><a href="class.evprepare.php" class="classname">EvPrepare</a></span>
  (or
  <span class="methodname"><a href="evloop.prepare.php" class="methodname">EvLoop::prepare()</a></span>)
  sets
  <strong><code><a href="class.ev.php#ev.constants.prepare">Ev::PREPARE</a></code></strong>,
  <span class="classname"><a href="class.evperiodic.php" class="classname">EvPeriodic</a></span>
  (or
  <span class="methodname"><a href="evloop.periodic.php" class="methodname">EvLoop::periodic()</a></span>)
  sets
  <strong><code><a href="class.ev.php#ev.constants.periodic">Ev::PERIODIC</a></code></strong>
  and so on, with the exception of I/O events (which can set both
  <strong><code><a href="class.ev.php#ev.constants.read">Ev::READ</a></code></strong>
  and
  <strong><code><a href="class.ev.php#ev.constants.write">Ev::WRITE</a></code></strong>
  bits).
 </p>
</div>
<?php manual_footer($setup); ?>