Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, Regents of the University of California. |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -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. |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -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. |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -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. |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -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. |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 19 | */ |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 20 | |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 21 | #ifndef FETCH_TASK_DB_H |
| 22 | #define FETCH_TASK_DB_H |
| 23 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 24 | #include "db-helper.hpp" |
| 25 | #include "core/chronoshare-common.hpp" |
| 26 | |
| 27 | #include <ndn-cxx/name.hpp> |
| 28 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 29 | #include <sqlite3.h> |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 30 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 31 | #include <boost/filesystem.hpp> |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace chronoshare { |
| 35 | |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 36 | class FetchTaskDb |
| 37 | { |
| 38 | public: |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 39 | class Error : public DbHelper::Error |
| 40 | { |
| 41 | public: |
| 42 | explicit Error(const std::string& what) |
| 43 | : DbHelper::Error(what) |
| 44 | { |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | typedef function<void(const Name&, const Name&, uint64_t, uint64_t, int)> FetchTaskCallback; |
| 49 | |
| 50 | public: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 51 | FetchTaskDb(const boost::filesystem::path& folder, const std::string& tag); |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 52 | ~FetchTaskDb(); |
| 53 | |
| 54 | // task with same deviceName and baseName combination will be added only once |
| 55 | // if task already exists, this call does nothing |
| 56 | void |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 57 | addTask(const Name& deviceName, const Name& baseName, uint64_t minSeqNo, uint64_t maxSeqNo, |
| 58 | int priority); |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 59 | |
| 60 | void |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 61 | deleteTask(const Name& deviceName, const Name& baseName); |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 62 | |
| 63 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 64 | foreachTask(const FetchTaskCallback& callback); |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 65 | |
| 66 | private: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 67 | sqlite3* m_db; |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 68 | }; |
| 69 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 70 | typedef shared_ptr<FetchTaskDb> FetchTaskDbPtr; |
| 71 | |
| 72 | } // namespace chronoshare |
| 73 | } // namespace ndn |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 74 | |
| 75 | #endif // FETCH_TASK_DB_H |