trust-store: /build/trust-store-git/src/trust-store/include/core/trust/store.h Source File

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>
23 #include <core/trust/tagged_integer.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 {
49 class CORE_TRUST_DLL_PUBLIC Store
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_
core::trust::Errors
All core::trust-specific error/exception types go here.
Definition: store.h:189
core::trust::Request
The Request struct encapsulates information about a trust request answered by the user.
Definition: request.h:55
core::trust::Store
Models read/write/query access to persisted trust requests.
Definition: store.h:50
core::trust::Store::Query::erase
virtual void erase()=0
After successful execution, erase the current element and advance to the next request.
core::trust::Store::Query::for_application_id
virtual void for_application_id(const std::string &id)=0
Limit the query to a specific application Id.
visibility.h
core::trust::Store::Query::Errors::NoCurrentResult::NoCurrentResult
NoCurrentResult()
Definition: store.h:110
core::trust::TaggedInteger< tag::Feature, std::uint64_t >
core::trust::Store::Query::Status
Status
The state of the query.
Definition: store.h:118
core::trust::Errors::ServiceNameMustNotBeEmpty
The ServiceNameMustNotBeEmpty is thrown if an empty service name is provided when creating a store.
Definition: store.h:199
core::trust::Store::Query::execute
virtual void execute()=0
Execute the query against the store.
core::trust::Store::add
virtual void add(const Request &request)=0
Add the provided request to the store. When this function returns true, the request has been persiste...
core::trust::Store::Query::~Query
virtual ~Query()=default
core::trust::Store::Query::for_answer
virtual void for_answer(Request::Answer answer)=0
Limit the query for a specific answer.
core::trust::Store::Query::for_interval
virtual void for_interval(const Request::Timestamp &begin, const Request::Timestamp &end)=0
Limit the query to the specified time interval.
core::trust::Store::Errors::ErrorResettingStore::ErrorResettingStore
ErrorResettingStore(const char *implementation_specific)
Definition: store.h:75
core::trust::Store::Query::all
virtual void all()=0
Query all stored requests.
core::trust::Store::Query::status
virtual Status status() const =0
Access the status of the query.
core::trust::Store::Errors
All Store-specific error/exception types go here.
Definition: store.h:54
tagged_integer.h
core
Definition: agent.h:29
core::trust::Store::Errors::ErrorResettingStore
Thrown if a store implementation could not reset state and drop all previously stored requests.
Definition: store.h:74
core::trust::Store::Query::Errors::QueryIsInErrorState
Thrown if functionality of a query is accessed although the query is in error state.
Definition: store.h:99
request.h
core::trust::Store::operator==
bool operator==(const Store &) const =delete
core::trust::Store::Query::Errors::QueryIsInErrorState::QueryIsInErrorState
QueryIsInErrorState()
Definition: store.h:100
core::trust::Request::Answer
Answer
Enumerates the possible answers given by a user.
Definition: request.h:66
core::trust::Store::Errors::ErrorOpeningStore::ErrorOpeningStore
ErrorOpeningStore(const char *implementation_specific)
Definition: store.h:64
core::trust::Store::Query
The Query class encapsulates queries against a trust store instance.
Definition: store.h:87
core::trust::Store::query
virtual std::shared_ptr< Query > query()=0
Create a query for this store.
core::trust::Store::operator=
Store & operator=(const Store &)=delete
core::trust::Store::Errors::ErrorOpeningStore
Thrown if a store implementation could not access the persistence backend.
Definition: store.h:63
core::trust::Store::Query::Errors
All Query-specific error/exception types go here.
Definition: store.h:91
core::trust::Store::Query::Query
Query(const Query &)=delete
CORE_TRUST_DLL_PUBLIC
#define CORE_TRUST_DLL_PUBLIC
Definition: visibility.h:26
core::trust::Store::~Store
virtual ~Store()=default
core::trust::Request::Timestamp
std::chrono::system_clock::time_point Timestamp
Requests are timestamped with wallclock time.
Definition: request.h:59
core::trust::Store::Query::next
virtual void next()=0
After successful execution, advance to the next request.
core::trust::create_default_store
CORE_TRUST_DLL_PUBLIC std::shared_ptr< Store > create_default_store(const std::string &service_name)
Creates an instance for the default store implementation.
core::trust::Errors::ServiceNameMustNotBeEmpty::ServiceNameMustNotBeEmpty
ServiceNameMustNotBeEmpty()
Definition: store.h:200
core::trust::Store::reset
virtual void reset()=0
Resets the state of the store, implementations should discard all persistent and non-persistent state...
core::trust::Store::Query::for_feature
virtual void for_feature(Feature feature)=0
Limit the query to a service-specific feature.
core::trust::Store::Query::current
virtual Request current()=0
Access the request the query currently points to.
core::trust::Store::Query::Errors::NoCurrentResult
Thrown when trying to access the current result although the query status is not has_more_results.
Definition: store.h:109
core::trust::Store::Store
Store(const Store &)=delete
core::trust::Store::Store
Store()=default
core::trust::Store::Query::Query
Query()=default