CCF
Loading...
Searching...
No Matches
endpoint_context.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6
7#include <functional>
8#include <memory>
9
10namespace ccf
11{
12 class RpcContext;
13}
14
20namespace ccf::endpoints
21{
22 // Commands are endpoints which do not interact with the kv, even to read
24 {
25 virtual ~CommandEndpointContext() = default;
26
27 CommandEndpointContext(const std::shared_ptr<ccf::RpcContext>& r) :
28 rpc_ctx(r)
29 {}
30
31 std::shared_ptr<ccf::RpcContext> rpc_ctx;
32 std::unique_ptr<AuthnIdentity> caller;
33
34 template <typename T>
35 const T* try_get_caller()
36 {
37 return dynamic_cast<const T*>(caller.get());
38 }
39
40 template <typename T>
41 const T& get_caller()
42 {
43 const T* ident = try_get_caller<T>();
44 if (ident == nullptr)
45 {
46 throw std::logic_error("Asked for unprovided identity type");
47 }
48 return *ident;
49 }
50 };
52 std::function<void(CommandEndpointContext& args)>;
53
55 {
56 EndpointContext(const std::shared_ptr<ccf::RpcContext>& r, ccf::kv::Tx& t) :
58 tx(t)
59 {}
60
62 };
63 using EndpointFunction = std::function<void(EndpointContext& args)>;
64
66 std::function<void(CommandEndpointContext& ctx, const ccf::TxID& txid)>;
67
68 // Read-only endpoints can only get values from the kv, they cannot write
70 {
72 const std::shared_ptr<ccf::RpcContext>& r, ccf::kv::ReadOnlyTx& t) :
74 tx(t)
75 {}
76
78 };
80 std::function<void(ReadOnlyEndpointContext& args)>;
81}
Definition tx.h:160
Definition tx.h:201
Definition endpoint.h:16
std::function< void(CommandEndpointContext &args)> CommandEndpointFunction
Definition endpoint_context.h:52
std::function< void(ReadOnlyEndpointContext &args)> ReadOnlyEndpointFunction
Definition endpoint_context.h:80
std::function< void(CommandEndpointContext &ctx, const ccf::TxID &txid)> LocallyCommittedEndpointFunction
Definition endpoint_context.h:66
std::function< void(EndpointContext &args)> EndpointFunction
Definition endpoint_context.h:63
Definition app_interface.h:14
Definition tx_id.h:44
Definition endpoint_context.h:24
const T & get_caller()
Definition endpoint_context.h:41
CommandEndpointContext(const std::shared_ptr< ccf::RpcContext > &r)
Definition endpoint_context.h:27
std::shared_ptr< ccf::RpcContext > rpc_ctx
Definition endpoint_context.h:31
const T * try_get_caller()
Definition endpoint_context.h:35
std::unique_ptr< AuthnIdentity > caller
Definition endpoint_context.h:32
Definition endpoint_context.h:55
EndpointContext(const std::shared_ptr< ccf::RpcContext > &r, ccf::kv::Tx &t)
Definition endpoint_context.h:56
ccf::kv::Tx & tx
Definition endpoint_context.h:61
Definition endpoint_context.h:70
ReadOnlyEndpointContext(const std::shared_ptr< ccf::RpcContext > &r, ccf::kv::ReadOnlyTx &t)
Definition endpoint_context.h:71
ccf::kv::ReadOnlyTx & tx
Definition endpoint_context.h:77