|
IBR-DTNSuite 0.6
|
#include <Client.h>


Classes | |
| class | AsyncReceiver |
Public Types | |
| enum | COMMUNICATION_MODE { MODE_BIDIRECTIONAL = 0, MODE_SENDONLY = 1 } |
Public Member Functions | |
| Client (const std::string &app, ibrcommon::tcpstream &stream, const COMMUNICATION_MODE mode=MODE_BIDIRECTIONAL) | |
| virtual | ~Client () |
| void | connect () |
| void | close () |
| virtual void | eventConnectionDown () |
| virtual void | eventBundleAck (size_t ack) |
| virtual void | eventShutdown (StreamConnection::ConnectionShutdownCases) |
| virtual void | eventTimeout () |
| virtual void | eventError () |
| virtual void | eventConnectionUp (const StreamContactHeader &) |
| virtual void | eventBundleRefused () |
| virtual void | eventBundleForwarded () |
| dtn::api::Bundle | getBundle (size_t timeout=0) throw (ConnectionException) |
Public Attributes | |
| size_t | lastack |
Protected Member Functions | |
| virtual void | received (const dtn::streams::StreamContactHeader &) |
| virtual void | received (const dtn::api::Bundle &b) |
This is an abstract class is the base for any API connection to a IBR-DTN daemon. It uses an existing I/O stream to communicate bidirectional with the daemon.
For asynchronous reception of bundle this class contains a thread which deals the receiving part of the communication and calls the received() methods which should be overwritten.
| dtn::api::Client::Client | ( | const std::string & | app, |
| ibrcommon::tcpstream & | stream, | ||
| const COMMUNICATION_MODE | mode = MODE_BIDIRECTIONAL |
||
| ) |
Constructor for the API Connection. At least a application suffix and an existing tcp stream are required. The suffix is appended to the node id of the daemon. E.g. dtn://<node-id>/example (in this case is "example" the application id. The stream connects the daemon and this application together and will be used with the bundle protocol for TCP (draft-irtf-dtnrg-tcp-clayer-02) provided by the StreamConnection class.
| app | Application suffix. |
| stream | TCP stream object. |
| mode | Communication mode. Default is bidirectional communication. |
Definition at line 73 of file Client.cpp.
| dtn::api::Client::~Client | ( | ) | [virtual] |
Virtual destructor for this class.
Definition at line 78 of file Client.cpp.
References ibrcommon::tcpstream::close(), IBRCOMMON_LOGGER_DEBUG, IBRCOMMON_LOGGER_ENDL, and ibrcommon::Exception::what().

| void dtn::api::Client::close | ( | ) |
Closes the client. Actually, this send out a SHUTDOWN message to the daemon. The connection itself has to be closed separately.
Definition at line 119 of file Client.cpp.
References dtn::streams::StreamConnection::shutdown().
Referenced by main(), and term().

| void dtn::api::Client::connect | ( | ) |
This method starts the thread and execute the handshake with the server.
Definition at line 94 of file Client.cpp.
References dtn::streams::StreamConnection::handshake(), IBRCOMMON_LOGGER, IBRCOMMON_LOGGER_ENDL, MODE_SENDONLY, dtn::streams::StreamContactHeader::REQUEST_ACKNOWLEDGMENTS, and ibrcommon::Exception::what().
Referenced by main().

| void dtn::api::Client::eventBundleAck | ( | size_t | ack | ) | [virtual] |
The bundle ack event is called by the StreamConnection object and stores the last ACK'd bundle size in the lastack variable.
| ack | ACK'd bundle size |
Implements dtn::streams::StreamConnection::Callback.
Definition at line 136 of file Client.cpp.
References lastack.
| virtual void dtn::api::Client::eventBundleForwarded | ( | ) | [inline, virtual] |
The bundle forwarded event callback method can overloaded to determine when a bundle is forwarded to the daemon.
Implements dtn::streams::StreamConnection::Callback.
| virtual void dtn::api::Client::eventBundleRefused | ( | ) | [inline, virtual] |
The bundle refused event callback method can overloaded to handle a bundle refused by the porresponding daemon.
Implements dtn::streams::StreamConnection::Callback.
| void dtn::api::Client::eventConnectionDown | ( | ) | [virtual] |
The connection down event is called by the StreamConnection object and aborts the blocking getBundle() method. If a client is working synchonous this method should not be overloaded!
Implements dtn::streams::StreamConnection::Callback.
Definition at line 125 of file Client.cpp.
References ibrcommon::Queue< T >::abort(), IBRCOMMON_LOGGER_DEBUG, IBRCOMMON_LOGGER_ENDL, and ibrcommon::Exception::what().

| virtual void dtn::api::Client::eventConnectionUp | ( | const StreamContactHeader & | ) | [inline, virtual] |
The connection up event callback method can overloaded to handle a successful connection handshake. In this call the header of the corresponding daemon is available.
Implements dtn::streams::StreamConnection::Callback.
| virtual void dtn::api::Client::eventError | ( | ) | [inline, virtual] |
The error event callback method can overloaded to handle errors occurring in the API protocol.
Implements dtn::streams::StreamConnection::Callback.
| virtual void dtn::api::Client::eventShutdown | ( | StreamConnection::ConnectionShutdownCases | ) | [inline, virtual] |
The shutdown event callback method can overloaded to handle shutdown events.
Implements dtn::streams::StreamConnection::Callback.
| virtual void dtn::api::Client::eventTimeout | ( | ) | [inline, virtual] |
The timeout event callback method can overloaded to handle timeouts occurring in the API protocol.
Implements dtn::streams::StreamConnection::Callback.
| dtn::api::Bundle dtn::api::Client::getBundle | ( | size_t | timeout = 0 | ) | throw (ConnectionException) |
This method is for synchronous API usage only. It blocks until a bundle is received and return it. If the connection is closed during the get() call an exception is thrown
| timeout |
Definition at line 151 of file Client.cpp.
References ibrcommon::QueueUnblockedException::QUEUE_ABORT, ibrcommon::QueueUnblockedException::QUEUE_TIMEOUT, ibrcommon::QueueUnblockedException::reason, and ibrcommon::Exception::what().
Referenced by main().

| virtual void dtn::api::Client::received | ( | const dtn::streams::StreamContactHeader & | ) | [inline, protected, virtual] |
| void dtn::api::Client::received | ( | const dtn::api::Bundle & | b | ) | [protected, virtual] |
This method is called on the receipt of a new bundle. If you like to use asynchronous API mode you should overload this method to receive bundles.
| b | The received bundle. |
Reimplemented in BundleStream.
Definition at line 141 of file Client.cpp.
References MODE_SENDONLY, and ibrcommon::Queue< T >::push().

| size_t dtn::api::Client::lastack |
Definition at line 227 of file Client.h.
Referenced by eventBundleAck(), and main().