#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_
#include "mojo/public/cpp/bindings/lib/message_queue.h"
#include "mojo/public/cpp/bindings/message.h"
#include "mojo/public/cpp/environment/default_async_waiter.h"
#include "mojo/public/cpp/system/core.h"
namespace mojo {
class ErrorHandler;
namespace internal {
class Connector : public MessageReceiver {
public:
explicit Connector(ScopedMessagePipeHandle message_pipe,
MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter());
virtual ~Connector();
void set_incoming_receiver(MessageReceiver* receiver) {
incoming_receiver_ = receiver;
}
void set_error_handler(ErrorHandler* error_handler) {
error_handler_ = error_handler;
}
bool encountered_error() const { return error_; }
void CloseMessagePipe();
virtual bool Accept(Message* message) MOJO_OVERRIDE;
virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
MOJO_OVERRIDE;
private:
static void CallOnHandleReady(void* closure, MojoResult result);
void OnHandleReady(MojoResult result);
void WaitToReadMore();
void ReadMore();
ErrorHandler* error_handler_;
MojoAsyncWaiter* waiter_;
ScopedMessagePipeHandle message_pipe_;
MessageReceiver* incoming_receiver_;
MojoAsyncWaitID async_wait_id_;
bool error_;
bool drop_writes_;
MOJO_DISALLOW_COPY_AND_ASSIGN(Connector);
};
}
}
#endif