ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.37 by root, Sat Nov 24 07:20:43 2007 UTC vs.
Revision 1.38 by root, Sat Nov 24 09:48:38 2007 UTC

856(and unfortunately a bit complex). 856(and unfortunately a bit complex).
857 857
858Unlike C<ev_timer>'s, they are not based on real time (or relative time) 858Unlike C<ev_timer>'s, they are not based on real time (or relative time)
859but on wallclock time (absolute time). You can tell a periodic watcher 859but on wallclock time (absolute time). You can tell a periodic watcher
860to trigger "at" some specific point in time. For example, if you tell a 860to trigger "at" some specific point in time. For example, if you tell a
861periodic watcher to trigger in 10 seconds (by specifiying e.g. c<ev_now () 861periodic watcher to trigger in 10 seconds (by specifiying e.g. C<ev_now ()
862+ 10.>) and then reset your system clock to the last year, then it will 862+ 10.>) and then reset your system clock to the last year, then it will
863take a year to trigger the event (unlike an C<ev_timer>, which would trigger 863take a year to trigger the event (unlike an C<ev_timer>, which would trigger
864roughly 10 seconds later and of course not if you reset your system time 864roughly 10 seconds later and of course not if you reset your system time
865again). 865again).
866 866
1310 1310
1311=back 1311=back
1312 1312
1313=head1 C++ SUPPORT 1313=head1 C++ SUPPORT
1314 1314
1315TBD. 1315Libev comes with some simplistic wrapper classes for C++ that mainly allow
1316you to use some convinience methods to start/stop watchers and also change
1317the callback model to a model using method callbacks on objects.
1318
1319To use it,
1320
1321 #include <ev++.h>
1322
1323(it is not installed by default). This automatically includes F<ev.h>
1324and puts all of its definitions (many of them macros) into the global
1325namespace. All C++ specific things are put into the C<ev> namespace.
1326
1327It should support all the same embedding options as F<ev.h>, most notably
1328C<EV_MULTIPLICITY>.
1329
1330Here is a list of things available in the C<ev> namespace:
1331
1332=over 4
1333
1334=item C<ev::READ>, C<ev::WRITE> etc.
1335
1336These are just enum values with the same values as the C<EV_READ> etc.
1337macros from F<ev.h>.
1338
1339=item C<ev::tstamp>, C<ev::now>
1340
1341Aliases to the same types/functions as with the C<ev_> prefix.
1342
1343=item C<ev::io>, C<ev::timer>, C<ev::periodic>, C<ev::idle>, C<ev::sig> etc.
1344
1345For each C<ev_TYPE> watcher in F<ev.h> there is a corresponding class of
1346the same name in the C<ev> namespace, with the exception of C<ev_signal>
1347which is called C<ev::sig> to avoid clashes with the C<signal> macro
1348defines by many implementations.
1349
1350All of those classes have these methods:
1351
1352=over 4
1353
1354=item ev::TYPE::TYPE (object *, object::method *)
1355
1356=item ev::TYPE::TYPE (object *, object::method *, struct ev_loop *)
1357
1358=item ev::TYPE::~TYPE
1359
1360The constructor takes a pointer to an object and a method pointer to
1361the event handler callback to call in this class. The constructor calls
1362C<ev_init> for you, which means you have to call the C<set> method
1363before starting it. If you do not specify a loop then the constructor
1364automatically associates the default loop with this watcher.
1365
1366The destructor automatically stops the watcher if it is active.
1367
1368=item w->set (struct ev_loop *)
1369
1370Associates a different C<struct ev_loop> with this watcher. You can only
1371do this when the watcher is inactive (and not pending either).
1372
1373=item w->set ([args])
1374
1375Basically the same as C<ev_TYPE_set>, with the same args. Must be
1376called at least once. Unlike the C counterpart, an active watcher gets
1377automatically stopped and restarted.
1378
1379=item w->start ()
1380
1381Starts the watcher. Note that there is no C<loop> argument as the
1382constructor already takes the loop.
1383
1384=item w->stop ()
1385
1386Stops the watcher if it is active. Again, no C<loop> argument.
1387
1388=item w->again () C<ev::timer>, C<ev::periodic> only
1389
1390For C<ev::timer> and C<ev::periodic>, this invokes the corresponding
1391C<ev_TYPE_again> function.
1392
1393=item w->sweep () C<ev::embed> only
1394
1395Invokes C<ev_embed_sweep>.
1396
1397=back
1398
1399=back
1400
1401Example: Define a class with an IO and idle watcher, start one of them in
1402the constructor.
1403
1404 class myclass
1405 {
1406 ev_io io; void io_cb (ev::io &w, int revents);
1407 ev_idle idle void idle_cb (ev::idle &w, int revents);
1408
1409 myclass ();
1410 }
1411
1412 myclass::myclass (int fd)
1413 : io (this, &myclass::io_cb),
1414 idle (this, &myclass::idle_cb)
1415 {
1416 io.start (fd, ev::READ);
1417 }
1316 1418
1317=head1 AUTHOR 1419=head1 AUTHOR
1318 1420
1319Marc Lehmann <libev@schmorp.de>. 1421Marc Lehmann <libev@schmorp.de>.
1320 1422

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines