Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 11 | * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 21 | #ifndef OBJECT_DB_H |
| 22 | #define OBJECT_DB_H |
| 23 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <sqlite3.h> |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 26 | #include <ndnx-common.h> |
| 27 | #include <ndnx-name.h> |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 28 | #include <boost/filesystem.hpp> |
Zhenkai Zhu | c3fd51e | 2013-01-22 10:45:54 -0800 | [diff] [blame] | 29 | #include <boost/shared_ptr.hpp> |
Zhenkai Zhu | 92bb695 | 2013-02-06 16:43:30 -0800 | [diff] [blame] | 30 | #include <ctime> |
| 31 | #include <vector> |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 33 | class ObjectDb |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 34 | { |
| 35 | public: |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 36 | // database will be create in <folder>/<first-pair-of-hash-bytes>/<rest-of-hash> |
| 37 | ObjectDb (const boost::filesystem::path &folder, const std::string &hash); |
| 38 | ~ObjectDb (); |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 40 | void |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 41 | saveContentObject (const Ndnx::Name &deviceName, sqlite3_int64 segment, const Ndnx::Bytes &data); |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 43 | Ndnx::BytesPtr |
| 44 | fetchSegment (const Ndnx::Name &deviceName, sqlite3_int64 segment); |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 46 | // sqlite3_int64 |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 47 | // getNumberOfSegments (const Ndnx::Name &deviceName); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 48 | |
Zhenkai Zhu | 92bb695 | 2013-02-06 16:43:30 -0800 | [diff] [blame] | 49 | time_t |
| 50 | secondsSinceLastUse(); |
| 51 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 52 | static bool |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 53 | DoesExist (const boost::filesystem::path &folder, const Ndnx::Name &deviceName, const std::string &hash); |
Alexander Afanasyev | b2e608d | 2013-01-23 20:00:53 -0800 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | void |
| 57 | willStartSave (); |
| 58 | |
| 59 | void |
| 60 | didStopSave (); |
| 61 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 62 | private: |
| 63 | sqlite3 *m_db; |
Zhenkai Zhu | 92bb695 | 2013-02-06 16:43:30 -0800 | [diff] [blame] | 64 | time_t m_lastUsed; |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
Zhenkai Zhu | c3fd51e | 2013-01-22 10:45:54 -0800 | [diff] [blame] | 67 | typedef boost::shared_ptr<ObjectDb> ObjectDbPtr; |
| 68 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 69 | #endif // OBJECT_DB_H |