IBR-DTNSuite  0.8
daemon/src/api/BinaryStreamClient.h
Go to the documentation of this file.
00001 /*
00002  * BinaryStreamClient.h
00003  *
00004  *  Created on: 19.07.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef BINARYSTREAMCLIENT_H_
00009 #define BINARYSTREAMCLIENT_H_
00010 
00011 #include "api/ClientHandler.h"
00012 #include <ibrdtn/streams/StreamConnection.h>
00013 #include <ibrdtn/streams/StreamContactHeader.h>
00014 
00015 namespace dtn
00016 {
00017         namespace api
00018         {
00019                 class BinaryStreamClient : public dtn::streams::StreamConnection::Callback, public ProtocolHandler
00020                 {
00021                         public:
00022                                 BinaryStreamClient(ClientHandler &client, ibrcommon::tcpstream &stream);
00023                                 virtual ~BinaryStreamClient();
00024 
00025                                 virtual void eventShutdown(dtn::streams::StreamConnection::ConnectionShutdownCases csc);
00026                                 virtual void eventTimeout();
00027                                 virtual void eventError();
00028                                 virtual void eventConnectionDown();
00029                                 virtual void eventConnectionUp(const dtn::streams::StreamContactHeader &header);
00030 
00031                                 virtual void eventBundleRefused();
00032                                 virtual void eventBundleForwarded();
00033                                 virtual void eventBundleAck(size_t ack);
00034 
00035                                 const dtn::data::EID& getPeer() const;
00036 
00037                                 void queue(const dtn::data::Bundle &bundle);
00038 
00039                                 void received(const dtn::streams::StreamContactHeader &h);
00040                                 void run();
00041                                 void finally();
00042                                 void __cancellation();
00043                                 bool good() const;
00044 
00045                         private:
00046                                 class Sender : public ibrcommon::JoinableThread, public ibrcommon::Queue<dtn::data::Bundle>
00047                                 {
00048                                 public:
00049                                         Sender(BinaryStreamClient &client);
00050                                         virtual ~Sender();
00051 
00052                                 protected:
00053                                         void run();
00054                                         void __cancellation();
00055 
00056                                         void received(const dtn::streams::StreamContactHeader &h);
00057                                         bool good() const;
00058 
00059                                 private:
00060                                         BinaryStreamClient &_client;
00061                                 };
00062 
00063                                 friend class Sender;
00064 
00065                                 BinaryStreamClient::Sender _sender;
00066 
00067                                 dtn::streams::StreamConnection _connection;
00068                                 dtn::streams::StreamContactHeader _contact;
00069 
00070                                 ibrcommon::Queue<dtn::data::Bundle> _sentqueue;
00071                                 size_t _lastack;
00072 
00073                                 dtn::data::EID _eid;
00074                 };
00075         }
00076 }
00077 
00078 #endif /* BINARYSTREAMCLIENT_H_ */