… | |
… | |
995 | (and unfortunately a bit complex). |
995 | (and unfortunately a bit complex). |
996 | .PP |
996 | .PP |
997 | Unlike \f(CW\*(C`ev_timer\*(C'\fR's, they are not based on real time (or relative time) |
997 | Unlike \f(CW\*(C`ev_timer\*(C'\fR's, they are not based on real time (or relative time) |
998 | but on wallclock time (absolute time). You can tell a periodic watcher |
998 | but on wallclock time (absolute time). You can tell a periodic watcher |
999 | to trigger \*(L"at\*(R" some specific point in time. For example, if you tell a |
999 | to trigger \*(L"at\*(R" some specific point in time. For example, if you tell a |
1000 | periodic watcher to trigger in 10 seconds (by specifiying e.g. c<ev_now () |
1000 | periodic watcher to trigger in 10 seconds (by specifiying e.g. \f(CW\*(C`ev_now () |
1001 | + 10.>) and then reset your system clock to the last year, then it will |
1001 | + 10.\*(C'\fR) and then reset your system clock to the last year, then it will |
1002 | take a year to trigger the event (unlike an \f(CW\*(C`ev_timer\*(C'\fR, which would trigger |
1002 | take a year to trigger the event (unlike an \f(CW\*(C`ev_timer\*(C'\fR, which would trigger |
1003 | roughly 10 seconds later and of course not if you reset your system time |
1003 | roughly 10 seconds later and of course not if you reset your system time |
1004 | again). |
1004 | again). |
1005 | .PP |
1005 | .PP |
1006 | They can also be used to implement vastly more complex timers, such as |
1006 | They can also be used to implement vastly more complex timers, such as |
… | |
… | |
1432 | .IP "* The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need to use the libev header file and library." 4 |
1432 | .IP "* The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need to use the libev header file and library." 4 |
1433 | .IX Item "The libev emulation is not ABI compatible to libevent, you need to use the libev header file and library." |
1433 | .IX Item "The libev emulation is not ABI compatible to libevent, you need to use the libev header file and library." |
1434 | .PD |
1434 | .PD |
1435 | .SH "\*(C+ SUPPORT" |
1435 | .SH "\*(C+ SUPPORT" |
1436 | .IX Header " SUPPORT" |
1436 | .IX Header " SUPPORT" |
1437 | \&\s-1TBD\s0. |
1437 | Libev comes with some simplistic wrapper classes for \*(C+ that mainly allow |
|
|
1438 | you to use some convinience methods to start/stop watchers and also change |
|
|
1439 | the callback model to a model using method callbacks on objects. |
|
|
1440 | .PP |
|
|
1441 | To use it, |
|
|
1442 | .PP |
|
|
1443 | .Vb 1 |
|
|
1444 | \& #include <ev++.h> |
|
|
1445 | .Ve |
|
|
1446 | .PP |
|
|
1447 | (it is not installed by default). This automatically includes \fIev.h\fR |
|
|
1448 | and puts all of its definitions (many of them macros) into the global |
|
|
1449 | namespace. All \*(C+ specific things are put into the \f(CW\*(C`ev\*(C'\fR namespace. |
|
|
1450 | .PP |
|
|
1451 | It should support all the same embedding options as \fIev.h\fR, most notably |
|
|
1452 | \&\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. |
|
|
1453 | .PP |
|
|
1454 | Here is a list of things available in the \f(CW\*(C`ev\*(C'\fR namespace: |
|
|
1455 | .ie n .IP """ev::READ""\fR, \f(CW""ev::WRITE"" etc." 4 |
|
|
1456 | .el .IP "\f(CWev::READ\fR, \f(CWev::WRITE\fR etc." 4 |
|
|
1457 | .IX Item "ev::READ, ev::WRITE etc." |
|
|
1458 | These are just enum values with the same values as the \f(CW\*(C`EV_READ\*(C'\fR etc. |
|
|
1459 | macros from \fIev.h\fR. |
|
|
1460 | .ie n .IP """ev::tstamp""\fR, \f(CW""ev::now""" 4 |
|
|
1461 | .el .IP "\f(CWev::tstamp\fR, \f(CWev::now\fR" 4 |
|
|
1462 | .IX Item "ev::tstamp, ev::now" |
|
|
1463 | Aliases to the same types/functions as with the \f(CW\*(C`ev_\*(C'\fR prefix. |
|
|
1464 | .ie n .IP """ev::io""\fR, \f(CW""ev::timer""\fR, \f(CW""ev::periodic""\fR, \f(CW""ev::idle""\fR, \f(CW""ev::sig"" etc." 4 |
|
|
1465 | .el .IP "\f(CWev::io\fR, \f(CWev::timer\fR, \f(CWev::periodic\fR, \f(CWev::idle\fR, \f(CWev::sig\fR etc." 4 |
|
|
1466 | .IX Item "ev::io, ev::timer, ev::periodic, ev::idle, ev::sig etc." |
|
|
1467 | For each \f(CW\*(C`ev_TYPE\*(C'\fR watcher in \fIev.h\fR there is a corresponding class of |
|
|
1468 | the same name in the \f(CW\*(C`ev\*(C'\fR namespace, with the exception of \f(CW\*(C`ev_signal\*(C'\fR |
|
|
1469 | which is called \f(CW\*(C`ev::sig\*(C'\fR to avoid clashes with the \f(CW\*(C`signal\*(C'\fR macro |
|
|
1470 | defines by many implementations. |
|
|
1471 | .Sp |
|
|
1472 | All of those classes have these methods: |
|
|
1473 | .RS 4 |
|
|
1474 | .IP "ev::TYPE::TYPE (object *, object::method *)" 4 |
|
|
1475 | .IX Item "ev::TYPE::TYPE (object *, object::method *)" |
|
|
1476 | .PD 0 |
|
|
1477 | .IP "ev::TYPE::TYPE (object *, object::method *, struct ev_loop *)" 4 |
|
|
1478 | .IX Item "ev::TYPE::TYPE (object *, object::method *, struct ev_loop *)" |
|
|
1479 | .IP "ev::TYPE::~TYPE" 4 |
|
|
1480 | .IX Item "ev::TYPE::~TYPE" |
|
|
1481 | .PD |
|
|
1482 | The constructor takes a pointer to an object and a method pointer to |
|
|
1483 | the event handler callback to call in this class. The constructor calls |
|
|
1484 | \&\f(CW\*(C`ev_init\*(C'\fR for you, which means you have to call the \f(CW\*(C`set\*(C'\fR method |
|
|
1485 | before starting it. If you do not specify a loop then the constructor |
|
|
1486 | automatically associates the default loop with this watcher. |
|
|
1487 | .Sp |
|
|
1488 | The destructor automatically stops the watcher if it is active. |
|
|
1489 | .IP "w\->set (struct ev_loop *)" 4 |
|
|
1490 | .IX Item "w->set (struct ev_loop *)" |
|
|
1491 | Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only |
|
|
1492 | do this when the watcher is inactive (and not pending either). |
|
|
1493 | .IP "w\->set ([args])" 4 |
|
|
1494 | .IX Item "w->set ([args])" |
|
|
1495 | Basically the same as \f(CW\*(C`ev_TYPE_set\*(C'\fR, with the same args. Must be |
|
|
1496 | called at least once. Unlike the C counterpart, an active watcher gets |
|
|
1497 | automatically stopped and restarted. |
|
|
1498 | .IP "w\->start ()" 4 |
|
|
1499 | .IX Item "w->start ()" |
|
|
1500 | Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument as the |
|
|
1501 | constructor already takes the loop. |
|
|
1502 | .IP "w\->stop ()" 4 |
|
|
1503 | .IX Item "w->stop ()" |
|
|
1504 | Stops the watcher if it is active. Again, no \f(CW\*(C`loop\*(C'\fR argument. |
|
|
1505 | .ie n .IP "w\->again () ""ev::timer""\fR, \f(CW""ev::periodic"" only" 4 |
|
|
1506 | .el .IP "w\->again () \f(CWev::timer\fR, \f(CWev::periodic\fR only" 4 |
|
|
1507 | .IX Item "w->again () ev::timer, ev::periodic only" |
|
|
1508 | For \f(CW\*(C`ev::timer\*(C'\fR and \f(CW\*(C`ev::periodic\*(C'\fR, this invokes the corresponding |
|
|
1509 | \&\f(CW\*(C`ev_TYPE_again\*(C'\fR function. |
|
|
1510 | .ie n .IP "w\->sweep () ""ev::embed"" only" 4 |
|
|
1511 | .el .IP "w\->sweep () \f(CWev::embed\fR only" 4 |
|
|
1512 | .IX Item "w->sweep () ev::embed only" |
|
|
1513 | Invokes \f(CW\*(C`ev_embed_sweep\*(C'\fR. |
|
|
1514 | .RE |
|
|
1515 | .RS 4 |
|
|
1516 | .RE |
|
|
1517 | .PP |
|
|
1518 | Example: Define a class with an \s-1IO\s0 and idle watcher, start one of them in |
|
|
1519 | the constructor. |
|
|
1520 | .PP |
|
|
1521 | .Vb 4 |
|
|
1522 | \& class myclass |
|
|
1523 | \& { |
|
|
1524 | \& ev_io io; void io_cb (ev::io &w, int revents); |
|
|
1525 | \& ev_idle idle void idle_cb (ev::idle &w, int revents); |
|
|
1526 | .Ve |
|
|
1527 | .PP |
|
|
1528 | .Vb 2 |
|
|
1529 | \& myclass (); |
|
|
1530 | \& } |
|
|
1531 | .Ve |
|
|
1532 | .PP |
|
|
1533 | .Vb 6 |
|
|
1534 | \& myclass::myclass (int fd) |
|
|
1535 | \& : io (this, &myclass::io_cb), |
|
|
1536 | \& idle (this, &myclass::idle_cb) |
|
|
1537 | \& { |
|
|
1538 | \& io.start (fd, ev::READ); |
|
|
1539 | \& } |
|
|
1540 | .Ve |
1438 | .SH "AUTHOR" |
1541 | .SH "AUTHOR" |
1439 | .IX Header "AUTHOR" |
1542 | .IX Header "AUTHOR" |
1440 | Marc Lehmann <libev@schmorp.de>. |
1543 | Marc Lehmann <libev@schmorp.de>. |