trust-store  2.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>
24 #include <core/trust/visibility.h>
25 
26 #include <functional>
27 #include <memory>
28 #include <stdexcept>
29 
30 namespace core
31 {
44 namespace trust
45 {
50 {
51 public:
53  struct Errors
54  {
56  Errors() = delete;
62  struct ErrorOpeningStore : public std::runtime_error
63  {
64  ErrorOpeningStore(const char* implementation_specific)
65  : std::runtime_error(implementation_specific)
66  {
67  }
68  };
69 
73  struct ErrorResettingStore : public std::runtime_error
74  {
75  ErrorResettingStore(const char* implementation_specific)
76  : std::runtime_error(implementation_specific)
77  {
78  }
79  };
80 
81  };
82 
86  class Query
87  {
88  public:
90  struct Errors
91  {
93  Errors() = delete;
98  struct QueryIsInErrorState : public std::runtime_error
99  {
100  QueryIsInErrorState() : std::runtime_error("Query is in error state, cannot extract result.")
101  {
102  }
103  };
104 
108  struct NoCurrentResult : public std::runtime_error
109  {
110  NoCurrentResult() : std::runtime_error("Query does not have a current result.")
111  {
112  }
113  };
114  };
115 
117  enum class Status
118  {
119  armed,
120  has_more_results,
121  eor,
122  error
123  };
124 
125  Query(const Query&) = delete;
126  virtual ~Query() = default;
127 
129  virtual Status status() const = 0;
130 
132  virtual void for_application_id(const std::string& id) = 0;
133 
135  virtual void for_feature(Feature feature) = 0;
136 
138  virtual void for_interval(const Request::Timestamp& begin, const Request::Timestamp& end) = 0;
139 
141  virtual void for_answer(Request::Answer answer) = 0;
142 
144  virtual void all() = 0;
145 
147  virtual void execute() = 0;
148 
150  virtual void next() = 0;
151 
153  virtual void erase() = 0;
154 
156  virtual Request current() = 0;
157 
158  protected:
159  Query() = default;
160  };
161 
162  Store(const Store&) = delete;
163  virtual ~Store() = default;
164 
165  Store& operator=(const Store&) = delete;
166  bool operator==(const Store&) const = delete;
167 
171  virtual void reset() = 0;
172 
176  virtual void add(const Request& request) = 0;
177 
181  virtual std::shared_ptr<Query> query() = 0;
182 
183 protected:
184  Store() = default;
185 };
186 
188 struct Errors
189 {
191  Errors() = delete;
198  struct ServiceNameMustNotBeEmpty : public std::runtime_error
199  {
200  ServiceNameMustNotBeEmpty() : std::runtime_error("Service name must not be empty")
201  {
202  }
203  };
204 };
205 
212 CORE_TRUST_DLL_PUBLIC std::shared_ptr<Store> create_default_store(const std::string& service_name);
213 }
214 }
215 
216 #endif // CORE_TRUST_STORE_H_
Thrown if a store implementation could not reset state and drop all previously stored requests...
Definition: store.h:73
The ServiceNameMustNotBeEmpty is thrown if an empty service name is provided when creating a store...
Definition: store.h:198
The Request struct encapsulates information about a trust request answered by the user...
Definition: request.h:54
Definition: agent.h:28
All Query-specific error/exception types go here.
Definition: store.h:90
STL namespace.
Thrown if a store implementation could not access the persistence backend.
Definition: store.h:62
Answer
Enumerates the possible answers given by a user.
Definition: request.h:65
Models read/write/query access to persisted trust requests.
Definition: store.h:49
Thrown when trying to access the current result although the query status is not has_more_results.
Definition: store.h:108
ErrorOpeningStore(const char *implementation_specific)
Definition: store.h:64
CORE_TRUST_DLL_PUBLIC bool operator==(const Agent::RequestParameters &lhs, const Agent::RequestParameters &rhs)
Returns true iff lhs and rhs are equal.
Thrown if functionality of a query is accessed although the query is in error state.
Definition: store.h:98
Status
The state of the query.
Definition: store.h:117
All Store-specific error/exception types go here.
Definition: store.h:53
std::chrono::system_clock::time_point Timestamp
Requests are timestamped with wallclock time.
Definition: request.h:59
The Query class encapsulates queries against a trust store instance.
Definition: store.h:86
ErrorResettingStore(const char *implementation_specific)
Definition: store.h:75
All core::trust-specific error/exception types go here.
Definition: store.h:188
#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.