MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
MFM::Connection Class Reference

#include <Connection.h>

Public Member Functions

 Connection ()
 
 ~Connection ()
 
void SetConnected (bool value)
 
bool IsConnected ()
 
bool IsLockedByAnother ()
 
bool Lock ()
 
void Unlock ()
 
void ReadBlocking (bool child, u8 *buffer, u32 length)
 
u32 Read (bool child, u8 *buffer, u32 length)
 
void PeekRead (bool output, u8 *buffer, u32 index, u32 length)
 
void Write (bool child, u8 *buffer, u32 length)
 
u32 InputByteCount ()
 
u32 OutputByteCount ()
 
void LogAllPackets ()
 
void ReportConnectionStatus (Logger::Level level, bool owned)
 

Detailed Description

A construct meant to be used by two threads as a communication channel, supporting reading and writing on both ends. Only one thread is able to access the IO of this construct at a time, allowing for thread safe operation.

Constructor & Destructor Documentation

MFM::Connection::Connection ( )
inline

Creates a new Connection which is not connected. Also initializes the internal mutex.

MFM::Connection::~Connection ( )
inline

Deconstructs this Connection, freeing the internal mutex.

Member Function Documentation

u32 MFM::Connection::InputByteCount ( )
inline

Number of bytes currently in the input buffer of this connection.

bool MFM::Connection::IsConnected ( )
inline

Checks whether or not this Connection is able to be used as a communication channel.

Returns
true if this Connection is able to be written to and read from on both ends, else false .
bool MFM::Connection::IsLockedByAnother ( )
inline

Test if the connection is currently locked by a thread other than the current thread.

FAILs with LOCK_FAILURE if the connection is locked by the current thread.

Returns
true if the lock is currently held by a thread other than the current thread, and false if the lock is currently unlocked
bool MFM::Connection::Lock ( )
inline

Locks the underlying mutex, allowing for thread-safe execution along this connection.

Returns
true if the lock was successfully taken, else false.
u32 MFM::Connection::OutputByteCount ( )
inline

Number of bytes currently in the output buffer of this connection.

void MFM::Connection::PeekRead ( bool  output,
u8 *  buffer,
u32  index,
u32  length 
)
inline

Reads a series of bytes from an underlying queue without blocking the calling thread. This FAILs with ARRAY_INDEX_OUT_OF_BOUNDS if reading will go over the bounds of this ThreadQueue. This does not consume any bytes from the ThreadQueue .

u32 MFM::Connection::Read ( bool  child,
u8 *  buffer,
u32  length 
)
inline

Reads from the corresponding underlying queue without blocking the calling thread.

Parameters
childThis should be true if the calling thread is not the owner of this Connection.
bufferThe location to read bytes into.
lengthThe number of bytes to read from the underlying buffer. Use 0 if wanting to read as many as possible.
Returns
The number of bytes successfully read from this Connection.
See Also
Write
void MFM::Connection::ReadBlocking ( bool  child,
u8 *  buffer,
u32  length 
)
inline

Waits until this Connection is not busy, then reads a specified amount of bytes into a specified buffer. This method blocks the calling thread until it is able to take control of this Connection.

Parameters
bufferThe buffer to write bytes read from this Connection to.
lengthThe number of bytes which will be written to buffer before this method returns.
void MFM::Connection::SetConnected ( bool  value)
inline

Sets the connection status of this Connection, allowing or disallowing communication.

Parameters
valueIf true , will allow this Connection to be written to and read from. Else, will disallow these features.
void MFM::Connection::Unlock ( )
inline

Unlocks the underlying mutex, allowing for another thread to lock this Connection. DO NOT call this method from a thread which does not already hold the lock!

void MFM::Connection::Write ( bool  child,
u8 *  buffer,
u32  length 
)
inline

Writes a series of bytes to a specified internal buffer of this Connection.

Parameters
childSelects which internal buffer to write to. If the calling object created this Connection, use true . If not, use false .
bufferThe buffer containing the bytes to write to this Connection.
lengthThe number of bytes which will be written to this Connection from buffer before this method returns.

The documentation for this class was generated from the following files: