Re: [protobuf] Disabling the 'gen_cpp' output of Services?

2010-03-11 Thread Andrew Kimpton
On Wed, Mar 10, 2010 at 8:50 PM, Kenton Varda ken...@google.com wrote:

 Note that to write your plugin, you do *not* have to copy the CppGenerator
 sources.  Instead, write your plugin to use
 output_directory-OpenForInsert() to insert additional code into what the
 C++ code generator already generated.  Specifically, you want to insert at
 the namespace_scope insertion point, documented here:


 http://code.google.com/apis/protocolbuffers/docs/reference/cpp-generated.html#plugins

 Then you would invoke protoc like:

   protoc --cpp_out=dir --my_plugin_out=dir foo.proto

 The C++ generator will be executed first, then your plugin.  Since they
 have the same output location, your plugin can insert into the code
 generated by the C++ code generator.

 This is working pretty well - with one exception :

My simple test_service.proto has a pair of messages (Request, Response) and
a single service that takes one and returns the other.

A 'generic' services cpp output includes a global const pointer for the
ServiceDescriptor and a  call to initialize that pointer in the 'AssignDesc'
generated method. If I turn off the generic output those two calls aren't
output - but I'd rather like them to be since it gives me a global instance
of the descriptor that I (expect) will help with 'discovery' and
'registration' in the server side of the RPC.

There doesn't seem to be a handy insertion point already present in the file
that I can use to inject my output, am I missing something ? Should I file a
bug ?

As a workaround I can introduce my own initializer to initialize these
pieces but I still don't see a way to get it to be called from the
GoogleOnceInit() call in $file$_AssignDescriptorsOnce() method.

I guess a third alternative would be to have my plugin generated
implementation of the Service subclass' descriptor() and GetDescriptor()
method just do the one time initialization of the global prior to returning
it ? Perhaps this is the best approach ?

Andrew 8-)

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Disabling the 'gen_cpp' output of Services?

2010-03-11 Thread Kenton Varda
On the first call to your descriptor() or GetDescriptor() method, you could
look up the ServiceDescriptor in
google::protobuf::DescriptorPool::generated_pool().

Alternatively, we could add a (public) way to directly fetch the file's
FileDescriptor, then your descriptor getter could simply return
file-service($index$).

I'd rather hide the details of descriptor initialization from plugins as
it's something that has changed many times and could change again.

On Thu, Mar 11, 2010 at 11:07 AM, Andrew Kimpton awkimp...@gmail.comwrote:



 On Wed, Mar 10, 2010 at 8:50 PM, Kenton Varda ken...@google.com wrote:

 Note that to write your plugin, you do *not* have to copy the CppGenerator
 sources.  Instead, write your plugin to use
 output_directory-OpenForInsert() to insert additional code into what the
 C++ code generator already generated.  Specifically, you want to insert at
 the namespace_scope insertion point, documented here:


 http://code.google.com/apis/protocolbuffers/docs/reference/cpp-generated.html#plugins

 Then you would invoke protoc like:

   protoc --cpp_out=dir --my_plugin_out=dir foo.proto

 The C++ generator will be executed first, then your plugin.  Since they
 have the same output location, your plugin can insert into the code
 generated by the C++ code generator.

 This is working pretty well - with one exception :

 My simple test_service.proto has a pair of messages (Request, Response) and
 a single service that takes one and returns the other.

 A 'generic' services cpp output includes a global const pointer for the
 ServiceDescriptor and a  call to initialize that pointer in the 'AssignDesc'
 generated method. If I turn off the generic output those two calls aren't
 output - but I'd rather like them to be since it gives me a global instance
 of the descriptor that I (expect) will help with 'discovery' and
 'registration' in the server side of the RPC.

 There doesn't seem to be a handy insertion point already present in the
 file that I can use to inject my output, am I missing something ? Should I
 file a bug ?

 As a workaround I can introduce my own initializer to initialize these
 pieces but I still don't see a way to get it to be called from the
 GoogleOnceInit() call in $file$_AssignDescriptorsOnce() method.

 I guess a third alternative would be to have my plugin generated
 implementation of the Service subclass' descriptor() and GetDescriptor()
 method just do the one time initialization of the global prior to returning
 it ? Perhaps this is the best approach ?

 Andrew 8-)




-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Disabling the 'gen_cpp' output of Services?

2010-03-11 Thread Andrew Kimpton
On Thu, Mar 11, 2010 at 2:27 PM, Kenton Varda ken...@google.com wrote:

 On the first call to your descriptor() or GetDescriptor() method, you could
 look up the ServiceDescriptor in
 google::protobuf::DescriptorPool::generated_pool().


I think that's what my generated code is essentially now doing :

In my generated service_subclass::descriptor() and ::GetDescriptor() methods
I call a 'protobuf_rpc_AssignDescriptorsOnce()' function that looks like
this :

void protobuf_rpc_AssignDesc_test_5fservice_2eproto() {
  const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()-FindFileByName(
  test_service.proto);
  GOOGLE_CHECK(file != NULL);
  TestingService_descriptor_ = file-service(0);
}

GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_rpc_AssignDescriptors_once_);
inline void protobuf_rpc_AssignDescriptorsOnce() {
  ::google::protobuf::GoogleOnceInit(protobuf_rpc_AssignDescriptors_once_,
 protobuf_rpc_AssignDesc_test_5fservice_2eproto);

Andrew 8-)

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Disabling the 'gen_cpp' output of Services?

