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 <[email protected]>wrote: > > > On Wed, Mar 10, 2010 at 8:50 PM, Kenton Varda <[email protected]> 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
