Re: https://groups.google.com/forum/#!topic/grpc-io/hUYIjv97Hhc "C++ async 
API"

I'm trying to use async messaging and streams. I've used the ideas from the 
above post, namely, creating a CallData class per RPC method (I called mine 
"Context" instead of CallData, and it inherits from a base class, but the 
idea is the same).

This works fine for RPCs that don't have any streaming. But when I created 
a new RPC that was identical to the others (different name, of course) but 
had stream on the return value, my naive cut-n-paste solution from the 
other class didn't work :-(

Here's a stripped down part of the code:

class Context_SubscribeStream : public Context {
public:
    Context_SubscribeStream(grpc_control::AsyncService* service, 
ServerCompletionQueue* cq) : Context (cq,service,SUBSCRIBESTREAM), 
responder_(&ctx_) {
        Proceed();
    }
    void Proceed() {
        if (status_ == CREATE) {
            status_ = PROCESS;
// doesn't compile:
            service_->RequestSubscribeStream (&request_, &responder_, cq_, 
cq_, this);
        } else if (status_ == PROCESS) {
            ... code elided for clarity ...
            status_ = FINISH;
// doesn't compile:
            responder_.Finish(reply_, Status::OK, this);
        } else {
            GPR_ASSERT(status_ == FINISH);
            delete this;
        }
    }

private:
    SubscribeArgs request_;
    SubscribeReply reply_;
    ServerAsyncWriter<SubscribeReply> responder_;
};

The compiler message I get is:

g++ -std=c++0x -I../proto -I../../../contrib/google/build-ads/include 
-pthread  -c -o aserver.o aserver.cc
aserver.cc: In member function 'void Context_SubscribeStream::Proceed()':
aserver.cc:152: error: no matching function for call to 
'grpc_open_config::grpc_control::WithAsyncMethod_Subscribe<grpc_open_config::grpc_control::WithAsyncMethod_SubscribeStream<grpc_open_config::grpc_control::WithAsyncMethod_Unsubscribe<grpc_open_config::grpc_control::Service>
 
> >::RequestSubscribeStream(grpc_open_config::SubscribeArgs*, 
grpc::ServerAsyncWriter<grpc_open_config::SubscribeReply>*, 
grpc::ServerCompletionQueue*&, grpc::ServerCompletionQueue*&, 
Context_SubscribeStream* const)'
../proto/grpcidl.grpc.pb.h:141: note: candidates are: void 
grpc_open_config::grpc_control::WithAsyncMethod_SubscribeStream<BaseClass>::RequestSubscribeStream(grpc::ServerContext*,
 
grpc_open_config::SubscribeArgs*, 
grpc::ServerAsyncWriter<grpc_open_config::SubscribeReply>*, 
grpc::CompletionQueue*, grpc::ServerCompletionQueue*, void*) [with 
BaseClass = 
grpc_open_config::grpc_control::WithAsyncMethod_Unsubscribe<grpc_open_config::grpc_control::Service>]
aserver.cc:162: error: no matching function for call to 
'grpc::ServerAsyncWriter<grpc_open_config::SubscribeReply>::Finish(grpc_open_config::SubscribeReply&,
 
const grpc::Status&, Context_SubscribeStream* const)'
../../../contrib/google/build-ads/include/grpc++/impl/codegen/async_stream.h:434:
 
note: candidates are: void grpc::ServerAsyncWriter<W>::Finish(const 
grpc::Status&, void*) [with W = grpc_open_config::SubscribeReply]
make-3.81: *** [aserver.o] Error 1

If I change responder_'s declaration to:

ServerAsyncResponseWriter<SubscribeReply> responder_;

Then the compiler error I get is:

g++ -std=c++0x -I../proto -I../../../contrib/google/build-ads/include 
-pthread  -c -o aserver.o aserver.cc
aserver.cc: In member function 'void Context_SubscribeStream::Proceed()':
aserver.cc:152: error: no matching function for call to 
'grpc_open_config::grpc_control::WithAsyncMethod_Subscribe<grpc_open_config::grpc_control::WithAsyncMethod_SubscribeStream<grpc_open_config::grpc_control::WithAsyncMethod_Unsubscribe<grpc_open_config::grpc_control::Service>
 
> >::RequestSubscribeStream(grpc_open_config::SubscribeArgs*, 
grpc::ServerAsyncResponseWriter<grpc_open_config::SubscribeReply>*, 
grpc::ServerCompletionQueue*&, grpc::ServerCompletionQueue*&, 
Context_SubscribeStream* const)'
../proto/grpcidl.grpc.pb.h:141: note: candidates are: void 
grpc_open_config::grpc_control::WithAsyncMethod_SubscribeStream<BaseClass>::RequestSubscribeStream(grpc::ServerContext*,
 
grpc_open_config::SubscribeArgs*, 
grpc::ServerAsyncWriter<grpc_open_config::SubscribeReply>*, 
grpc::CompletionQueue*, grpc::ServerCompletionQueue*, void*) [with 
BaseClass = 
grpc_open_config::grpc_control::WithAsyncMethod_Unsubscribe<grpc_open_config::grpc_control::Service>]
make-3.81: *** [aserver.o] Error 1

Sadly, I'm not experienced enough in C++ to be able to make sense of the 
error messages.

Anything obviously dumb I'm doing?

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/6531c3ad-b29c-4656-be8b-f8adda1de160%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to