Dashel::Hub Class Reference

#include <dashel.h>

Inheritance diagram for Dashel::Hub:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::set< Stream * > StreamsSet
 A list of streams.
typedef std::set< Stream * > StreamsSet
 A list of streams.

Public Member Functions

void closeStream (Stream *stream)
void closeStream (Stream *stream)
Streamconnect (const std::string &target)
Streamconnect (const std::string &target)
 Hub (const bool resolveIncomingNames=true)
 Hub (const bool resolveIncomingNames=true)
void lock ()
void lock ()
void run ()
void run ()
bool step (const int timeout=0)
bool step (const int timeout=0)
void stop ()
 Stops running, subclasses or external code may call this function, that is the only thread-safe function of the Hub.
void stop ()
 Stops running, subclasses or external code may call this function, that is the only thread-safe function of the Hub.
void unlock ()
void unlock ()
virtual ~Hub ()
 Destructor, closes all connections.
virtual ~Hub ()
 Destructor, closes all connections.

Protected Member Functions

virtual void connectionClosed (Stream *, bool)
virtual void connectionClosed (Stream *, bool)
virtual void connectionCreated (Stream *)
virtual void connectionCreated (Stream *)
virtual void incomingData (Stream *)
virtual void incomingData (Stream *)

Protected Attributes

StreamsSet dataStreams
 All our streams that transfer data (in opposition to streams that just listen for data).
const bool resolveIncomingNames
 Whether Dashel should try to resolve the peer's hostname of incoming TCP connections.

Private Attributes

void * hTerminate
 Set when this thing goes down.
StreamsSet streams
 All our streams.
void * streamsLock
 Platform-dependant mutex to protect access to streams.

Detailed Description

The central place where to create, destroy, and synchronize streams. To create a client connection, users of the library have to subclass Hub and implement incomingConnection(), incomingData(), and connectionClosed().

Definition at line 404 of file dashel.h.


Member Typedef Documentation

typedef std::set<Stream*> Dashel::Hub::StreamsSet

A list of streams.

Definition at line 408 of file dashel.h.

typedef std::set<Stream*> Dashel::Hub::StreamsSet

A list of streams.

Definition at line 408 of file dashel.h.


Constructor & Destructor Documentation

Dashel::Hub::Hub ( const bool  resolveIncomingNames = true  ) 

Constructor.

Parameters:
resolveIncomingNames if true, try to resolve the peer's hostname of incoming TCP connections

Definition at line 943 of file dashel-posix.cpp.

Dashel::Hub::~Hub (  )  [virtual]

Destructor, closes all connections.

Definition at line 959 of file dashel-posix.cpp.

Dashel::Hub::Hub ( const bool  resolveIncomingNames = true  ) 

Constructor.

Parameters:
resolveIncomingNames if true, try to resolve the peer's hostname of incoming TCP connections
virtual Dashel::Hub::~Hub (  )  [virtual]

Destructor, closes all connections.


Member Function Documentation

void Dashel::Hub::closeStream ( Stream stream  ) 

Close a stream, remove it from the Hub, and delete it. If the stream is not present in the Hub, it is deleted nevertheless. Note that connectionClosed() is not called by closeStream() and that you must not call closeStream(s) from inside connectionClosed(s) for the same stream.

Parameters:
stream stream to remove
void Dashel::Hub::closeStream ( Stream stream  ) 

Close a stream, remove it from the Hub, and delete it. If the stream is not present in the Hub, it is deleted nevertheless. Note that connectionClosed() is not called by closeStream() and that you must not call closeStream(s) from inside connectionClosed(s) for the same stream.

Parameters:
stream stream to remove

Definition at line 292 of file dashel-common.cpp.

Stream* Dashel::Hub::connect ( const std::string &  target  ) 

Listens for incoming connections on a target. Some targets, such as a serial ports and files may directly generate a new connection; others, such as network interfaces, will only generate news connections when a peer connects. May throw a ConnectionError exception if the target does not exists or is not ready.

Parameters:
target destination to listen connections from (see Section TargetNamingSec)
Returns:
the stream we are connected to; if connect was not possible, an exception was throw.
Stream * Dashel::Hub::connect ( const std::string &  target  ) 

