[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] A patch for evrpc, allowing extra argument of request_new and reply_new



Hi Niels,

> It breaks regress_rpc.c - because the API for (msg)_new() has changed.

Oops, please take a look at a new one, which is shorter than previous one:
http://evproto.googlecode.com/svn-history/r8/trunk/libevent-2.0.4-alpha-msg-new-with-arg.patch

> However, I am curious, how you can use this to make protocol buffers
> work.   Do you have a code example?

1. Every generated protocol buffers class is derived from a common
base class google::protobuf::Message
2. The 'Message' base class defines a pure virtual function New(),
which returns a pointer to newly created (most-derived) 'Message'
object. Since it's virtual, every generated class overrides it, and
returns 'new ThisType'.
3. Every generated class has a default instance, which is statically
constructed, and accessible from the 'Method' object.

What I did is, when registering a method to evrpc
1. passing the address of the 'default instance' of request object as
request_new_arg,
2. in request_new, cast arg from void* to Message*,
3. call ((Message*)arg)->New() to create the request object.
4. do the same for reply object.
It is the prototype pattern, I think. So I don't write (msg)_new()
function for each message, but reusing one.

For code example, please have a look at
http://code.google.com/p/evproto/source/browse/trunk/evproto/rpccontroller.cc
 line 65
http://code.google.com/p/evproto/source/browse/trunk/evproto/rpcserver.cc
 line 53

Regards,
Shuo Chen

On Wed, Mar 24, 2010 at 9:39 AM, Niels Provos <provos@xxxxxxxxx> wrote:
> On Sat, Mar 20, 2010 at 9:21 PM, Shuo Chen <giantchen@xxxxxxxxx> wrote:
>> It passes regression test, and doesn't break the current usage I think,
>> just to rerun event_rpcgen.py and recompile the code.
>
> It breaks regress_rpc.c - because the API for (msg)_new() has changed.
>  How about changing the code/generator so that we get
>
> struct (msg)* (msg)_new(void) {}
> struct (msg)* (msg)_new_with_arg(void *) {}
>
> Then we can deprecate the old new but still make old programs work.
>
> However, I am curious, how you can use this to make protocol buffers
> work.   Do you have a code example?
>
> Thanks,
>  Niels.
> ***********************************************************************
> To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
> unsubscribe libevent-users    in the body.
>
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.