#include <dashel.h>
Public Types | |
| typedef std::set< Stream * > | StreamsSet |
| A list of streams. | |
Public Member Functions | |
| Hub () | |
| Constructor. | |
| virtual | ~Hub () |
| Destructor, closes all connections. | |
| Stream * | connect (const std::string &target) |
| Listens for incoming connections on a target. | |
| void | closeStream (Stream *stream) |
| Close a stream, remove it from the Hub, and delete it. | |
| void | run (void) |
| Runs and returns only when an external event requests the application to stop. | |
| bool | step (int timeout=0) |
| Waits for data from the transfers streams or connections from the listening streams. | |
| void | stop () |
| Stops running, subclasses or external code may call this function, that is the only thread-safe function of the Hub. | |
Protected Member Functions | |
| virtual void | connectionCreated (Stream *stream) |
| Called when any data connection is created. | |
| virtual void | incomingData (Stream *stream) |
| Called when data is available for reading on the stream. | |
| virtual void | connectionClosed (Stream *stream, bool abnormal) |
| Called when target closes connection. | |
Protected Attributes | |
| StreamsSet | dataStreams |
| All our streams that transfer data (in opposition to streams that just listen for data). | |
To create a client connection, users of the library have to subclass Hub and implement incomingConnection(), incomingData(), and connectionClosed().
| 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.
| target | destination to listen connections from (see Section Targets Naming) |
| 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 s.
| stream | stream to remove |
| bool Dashel::Hub::step | ( | int | timeout = 0 |
) |
Waits for data from the transfers streams or connections from the listening streams.
Read all available data.
| timeout | if -1, waits until data arrive. If 0, do not wait, just poll for activity. If positive, waits at maximum timeout ms. |
| virtual void Dashel::Hub::connectionCreated | ( | Stream * | 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.
| stream | stream to the target |
| virtual void Dashel::Hub::incomingData | ( | Stream * | 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.
| stream | stream to the target |
| virtual void Dashel::Hub::connectionClosed | ( | Stream * | stream, | |
| bool | abnormal | |||
| ) | [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.
| stream | stream to the target. | |
| abnormal | whether the connection was closed during step (abnormal == false) or when an operation was performed (abnormal == true) |
1.5.1