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

#include <Client.h>

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

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)
 
void setMonitor (bool val)
 
void resetMonitorStats ()
 
size_t getMonitorStat (int index)
 
- Public Member Functions inherited from dtn::streams::StreamConnection::Callback
virtual void eventShutdown (StreamConnection::ConnectionShutdownCases csc)=0 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)
 

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 80 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::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.

Parameters
appApplication suffix.
streamTCP stream object.
modeCommunication 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.

dtn::api::Client::~Client ( )
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().

Here is the call graph for this function:

Member Function Documentation

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

Here is the call graph for this function:

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

Here is the call graph for this function:

void dtn::api::Client::eventBundleAck ( const dtn::data::Length ack) throw ()
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 181 of file Client.cpp.

virtual void dtn::api::Client::eventBundleForwarded ( ) throw ()
inlinevirtual

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 ( ) throw ()
inlinevirtual

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.

void dtn::api::Client::eventConnectionDown ( ) throw ()
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().

Here is the call graph for this function:

virtual void dtn::api::Client::eventConnectionUp ( const dtn::streams::StreamContactHeader ) throw ()
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.

Definition at line 209 of file Client.h.

virtual void dtn::api::Client::eventError ( ) throw ()
inlinevirtual

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.

virtual void dtn::api::Client::eventShutdown ( StreamConnection::ConnectionShutdownCases  ) throw ()
inlinevirtual

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

Definition at line 190 of file Client.h.

virtual void dtn::api::Client::eventTimeout ( ) throw ()
inlinevirtual

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.

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

Parameters
timeout
Returns

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

Here is the call graph for this function:

void dtn::api::Client::operator<< ( const dtn::data::Bundle b)

Send a bundle to the daemon

Definition at line 197 of file Client.cpp.

virtual void dtn::api::Client::received ( const dtn::streams::StreamContactHeader )
inlineprotectedvirtual

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 246 of file Client.h.

void dtn::api::Client::received ( const dtn::data::Bundle b)
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.

Parameters
bThe received bundle.

Reimplemented in BundleStream.

Definition at line 186 of file Client.cpp.

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

Here is the call graph for this function:

Member Data Documentation

dtn::data::Length dtn::api::Client::lastack

Definition at line 238 of file Client.h.


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