• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ibrdtn/ibrdtn/api/Client.h

Go to the documentation of this file.
00001 /*
00002  * ApiClient.h
00003  *
00004  *  Created on: 24.06.2009
00005  *      Author: morgenro
00006  */
00007 
00008 
00009 #ifndef CLIENT_H_
00010 #define CLIENT_H_
00011 
00012 #include "ibrdtn/api/Bundle.h"
00013 #include "ibrdtn/data/Bundle.h"
00014 #include "ibrdtn/streams/StreamConnection.h"
00015 #include <ibrcommon/net/tcpstream.h>
00016 #include <ibrcommon/thread/Mutex.h>
00017 #include <ibrcommon/thread/MutexLock.h>
00018 #include <ibrcommon/Exceptions.h>
00019 #include <ibrcommon/thread/Queue.h>
00020 
00021 using namespace dtn::data;
00022 using namespace dtn::streams;
00023 
00024 namespace dtn
00025 {
00026         namespace api
00027         {
00031                 class ConnectionException : public ibrcommon::Exception
00032                 {
00033                 public:
00034                         ConnectionException(string what = "A connection error occurred.") throw() : ibrcommon::Exception(what)
00035                         {
00036                         };
00037                 };
00038 
00042                 class ConnectionTimeoutException : public ConnectionException
00043                 {
00044                 public:
00045                         ConnectionTimeoutException(string what = "Timeout.") throw() : ConnectionException(what)
00046                         {
00047                         };
00048                 };
00049 
00053                 class ConnectionAbortedException : public ConnectionException
00054                 {
00055                 public:
00056                         ConnectionAbortedException(string what = "Aborted.") throw() : ConnectionException(what)
00057                         {
00058                         };
00059                 };
00060 
00070                 class Client : public StreamConnection, public StreamConnection::Callback
00071                 {
00072                 private:
00080                         class AsyncReceiver : public ibrcommon::JoinableThread
00081                         {
00082                         public:
00088                                 AsyncReceiver(Client &client);
00089 
00094                                 virtual ~AsyncReceiver();
00095 
00096                         protected:
00102                                 void run();
00103 
00104                         private:
00105                                 // member variable for the reference to the client object
00106                                 Client &_client;
00107                         };
00108 
00112                         enum HANDSHAKE_FLAGS
00113                         {
00114                                 HANDSHAKE_NONE = 0x0,    
00115                                 HANDSHAKE_SENDONLY = 0x80
00116                         };
00117 
00118 
00119                 public:
00123                         enum COMMUNICATION_MODE
00124                         {
00125                                 MODE_BIDIRECTIONAL = 0,         
00126                                 MODE_SENDONLY = 1                       
00127                         };
00128 
00140                         Client(const std::string &app, ibrcommon::tcpstream &stream, const COMMUNICATION_MODE mode = MODE_BIDIRECTIONAL);
00141 
00145                         virtual ~Client();
00146 
00150                         void connect();
00151 
00156                         void close();
00157 
00163                         virtual void eventConnectionDown();
00164 
00170                         virtual void eventBundleAck(size_t ack);
00171 
00176                         virtual void eventShutdown(StreamConnection::ConnectionShutdownCases) {};
00177 
00182                         virtual void eventTimeout() {};
00183 
00188                         virtual void eventError() {};
00189 
00195                         virtual void eventConnectionUp(const StreamContactHeader&) {};
00196 
00201                         virtual void eventBundleRefused() {};
00202 
00207                         virtual void eventBundleForwarded() {};
00208 
00216                         dtn::api::Bundle getBundle(size_t timeout = 0) throw (ConnectionException);
00217 
00218                         // public variable
00219                         size_t lastack;
00220 
00221                 protected:
00227                         virtual void received(const dtn::streams::StreamContactHeader&) {};
00228 
00234                         virtual void received(const dtn::api::Bundle &b);
00235 
00236                 private:
00237                         // tcp stream reference to send/receive data to the daemon
00238                         ibrcommon::tcpstream &_stream;
00239 
00240                         // communication mode flags
00241                         COMMUNICATION_MODE _mode;
00242 
00243                         // own application suffix
00244                         string _app;
00245 
00246                         // The asynchronous receiver thread which receives incoming bundles
00247                         Client::AsyncReceiver _receiver;
00248 
00249                         // the queue for incoming bundles, when used in synchronous mode
00250                         ibrcommon::Queue<dtn::api::Bundle> _inqueue;
00251                 };
00252         }
00253 }
00254 
00255 #endif /* CLIENT_H_ */

Generated on Wed Mar 30 2011 11:11:49 for IBR-DTNSuite by  doxygen 1.7.1