#ifndef MOJO_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
#define MOJO_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
#include <utility>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "mojo/system/dispatcher.h"
#include "mojo/system/system_impl_export.h"
namespace mojo {
namespace system {
class MessagePipe;
class MessagePipeDispatcherTransport;
class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher : public Dispatcher {
public:
MessagePipeDispatcher();
void Init(scoped_refptr<MessagePipe> message_pipe, unsigned port);
virtual Type GetType() const OVERRIDE;
static std::pair<scoped_refptr<MessagePipeDispatcher>,
scoped_refptr<MessagePipe> > CreateRemoteMessagePipe();
static scoped_refptr<MessagePipeDispatcher> Deserialize(Channel* channel,
const void* source,
size_t size);
private:
friend class MessagePipeDispatcherTransport;
virtual ~MessagePipeDispatcher();
MessagePipe* GetMessagePipeNoLock() const;
unsigned GetPortNoLock() const;
virtual void CancelAllWaitersNoLock() OVERRIDE;
virtual void CloseImplNoLock() OVERRIDE;
virtual scoped_refptr<Dispatcher>
CreateEquivalentDispatcherAndCloseImplNoLock() OVERRIDE;
virtual MojoResult WriteMessageImplNoLock(
const void* bytes,
uint32_t num_bytes,
std::vector<DispatcherTransport>* transports,
MojoWriteMessageFlags flags) OVERRIDE;
virtual MojoResult ReadMessageImplNoLock(
void* bytes,
uint32_t* num_bytes,
std::vector<scoped_refptr<Dispatcher> >* dispatchers,
uint32_t* num_dispatchers,
MojoReadMessageFlags flags) OVERRIDE;
virtual MojoResult AddWaiterImplNoLock(Waiter* waiter,
MojoWaitFlags flags,
MojoResult wake_result) OVERRIDE;
virtual void RemoveWaiterImplNoLock(Waiter* waiter) OVERRIDE;
virtual size_t GetMaximumSerializedSizeImplNoLock(
const Channel* channel) const OVERRIDE;
virtual bool SerializeAndCloseImplNoLock(Channel* channel,
void* destination,
size_t* actual_size) OVERRIDE;
scoped_refptr<MessagePipe> message_pipe_;
unsigned port_;
DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher);
};
class MessagePipeDispatcherTransport : public DispatcherTransport {
public:
explicit MessagePipeDispatcherTransport(DispatcherTransport transport);
MessagePipe* GetMessagePipe() {
return message_pipe_dispatcher()->GetMessagePipeNoLock();
}
unsigned GetPort() { return message_pipe_dispatcher()->GetPortNoLock(); }
private:
MessagePipeDispatcher* message_pipe_dispatcher() {
return static_cast<MessagePipeDispatcher*>(dispatcher());
}
};
}
}
#endif