#ifndef MOJO_SYSTEM_CORE_IMPL_H_
#define MOJO_SYSTEM_CORE_IMPL_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "mojo/public/system/core_private.h"
#include "mojo/system/handle_table.h"
#include "mojo/system/mapping_table.h"
#include "mojo/system/system_impl_export.h"
namespace mojo {
namespace system {
class Dispatcher;
class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core {
public:
CoreImpl();
virtual ~CoreImpl();
MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher);
virtual MojoTimeTicks GetTimeTicksNow() OVERRIDE;
virtual MojoResult Close(MojoHandle handle) OVERRIDE;
virtual MojoResult Wait(MojoHandle handle,
MojoWaitFlags flags,
MojoDeadline deadline) OVERRIDE;
virtual MojoResult WaitMany(const MojoHandle* handles,
const MojoWaitFlags* flags,
uint32_t num_handles,
MojoDeadline deadline) OVERRIDE;
virtual MojoResult CreateMessagePipe(
MojoHandle* message_pipe_handle0,
MojoHandle* message_pipe_handle1) OVERRIDE;
virtual MojoResult WriteMessage(MojoHandle message_pipe_handle,
const void* bytes,
uint32_t num_bytes,
const MojoHandle* handles,
uint32_t num_handles,
MojoWriteMessageFlags flags) OVERRIDE;
virtual MojoResult ReadMessage(MojoHandle message_pipe_handle,
void* bytes,
uint32_t* num_bytes,
MojoHandle* handles,
uint32_t* num_handles,
MojoReadMessageFlags flags) OVERRIDE;
virtual MojoResult CreateDataPipe(
const MojoCreateDataPipeOptions* options,
MojoHandle* data_pipe_producer_handle,
MojoHandle* data_pipe_consumer_handle) OVERRIDE;
virtual MojoResult WriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags) OVERRIDE;
virtual MojoResult BeginWriteData(MojoHandle data_pipe_producer_handle,
void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags) OVERRIDE;
virtual MojoResult EndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_written) OVERRIDE;
virtual MojoResult ReadData(MojoHandle data_pipe_consumer_handle,
void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) OVERRIDE;
virtual MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle,
const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags) OVERRIDE;
virtual MojoResult EndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_read) OVERRIDE;
virtual MojoResult CreateSharedBuffer(
const MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
MojoHandle* shared_buffer_handle) OVERRIDE;
virtual MojoResult DuplicateBufferHandle(
MojoHandle buffer_handle,
const MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle) OVERRIDE;
virtual MojoResult MapBuffer(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
void** buffer,
MojoMapBufferFlags flags) OVERRIDE;
virtual MojoResult UnmapBuffer(void* buffer) OVERRIDE;
private:
friend bool internal::ShutdownCheckNoLeaks(CoreImpl*);
struct HandleTableEntry {
HandleTableEntry();
explicit HandleTableEntry(const scoped_refptr<Dispatcher>& dispatcher);
~HandleTableEntry();
scoped_refptr<Dispatcher> dispatcher;
bool busy;
};
typedef base::hash_map<MojoHandle, HandleTableEntry> HandleTableMap;
scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle);
MojoResult WaitManyInternal(const MojoHandle* handles,
const MojoWaitFlags* flags,
uint32_t num_handles,
MojoDeadline deadline);
base::Lock handle_table_lock_;
HandleTable handle_table_;
base::Lock mapping_table_lock_;
MappingTable mapping_table_;
DISALLOW_COPY_AND_ASSIGN(CoreImpl);
};
}
}
#endif