blob: e64d677d095c435d3fd6ba39435c2359b56fe044 [file] [log] [blame]
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California
4 *
5 * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
6 * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
7 *
8 * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms
9 * 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 *
12 * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * 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
17 * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
20 */
21
22#ifndef GEP_GROUP_MANAGER_DB_HPP
23#define GEP_GROUP_MANAGER_DB_HPP
24
25#include "schedule.hpp"
26
27namespace ndn {
28namespace gep {
29
30/**
31 * @brief GroupManagerDB is a class to manage the database of group manager.
32 *
33 * It contains two tables to store Schedules and Members
34 */
35class GroupManagerDB
36{
37public:
38 class Error : public std::runtime_error
39 {
40 public:
41 explicit
42 Error(const std::string& what)
43 : std::runtime_error(what)
44 {
45 }
46 };
47
48public:
49 explicit
50 GroupManagerDB(const std::string& dbDir);
51
52 ~GroupManagerDB();
53
54public:
55 ////////////////////////////////////////////////////// schedule management
56
57 /**
58 * @brief Check if there is a schedule with @p name
59 */
60 bool
61 hasSchedule(const std::string& name) const;
62
63 /**
64 * @brief List all the names of the schedules
65 * @return A list of the name of all schedules.
66 */
67 std::list<std::string>
68 listAllScheduleNames() const;
69
70 /**
71 * @brief Get a schedule with @p name.
72 * @throw Error if the schedule does not exist
73 */
74 Schedule
75 getSchedule(const std::string& name) const;
76
77 /**
78 * @brief Get member information of a schedule with @p name.
79 * The member information include member name and certificate.
80 */
81 std::map<Name, Data>
82 getScheduleMembers(const std::string& name) const;
83
84 /**
85 * @brief Add a @p schedule with @p name
86 * @pre Name.length() != 0
87 *
88 * @throw Error if add operation fails, e.g., a schedule with the same name already exists
89 */
90 void
91 addSchedule(const std::string& name, const Schedule& schedule);
92
93 /**
94 * @brief Delete the schedule with @p name
95 */
96 void
97 deleteSchedule(const std::string& name);
98
99 /**
100 * @brief Rename a schedule with @p oldName to @p newName
101 * @pre newName.length() != 0
102 *
103 * @throw Error if update operation fails, e.g., a schedule with @p newName already exists
104 */
105 void
106 renameSchedule(const std::string& oldName, const std::string& newName);
107
108 /**
109 * @brief Update the schedule with @p name and replace the old object with @p schedule
110 *
111 * if no schedule with @p name exists, a new schedule
112 * with @p name and @p schedule will be added to database
113 */
114 void
115 updateSchedule(const std::string& name, const Schedule& schedule);
116
117 ////////////////////////////////////////////////////// member management
118
119 /**
120 * @brief Check if there is a member with name @p identity
121 */
122 bool
123 hasMember(const Name& identity) const;
124
125 /**
126 * @brief List all the members
127 */
128 std::list<Name>
129 listAllMembers() const;
130
131 /**
132 * @brief Get the certificate of the member with name @p identity
133 *
134 * @throw Error if there is no member with name @p identity in database
135 */
136 Data
137 getMemberCert(const Name& identity) const;
138
139 /**
140 * @brief Get the schedule name of a member with name @p identity
141 *
142 * @throw Error if there is no member with name @p identity in database
143 */
144 std::string
145 getMemberSchedule(const Name& identity) const;
146
147 /**
148 * @brief Add a new member with @p certificate into a schedule with name @p scheduleName.
149 *
150 * @throw Error when there's no schedule named @p scheduleName
151 * @throw Error if add operation fails, e.g., a member with the same name exists
152 */
153 void
154 addMember(const std::string& scheduleName, const Data& certificate);
155
156 /**
157 * @brief Change the schedule of a member with name @p identity to a schedule with @p scheduleName
158 *
159 * @throw Error when there's no schedule named @p scheduleName
160 */
161 void
162 updateMemberSchedule(const Name& identity, const std::string& scheduleName);
163
164 /**
165 * @brief Delete a member with name @p identity from database
166 */
167 void
168 deleteMember(const Name& identity);
169
170private:
171 class Impl;
172 unique_ptr<Impl> m_impl;
173};
174
175} // namespace gep
176} // namespace ndn
177
178#endif // GEP_GROUP_MANAGER_DB_HPP