00001 /* 00002 * SQLiteBundleStorage.h 00003 * 00004 * Created on: 09.01.2010 00005 * Author: Myrtus 00006 * 00007 * Potentielle Erweiterungen: 00008 * 1) Zweite Tabelle für die Fragmente 00009 * 2) 00010 */ 00011 00012 #ifndef SQLITEBUNDLESTORAGE_H_ 00013 #define SQLITEBUNDLESTORAGE_H_ 00014 00015 #include "Component.h" 00016 #include "core/BundleStorage.h" 00017 #include "core/EventReceiver.h" 00018 00019 #include <ibrcommon/thread/Thread.h> 00020 #include <ibrcommon/thread/Conditional.h> 00021 #include <ibrcommon/data/File.h> 00022 #include <ibrcommon/thread/ThreadSafeQueue.h> 00023 00024 #include <sqlite3.h> 00025 #include <string> 00026 #include <set> 00027 #include <vector> 00028 00029 00030 namespace dtn 00031 { 00032 namespace core 00033 { 00034 class SQLiteBundleStorage : public BundleStorage, public EventReceiver, public dtn::daemon::IndependentComponent 00035 { 00036 private: 00037 class Task 00038 { 00039 public: 00040 virtual ~Task() {}; 00041 virtual void run() = 0; 00042 }; 00043 00044 public: 00051 SQLiteBundleStorage(ibrcommon::File dbPath ,string dbFile , size_t size); 00052 00056 virtual ~SQLiteBundleStorage(); 00057 00062 void store(const dtn::data::Bundle &bundle); 00063 00069 dtn::data::Bundle get(const ibrcommon::BloomFilter &filter); 00070 00077 dtn::data::Bundle get(const dtn::data::BundleID &id); 00078 00086 dtn::data::Bundle get(const dtn::data::EID &eid); 00087 00093 void remove(const dtn::data::BundleID &id); 00094 00098 void clear(); 00099 00103 bool empty(); 00104 00108 unsigned int count(); 00109 00115 void releaseCustody(dtn::data::BundleID &bundle); 00116 00120 //int availableSpace(); 00121 00126 void raiseEvent(const Event *evt); 00127 00128 protected: 00129 virtual void componentUp(); 00130 virtual void componentRun(); 00131 virtual void componentDown(); 00132 00133 private: 00134 // /** 00135 // * This Function stores Fragments. 00136 // * @param bundle The bundle to store. 00137 // */ 00138 // void storeFragment(const dtn::data::Bundle &bundle); 00139 00145 sqlite3_stmt* prepareStatement(string sqlquery); 00146 00152 void deleteexpired(); 00153 00154 //Tablename 00155 const std::string _BundleTable; 00156 const std::string _FragmentTable; 00157 00158 ibrcommon::File dbPath; 00159 string dbFile; 00160 size_t dbSize; 00161 sqlite3 *database; 00162 ibrcommon::Conditional dbMutex; 00163 ibrcommon::ThreadSafeQueue<Task*> _tasks; 00164 00165 sqlite3_stmt *getTTL; 00166 sqlite3_stmt *getBundleByDestination; 00167 sqlite3_stmt *getBundleByID; 00168 sqlite3_stmt *getFragements; 00169 sqlite3_stmt *store_Bundle; 00170 sqlite3_stmt *store_Fragment; 00171 sqlite3_stmt *clearStorage; 00172 sqlite3_stmt *countEntries; 00173 sqlite3_stmt *vacuum; 00174 sqlite3_stmt *getROWID; 00175 sqlite3_stmt *removeBundle; 00176 sqlite3_stmt *removeFragments; 00177 00178 }; 00179 } 00180 } 00181 00182 #endif /* SQLITEBUNDLESTORAGE_H_ */
1.6.3