IBR-DTNSuite  0.8
dtn::api::Client Class Reference

#include <Client.h>

Inheritance diagram for dtn::api::Client:
Collaboration diagram for dtn::api::Client:

List of all members.

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)
 Client (const std::string &app, const dtn::data::EID &group, ibrcommon::tcpstream &stream, const COMMUNICATION_MODE mode=MODE_BIDIRECTIONAL)
virtual ~Client ()
void connect ()
void close ()
void abort ()
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)

Detailed Description

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.

Definition at line 70 of file Client.h.


Member Enumeration Documentation

This are the communication flags.

Enumerator:
MODE_BIDIRECTIONAL 

bidirectional communication is requested

MODE_SENDONLY 

unidirectional communication is requested, no reception of bundles

Definition at line 131 of file Client.h.


Constructor & Destructor Documentation

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.

Parameters:
appApplication suffix.
streamTCP stream object.
modeCommunication mode. Default is bidirectional communication.

Definition at line 75 of file Client.cpp.

dtn::api::Client::Client ( const std::string &  app,
const dtn::data::EID group,
ibrcommon::tcpstream stream,
const COMMUNICATION_MODE  mode = MODE_BIDIRECTIONAL 
)

Definition at line 70 of file Client.cpp.

Virtual destructor for this class.

Definition at line 80 of file Client.cpp.

References ibrcommon::tcpstream::close(), IBRCOMMON_LOGGER_DEBUG, IBRCOMMON_LOGGER_ENDL, and ibrcommon::Exception::what().

Here is the call graph for this function:


Member Function Documentation

Aborts blocking calls of getBundle()

Definition at line 145 of file Client.cpp.

References ibrcommon::Queue< T >::abort(), and dtn::streams::StreamConnection::shutdown().

Referenced by term().

Here is the call graph for this function:

Closes the client. Actually, this send out a SHUTDOWN message to the daemon. The connection itself has to be closed separately.

Definition at line 139 of file Client.cpp.

References dtn::streams::StreamConnection::shutdown().

Referenced by main(), and term().

Here is the call graph for this function:

This method starts the thread and execute the handshake with the server.

Definition at line 96 of file Client.cpp.

References dtn::data::EID::getString(), dtn::streams::StreamConnection::handshake(), IBRCOMMON_LOGGER, IBRCOMMON_LOGGER_ENDL, dtn::data::EID::isNone(), MODE_SENDONLY, dtn::streams::StreamContactHeader::REQUEST_ACKNOWLEDGMENTS, and ibrcommon::Exception::what().

Referenced by main().

Here is the call graph for this function:

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.

Parameters:
ackACK'd bundle size

Implements dtn::streams::StreamConnection::Callback.

Definition at line 164 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.

Definition at line 221 of file Client.h.

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.

Definition at line 215 of file Client.h.

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 153 of file Client.cpp.

References ibrcommon::Queue< T >::abort(), IBRCOMMON_LOGGER_DEBUG, IBRCOMMON_LOGGER_ENDL, and ibrcommon::Exception::what().

Here is the call graph for this function:

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.

Definition at line 209 of file Client.h.

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.

Definition at line 202 of file Client.h.

The shutdown event callback method can overloaded to handle shutdown events.

Implements dtn::streams::StreamConnection::Callback.

Definition at line 190 of file Client.h.

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.

Definition at line 196 of file Client.h.

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

Parameters:
timeout
Returns:

Definition at line 180 of file Client.cpp.

References ibrcommon::QueueUnblockedException::QUEUE_ABORT, ibrcommon::QueueUnblockedException::QUEUE_TIMEOUT, ibrcommon::QueueUnblockedException::reason, and ibrcommon::Exception::what().

Referenced by main().

Here is the call graph for this function:

virtual void dtn::api::Client::received ( const dtn::streams::StreamContactHeader ) [inline, protected, virtual]

This method is called on the receipt of the handshake of the daemon. If you like to validate your connection you could overload this method, but must call the super method.

Definition at line 241 of file Client.h.

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.

Parameters:
bThe received bundle.

Reimplemented in BundleStream.

Definition at line 169 of file Client.cpp.

References MODE_SENDONLY, and ibrcommon::Queue< T >::push().

Here is the call graph for this function:


Member Data Documentation

Definition at line 233 of file Client.h.

Referenced by eventBundleAck().


The documentation for this class was generated from the following files: