trust-store  1.0.0
Provides a common implementation of a trust store to be used by trusted helpers.
store.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef CORE_TRUST_STORE_H_
20 #define CORE_TRUST_STORE_H_
21 
22 #include <core/trust/request.h>
23 #include <core/trust/visibility.h>
24 
25 #include <functional>
26 #include <memory>
27 #include <stdexcept>
28 
29 namespace core
30 {
43 namespace trust
44 {
49 {
50 public:
52  struct Errors
53  {
55  Errors() = delete;
61  struct ErrorOpeningStore : public std::runtime_error
62  {
63  ErrorOpeningStore(const char* implementation_specific)
64  : std::runtime_error(implementation_specific)
65  {
66  }
67  };
68 
72  struct ErrorResettingStore : public std::runtime_error
73  {
74  ErrorResettingStore(const char* implementation_specific)
75  : std::runtime_error(implementation_specific)
76  {
77  }
78  };
79 
80  };
81 
85  class Query
86  {
87  public:
89  struct Errors
90  {
92  Errors() = delete;
97  struct QueryIsInErrorState : public std::runtime_error
98  {
99  QueryIsInErrorState() : std::runtime_error("Query is in error state, cannot extract result.")
100  {
101  }
102  };
103 
107  struct NoCurrentResult : public std::runtime_error
108  {
109  NoCurrentResult() : std::runtime_error("Query does not have a current result.")
110  {
111  }
112  };
113  };
114 
116  enum class Status
117  {
118  armed,
119  has_more_results,
120  eor,
121  error
122  };
123 
124  Query(const Query&) = delete;
125  virtual ~Query() = default;
126 
128  virtual Status status() const = 0;
129 
131  virtual void for_application_id(const std::string& id) = 0;
132 
134  virtual void for_feature(std::uint64_t feature) = 0;
135 
137  virtual void for_interval(const Request::Timestamp& begin, const Request::Timestamp& end) = 0;
138 
140  virtual void for_answer(Request::Answer answer) = 0;
141 
143  virtual void all() = 0;
144 
146  virtual void execute() = 0;
147 
149  virtual void next() = 0;
150 
152  virtual void erase() = 0;
153 
155  virtual Request current() = 0;
156 
157  protected:
158  Query() = default;
159  };
160 
161  Store(const Store&) = delete;
162  virtual ~Store() = default;
163 
164  Store& operator=(const Store&) = delete;
165  bool operator==(const Store&) const = delete;
166 
170  virtual void reset() = 0;
171 
175  virtual void add(const Request& request) = 0;
176 
180  virtual std::shared_ptr<Query> query() = 0;
181 
182 protected:
183  Store() = default;
184 };
185 
187 struct Errors
188 {
190  Errors() = delete;
197  struct ServiceNameMustNotBeEmpty : public std::runtime_error
198  {
199  ServiceNameMustNotBeEmpty() : std::runtime_error("Service name must not be empty")
200  {
201  }
202  };
203 };
204 
211 CORE_TRUST_DLL_PUBLIC std::shared_ptr<Store> create_default_store(const std::string& service_name);
212 }
213 }
214 
215 #endif // CORE_TRUST_STORE_H_
Thrown if a store implementation could not reset state and drop all previously stored requests...
Definition: store.h:72
The ServiceNameMustNotBeEmpty is thrown if an empty service name is provided when creating a store...
Definition: store.h:197
The Request struct encapsulates information about a trust request answered by the user...
Definition: request.h:53
All Query-specific error/exception types go here.
Definition: store.h:89
Thrown if a store implementation could not access the persistence backend.
Definition: store.h:61
Models read/write/query access to persisted trust requests.
Definition: store.h:48
Thrown when trying to access the current result although the query status is not has_more_results.
Definition: store.h:107
ErrorOpeningStore(const char *implementation_specific)
Definition: store.h:63
Thrown if functionality of a query is accessed although the query is in error state.
Definition: store.h:97
Status
The state of the query.
Definition: store.h:116
All Store-specific error/exception types go here.
Definition: store.h:52
Answer
Enumerates the possible answers given by a user.
Definition: request.h:64
std::chrono::system_clock::time_point Timestamp
Requests are timestamped with wallclock time.
Definition: request.h:58
The Query class encapsulates queries against a trust store instance.
Definition: store.h:85
CORE_TRUST_DLL_PUBLIC bool operator==(const Request &lhs, const Request &rhs)
operator == compares two Requests for equality.
ErrorResettingStore(const char *implementation_specific)
Definition: store.h:74
All core::trust-specific error/exception types go here.
Definition: store.h:187
#define CORE_TRUST_DLL_PUBLIC
Definition: visibility.h:26
CORE_TRUST_DLL_PUBLIC std::shared_ptr< Store > create_default_store(const std::string &service_name)
Creates an instance for the default store implementation.