00001
00002
00003
00004
00005
00006
00007
00008 #ifndef SQLITEBUNDLESTORAGE_H_
00009 #define SQLITEBUNDLESTORAGE_H_
00010
00011 #include "config.h"
00012
00013 #ifdef HAVE_LIBSQLITE3
00014
00015 #include "core/AbstractBundleStorage.h"
00016 #include "core/CustodyManager.h"
00017 #include "data/Bundle.h"
00018 #include "utils/Service.h"
00019 #include <list>
00020 #include <vector>
00021 #include <sqlite3.h>
00022 #include "data/Exceptions.h"
00023 #include "utils/MutexLock.h"
00024 #include "utils/Mutex.h"
00025 #include <map>
00026
00027 using namespace dtn::data;
00028 using namespace dtn::utils;
00029
00030 namespace dtn
00031 {
00032 namespace exceptions
00033 {
00034 class SQLitePrepareException : public Exception
00035 {
00036 public:
00037 SQLitePrepareException() : Exception("error while prepare the sql statement")
00038 {
00039 };
00040
00041 SQLitePrepareException(string what) : Exception(what)
00042 {
00043 };
00044 };
00045
00046 class DuplicateException : public Exception
00047 {
00048 public:
00049 DuplicateException() : Exception("this item already exists!")
00050 {
00051 };
00052
00053 DuplicateException(string what) : Exception(what)
00054 {
00055 };
00056 };
00057 }
00058
00059 namespace core
00060 {
00064 class SQLiteBundleStorage : public Service, public AbstractBundleStorage
00065 {
00066 public:
00072 SQLiteBundleStorage(string dbfile, bool flush = false);
00073
00077 virtual ~SQLiteBundleStorage();
00078
00082 void store(const BundleSchedule &schedule);
00083
00087 Bundle* storeFragment(const Bundle &bundle);
00088
00092 BundleSchedule getSchedule(unsigned int dtntime);
00093
00097 BundleSchedule getSchedule(string destination);
00098
00102 void clear();
00103
00107 bool isEmpty();
00108
00109 unsigned int getSize();
00110
00114 unsigned int getCount();
00115
00116 protected:
00120 virtual void tick();
00121
00122 void terminate();
00123
00124 void eventNodeAvailable(const Node &node);
00125 void eventNodeUnavailable(const Node &node);
00126
00127 private:
00128 void sqlQuery(string query, int id1 = -1, int id2 = -1, int id3 = -1);
00129 sqlite3_stmt* prepareStatement(string query);
00130 sqlite3_int64 storeBundle(const Bundle &bundle);
00131
00132 sqlite3 *m_db;
00133
00134 Mutex m_dblock;
00135 unsigned int last_gettime;
00136
00137 sqlite3_stmt *m_stmt_size;
00138 sqlite3_stmt *m_stmt_getbytime;
00139 sqlite3_stmt *m_stmt_getbyeid;
00140 sqlite3_stmt *m_stmt_store_bundle;
00141 sqlite3_stmt *m_stmt_store_schedule;
00142
00143 sqlite3_stmt *m_stmt_store_fragment;
00144 sqlite3_stmt *m_stmt_check_fragment;
00145 sqlite3_stmt *m_stmt_get_fragment;
00146 sqlite3_stmt *m_stmt_delete_fragment;
00147
00148 sqlite3_stmt *m_stmt_outdate_fragments;
00149 sqlite3_stmt *m_stmt_outdate_bundles;
00150
00151 map<string,Node> m_neighbours;
00152 };
00153 }
00154 }
00155
00156 #endif
00157
00158 #endif
00159