| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2013-2016, Regents of the University of California. |
| * |
| * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
| * |
| * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, either |
| * version 3 of the License, or (at your option) any later version. |
| * |
| * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received copies of the GNU General Public License along with |
| * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| * |
| * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
| */ |
| |
| #ifndef OBJECT_DB_H |
| #define OBJECT_DB_H |
| |
| #include <boost/filesystem.hpp> |
| #include <boost/shared_ptr.hpp> |
| #include <ccnx-common.h> |
| #include <ccnx-name.h> |
| #include <ctime> |
| #include <sqlite3.h> |
| #include <string> |
| #include <vector> |
| |
| class ObjectDb |
| { |
| public: |
| // database will be create in <folder>/<first-pair-of-hash-bytes>/<rest-of-hash> |
| ObjectDb(const boost::filesystem::path& folder, const std::string& hash); |
| ~ObjectDb(); |
| |
| void |
| saveContentObject(const Ccnx::Name& deviceName, sqlite3_int64 segment, const Ccnx::Bytes& data); |
| |
| Ccnx::BytesPtr |
| fetchSegment(const Ccnx::Name& deviceName, sqlite3_int64 segment); |
| |
| // sqlite3_int64 |
| // getNumberOfSegments (const Ndnx::Name &deviceName); |
| |
| time_t |
| secondsSinceLastUse(); |
| |
| static bool |
| DoesExist(const boost::filesystem::path& folder, const Ccnx::Name& deviceName, |
| const std::string& hash); |
| |
| private: |
| void |
| willStartSave(); |
| |
| void |
| didStopSave(); |
| |
| private: |
| sqlite3* m_db; |
| time_t m_lastUsed; |
| }; |
| |
| typedef boost::shared_ptr<ObjectDb> ObjectDbPtr; |
| |
| #endif // OBJECT_DB_H |