Marc Lehmann, el 31 de enero a las 11:34 me escribiste:
> On Mon, Jan 28, 2008 at 07:51:04PM -0200, Leandro Lucarella <[EMAIL 
> PROTECTED]> wrote:
> > About loop_ref. If you want the patch to rename it to loop rebased to
> > current CVS, let me know.
> 
> I think I prefer loop, but I cannot see what other changes this would result
> in.

Not much, this are the changes needed (against an older CVS):
http://git.llucax.com.ar/?p=software/libev.git;a=commitdiff;h=9c18c7bae1b497ad13361475c4af0624eb42596b

> So what I want is for you to decide whats best, and optionally implement it.

The only drawback of 'loop' is the method loop() has to be renamed to
run(). And maybe that it hides a little that even if it's an "object" it
has reference/pointer semantics, because you're not creating any loop when
you instantiate a 'loop'.

> Most pressing, I think, is the documentation now, as the basic framework
> is there and won't change fundamentally anymore (I think :).

Ok. I don't know anything about POD format but I did my best. Attached is
a patch with some initial (but fairly complete) documentation. I didn't
explain anything about exceptions nor the default_loop because I don't
know if they'll stay that way. I used 'loop_ref' because is much simpler to
s/loop_ref/loop/g than replacing loop with loop_ref ;)

My english is not that good so it could use some love from a better english
speaker =)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Yo soy Peperino Mártir Sanito, yo soy aquel, que come los flanes
serenito.
        -- Peperino Pómoro
diff --git a/ev.pod b/ev.pod
index 9ef6da2..d7ab67d 100644
--- a/ev.pod
+++ b/ev.pod
@@ -2134,7 +2134,8 @@ to use the libev header file and library.
 
 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.
+the callback model to a model using method callbacks on objects. It provide
+a simple (optional) loop abstraction too.
 
 To use it,
    
@@ -2148,7 +2149,9 @@ options as F<ev.h>, most notably C<EV_MULTIPLICITY>.
 Care has been taken to keep the overhead low. The only data member the C++
 classes add (compared to plain C-style watchers) is the event loop pointer
 that the watcher is associated with (or no additional members at all if
-you disable C<EV_MULTIPLICITY> when embedding libev).
+you disable C<EV_MULTIPLICITY> when embedding libev). The loop abstraction
+consist only in a struct ev_loop* (or nothing if you disable
+C<EV_MULTIPLICITY>), so it should not impose any overhead at all.
 
 Currently, functions, and static and non-static member functions can be
 used as callbacks. Other types should be easy to add as long as they only
@@ -2163,11 +2166,18 @@ Here is a list of things available in the C<ev> namespace:
 =item C<ev::READ>, C<ev::WRITE> etc.
 
 These are just enum values with the same values as the C<EV_READ> etc.
-macros from F<ev.h>.
+macros from F<ev.h>. All constants are provided. C<ev::ONE> and C<ev::ALL>
+are special cases because they belong to a named enum C<ev::how_t>, to ensure
+some type-safety when calling C<loop_ref::unloop>.
 
-=item C<ev::tstamp>, C<ev::now>
+=item C<ev::version_major>, C<ev::version_minor>, C<ev::tstamp>, C<ev::now> etc.
 
-Aliases to the same types/functions as with the C<ev_> prefix.
+Aliases to the same types/functions as with the C<ev_> prefix. All "free
+functions" (functions not "attached" to a watcher or a loop) are provided.
+
+Some names has been changed to avoid name clashing with well know libc/POSIX
+symbols: C<ev_time> is C<ev::now> (C<ev_now> is a member function of
+C<ev::loop_ref>) and C<ev_sleep> is C<ev::delay>.
 
 =item C<ev::io>, C<ev::timer>, C<ev::periodic>, C<ev::idle>, C<ev::sig> etc.
 
@@ -2182,12 +2192,14 @@ All of those classes have these methods:
 
 =item ev::TYPE::TYPE ()
 
-=item ev::TYPE::TYPE (struct ev_loop *)
+=item ev::TYPE::TYPE (ev::loop_ref)
 
 =item ev::TYPE::~TYPE
 
 The constructor (optionally) takes an event loop to associate the watcher
-with. If it is omitted, it will use C<EV_DEFAULT>.
+with. If it is omitted, it will use C<EV_DEFAULT>. Note that C<ev_loop*>
+can be implicitly converted to C<ev::loop_ref> so there is no need to use
+the loop C++ interface to use the watcher C++ interface.
 
 The constructor calls C<ev_init> for you, which means you have to call the
 C<set> method before starting it.
@@ -2297,6 +2309,50 @@ the constructor.
   }
 
 
+=item C<ev::loop_ref>, C<ev::dynamic_loop>, C<ev::default_loop>.
+
+C<ev::loop_ref> represents a reference to a loop (default or not). It has all
+the functions that are called with a ev_loop* first (when C<EV_MULTIPLICITY> is
+enabled) as member functions: C<loop_ref::loop>, C<loop_ref::unloop>,
+C<loop_ref::post_fork> (this is C<ev_XXX_fork>), C<loop_ref::count>,
+C<loop_ref::backend>, C<loop_ref::now>, C<loop_ref::ref>, C<loop_ref::unref>,
+C<loop_ref::set_io_collect_interval>, C<loop_ref::set_timeout_collect_interval>,
+C<loop_ref::feed_fd_event>, C<loop_ref::feed_signal_event> and
+C<loop_ref::once>, which needs a special mention because you can use it with
+different kind of callbacks.
+
+C<loop_ref::once> can take member or static functions with this signatures:
+
+  void cb (int revents, void* arg); // free function
+  void cb (int revents); // free function or member function
+  void cb (); // free function or member function
+
+Similar to watchers C<set> method, the way to call C<loop_ref::once> is with
+explicit template arguments, for example:
+
+  class myclass
+  {
+    void once_cb (int revents);
+  }
+
+  void once_cb ();
+
+  ev::loop_ref loop = ev_default_loop (0);
+  myclass mc;
+
+  loop.once <myclass, &myclass::once_cb> (fd, ev::READ, 0., &mc);
+  loop.once <&once_cb> (fd, ev::WRITE, 10.);
+
+
+Some operators (==, =, cast, etc.) are overloaded so you can use
+C<ev::loop_ref> or C<ev_loop*> indistinctly.
+
+C<ev::dynamic_loop> is identical to C<ev::loop_ref> but the constructor
+calls C<ev_loop_new> for you, creating a new loop (and the destructor
+calls C<ev_loop_destroy>). This is available only if C<EV_MULTIPLICITY>
+is enabled.
+
+
 =head1 MACRO MAGIC
 
 Libev can be compiled with a variety of options, the most fundamantal
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to