Listens for incoming connections on a target. Some targets, such as a serial ports and files may directly generate a new connection; others, such as network interfaces, will only generate news connections when a peer connects. May throw a ConnectionError exception if the target does not exists or is not ready.

Parameters:
target destination to listen connections from (see Section TargetNamingSec)
Returns:
the stream we are connected to; if connect was not possible, an exception was throw.

Definition at line 977 of file dashel-posix.cpp.

virtual void Dashel::Hub::connectionClosed ( Stream ,
bool   
) [inline, protected, virtual]

Called when target closes connection. The only valid method to call on the stream is getTargetName(), input/output operations are forbidden. You must not call closeStream(stream) from within this method for the same stream as the one passed as parameter. Subclass can implement this method. Called with the stream lock held.

Parameters:
stream stream to the target.
abnormal whether the connection was closed during step (abnormal == false) or when an operation was performed (abnormal == true)

Reimplemented in Aseba::Dump, EventLogger, Aseba::Hub, Aseba::Player, Aseba::DashelInterface, Aseba::Switch, Enki::AsebaFeedableEPuck, Enki::AsebaMarxbot, Enki::PlaygroundViewer, ChatServer, ChatClient, MicroTerm, PingServer, PingClient, and AsebaDashelHub.

Definition at line 514 of file dashel.h.

virtual void Dashel::Hub::connectionClosed ( Stream ,
bool   
) [inline, protected, virtual]

Called when target closes connection. The only valid method to call on the stream is getTargetName(), input/output operations are forbidden. You must not call closeStream(stream) from within this method for the same stream as the one passed as parameter. Subclass can implement this method. Called with the stream lock held.

Parameters:
stream stream to the target.
abnormal whether the connection was closed during step (abnormal == false) or when an operation was performed (abnormal == true)

Reimplemented in Aseba::Dump, EventLogger, Aseba::Hub, Aseba::Player, Aseba::DashelInterface, Aseba::Switch, Enki::AsebaFeedableEPuck, Enki::AsebaMarxbot, Enki::PlaygroundViewer, ChatServer, ChatClient, MicroTerm, PingServer, PingClient, and AsebaDashelHub.

Definition at line 514 of file dashel.h.

virtual void Dashel::Hub::connectionCreated ( Stream  )  [inline, protected, virtual]

Called when any data connection is created. It is not called when a listening connection (eg tcpin:) is created. If the stream is closed during this method, an exception occurs: the caller is responsible to handle it. The stream is already inserted in the stream list when this function is called. Subclass can implement this method. Called with the stream lock held.

Parameters:
stream stream to the target

Reimplemented in Aseba::Dump, Aseba::Hub, Aseba::Player, Aseba::Switch, Enki::AsebaFeedableEPuck, Enki::AsebaMarxbot, Enki::PlaygroundViewer, ChatServer, ChatClient, MicroTerm, PingServer, PingClient, and AsebaDashelHub.

Definition at line 489 of file dashel.h.

virtual void Dashel::Hub::connectionCreated ( Stream  )  [inline, protected, virtual]

Called when any data connection is created. It is not called when a listening connection (eg tcpin:) is created. If the stream is closed during this method, an exception occurs: the caller is responsible to handle it. The stream is already inserted in the stream list when this function is called. Subclass can implement this method. Called with the stream lock held.

Parameters:
stream stream to the target

Reimplemented in Aseba::Dump, Aseba::Hub, Aseba::Player, Aseba::Switch, Enki::AsebaFeedableEPuck, Enki::AsebaMarxbot, Enki::PlaygroundViewer, ChatServer, ChatClient, MicroTerm, PingServer, PingClient, and AsebaDashelHub.

Definition at line 489 of file dashel.h.

virtual void Dashel::Hub::incomingData ( Stream  )  [inline, protected, virtual]

Called when data is available for reading on the stream. If the stream is closed during this method, an exception occurs: Hub stops the execution of this method and calls connectionClosed(); objects dynamically allocated must thus be handled with auto_ptr. If step() is used, subclass must implement this method and call read at least once. Called with the stream lock held.

Parameters:
stream stream to the target

