• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

daemon/src/core/SQLiteBundleStorage.h

Go to the documentation of this file.
00001 /*
00002  * SQLiteBundleStorage.h
00003  *
00004  *  Created on: 09.01.2010
00005  *      Author: Myrtus
00006  */
00007 
00008 
00009 #ifndef SQLITEBUNDLESTORAGE_H_
00010 #define SQLITEBUNDLESTORAGE_H_
00011 
00012 #include "BundleStorage.h"
00013 #include "Component.h"
00014 #include "EventReceiver.h"
00015 #include "core/BundleStorage.h"
00016 #include "core/EventReceiver.h"
00017 #include <ibrdtn/data/MetaBundle.h>
00018 
00019 #include <ibrcommon/thread/Thread.h>
00020 #include <ibrcommon/thread/Conditional.h>
00021 #include <ibrcommon/data/File.h>
00022 #include <ibrcommon/thread/Queue.h>
00023 #include <ibrcommon/thread/Thread.h>
00024 #include <ibrcommon/thread/Conditional.h>
00025 #include <ibrcommon/data/File.h>
00026 
00027 #include <sqlite3.h>
00028 #include <string>
00029 #include <list>
00030 #include <set>
00031 
00032 
00033 namespace dtn {
00034 namespace testsuite{
00035         class SQLiteBundleStorageTestSuite;
00036 }
00037 
00038 namespace core {
00039 
00040 class SQLiteBundleStorage: public BundleStorage, public EventReceiver, public ibrcommon::JoinableThread
00041 {
00042         enum SQL_TABLES
00043         {
00044                 SQL_TABLE_BUNDLE = 0,
00045                 SQL_TABLE_FRAGMENT = 1,
00046                 SQL_TABLE_BLOCK = 2,
00047                 SQL_TABLE_ROUTING = 3,
00048                 SQL_TABLE_BUNDLE_ROUTING_INFO = 4,
00049                 SQL_TABLE_NODE_ROUTING_INFO = 5,
00050                 SQL_TABLE_END = 6
00051         };
00052 
00053         static const std::string _tables[SQL_TABLE_END];
00054 
00055 public:
00056         friend class testsuite::SQLiteBundleStorageTestSuite;
00057 
00058         class SQLiteQuerryException : public ibrcommon::Exception
00059         {
00060         public:
00061                 SQLiteQuerryException(string what = "Unable to execute Querry.") throw(): Exception(what)
00062                 {
00063                 }
00064         };
00065 
00069         class NoBundleFoundException : public ibrcommon::Exception
00070         {
00071                 public:
00072                         NoBundleFoundException(string what = "No bundle available.") throw() : Exception(what)
00073                         {
00074                         };
00075         };
00076 
00083         SQLiteBundleStorage(const ibrcommon::File &dbPath, const string &dbFile, const int &size);
00084 
00088         virtual ~SQLiteBundleStorage();
00089 
00094         void store(const dtn::data::Bundle &bundle);
00095 
00101         void storeBundleRoutingInfo(const data::BundleID &BundleID, const int &key, const string &routingInfo);
00102 
00108         void storeNodeRoutingInfo(const data::EID &nodel, const int &key, const std::string &routingInfo);
00109 
00115         void storeRoutingInfo(const int &key, const std::string &routingInfo);
00116 
00123         dtn::data::Bundle get(const dtn::data::BundleID &id);
00124 
00132         const dtn::data::MetaBundle getByDestination(const dtn::data::EID &eid, bool exact = false);
00133 
00139         const dtn::data::MetaBundle getByFilter(const ibrcommon::BloomFilter &filter);
00140 
00145         std::string getBundleRoutingInfo(const data::BundleID &bundleID, const int &key);
00146 
00152         std::string getNodeRoutingInfo(const data::EID &eid, const int &key);
00153 
00159         std::string getRoutingInfo(const int &key);
00160 
00165         void removeBundleRoutingInfo(const data::BundleID &bundleID, const int &key);
00166 
00171         void removeNodeRoutingInfo(const data::EID &eid, const int &key);
00172 
00177         void removeRoutingInfo(const int &key);
00178 
00184         void remove(const dtn::data::BundleID &id);
00185 
00189         void clear();
00190 
00194         void clearAll();
00195 
00199         bool empty();
00200 
00204         unsigned int count();
00205 
00209         void releaseCustody(dtn::data::BundleID &bundle);
00210 
00216         void setPriority(const int priority,const dtn::data::BundleID &id);
00217 
00223         list<data::Bundle> getBundleBySize(const int &limit);
00224 
00230         list<data::Bundle> getBundleByTTL (const int &limit);
00231 
00237         list<data::Bundle> getBundlesBySource(const dtn::data::EID &sourceID);
00238 
00244         list<data::Bundle> getBundlesByDestination(const dtn::data::EID &sourceID);
00245 
00252         list<data::Block> getBlock(const data::BundleID &bundleID,const char &blocktype);
00253 
00258         int occupiedSpace();
00259 
00264         void raiseEvent(const Event *evt);
00265 
00266 protected:
00267         void run(void);
00268         bool __cancellation();
00269 
00270 private:
00275         void storeFragment(const dtn::data::Bundle &bundle);
00276 
00282         sqlite3_stmt* prepareStatement(string sqlquery);
00283 
00289         void deleteexpired();
00290 
00298         int prepareBundle(list<std::string> &filenames, dtn::data::Bundle &bundle);
00299 
00305         int storeBlocks(const data::Bundle &bundle);
00306 
00311         dtn::data::MetaBundle remove(const ibrcommon::BloomFilter&) { return dtn::data::MetaBundle(); };
00312 
00319         int readBlocks(data::Bundle &bundle, const string &bundleID);
00320 
00324         void idle_work();
00325 
00326 
00330         void consistenceCheck();
00331 
00335         void updateexpiredTime();
00336 
00340         virtual const std::string getName() const;
00341 
00342         bool global_shutdown;
00343         string dbPath, dbFile;
00344         int dbSize;
00345         sqlite3 *database;
00346         ibrcommon::Conditional dbMutex, timeeventConditional;
00347 
00348         ibrcommon::Mutex time_change;// idle_mutex;
00349 
00350         //local Variable which saves the timestamp from incoming Timeevents
00351         size_t actual_time;
00352         size_t nextExpiredTime;
00353         bool idle;
00354 
00355         //list containing filenames (inclusive path) which could be deleted
00356         list<string> deleteList;
00357 
00358         sqlite3_stmt *getBundleTTL;
00359         sqlite3_stmt *getFragmentTTL;
00360         sqlite3_stmt *deleteBundleTTL;
00361         sqlite3_stmt *deleteFragementTTL;
00362         sqlite3_stmt *getBundleByDestination;
00363         sqlite3_stmt *getBundleByID;
00364         sqlite3_stmt *getFragements;
00365         sqlite3_stmt *store_Bundle;
00366         sqlite3_stmt *store_Fragment;
00367         sqlite3_stmt *clearBundles;
00368         sqlite3_stmt *clearFragments;
00369         sqlite3_stmt *clearBlocks;
00370         sqlite3_stmt *clearRouting;
00371         sqlite3_stmt *clearNodeRouting;
00372         sqlite3_stmt *countEntries;
00373         sqlite3_stmt *vacuum;
00374         sqlite3_stmt *getROWID;
00375         sqlite3_stmt *removeBundle;
00376         sqlite3_stmt *removeFragments;
00377         sqlite3_stmt *getBlocksByID;
00378         sqlite3_stmt *storeBlock;
00379         sqlite3_stmt *getBundlesBySize;
00380         sqlite3_stmt *getBundleBySource;
00381         sqlite3_stmt *getBundlesByTTL;
00382         sqlite3_stmt *getBlocks;
00383         sqlite3_stmt *getProcFlags;
00384         sqlite3_stmt *updateProcFlags;
00385         sqlite3_stmt *storeBundleRouting;
00386         sqlite3_stmt *getBundleRouting;
00387         sqlite3_stmt *removeBundleRouting;
00388         sqlite3_stmt *storeRouting;
00389         sqlite3_stmt *getRouting;
00390         sqlite3_stmt *removeRouting;
00391         sqlite3_stmt *storeNodeRouting;
00392         sqlite3_stmt *getNodeRouting;
00393         sqlite3_stmt *removeNodeRouting;
00394         sqlite3_stmt *getnextExpiredBundle;
00395         sqlite3_stmt *getnextExpiredFragment;
00396 
00397 };
00398 
00399 }
00400 }
00401 
00402 #endif /* SQLITEBUNDLESTORAGE_H_ */

Generated on Thu Nov 11 2010 09:49:46 for IBR-DTNSuite by  doxygen 1.7.1