#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_
#include <map>
#include "mojo/public/cpp/bindings/lib/connector.h"
#include "mojo/public/cpp/bindings/lib/shared_data.h"
namespace mojo {
namespace internal {
class Router : public MessageReceiver {
public:
explicit Router(ScopedMessagePipeHandle message_pipe,
MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter());
virtual ~Router();
void set_incoming_receiver(MessageReceiver* receiver) {
incoming_receiver_ = receiver;
}
void set_error_handler(ErrorHandler* error_handler) {
connector_.set_error_handler(error_handler);
}
bool encountered_error() const { return connector_.encountered_error(); }
virtual bool Accept(Message* message) MOJO_OVERRIDE;
virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
MOJO_OVERRIDE;
private:
typedef std::map<uint64_t, MessageReceiver*> ResponderMap;
class HandleIncomingMessageThunk : public MessageReceiver {
public:
HandleIncomingMessageThunk(Router* router);
virtual ~HandleIncomingMessageThunk();
virtual bool Accept(Message* message) MOJO_OVERRIDE;
virtual bool AcceptWithResponder(Message* message,
MessageReceiver* responder) MOJO_OVERRIDE;
private:
Router* router_;
};
bool HandleIncomingMessage(Message* message);
Connector connector_;
SharedData<Router*> weak_self_;
MessageReceiver* incoming_receiver_;
HandleIncomingMessageThunk thunk_;
ResponderMap responders_;
uint64_t next_request_id_;
};
}
}
#endif