Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions

Barry::SocketRoutingQueue Class Reference

Collaboration diagram for Barry::SocketRoutingQueue:
Collaboration graph
[legend]

List of all members.

Classes

struct  QueueEntry
class  SimpleSocketDataHandler
class  SocketDataHandler

Public Member Functions

void AllocateBuffers (int count)
 This class starts out with no buffers, and will grow one buffer at a time if needed.
bool DefaultRead (Data &receive, int timeout=-1)
 Returns the data for the next unregistered socket.
DataHandle DefaultRead (int timeout=-1)
 This version does not perform a copy.
void RegisterInterest (SocketId socket, SocketDataHandlerPtr handler)
 Register an interest in data from a certain socket.
void UnregisterInterest (SocketId socket)
 Unregisters interest in data from the given socket, and discards any existing data in its interest queue.
bool SocketRead (SocketId socket, Data &receive, int timeout=-1)
 Reads data from the interested socket cache.
DataHandle SocketRead (SocketId socket, int timeout=-1)
 Copying is not performed with this function.
void DoRead (int timeout=-1)
 Called by the application's "read thread" to read the next usb packet and route it to the correct queue.

Protected Member Functions

void ReturnBuffer (Data *buf)
 Provides a method of returning a buffer to the free queue after processing.

Static Protected Member Functions

static void * SimpleReadThread (void *userptr)
 Convenience thread to handle USB read activity.

Detailed Description

Definition at line 39 of file router.h.


Member Function Documentation

void Barry::SocketRoutingQueue::AllocateBuffers ( int  count  ) 

This class starts out with no buffers, and will grow one buffer at a time if needed.

Call this to allocate count buffers all at once and place them on the free queue. After calling this function, at least count buffers will exist in the free queue. If there are already count buffers, none will be added.

Definition at line 163 of file router.cc.

References Barry::DataQueue::push(), and Barry::DataQueue::size().

Here is the call graph for this function:

bool Barry::SocketRoutingQueue::DefaultRead ( Data receive,
int  timeout = -1 
)

Returns the data for the next unregistered socket.

Blocks until timeout or data is available. Returns false (or null pointer) on timeout and no data. With the return version of the function, there is no copying performed.

This version performs a copy.

Definition at line 184 of file router.cc.

DataHandle Barry::SocketRoutingQueue::DefaultRead ( int  timeout = -1  ) 

This version does not perform a copy.

Definition at line 198 of file router.cc.

References Barry::DataQueue::wait_pop().

Here is the call graph for this function:

void Barry::SocketRoutingQueue::DoRead ( int  timeout = -1  ) 

Called by the application's "read thread" to read the next usb packet and route it to the correct queue.

Returns after every read, even if a handler is associated with a queue. Note: this function is safe to call before SetUsbDevice() is called... it just doesn't do anything if there is no usb device to work with.

Timeout is in milliseconds.

Definition at line 371 of file router.cc.

References Barry::DataQueue::pop(), and Barry::DataQueue::push().

Referenced by SimpleReadThread().

Here is the call graph for this function:

Here is the caller graph for this function:

void Barry::SocketRoutingQueue::RegisterInterest ( SocketId  socket,
SocketDataHandlerPtr  handler 
)

Register an interest in data from a certain socket.

To read from that socket, use the SocketRead() function from then on.

Any non-registered socket goes in the default queue and must be read by DefaultRead()

If not null, handler is called when new data is read. It will be called in the same thread instance that DoRead() is called from. Handler is passed the DataQueue Data pointer, and so no copying is done. Once the handler returns, the data is considered processed and not added to the interested queue, but instead returned to m_free.

Throws std::logic_error if already registered.

Definition at line 233 of file router.cc.

void Barry::SocketRoutingQueue::ReturnBuffer ( Data buf  )  [protected]

Provides a method of returning a buffer to the free queue after processing.

The DataHandle class calls this automatically from its destructor.

Definition at line 87 of file router.cc.

References Barry::DataQueue::push().

Here is the call graph for this function:

void * Barry::SocketRoutingQueue::SimpleReadThread ( void *  userptr  )  [static, protected]

Convenience thread to handle USB read activity.

Definition at line 98 of file router.cc.

References DoRead().

Here is the call graph for this function:

DataHandle Barry::SocketRoutingQueue::SocketRead ( SocketId  socket,
int  timeout = -1 
)

Copying is not performed with this function.

Throws std::logic_error if a socket was requested that was not previously registered.

Definition at line 307 of file router.cc.

References Barry::DataQueue::wait_pop().

Here is the call graph for this function:

bool Barry::SocketRoutingQueue::SocketRead ( SocketId  socket,
Data receive,
int  timeout = -1 
)

Reads data from the interested socket cache.

Can only read from sockets that have been previously registered.

Blocks until timeout or data is available.

Returns false (or null pointer) on timeout and no data. With the return version of the function, there is no copying performed.

Throws std::logic_error if a socket was requested that was not previously registered.

Copying is performed with this function.

Definition at line 290 of file router.cc.

void Barry::SocketRoutingQueue::UnregisterInterest ( SocketId  socket  ) 

Unregisters interest in data from the given socket, and discards any existing data in its interest queue.

Any new incoming data for this socket will be placed in the default queue.

Definition at line 254 of file router.cc.

References Barry::DataQueue::append_from().

Here is the call graph for this function:


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