… | |
… | |
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 |
1899 | This automatically includes \fIev.h\fR and puts all of its definitions (many |
1900 | and puts all of its definitions (many of them macros) into the global |
1900 | of them macros) into the global namespace. All \*(C+ specific things are |
1901 | namespace. All \*(C+ specific things are put into the \f(CW\*(C`ev\*(C'\fR namespace. |
1901 | put into the \f(CW\*(C`ev\*(C'\fR namespace. It should support all the same embedding |
|
|
1902 | options as \fIev.h\fR, most notably \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. |
1902 | .PP |
1903 | .PP |
1903 | It should support all the same embedding options as \fIev.h\fR, most notably |
1904 | Care has been taken to keep the overhead low. The only data member added |
1904 | \&\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. |
1905 | to 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 |
|
|
1907 | embedding libev). |
|
|
1908 | .PP |
|
|
1909 | Currently, functions and static and non-static member functions can be |
|
|
1910 | used as callbacks. Other types should be easy to add as long as they only |
|
|
1911 | need one additional pointer for context. If you need support for other |
|
|
1912 | types of functors please contact the author (preferably after implementing |
|
|
1913 | it). |
1905 | .PP |
1914 | .PP |
1906 | Here is a list of things available in the \f(CW\*(C`ev\*(C'\fR namespace: |
1915 | Here 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." |
… | |
… | |
1921 | which is called \f(CW\*(C`ev::sig\*(C'\fR to avoid clashes with the \f(CW\*(C`signal\*(C'\fR macro |
1930 | which is called \f(CW\*(C`ev::sig\*(C'\fR to avoid clashes with the \f(CW\*(C`signal\*(C'\fR macro |
1922 | defines by many implementations. |
1931 | defines by many implementations. |
1923 | .Sp |
1932 | .Sp |
1924 | All of those classes have these methods: |
1933 | All 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 |
1934 | The constructor takes a pointer to an object and a method pointer to |
1943 | The constructor (optionally) takes an event loop to associate the watcher |
1935 | the event handler callback to call in this class. The constructor calls |
1944 | with. 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 |
1937 | before starting it. If you do not specify a loop then the constructor |
1946 | The constructor calls \f(CW\*(C`ev_init\*(C'\fR for you, which means you have to call the |
1938 | automatically associates the default loop with this watcher. |
1947 | \&\f(CW\*(C`set\*(C'\fR method before starting it. |
|
|
1948 | .Sp |
|
|
1949 | It will not set a callback, however: You have to call the templated \f(CW\*(C`set\*(C'\fR |
|
|
1950 | method 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 |
|
|
1953 | not allow explicit template arguments for constructors). |
1939 | .Sp |
1954 | .Sp |
1940 | The destructor automatically stops the watcher if it is active. |
1955 | The 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 *)" |
|
|
1958 | This method sets the callback method to call. The method has to have a |
|
|
1959 | signature of \f(CW\*(C`void (*)(ev_TYPE &, int)\*(C'\fR, it receives the watcher as |
|
|
1960 | first argument and the \f(CW\*(C`revents\*(C'\fR as second. The object must be given as |
|
|
1961 | parameter and is stored in the \f(CW\*(C`data\*(C'\fR member of the watcher. |
|
|
1962 | .Sp |
|
|
1963 | This method synthesizes efficient thunking code to call your method from |
|
|
1964 | the C callback that libev requires. If your compiler can inline your |
|
|
1965 | callback (i.e. it is visible to it at the place of the \f(CW\*(C`set\*(C'\fR call and |
|
|
1966 | your compiler is good :), then the method will be fully inlined into the |
|
|
1967 | thunking function, making it as fast as a direct C callback. |
|
|
1968 | .Sp |
|
|
1969 | Example: 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)" |
|
|
1985 | Also sets a callback, but uses a static method or plain function as |
|
|
1986 | callback. 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 |
|
|
1989 | See 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 *)" |
1943 | Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only |
1992 | Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only |
1944 | do this when the watcher is inactive (and not pending either). |
1993 | do 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])" |
1947 | Basically the same as \f(CW\*(C`ev_TYPE_set\*(C'\fR, with the same args. Must be |
1996 | Basically the same as \f(CW\*(C`ev_TYPE_set\*(C'\fR, with the same args. Must be |
1948 | called at least once. Unlike the C counterpart, an active watcher gets |
1997 | called at least once. Unlike the C counterpart, an active watcher gets |
1949 | automatically stopped and restarted. |
1998 | automatically stopped and restarted when reconfiguring it with this |
|
|
1999 | method. |
1950 | .IP "w\->start ()" 4 |
2000 | .IP "w\->start ()" 4 |
1951 | .IX Item "w->start ()" |
2001 | .IX Item "w->start ()" |
1952 | Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument as the |
2002 | Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the |
1953 | constructor already takes the loop. |
2003 | constructor 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 ()" |
1956 | Stops the watcher if it is active. Again, no \f(CW\*(C`loop\*(C'\fR argument. |
2006 | Stops 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" |