#ifndef MOJO_SYSTEM_LOCAL_DATA_PIPE_H_
#define MOJO_SYSTEM_LOCAL_DATA_PIPE_H_
#include "base/basictypes.h"
#include "base/memory/aligned_memory.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "mojo/system/data_pipe.h"
#include "mojo/system/system_impl_export.h"
namespace mojo {
namespace system {
class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipe : public DataPipe {
public:
explicit LocalDataPipe(const MojoCreateDataPipeOptions& validated_options);
private:
friend class base::RefCountedThreadSafe<LocalDataPipe>;
virtual ~LocalDataPipe();
virtual void ProducerCloseImplNoLock() OVERRIDE;
virtual MojoResult ProducerWriteDataImplNoLock(const void* elements,
uint32_t* num_bytes,
bool all_or_none) OVERRIDE;
virtual MojoResult ProducerBeginWriteDataImplNoLock(
void** buffer,
uint32_t* buffer_num_bytes,
bool all_or_none) OVERRIDE;
virtual MojoResult ProducerEndWriteDataImplNoLock(
uint32_t num_bytes_written) OVERRIDE;
virtual MojoWaitFlags ProducerSatisfiedFlagsNoLock() OVERRIDE;
virtual MojoWaitFlags ProducerSatisfiableFlagsNoLock() OVERRIDE;
virtual void ConsumerCloseImplNoLock() OVERRIDE;
virtual MojoResult ConsumerReadDataImplNoLock(void* elements,
uint32_t* num_bytes,
bool all_or_none) OVERRIDE;
virtual MojoResult ConsumerDiscardDataImplNoLock(uint32_t* num_bytes,
bool all_or_none) OVERRIDE;
virtual MojoResult ConsumerQueryDataImplNoLock(uint32_t* num_bytes) OVERRIDE;
virtual MojoResult ConsumerBeginReadDataImplNoLock(const void** buffer,
uint32_t* buffer_num_bytes,
bool all_or_none) OVERRIDE;
virtual MojoResult ConsumerEndReadDataImplNoLock(
uint32_t num_bytes_read) OVERRIDE;
virtual MojoWaitFlags ConsumerSatisfiedFlagsNoLock() OVERRIDE;
virtual MojoWaitFlags ConsumerSatisfiableFlagsNoLock() OVERRIDE;
void EnsureBufferNoLock();
void DestroyBufferNoLock();
size_t GetMaxNumBytesToWriteNoLock();
size_t GetMaxNumBytesToReadNoLock();
void MarkDataAsConsumedNoLock(size_t num_bytes);
scoped_ptr<char, base::AlignedFreeDeleter> buffer_;
size_t start_index_;
size_t current_num_bytes_;
DISALLOW_COPY_AND_ASSIGN(LocalDataPipe);
};
}
}
#endif