blob: 45d405dc5008e5721838925e9a57e9def3db1eaa [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Lijing Wanga697cf22016-12-25 14:44:22 -08003 * Copyright (c) 2013-2017, Regents of the University of California.
Zhenkai Zhuda686882013-01-29 22:32:24 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Zhenkai Zhuda686882013-01-29 22:32:24 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * 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 Zhuda686882013-01-29 22:32:24 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * 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 Zhuda686882013-01-29 22:32:24 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * 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 Zhuda686882013-01-29 22:32:24 -080019 */
Lijing Wanga697cf22016-12-25 14:44:22 -080020
Zhenkai Zhuda686882013-01-29 22:32:24 -080021#ifndef FETCH_TASK_DB_H
22#define FETCH_TASK_DB_H
23
Lijing Wanga697cf22016-12-25 14:44:22 -080024#include "db-helper.hpp"
25#include "core/chronoshare-common.hpp"
26
27#include <ndn-cxx/name.hpp>
28
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080029#include <sqlite3.h>
Zhenkai Zhuda686882013-01-29 22:32:24 -080030
Lijing Wanga697cf22016-12-25 14:44:22 -080031#include <boost/filesystem.hpp>
32
33namespace ndn {
34namespace chronoshare {
35
Zhenkai Zhuda686882013-01-29 22:32:24 -080036class FetchTaskDb
37{
38public:
Lijing Wanga697cf22016-12-25 14:44:22 -080039 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
50public:
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080051 FetchTaskDb(const boost::filesystem::path& folder, const std::string& tag);
Zhenkai Zhuda686882013-01-29 22:32:24 -080052 ~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 Wanga697cf22016-12-25 14:44:22 -080057 addTask(const Name& deviceName, const Name& baseName, uint64_t minSeqNo, uint64_t maxSeqNo,
58 int priority);
Zhenkai Zhuda686882013-01-29 22:32:24 -080059
60 void
Lijing Wanga697cf22016-12-25 14:44:22 -080061 deleteTask(const Name& deviceName, const Name& baseName);
Zhenkai Zhuda686882013-01-29 22:32:24 -080062
63 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080064 foreachTask(const FetchTaskCallback& callback);
Zhenkai Zhuda686882013-01-29 22:32:24 -080065
66private:
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080067 sqlite3* m_db;
Zhenkai Zhuda686882013-01-29 22:32:24 -080068};
69
Lijing Wanga697cf22016-12-25 14:44:22 -080070typedef shared_ptr<FetchTaskDb> FetchTaskDbPtr;
71
72} // namespace chronoshare
73} // namespace ndn
Zhenkai Zhuda686882013-01-29 22:32:24 -080074
75#endif // FETCH_TASK_DB_H