store.h
Go to the documentation of this file.
/*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#ifndef CORE_TRUST_STORE_H_
#define CORE_TRUST_STORE_H_
#include <core/trust/request.h>
#include <core/trust/tagged_integer.h>
#include <core/trust/visibility.h>
#include <functional>
#include <memory>
#include <stdexcept>
namespace core
{
namespace trust
{
class CORE_TRUST_DLL_PUBLIC Store
{
public:
struct Errors
{
Errors() = delete;
struct ErrorOpeningStore : public std::runtime_error
{
ErrorOpeningStore(const char* implementation_specific)
: std::runtime_error(implementation_specific)
{
}
};
struct ErrorResettingStore : public std::runtime_error
{
ErrorResettingStore(const char* implementation_specific)
: std::runtime_error(implementation_specific)
{
}
};
};
class Query
{
public:
struct Errors
{
Errors() = delete;
struct QueryIsInErrorState : public std::runtime_error
{
QueryIsInErrorState() : std::runtime_error("Query is in error state, cannot extract result.")
{
}
};
struct NoCurrentResult : public std::runtime_error
{
NoCurrentResult() : std::runtime_error("Query does not have a current result.")
{
}
};
};
enum class Status
{
armed,
has_more_results,
eor,
error
};
Query(const Query&) = delete;
virtual ~Query() = default;
virtual Status status() const = 0;
virtual void for_application_id(const std::string& id) = 0;
virtual void for_feature(Feature feature) = 0;
virtual void for_interval(const Request::Timestamp& begin, const Request::Timestamp& end) = 0;
virtual void for_answer(Request::Answer answer) = 0;
virtual void all() = 0;
virtual void execute() = 0;
virtual void next() = 0;
virtual void erase() = 0;
virtual Request current() = 0;
protected:
Query() = default;
};
Store(const Store&) = delete;
virtual ~Store() = default;
Store& operator=(const Store&) = delete;
bool operator==(const Store&) const = delete;
virtual void reset() = 0;
virtual void add(const Request& request) = 0;
virtual std::shared_ptr<Query> query() = 0;
protected:
Store() = default;
};
struct Errors
{
Errors() = delete;
struct ServiceNameMustNotBeEmpty : public std::runtime_error
{
ServiceNameMustNotBeEmpty() : std::runtime_error("Service name must not be empty")
{
}
};
};
CORE_TRUST_DLL_PUBLIC std::shared_ptr<Store> create_default_store(const std::string& service_name);
}
}
#endif // CORE_TRUST_STORE_H_
core::trust::Store::Errors::ErrorResettingStore
Thrown if a store implementation could not reset state and drop all previously stored requests...
Definition: store.h:73
core::trust::Errors::ServiceNameMustNotBeEmpty
The ServiceNameMustNotBeEmpty is thrown if an empty service name is provided when creating a store...
Definition: store.h:198
core::trust::Request
The Request struct encapsulates information about a trust request answered by the user...
Definition: request.h:54
core
Definition: agent.h:28
core::trust::Store::Query::Errors
All Query-specific error/exception types go here.
Definition: store.h:90
std
STL namespace.
core::trust::Store::Errors::ErrorOpeningStore
Thrown if a store implementation could not access the persistence backend.
Definition: store.h:62
core::trust::TaggedInteger< tag::Feature, std::uint64_t >
core::trust::Request::Answer
Answer
Enumerates the possible answers given by a user.
Definition: request.h:65
core::trust::Store
Models read/write/query access to persisted trust requests.
Definition: store.h:49
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:108
visibility.h
core::trust::Store::Errors::ErrorOpeningStore::ErrorOpeningStore
ErrorOpeningStore(const char *implementation_specific)
Definition: store.h:64
core::trust::Store::Query::Errors::QueryIsInErrorState::QueryIsInErrorState
QueryIsInErrorState()
Definition: store.h:100
core::trust::operator==
CORE_TRUST_DLL_PUBLIC bool operator==(const Agent::RequestParameters &lhs, const Agent::RequestParameters &rhs)
Returns true iff lhs and rhs are equal.
core::trust::Store::Query::Errors::QueryIsInErrorState
Thrown if functionality of a query is accessed although the query is in error state.
Definition: store.h:98
core::trust::Store::Query::Status
Status
The state of the query.
Definition: store.h:117
core::trust::Store::Errors
All Store-specific error/exception types go here.
Definition: store.h:53
core::trust::Store::Query::Errors::NoCurrentResult::NoCurrentResult
NoCurrentResult()
Definition: store.h:110
tagged_integer.h
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
The Query class encapsulates queries against a trust store instance.
Definition: store.h:86
request.h
core::trust::Store::Errors::ErrorResettingStore::ErrorResettingStore
ErrorResettingStore(const char *implementation_specific)
Definition: store.h:75
core::trust::Errors
All core::trust-specific error/exception types go here.
Definition: store.h:188
core::trust::Errors::ServiceNameMustNotBeEmpty::ServiceNameMustNotBeEmpty
ServiceNameMustNotBeEmpty()
Definition: store.h:200
CORE_TRUST_DLL_PUBLIC
#define CORE_TRUST_DLL_PUBLIC
Definition: visibility.h:26
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.