IBR-DTNSuite
0.12
|
#include <Client.h>
Public Types | |
enum | COMMUNICATION_MODE { MODE_BIDIRECTIONAL = 0, MODE_SENDONLY = 1 } |
Public Types inherited from dtn::streams::StreamConnection | |
enum | ConnectionShutdownCases { CONNECTION_SHUTDOWN_NOTSET = 0, CONNECTION_SHUTDOWN_IDLE = 1, CONNECTION_SHUTDOWN_ERROR = 2, CONNECTION_SHUTDOWN_SIMPLE_SHUTDOWN = 3, CONNECTION_SHUTDOWN_NODE_TIMEOUT = 4, CONNECTION_SHUTDOWN_PEER_SHUTDOWN = 5 } |
Public Member Functions | |
Client (const std::string &app, ibrcommon::socketstream &stream, const COMMUNICATION_MODE mode=MODE_BIDIRECTIONAL) | |
Client (const std::string &app, const dtn::data::EID &group, ibrcommon::socketstream &stream, const COMMUNICATION_MODE mode=MODE_BIDIRECTIONAL) | |
virtual | ~Client () |
void | connect () |
void | close () |
void | abort () |
virtual void | eventConnectionDown () throw () |
virtual void | eventBundleAck (const dtn::data::Length &ack) throw () |
virtual void | eventShutdown (StreamConnection::ConnectionShutdownCases) throw () |
virtual void | eventTimeout () throw () |
virtual void | eventError () throw () |
virtual void | eventConnectionUp (const dtn::streams::StreamContactHeader &) throw () |
virtual void | eventBundleRefused () throw () |
virtual void | eventBundleForwarded () throw () |
void | operator<< (const dtn::data::Bundle &b) |
dtn::data::Bundle | getBundle (const dtn::data::Timeout timeout=0) throw (ConnectionException) |
Public Member Functions inherited from dtn::streams::StreamConnection | |
StreamConnection (StreamConnection::Callback &cb, iostream &stream, const dtn::data::Length buffer_size=4096) | |
virtual | ~StreamConnection () |
void | handshake (const dtn::data::EID &eid, const dtn::data::Timeout &timeout, const dtn::data::Bitset< StreamContactHeader::HEADER_BITS > &flags) |
void | shutdown (ConnectionShutdownCases csc=CONNECTION_SHUTDOWN_SIMPLE_SHUTDOWN) |
void | reject () |
void | keepalive () |
void | enableIdleTimeout (const dtn::data::Timeout &seconds) |
Public Member Functions inherited from dtn::streams::StreamConnection::Callback | |
virtual void | eventShutdown (StreamConnection::ConnectionShutdownCases csc)=0 throw () |
virtual void | addTrafficIn (size_t) throw () |
virtual void | addTrafficOut (size_t) throw () |
Public Attributes | |
dtn::data::Length | lastack |
Protected Member Functions | |
virtual void | received (const dtn::streams::StreamContactHeader &) |
virtual void | received (const dtn::data::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::socketstream & | 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 92 of file Client.cpp.
dtn::api::Client::Client | ( | const std::string & | app, |
const dtn::data::EID & | group, | ||
ibrcommon::socketstream & | stream, | ||
const COMMUNICATION_MODE | mode = MODE_BIDIRECTIONAL |
||
) |
Definition at line 87 of file Client.cpp.
|
virtual |
Virtual destructor for this class.
Definition at line 97 of file Client.cpp.
References ibrcommon::socketstream::close(), IBRCOMMON_LOGGER_DEBUG_TAG, IBRCOMMON_LOGGER_ENDL, and ibrcommon::Exception::what().
void dtn::api::Client::abort | ( | ) |
Aborts blocking calls of getBundle()
Definition at line 162 of file Client.cpp.
References ibrcommon::Queue< T >::abort(), and dtn::streams::StreamConnection::shutdown().
Referenced by term().
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 156 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 113 of file Client.cpp.
References ibrcommon::LogLevel::error, dtn::data::EID::getString(), dtn::streams::StreamConnection::handshake(), dtn::streams::StreamContactHeader::HANDSHAKE_SENDONLY, IBRCOMMON_LOGGER_ENDL, IBRCOMMON_LOGGER_TAG, dtn::data::EID::isNone(), MODE_SENDONLY, dtn::streams::StreamContactHeader::REQUEST_ACKNOWLEDGMENTS, dtn::data::Bitset< E >::setBit(), and ibrcommon::Exception::what().
Referenced by main().
|
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 181 of file Client.cpp.
|
inlinevirtual |
The bundle forwarded event callback method can overloaded to determine when a bundle is forwarded to the daemon.
Implements dtn::streams::StreamConnection::Callback.
|
inlinevirtual |
The bundle refused event callback method can overloaded to handle a bundle refused by the porresponding daemon.
Implements dtn::streams::StreamConnection::Callback.
|
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 170 of file Client.cpp.
References ibrcommon::Queue< T >::abort(), ibrcommon::LogLevel::error, IBRCOMMON_LOGGER_ENDL, IBRCOMMON_LOGGER_TAG, and ibrcommon::Exception::what().
|
inlinevirtual |
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.
|
inlinevirtual |
The error event callback method can overloaded to handle errors occurring in the API protocol.
Implements dtn::streams::StreamConnection::Callback.
|
inlinevirtual |
|
inlinevirtual |
The timeout event callback method can overloaded to handle timeouts occurring in the API protocol.
Implements dtn::streams::StreamConnection::Callback.
dtn::data::Bundle dtn::api::Client::getBundle | ( | const dtn::data::Timeout | 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 209 of file Client.cpp.
References ibrcommon::QueueUnblockedException::QUEUE_ABORT, ibrcommon::QueueUnblockedException::QUEUE_TIMEOUT, ibrcommon::QueueUnblockedException::reason, and ibrcommon::Exception::what().
Referenced by main().
void dtn::api::Client::operator<< | ( | const dtn::data::Bundle & | b) |
Send a bundle to the daemon
Definition at line 197 of file Client.cpp.
|
inlineprotectedvirtual |
|
protectedvirtual |
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 186 of file Client.cpp.
References MODE_SENDONLY, and ibrcommon::Queue< T >::push().
dtn::data::Length dtn::api::Client::lastack |