53 is_listening_ =
false;
60 std::shared_ptr<StreamHandler<T>> shared_handler(handler.release());
61 const MethodCodec<T>* codec = codec_;
62 const std::string channel_name = name_;
63 const BinaryMessenger* messenger = messenger_;
67 const size_t message_size,
69 constexpr
char kOnListenMethod[] =
"listen";
70 constexpr
char kOnCancelMethod[] =
"cancel";
73 codec->DecodeMethodCall(message, message_size);
75 std::cerr <<
"Unable to construct method call from message on channel: " 76 << channel_name << std::endl;
81 const std::string& method = method_call->method_name();
82 if (method.compare(kOnListenMethod) == 0) {
84 std::unique_ptr<StreamHandlerError<T>>
error =
85 shared_handler->OnCancel(
nullptr);
87 std::cerr <<
"Failed to cancel existing stream: " 88 << (error->error_code) <<
", " << (error->error_message)
89 <<
", " << (error->error_details);
94 std::unique_ptr<std::vector<uint8_t>>
result;
95 auto sink = std::make_unique<EventSinkImplementation>(
96 messenger, channel_name, codec);
97 std::unique_ptr<StreamHandlerError<T>> error =
98 shared_handler->OnListen(method_call->arguments(), std::move(sink));
100 result = codec->EncodeErrorEnvelope(
101 error->error_code, error->error_message, error->error_details);
103 result = codec->EncodeSuccessEnvelope();
105 reply(result->data(), result->size());
106 }
else if (method.compare(kOnCancelMethod) == 0) {
107 std::unique_ptr<std::vector<uint8_t>>
result;
109 std::unique_ptr<StreamHandlerError<T>> error =
110 shared_handler->OnCancel(method_call->arguments());
112 result = codec->EncodeErrorEnvelope(
113 error->error_code, error->error_message, error->error_details);
115 result = codec->EncodeSuccessEnvelope();
117 is_listening_ =
false;
119 result = codec->EncodeErrorEnvelope(
120 "error",
"No active stream to cancel",
nullptr);
122 reply(result->data(), result->size());
G_BEGIN_DECLS FlMethodCall * method_call
const uint8_t uint32_t uint32_t GError ** error
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler