blob: 6147204d8fe1a2bf1c21b9852499896e2911f339 [file] [log] [blame]
Prashanth Swaminathanb2105902015-08-20 14:28:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07003 * Copyright (c) 2014-2018, Regents of the University of California
Prashanth Swaminathanb2105902015-08-20 14:28:54 -07004 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04005 * This file is part of NAC (Name-Based Access Control for NDN).
6 * See AUTHORS.md for complete list of NAC authors and contributors.
Prashanth Swaminathanb2105902015-08-20 14:28:54 -07007 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04008 * NAC is free software: you can redistribute it and/or modify it under the terms
Prashanth Swaminathanb2105902015-08-20 14:28:54 -07009 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -040012 * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070013 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
Alexander Afanasyev9091d832018-04-18 17:21:08 -040017 * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070018 *
19 * @author Prashanth Swaminathan <prashanthsw@gmail.com>
20 */
21
Alexander Afanasyev9091d832018-04-18 17:21:08 -040022#ifndef NDN_NAC_PRODUCER_DB_HPP
23#define NDN_NAC_PRODUCER_DB_HPP
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070024
25#include "common.hpp"
26
27namespace ndn {
Alexander Afanasyev9091d832018-04-18 17:21:08 -040028namespace nac {
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070029
30/**
31 * @brief ProducerDB is a class to manage the database of data producer.
32 * It contains one table that maps timeslots (to the nearest hour) to the
33 * content key created for that timeslot.
34 */
35class ProducerDB
36{
37public:
38 class Error : public std::runtime_error
39 {
40 public:
Alexander Afanasyev9091d832018-04-18 17:21:08 -040041 using std::runtime_error::runtime_error;
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070042 };
43
44public:
Alexander Afanasyev9091d832018-04-18 17:21:08 -040045 explicit
46 ProducerDB(const std::string& dbPath);
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070047
48 ~ProducerDB();
49
50public:
51 /**
52 * @brief Check if content key exists for the hour covering @p timeslot
53 */
54 bool
55 hasContentKey(const time::system_clock::TimePoint& timeslot) const;
56
57 /**
58 * @brief Get content key for the hour covering @p timeslot
59 * @throws Error if the key does not exist
60 */
61 Buffer
62 getContentKey(const time::system_clock::TimePoint& timeslot) const;
63
64 /**
65 * @brief Add @p key as the content key for the hour covering @p timeslot
66 * @throws Error if a key for the same hour already exists
67 */
68 void
69 addContentKey(const time::system_clock::TimePoint& timeslot, const Buffer& key);
70
71 /**
72 * @brief Delete content key for the hour covering @p timeslot
73 */
74 void
75 deleteContentKey(const time::system_clock::TimePoint& timeslot);
76
77private:
78 class Impl;
79 unique_ptr<Impl> m_impl;
80};
81
Alexander Afanasyev9091d832018-04-18 17:21:08 -040082} // namespace nac
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070083} // namespace ndn
84
Alexander Afanasyev9091d832018-04-18 17:21:08 -040085#endif // NDN_NAC_PRODUCER_DB_HPP