mirror of
https://github.com/debauchee/barrier.git
synced 2024-12-18 08:22:06 +03:00
fee4095624
synergy.cpp and server.cpp into cmd/synergyd as synergyd.cpp. Moved and renamed related files. Moved remaining source files into lib/.... Modified and added makefiles as appropriate. Result is that library files are under lib with each library in its own directory and program files are under cmd with each command in its own directory.
75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
#ifndef CBUFFEREDOUTPUTSTREAM_H
|
|
#define CBUFFEREDOUTPUTSTREAM_H
|
|
|
|
#include "IOutputStream.h"
|
|
#include "CStreamBuffer.h"
|
|
#include "CCondVar.h"
|
|
|
|
class CMutex;
|
|
class IJob;
|
|
|
|
//! Memory buffer output stream
|
|
/*!
|
|
This class provides an output stream that writes to a memory buffer.
|
|
It also provides a means for the owner to ensure thread safe access.
|
|
Typically, an owner object will make this object visible to clients
|
|
that need access to an IOutputStream while using the CBufferedOutputStream
|
|
methods to read the data written to the stream.
|
|
*/
|
|
class CBufferedOutputStream : public IOutputStream {
|
|
public:
|
|
/*!
|
|
The \c mutex must not be NULL and will be used to ensure thread
|
|
safe access. If \c adoptedCloseCB is not NULL it will be called
|
|
when close() is called, allowing the creator to detect the close.
|
|
*/
|
|
CBufferedOutputStream(CMutex* mutex, IJob* adoptedCloseCB);
|
|
~CBufferedOutputStream();
|
|
|
|
//! @name manipulators
|
|
//@{
|
|
|
|
//! Read data without removing from buffer
|
|
/*!
|
|
Returns a buffer of \c n bytes (which must be <= getSize()). The
|
|
caller must not modify the buffer nor delete it. The mutex must
|
|
be locked before calling this.
|
|
*/
|
|
const void* peek(UInt32 n);
|
|
|
|
//! Discard data
|
|
/*!
|
|
Discards the next \c n bytes. If \c n >= getSize() then the buffer
|
|
is cleared. The mutex must be locked before calling this.
|
|
*/
|
|
void pop(UInt32 n);
|
|
|
|
//@}
|
|
//! @name accessors
|
|
//@{
|
|
|
|
//! Get size of buffer
|
|
/*!
|
|
Returns the number of bytes in the buffer. The mutex must be locked
|
|
before calling this.
|
|
*/
|
|
UInt32 getSize() const;
|
|
|
|
//@}
|
|
|
|
// IOutputStream overrides
|
|
// these all lock the mutex for their duration
|
|
virtual void close();
|
|
virtual UInt32 write(const void*, UInt32 n);
|
|
virtual void flush();
|
|
|
|
private:
|
|
CMutex* m_mutex;
|
|
IJob* m_closeCB;
|
|
CCondVar<bool> m_empty;
|
|
CStreamBuffer m_buffer;
|
|
bool m_closed;
|
|
};
|
|
|
|
#endif
|