IBR-DTNSuite  0.8
daemon/src/api/OrderedStreamHandler.h
Go to the documentation of this file.
00001 /*
00002  * OrderedStreamHandler.h
00003  *
00004  *  Created on: 17.11.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef ORDEREDSTREAMHANDLER_H_
00009 #define ORDEREDSTREAMHANDLER_H_
00010 
00011 #include "api/Registration.h"
00012 #include "api/ClientHandler.h"
00013 #include "api/BundleStreamBuf.h"
00014 
00015 #include <iostream>
00016 
00017 namespace dtn
00018 {
00019         namespace api
00020         {
00021                 class OrderedStreamHandler : public ProtocolHandler, public BundleStreamBufCallback
00022                 {
00023                 public:
00024                         OrderedStreamHandler(ClientHandler &client, ibrcommon::tcpstream &stream);
00025                         virtual ~OrderedStreamHandler();
00026 
00027                         virtual void run();
00028                         virtual void finally();
00029                         virtual void __cancellation();
00030 
00031                         virtual void put(dtn::data::Bundle &b);
00032                         virtual dtn::data::MetaBundle get(size_t timeout = 0);
00033                         virtual void delivered(const dtn::data::MetaBundle &m);
00034 
00035                 private:
00036                         class Sender : public ibrcommon::JoinableThread
00037                         {
00038                         public:
00039                                 Sender(OrderedStreamHandler &conn);
00040                                 virtual ~Sender();
00041 
00042                         protected:
00043                                 void run();
00044                                 void finally();
00045                                 void __cancellation();
00046 
00047                         private:
00048                                 OrderedStreamHandler &_handler;
00049                         } _sender;
00050 
00051                         BundleStreamBuf _streambuf;
00052                         std::iostream _bundlestream;
00053 
00054                         dtn::data::EID _peer;
00055                         dtn::data::EID _endpoint;
00056                         bool _group;
00057                         size_t _lifetime;
00058                 };
00059         } /* namespace api */
00060 } /* namespace dtn */
00061 #endif /* ORDEREDSTREAMHANDLER_H_ */