Reimplemented in Aseba::Dump, EventLogger, Aseba::Hub, Aseba::Player, Aseba::Recorder, Aseba::DashelInterface, Aseba::Switch, Enki::AsebaFeedableEPuck, Enki::AsebaMarxbot, Enki::PlaygroundViewer, ChatServer, ChatClient, MicroTerm, PingServer, PingClient, and AsebaDashelHub.

Definition at line 501 of file dashel.h.

virtual void Dashel::Hub::incomingData ( Stream  )  [inline, protected, virtual]

Called when data is available for reading on the stream. If the stream is closed during this method, an exception occurs: Hub stops the execution of this method and calls connectionClosed(); objects dynamically allocated must thus be handled with auto_ptr. If step() is used, subclass must implement this method and call read at least once. Called with the stream lock held.

Parameters:
stream stream to the target

Reimplemented in Aseba::Dump, EventLogger, Aseba::Hub, Aseba::Player, Aseba::Recorder, Aseba::DashelInterface, Aseba::Switch, Enki::AsebaFeedableEPuck, Enki::AsebaMarxbot, Enki::PlaygroundViewer, ChatServer, ChatClient, MicroTerm, PingServer, PingClient, and AsebaDashelHub.

Definition at line 501 of file dashel.h.

void Dashel::Hub::lock (  ) 

Block any hub processing so another thread can access the streams safely. Currently only implemented on POSIX platform, no-op on others.

void Dashel::Hub::lock (  ) 

Block any hub processing so another thread can access the streams safely. Currently only implemented on POSIX platform, no-op on others.

Definition at line 1224 of file dashel-posix.cpp.

void Dashel::Hub::run (  ) 

Runs and returns only when an external event requests the application to stop.

Reimplemented in Aseba::Hub, and Aseba::DashelInterface.

void Dashel::Hub::run (  ) 

Runs and returns only when an external event requests the application to stop.

Reimplemented in Aseba::Hub, and Aseba::DashelInterface.

Definition at line 1021 of file dashel-posix.cpp.

bool Dashel::Hub::step ( const int  timeout = 0  ) 

Waits for data from the transfers streams or connections from the listening streams. Read all available data.

Parameters:
timeout if -1, waits until data arrive. If 0, do not wait, just poll for activity. If positive, waits at maximum timeout ms.
Returns:
false if stop() was called or the application was requested to terminate, true otherwise.
bool Dashel::Hub::step ( const int  timeout = 0  ) 

Waits for data from the transfers streams or connections from the listening streams. Read all available data.

Parameters:
timeout if -1, waits until data arrive. If 0, do not wait, just poll for activity. If positive, waits at maximum timeout ms.
Returns:
false if stop() was called or the application was requested to terminate, true otherwise.

Definition at line 1026 of file dashel-posix.cpp.

void Dashel::Hub::stop (  ) 

Stops running, subclasses or external code may call this function, that is the only thread-safe function of the Hub.

void Dashel::Hub::stop (  ) 

Stops running, subclasses or external code may call this function, that is the only thread-safe function of the Hub.

Definition at line 1234 of file dashel-posix.cpp.

void Dashel::Hub::unlock (  ) 

Release the lock aquired by lock(). Currently only implemented on POSIX platform, no-op on others.

void Dashel::Hub::unlock (  ) 

Release the lock aquired by lock(). Currently only implemented on POSIX platform, no-op on others.

Definition at line 1229 of file dashel-posix.cpp.


Member Data Documentation

All our streams that transfer data (in opposition to streams that just listen for data).

Definition at line 416 of file dashel.h.

void * Dashel::Hub::hTerminate [private]

Set when this thing goes down.

Definition at line 411 of file dashel.h.

const bool Dashel::Hub::resolveIncomingNames [protected]

Whether Dashel should try to resolve the peer's hostname of incoming TCP connections.

Definition at line 417 of file dashel.h.

All our streams.

Definition at line 413 of file dashel.h.

void * Dashel::Hub::streamsLock [private]

Platform-dependant mutex to protect access to streams.

Definition at line 412 of file dashel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


asebaros
Author(s): $author
autogenerated on Mon Sep 5 08:42:16 2011