00001 #ifndef BUNDLEFACTORY_H_
00002 #define BUNDLEFACTORY_H_
00003
00004 #include "Bundle.h"
00005 #include "PrimaryFlags.h"
00006 #include "Exceptions.h"
00007 #include "NetworkFrame.h"
00008 #include "BlockFactory.h"
00009 #include <vector>
00010 #include <list>
00011
00012 namespace dtn
00013 {
00014 namespace data
00015 {
00019 class BundleFactory
00020 {
00021 public:
00025 static BundleFactory& getInstance();
00026
00031 void registerExtensionBlock(BlockFactory *f);
00032
00037 void unregisterExtensionBlock(BlockFactory *f);
00038
00044 Bundle* parse(const unsigned char *data, unsigned int size) const;
00045
00050 Bundle* newBundle();
00051
00057 Block* copyBlock(const Block &block) const;
00058
00063 static unsigned int getDTNTime();
00064
00069 unsigned int getSequenceNumber();
00070
00077 static list<Bundle> split(const Bundle &bundle, unsigned int maxsize);
00078
00087 static Bundle* slice(const Bundle &bundle, unsigned int size, unsigned int& offset);
00088
00097 static Bundle* cut(const Bundle &bundle, unsigned int size, unsigned int& offset);
00098
00107 static pair<Bundle*, Bundle*> cutAt(const Bundle &bundle, unsigned int position);
00108
00118 static Bundle* merge(list<Bundle> &bundles);
00119
00130 static Bundle* merge(const Bundle &fragment1, const Bundle &fragment2);
00131
00132 private:
00133 BundleFactory();
00134 virtual ~BundleFactory();
00135
00136 BlockFactory& getExtension(unsigned char type);
00137 map<char, BlockFactory*>& getExtensions();
00138
00139 Bundle* createBundle(bool fragmented = false);
00140
00141 NetworkFrame* parsePrimaryBlock(const unsigned char *data, unsigned int size) const;
00142
00146 static bool compareFragments(const Bundle &first, const Bundle &second);
00147 static Block* getBlock(const unsigned char *data, unsigned int size);
00148
00149 static unsigned int SECONDS_TILL_2000;
00150 BlockFactory m_blockfactory;
00151 map<char, BlockFactory*> m_extensions;
00152 };
00153 }
00154 }
00155
00156 #endif