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.
bool QueuePacket (SocketId socket, DataHandle &buf)
 Helper function to add a buffer to a socket queue.
bool RouteOrQueuePacket (SocketId socket, DataHandle &buf)
 Same as QueuePacket, except sends the data to the callback if a callback is available.

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 264 of file router.cc.

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

Here is the call graph for this function:

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

This version does not perform a copy.

Definition at line 299 of file router.cc.

References Barry::DataQueue::wait_pop().

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 285 of file router.cc.

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 475 of file router.cc.

References Barry::DataQueue::pop(), QueuePacket(), and RouteOrQueuePacket().

Referenced by SimpleReadThread().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Barry::SocketRoutingQueue::QueuePacket ( SocketId  socket,
DataHandle buf 
) [protected]

Helper function to add a buffer to a socket queue.

Returns false if no queue is available for that socket. Also empties the DataHandle on success.

Definition at line 115 of file router.cc.

Referenced by DoRead().

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 334 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 102 of file router.cc.

References Barry::DataQueue::push().

Here is the call graph for this function:

bool Barry::SocketRoutingQueue::RouteOrQueuePacket ( SocketId  socket,
DataHandle buf 
) [protected]

Same as QueuePacket, except sends the data to the callback if a callback is available.

This function duplicates code from QueuePacket(), in order to optimize the mutex locking.

Definition at line 148 of file router.cc.

Referenced by DoRead().

Here is the caller graph for this function:

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

Convenience thread to handle USB read activity.

Definition at line 186 of file router.cc.

References DoRead().

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 394 of file router.cc.

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 411 of file router.cc.

References Barry::DataQueue::wait_pop().

Here is the call graph for this function:

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 355 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: