IBR-DTNSuite
0.8
|
00001 /* 00002 * FragmentManager.h 00003 * 00004 * Created on: 03.02.2012 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef FRAGMENTMANAGER_H_ 00009 #define FRAGMENTMANAGER_H_ 00010 00011 #include "Component.h" 00012 #include "core/EventReceiver.h" 00013 #include <ibrdtn/data/MetaBundle.h> 00014 #include <ibrdtn/data/BundleList.h> 00015 #include <ibrcommon/thread/Queue.h> 00016 #include <ibrcommon/thread/Mutex.h> 00017 #include <list> 00018 #include <set> 00019 00020 namespace dtn 00021 { 00022 namespace core 00023 { 00024 class FragmentManager : public dtn::daemon::IndependentComponent, public dtn::core::EventReceiver 00025 { 00026 public: 00027 FragmentManager(); 00028 virtual ~FragmentManager(); 00029 00030 void signal(const dtn::data::MetaBundle &meta); 00031 00032 void __cancellation(); 00033 00034 void componentUp(); 00035 void componentRun(); 00036 void componentDown(); 00037 00038 void raiseEvent(const Event *evt); 00039 00040 const std::string getName() const; 00041 00048 static void setOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id, size_t abs_offset); 00049 00056 static size_t getOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id); 00057 00058 private: 00059 class Transmission 00060 { 00061 public: 00062 Transmission(); 00063 virtual ~Transmission(); 00064 00065 bool operator<(const Transmission &other) const; 00066 bool operator==(const Transmission &other) const; 00067 00068 dtn::data::EID peer; 00069 dtn::data::BundleID id; 00070 size_t offset; 00071 size_t expires; 00072 }; 00073 00074 static void expire_offsets(size_t timestamp); 00075 static size_t get_payload_offset(const dtn::data::Bundle &bundle, size_t abs_offset); 00076 00077 // search for similar bundles in the storage 00078 const std::list<dtn::data::MetaBundle> search(const dtn::data::MetaBundle &meta); 00079 00080 ibrcommon::Queue<dtn::data::MetaBundle> _incoming; 00081 dtn::data::BundleList _fragments; 00082 bool _running; 00083 00084 static ibrcommon::Mutex _offsets_mutex; 00085 static std::set<Transmission> _offsets; 00086 }; 00087 } /* namespace core */ 00088 } /* namespace dtn */ 00089 #endif /* FRAGMENTMANAGER_H_ */