Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions

dtn::api::Client Class Reference

#include <Client.h>

Inherits dtn::streams::StreamConnection, and dtn::streams::StreamConnection::Callback.

Inherited by BundleStream, CAPIGateway, EchoClient, Tracer, and TUN2BundleGateway.

Collaboration diagram for dtn::api::Client:
Collaboration graph
[legend]

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)
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)

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 123 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:
app Application suffix.
stream TCP stream object.
mode Communication mode. Default is bidirectional communication.

Definition at line 67 of file Client.cpp.

dtn::api::Client::~Client (  )  [virtual]

Virtual destructor for this class.

Definition at line 72 of file Client.cpp.

References IBRCOMMON_LOGGER_DEBUG, and ibrcommon::Exception::what().

Here is the call graph for this function:


Member Function Documentation

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

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

Referenced by main(), and term().

Here is the call graph for this function:

void dtn::api::Client::connect (  ) 

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

Definition at line 83 of file Client.cpp.

References dtn::streams::StreamConnection::handshake(), IBRCOMMON_LOGGER, MODE_SENDONLY, 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:
ack ACK'd bundle size

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

Definition at line 124 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 207 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 201 of file Client.h.

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

References ibrcommon::Queue< T >::abort(), IBRCOMMON_LOGGER_DEBUG, 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 195 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 188 of file Client.h.

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.

Definition at line 176 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 182 of file Client.h.

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

Parameters:
timeout 
Returns:

Definition at line 137 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 227 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:
b The received bundle.

Reimplemented in BundleStream.

Definition at line 129 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 219 of file Client.h.

Referenced by eventBundleAck(), and main().


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