From 73ce65a9122dd90fac253802fe20630572fdd4be Mon Sep 17 00:00:00 2001 From: root Date: Sat, 24 Nov 2007 09:48:37 +0000 Subject: document c++ api --- ev.html | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 4 deletions(-) (limited to 'ev.html') diff --git a/ev.html b/ev.html index b6e3e6e..8c61bc2 100644 --- a/ev.html +++ b/ev.html @@ -6,7 +6,7 @@ - + @@ -879,8 +879,8 @@ inactivity.

Unlike ev_timer's, they are not based on real time (or relative time) but on wallclock time (absolute time). You can tell a periodic watcher to trigger "at" some specific point in time. For example, if you tell a -periodic watcher to trigger in 10 seconds (by specifiying e.g. c<ev_now () -+ 10.>) and then reset your system clock to the last year, then it will +periodic watcher to trigger in 10 seconds (by specifiying e.g. ev_now () ++ 10.) and then reset your system clock to the last year, then it will take a year to trigger the event (unlike an ev_timer, which would trigger roughly 10 seconds later and of course not if you reset your system time again).

@@ -1308,7 +1308,100 @@ to use the libev header file and library.

C++ SUPPORT

Top

-

TBD.

+

Libev comes with some simplistic wrapper classes for C++ that mainly allow +you to use some convinience methods to start/stop watchers and also change +the callback model to a model using method callbacks on objects.

+

To use it,

+
  #include <ev++.h>
+
+
+

(it is not installed by default). This automatically includes ev.h +and puts all of its definitions (many of them macros) into the global +namespace. All C++ specific things are put into the ev namespace.

+

It should support all the same embedding options as ev.h, most notably +EV_MULTIPLICITY.

+

Here is a list of things available in the ev namespace:

+
+
ev::READ, ev::WRITE etc.
+
+

These are just enum values with the same values as the EV_READ etc. +macros from ev.h.

+
+
ev::tstamp, ev::now
+
+

Aliases to the same types/functions as with the ev_ prefix.

+
+
ev::io, ev::timer, ev::periodic, ev::idle, ev::sig etc.
+
+

For each ev_TYPE watcher in ev.h there is a corresponding class of +the same name in the ev namespace, with the exception of ev_signal +which is called ev::sig to avoid clashes with the signal macro +defines by many implementations.

+

All of those classes have these methods:

+

+

+
ev::TYPE::TYPE (object *, object::method *)
+
ev::TYPE::TYPE (object *, object::method *, struct ev_loop *)
+
ev::TYPE::~TYPE
+
+

The constructor takes a pointer to an object and a method pointer to +the event handler callback to call in this class. The constructor calls +ev_init for you, which means you have to call the set method +before starting it. If you do not specify a loop then the constructor +automatically associates the default loop with this watcher.

+

The destructor automatically stops the watcher if it is active.

+
+
w->set (struct ev_loop *)
+
+

Associates a different struct ev_loop with this watcher. You can only +do this when the watcher is inactive (and not pending either).

+
+
w->set ([args])
+
+

Basically the same as ev_TYPE_set, with the same args. Must be +called at least once. Unlike the C counterpart, an active watcher gets +automatically stopped and restarted.

+
+
w->start ()
+
+

Starts the watcher. Note that there is no loop argument as the +constructor already takes the loop.

+
+
w->stop ()
+
+

Stops the watcher if it is active. Again, no loop argument.

+
+
w->again () ev::timer, ev::periodic only
+
+

For ev::timer and ev::periodic, this invokes the corresponding +ev_TYPE_again function.

+
+
w->sweep () ev::embed only
+
+

Invokes ev_embed_sweep.

+
+
+

+
+
+

Example: Define a class with an IO and idle watcher, start one of them in +the constructor.

+
  class myclass
+  {
+    ev_io   io;   void io_cb   (ev::io   &w, int revents);
+    ev_idle idle  void idle_cb (ev::idle &w, int revents);
+
+    myclass ();
+  }
+
+  myclass::myclass (int fd)
+  : io   (this, &myclass::io_cb),
+    idle (this, &myclass::idle_cb)
+  {
+    io.start (fd, ev::READ);
+  }
+
+

AUTHOR

Top

-- cgit v1.2.3