Barry::SocketRoutingQueue Class Reference

List of all members.

Detailed Description

Definition at line 39 of file router.h.

Public Types

typedef void(*) SocketDataHandler (void *ctx, Data *)
typedef std::tr1::shared_ptr<
QueueEntry
QueueEntryPtr
typedef uint16_t SocketId
typedef std::map< SocketId,
QueueEntryPtr
SocketQueueMap

Public Member Functions

 SocketRoutingQueue (int prealloc_buffer_count=4)
 ~SocketRoutingQueue ()
void SetUsbDevice (Usb::Device *dev, int writeEp, int readEp)
void ClearUsbDevice ()
bool UsbDeviceReady ()
Usb::DeviceGetUsbDevice ()
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, SocketDataHandler handler=0, void *context=0)
 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.
bool IsAvailable (SocketId socket) const
bool DoRead (std::string &msg, int timeout=-1)
 Called by the application's "read thread" to read the next usb packet and route it to the correct queue.
void SpinoffSimpleReadThread ()

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.

Friends

class DataHandle

Classes

struct  QueueEntry


Member Function Documentation

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

References Barry::DataQueue::push().

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

Convenience thread to handle USB read activity.

Definition at line 80 of file router.cc.

References DoRead(), and m_continue_reading.

Referenced by SpinoffSimpleReadThread().

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

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

Referenced by SocketRoutingQueue().

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

References Barry::DataHandle::get().

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

This version does not perform a copy.

Definition at line 171 of file router.cc.

References DataHandle, and Barry::DataQueue::wait_pop().

void Barry::SocketRoutingQueue::RegisterInterest ( SocketId  socket,
SocketDataHandler  handler = 0,
void *  context = 0 
)

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

Referenced by Barry::Socket::RegisterInterest().

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

References Barry::DataQueue::append_from().

Referenced by Barry::Socket::UnregisterInterest().

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

References Barry::DataHandle::get().

Referenced by Barry::Socket::Receive().

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

References DataHandle, Barry::DataQueue::m_queue, and Barry::DataQueue::wait_pop().

bool Barry::SocketRoutingQueue::DoRead ( std::string &  msg,
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.

Returns false in the case of USB errors and puts the error message in msg.

Definition at line 336 of file router.cc.

References btohs, Usb::Device::BulkRead(), DataHandle, Barry::DataHandle::get(), Barry::Data::GetSize(), MAKE_PACKET, Barry::DataQueue::pop(), Barry::DataQueue::push(), Barry::DataHandle::release(), and Barry::scoped_lock::unlock().

Referenced by SimpleReadThread().


The documentation for this class was generated from the following files:
Generated on Wed Sep 24 21:27:33 2008 for Barry by  doxygen 1.5.1