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

Comparing libev/ev.3 (file contents):
Revision 1.40 by root, Fri Dec 7 19:23:48 2007 UTC vs.
Revision 1.41 by root, Fri Dec 7 20:13:09 2007 UTC

1894.PP 1894.PP
1895.Vb 1 1895.Vb 1
1896\& #include <ev++.h> 1896\& #include <ev++.h>
1897.Ve 1897.Ve
1898.PP 1898.PP
1899(it is not installed by default). This automatically includes \fIev.h\fR 1899This automatically includes \fIev.h\fR and puts all of its definitions (many
1900and puts all of its definitions (many of them macros) into the global 1900of them macros) into the global namespace. All \*(C+ specific things are
1901namespace. All \*(C+ specific things are put into the \f(CW\*(C`ev\*(C'\fR namespace. 1901put into the \f(CW\*(C`ev\*(C'\fR namespace. It should support all the same embedding
1902options as \fIev.h\fR, most notably \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR.
1902.PP 1903.PP
1903It should support all the same embedding options as \fIev.h\fR, most notably 1904Care has been taken to keep the overhead low. The only data member added
1904\&\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. 1905to the C\-style watchers is the event loop the watcher is associated with
1906(or no additional members at all if you disable \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR when
1907embedding libev).
1908.PP
1909Currently, functions and static and non-static member functions can be
1910used as callbacks. Other types should be easy to add as long as they only
1911need one additional pointer for context. If you need support for other
1912types of functors please contact the author (preferably after implementing
1913it).
1905.PP 1914.PP
1906Here is a list of things available in the \f(CW\*(C`ev\*(C'\fR namespace: 1915Here is a list of things available in the \f(CW\*(C`ev\*(C'\fR namespace:
1907.ie n .IP """ev::READ""\fR, \f(CW""ev::WRITE"" etc." 4 1916.ie n .IP """ev::READ""\fR, \f(CW""ev::WRITE"" etc." 4
1908.el .IP "\f(CWev::READ\fR, \f(CWev::WRITE\fR etc." 4 1917.el .IP "\f(CWev::READ\fR, \f(CWev::WRITE\fR etc." 4
1909.IX Item "ev::READ, ev::WRITE etc." 1918.IX Item "ev::READ, ev::WRITE etc."
1921which is called \f(CW\*(C`ev::sig\*(C'\fR to avoid clashes with the \f(CW\*(C`signal\*(C'\fR macro 1930which is called \f(CW\*(C`ev::sig\*(C'\fR to avoid clashes with the \f(CW\*(C`signal\*(C'\fR macro
1922defines by many implementations. 1931defines by many implementations.
1923.Sp 1932.Sp
1924All of those classes have these methods: 1933All of those classes have these methods:
1925.RS 4 1934.RS 4
1926.IP "ev::TYPE::TYPE (object *, object::method *)" 4 1935.IP "ev::TYPE::TYPE ()" 4
1927.IX Item "ev::TYPE::TYPE (object *, object::method *)" 1936.IX Item "ev::TYPE::TYPE ()"
1928.PD 0 1937.PD 0
1929.IP "ev::TYPE::TYPE (object *, object::method *, struct ev_loop *)" 4 1938.IP "ev::TYPE::TYPE (struct ev_loop *)" 4
1930.IX Item "ev::TYPE::TYPE (object *, object::method *, struct ev_loop *)" 1939.IX Item "ev::TYPE::TYPE (struct ev_loop *)"
1931.IP "ev::TYPE::~TYPE" 4 1940.IP "ev::TYPE::~TYPE" 4
1932.IX Item "ev::TYPE::~TYPE" 1941.IX Item "ev::TYPE::~TYPE"
1933.PD 1942.PD
1934The constructor takes a pointer to an object and a method pointer to 1943The constructor (optionally) takes an event loop to associate the watcher
1935the event handler callback to call in this class. The constructor calls 1944with. If it is omitted, it will use \f(CW\*(C`EV_DEFAULT\*(C'\fR.
1936\&\f(CW\*(C`ev_init\*(C'\fR for you, which means you have to call the \f(CW\*(C`set\*(C'\fR method 1945.Sp
1937before starting it. If you do not specify a loop then the constructor 1946The constructor calls \f(CW\*(C`ev_init\*(C'\fR for you, which means you have to call the
1938automatically associates the default loop with this watcher. 1947\&\f(CW\*(C`set\*(C'\fR method before starting it.
1948.Sp
1949It will not set a callback, however: You have to call the templated \f(CW\*(C`set\*(C'\fR
1950method to set a callback before you can start the watcher.
1951.Sp
1952(The reason why you have to use a method is a limitation in \*(C+ which does
1953not allow explicit template arguments for constructors).
1939.Sp 1954.Sp
1940The destructor automatically stops the watcher if it is active. 1955The destructor automatically stops the watcher if it is active.
1956.IP "w\->set<class, &class::method> (object *)" 4
1957.IX Item "w->set<class, &class::method> (object *)"
1958This method sets the callback method to call. The method has to have a
1959signature of \f(CW\*(C`void (*)(ev_TYPE &, int)\*(C'\fR, it receives the watcher as
1960first argument and the \f(CW\*(C`revents\*(C'\fR as second. The object must be given as
1961parameter and is stored in the \f(CW\*(C`data\*(C'\fR member of the watcher.
1962.Sp
1963This method synthesizes efficient thunking code to call your method from
1964the C callback that libev requires. If your compiler can inline your
1965callback (i.e. it is visible to it at the place of the \f(CW\*(C`set\*(C'\fR call and
1966your compiler is good :), then the method will be fully inlined into the
1967thunking function, making it as fast as a direct C callback.
1968.Sp
1969Example: simple class declaration and watcher initialisation
1970.Sp
1971.Vb 4
1972\& struct myclass
1973\& {
1974\& void io_cb (ev::io &w, int revents) { }
1975\& }
1976.Ve
1977.Sp
1978.Vb 3
1979\& myclass obj;
1980\& ev::io iow;
1981\& iow.set <myclass, &myclass::io_cb> (&obj);
1982.Ve
1983.IP "w\->set (void (*function)(watcher &w, int), void *data = 0)" 4
1984.IX Item "w->set (void (*function)(watcher &w, int), void *data = 0)"
1985Also sets a callback, but uses a static method or plain function as
1986callback. The optional \f(CW\*(C`data\*(C'\fR argument will be stored in the watcher's
1987\&\f(CW\*(C`data\*(C'\fR member and is free for you to use.
1988.Sp
1989See the method\-\f(CW\*(C`set\*(C'\fR above for more details.
1941.IP "w\->set (struct ev_loop *)" 4 1990.IP "w\->set (struct ev_loop *)" 4
1942.IX Item "w->set (struct ev_loop *)" 1991.IX Item "w->set (struct ev_loop *)"
1943Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only 1992Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only
1944do this when the watcher is inactive (and not pending either). 1993do this when the watcher is inactive (and not pending either).
1945.IP "w\->set ([args])" 4 1994.IP "w\->set ([args])" 4
1946.IX Item "w->set ([args])" 1995.IX Item "w->set ([args])"
1947Basically the same as \f(CW\*(C`ev_TYPE_set\*(C'\fR, with the same args. Must be 1996Basically the same as \f(CW\*(C`ev_TYPE_set\*(C'\fR, with the same args. Must be
1948called at least once. Unlike the C counterpart, an active watcher gets 1997called at least once. Unlike the C counterpart, an active watcher gets
1949automatically stopped and restarted. 1998automatically stopped and restarted when reconfiguring it with this
1999method.
1950.IP "w\->start ()" 4 2000.IP "w\->start ()" 4
1951.IX Item "w->start ()" 2001.IX Item "w->start ()"
1952Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument as the 2002Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the
1953constructor already takes the loop. 2003constructor already stores the event loop.
1954.IP "w\->stop ()" 4 2004.IP "w\->stop ()" 4
1955.IX Item "w->stop ()" 2005.IX Item "w->stop ()"
1956Stops the watcher if it is active. Again, no \f(CW\*(C`loop\*(C'\fR argument. 2006Stops the watcher if it is active. Again, no \f(CW\*(C`loop\*(C'\fR argument.
1957.ie n .IP "w\->again () ""ev::timer""\fR, \f(CW""ev::periodic"" only" 4 2007.ie n .IP "w\->again () ""ev::timer""\fR, \f(CW""ev::periodic"" only" 4
1958.el .IP "w\->again () \f(CWev::timer\fR, \f(CWev::periodic\fR only" 4 2008.el .IP "w\->again () \f(CWev::timer\fR, \f(CWev::periodic\fR only" 4
1984.Vb 2 2034.Vb 2
1985\& myclass (); 2035\& myclass ();
1986\& } 2036\& }
1987.Ve 2037.Ve
1988.PP 2038.PP
1989.Vb 6 2039.Vb 4
1990\& myclass::myclass (int fd) 2040\& myclass::myclass (int fd)
1991\& : io (this, &myclass::io_cb),
1992\& idle (this, &myclass::idle_cb)
1993\& { 2041\& {
2042\& io .set <myclass, &myclass::io_cb > (this);
2043\& idle.set <myclass, &myclass::idle_cb> (this);
2044.Ve
2045.PP
2046.Vb 2
1994\& io.start (fd, ev::READ); 2047\& io.start (fd, ev::READ);
1995\& } 2048\& }
1996.Ve 2049.Ve
1997.SH "MACRO MAGIC" 2050.SH "MACRO MAGIC"
1998.IX Header "MACRO MAGIC" 2051.IX Header "MACRO MAGIC"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines