00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef SQLITEBUNDLESTORAGE_H_
00013 #define SQLITEBUNDLESTORAGE_H_
00014
00015 #include "BundleStorage.h"
00016 #include <sqlite3.h>
00017 #include <string>
00018 #include "EventReceiver.h"
00019 #include "ibrcommon/thread/Thread.h"
00020 #include "ibrcommon/data/File.h"
00021 #include <set>
00022 #include <vector>
00023
00024
00025 namespace dtn {
00026 namespace core {
00027
00028 class SQLiteBundleStorage: public BundleStorage, public EventReceiver, public ibrcommon::JoinableThread{
00029 public:
00030
00037 SQLiteBundleStorage(ibrcommon::File dbPath ,string dbFile , int size);
00038
00042 virtual ~SQLiteBundleStorage();
00043
00048 void store(const dtn::data::Bundle &bundle);
00049
00056 dtn::data::Bundle get(const dtn::data::BundleID &id);
00057
00065 dtn::data::Bundle get(const dtn::data::EID &eid);
00066
00071 void unblock(const dtn::data::EID &eid);
00072
00078 void remove(const dtn::data::BundleID &id);
00079
00083 void clear();
00084
00088 bool empty();
00089
00093 unsigned int count();
00094
00095 void getVector(vector<dtn::data::Bundle> &bundles);
00096
00100
00101
00106 void raiseEvent(const Event *evt);
00107
00111 void run(void);
00112
00113 private:
00118 void storeFragment(const dtn::data::Bundle &bundle);
00119
00125 sqlite3_stmt* prepareStatement(string sqlquery);
00126
00132 void deleteexpired();
00133
00139 bool getBundle(const dtn::data::EID &eid, dtn::data::Bundle &bundle);
00140
00141
00142 const std::string _BundleTable;
00143 const std::string _FragmentTable;
00144
00145 bool global_shutdown;
00146 ibrcommon::File dbPath;
00147 string dbFile;
00148 int dbSize;
00149 sqlite3 *database;
00150 ibrcommon::Conditional dbMutex, timeeventConditional;
00151
00152
00153
00154
00155 set<data::EID> unblockEID;
00156
00157 sqlite3_stmt *getTTL;
00158 sqlite3_stmt *getBundleByDestination;
00159 sqlite3_stmt *getBundleByID;
00160 sqlite3_stmt *getFragements;
00161 sqlite3_stmt *store_Bundle;
00162 sqlite3_stmt *store_Fragment;
00163 sqlite3_stmt *clearStorage;
00164 sqlite3_stmt *countEntries;
00165 sqlite3_stmt *vacuum;
00166 sqlite3_stmt *getROWID;
00167 sqlite3_stmt *removeBundle;
00168 sqlite3_stmt *removeFragments;
00169
00170 };
00171
00172 }
00173 }
00174
00175 #endif