protocol buffers - How to generate BlockingStub in C++ in Protobuf? -


i'm having following .proto protobuf (2.6.1 more detailed):

service installservice {     rpc getwifinetworks (wifirequest) returns (wifiresponse); } 

i've generated java files , i'm having blockingstub:

testinstallservice.blockinginterface service = testinstallservice.newblockingstub(channel); 

and can use if in blocking way (works good):

wifi.wifiresponse response = service.getwifinetworks(controller, request); 

now i'm creating c++ client should work in blocking way can't see blocking interfaces neither in proto nor in generated c++ code. how generate blockingstub in c++ in protobuf? how can pass closure if working in async way?

generated c++ service file (.cpp):

class installservice_stub;  class installservice : public ::google::protobuf::service {  protected:   // class should treated abstract interface.   inline installservice() {};  public:   virtual ~installservice();    typedef installservice_stub stub;    static const ::google::protobuf::servicedescriptor* descriptor();    virtual void getwifinetworks(::google::protobuf::rpccontroller* controller,                        const ::wifirequest* request,                        ::wifiresponse* response,                        ::google::protobuf::closure* done);    // implements service ----------------------------------------------    const ::google::protobuf::servicedescriptor* getdescriptor();   void callmethod(const ::google::protobuf::methoddescriptor* method,                   ::google::protobuf::rpccontroller* controller,                   const ::google::protobuf::message* request,                   ::google::protobuf::message* response,                   ::google::protobuf::closure* done);   const ::google::protobuf::message& getrequestprototype(     const ::google::protobuf::methoddescriptor* method) const;   const ::google::protobuf::message& getresponseprototype(     const ::google::protobuf::methoddescriptor* method) const;   private:   google_disallow_evil_constructors(installservice); };  class installservice_stub : public installservice {  public:   installservice_stub(::google::protobuf::rpcchannel* channel);   installservice_stub(::google::protobuf::rpcchannel* channel,                    ::google::protobuf::service::channelownership ownership);   ~installservice_stub();    inline ::google::protobuf::rpcchannel* channel() { return channel_; }    // implements installservice ------------------------------------------    void getwifinetworks(::google::protobuf::rpccontroller* controller,                        const ::wifirequest* request,                        ::wifiresponse* response,                        ::google::protobuf::closure* done);  private:   ::google::protobuf::rpcchannel* channel_;   bool owns_channel_;   google_disallow_evil_constructors(installservice_stub); }; 

it seems no blocking code generated protoc had use self-made blocking:

bool callbackfired = false;  void mycallback() {     // ...     callbackfired = true; }  // run service method service->mymethod(rpccontroller, request, response, newcallback(&mycallback));  // block thread until callback invoked while (!callbackfired);  ... 

c++ client usage example: https://github.com/4ntoine/protobuf-socket-rpc


Comments