2010-03-11 Thread Kenton Varda
Cool.  If you like, feel free to propose a modification to the standard code
generator which makes the file descriptor pointer directly accessible, so
that you don't have to have the extra lookup step.

On Thu, Mar 11, 2010 at 11:58 AM, Andrew Kimpton awkimp...@gmail.comwrote:



 On Thu, Mar 11, 2010 at 2:27 PM, Kenton Varda ken...@google.com wrote:

 On the first call to your descriptor() or GetDescriptor() method, you
 could look up the ServiceDescriptor in
 google::protobuf::DescriptorPool::generated_pool().


 I think that's what my generated code is essentially now doing :

 In my generated service_subclass::descriptor() and ::GetDescriptor()
 methods I call a 'protobuf_rpc_AssignDescriptorsOnce()' function that looks
 like this :

 void protobuf_rpc_AssignDesc_test_5fservice_2eproto() {
   const ::google::protobuf::FileDescriptor* file =
 ::google::protobuf::DescriptorPool::generated_pool()-FindFileByName(
   test_service.proto);
   GOOGLE_CHECK(file != NULL);
   TestingService_descriptor_ = file-service(0);
 }

 GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_rpc_AssignDescriptors_once_);
 inline void protobuf_rpc_AssignDescriptorsOnce() {
   ::google::protobuf::GoogleOnceInit(protobuf_rpc_AssignDescriptors_once_,
  protobuf_rpc_AssignDesc_test_5fservice_2eproto);

 Andrew 8-)


-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Disabling the 'gen_cpp' output of Services?

2010-03-10 Thread Jason Hsueh
In your .proto file, just specify the file-level option cc_generic_services
= false.

Comments from descriptor.proto:

  // Should generic services be generated in each language?  Generic
services
  // are not specific to any particular RPC system.  They are generated by
the
  // main code generators in each language (without additional plugins).
  // Generic services were the only kind of service generation supported by
  // early versions of proto2.
  //
  // Generic services are now considered deprecated in favor of using
plugins
  // that generate code specific to your particular RPC system.  If you are
  // using such a plugin, set these to false.  In the future, we may change
  // the default to false, so if you explicitly want generic services, you
  // should explicitly set these to true.
  optional bool cc_generic_services = 16 [default=true];
  optional bool java_generic_services = 17 [default=true];
  optional bool py_generic_services = 18 [default=true];


On Wed, Mar 10, 2010 at 1:55 PM, awk awkimp...@gmail.com wrote:

 I'm trying to throw together an alternative RPC mechanism using a
 protoc plugin/CodeGenerator (rather than use the deprecated headers).

 I've hacked a new plugin together by liberally grabbing from the
 current compiler/cpp generator sources. It works to output code that
 looks good to my eyes however because I (deliberately) want to use the
 Message subclasses etc. that are output from CppGenerator I get a
 clash between the Service subclass definition output by my plugin and
 the one output by CppGenerator.

 Other than removing the 'HasServices' call and the ServiceGenerator
 subclass from the current compiler/cpp sources is there any other way
 I can disable the CppGenerator output of my Service instance ? A
 namespace doesn't really help since that's just driven from the
 package clause in the .proto source

 Ideally what I'll have at the end of this is a protoc plugin that
 basically does the same as the current CppGenerator for Services
 (only) and could be used today by anyone who's already subclassed
 Service, RpcController  RpcChannel, and can be used by others as a
 basis to writing their own generator for services.

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/protobuf?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Disabling the 'gen_cpp' output of Services?

2010-03-10 Thread Kenton Varda
Note that to write your plugin, you do *not* have to copy the CppGenerator
sources.  Instead, write your plugin to use
output_directory-OpenForInsert() to insert additional code into what the
C++ code generator already generated.  Specifically, you want to insert at
the namespace_scope insertion point, documented here:


http://code.google.com/apis/protocolbuffers/docs/reference/cpp-generated.html#plugins

Then you would invoke protoc like:

  protoc --cpp_out=dir --my_plugin_out=dir foo.proto

The C++ generator will be executed first, then your plugin.  Since they have
the same output location, your plugin can insert into the code generated by
the C++ code generator.

On Wed, Mar 10, 2010 at 1:55 PM, awk awkimp...@gmail.com wrote:

 I'm trying to throw together an alternative RPC mechanism using a
 protoc plugin/CodeGenerator (rather than use the deprecated headers).

 I've hacked a new plugin together by liberally grabbing from the
 current compiler/cpp generator sources. It works to output code that
 looks good to my eyes however because I (deliberately) want to use the
 Message subclasses etc. that are output from CppGenerator I get a
 clash between the Service subclass definition output by my plugin and
 the one output by CppGenerator.

 Other than removing the 'HasServices' call and the ServiceGenerator
 subclass from the current compiler/cpp sources is there any other way
 I can disable the CppGenerator output of my Service instance ? A
 namespace doesn't really help since that's just driven from the
 package clause in the .proto source

 Ideally what I'll have at the end of this is a protoc plugin that
 basically does the same as the current CppGenerator for Services
 (only) and could be used today by anyone who's already subclassed
 Service, RpcController  RpcChannel, and can be used by others as a
 basis to writing their own generator for services.

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/protobuf?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.