AWS IoT Device SDK C++ v2  1.34.0
AWS IoT Device SDK C++ v2
RuleEngine.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <aws/crt/Types.h>
8 
9 struct aws_endpoints_rule_engine;
10 struct aws_endpoints_request_context;
11 struct aws_endpoints_resolved_endpoint;
12 
13 namespace Aws
14 {
15  namespace Crt
16  {
17  namespace Endpoints
18  {
19  /*
20  * Add parameter to the context.
21  * Only string and boolean values are supported.
22  * Adding parameter several times with the same name will overwrite
23  * previous values.
24  */
26  {
27  public:
28  RequestContext(Allocator *allocator = ApiAllocator()) noexcept;
29  ~RequestContext();
30 
31  /* TODO: move/copy semantics */
32  RequestContext(const RequestContext &) = delete;
36 
40  operator bool() const noexcept { return m_requestContext != nullptr; }
41 
42  /*
43  * Add string parameter.
44  * True if added successfully and false if failed.
45  * Aws::Crt::LastError() can be used to retrieve failure error code.
46  */
47  bool AddString(const ByteCursor &name, const ByteCursor &value);
48 
49  /*
50  * Add boolean parameter.
51  * True if added successfully and false if failed.
52  * Aws::Crt::LastError() can be used to retrieve failure error code.
53  */
54  bool AddBoolean(const ByteCursor &name, bool value);
55 
56  /*
57  * Add string array parameter.
58  * True if added successfully and false if failed.
59  * Aws::Crt::LastError() can be used to retrieve failure error code.
60  */
61  bool AddStringArray(const ByteCursor &name, const Vector<ByteCursor> &value);
62 
64  aws_endpoints_request_context *GetNativeHandle() const noexcept { return m_requestContext; }
65 
66  private:
67  Allocator *m_allocator;
68  aws_endpoints_request_context *m_requestContext;
69  };
70 
71  /*
72  * Outcome of Endpoint Resolution.
73  * Outcome can be either endpoint (IsEndpoint) or error (IsError).
74  * Endpoint outcome means that engine was able to resolve context to
75  * an endpoint and outcome can have the following fields defined:
76  * - Url (required) - resolved url
77  * - Headers (optional) - additional headers to be included with request
78  * - Properties (optional) - custom list of properties associated
79  * with request (json blob to be interpreted by the caller.)
80  *
81  * Error outcome means that context could not be resolved to an endpoint.
82  * Outcome will have following fields:
83  * - Error (required) - error message providing more info on why
84  * endpoint could not be resolved.
85  */
87  {
88  public:
90 
91  /* TODO: move/copy semantics */
94  ResolutionOutcome(ResolutionOutcome &&toMove) noexcept;
95  ResolutionOutcome &operator=(ResolutionOutcome &&);
96 
97  bool IsEndpoint() const noexcept;
98  bool IsError() const noexcept;
99 
100  /*
101  * Endpoint properties.
102  * Note: following fields are none if outcome is error.
103  * Headers and Properties are optional and could also be None.
104  */
105  Optional<StringView> GetUrl() const;
106  Optional<StringView> GetProperties() const;
107  Optional<UnorderedMap<StringView, Vector<StringView>>> GetHeaders() const;
108 
109  /*
110  * Error properties.
111  * Note: following fields are none if outcome is error.
112  */
113  Optional<StringView> GetError() const;
114 
118  operator bool() const noexcept { return m_resolvedEndpoint != nullptr; }
119 
121  ResolutionOutcome(aws_endpoints_resolved_endpoint *impl);
122 
123  private:
124  aws_endpoints_resolved_endpoint *m_resolvedEndpoint;
125  };
126 
131  {
132  public:
133  RuleEngine(
134  const ByteCursor &rulesetCursor,
135  const ByteCursor &partitionsCursor,
136  Allocator *allocator = ApiAllocator()) noexcept;
137  ~RuleEngine();
138 
139  RuleEngine(const RuleEngine &) = delete;
140  RuleEngine &operator=(const RuleEngine &) = delete;
141  RuleEngine(RuleEngine &&) = delete;
143 
147  operator bool() const noexcept { return m_ruleEngine != nullptr; }
148 
149  /*
150  * Resolves rules against the provided context.
151  * If successful return will have resolution outcome.
152  * If not, return will be none and Aws::Crt::LastError() can be
153  * used to retrieve CRT error code.
154  */
155  Optional<ResolutionOutcome> Resolve(const RequestContext &context) const;
156 
157  private:
158  aws_endpoints_rule_engine *m_ruleEngine;
159  };
160  } // namespace Endpoints
161  } // namespace Crt
162 } // namespace Aws
Aws::Crt::ApiAllocator
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition: Allocator.cpp:24
Aws::Crt::Endpoints::RuleEngine
Definition: RuleEngine.h:131
Aws::Crt::Endpoints::ResolutionOutcome::operator=
ResolutionOutcome & operator=(const ResolutionOutcome &)=delete
Aws::Crt::Endpoints::RuleEngine::operator=
RuleEngine & operator=(RuleEngine &&)=delete
Aws::Crt::Endpoints::RuleEngine::operator=
RuleEngine & operator=(const RuleEngine &)=delete
Aws::Crt::Endpoints::RequestContext::RequestContext
RequestContext(RequestContext &&)=delete
Aws::Crt::Optional
Definition: Optional.h:18
Aws::Crt::Endpoints::RuleEngine::RuleEngine
RuleEngine(const RuleEngine &)=delete
Aws::Crt::Endpoints::RequestContext::RequestContext
RequestContext(const RequestContext &)=delete
Aws::Crt::Endpoints::RuleEngine::RuleEngine
RuleEngine(RuleEngine &&)=delete
Aws::Crt::Endpoints::ResolutionOutcome
Definition: RuleEngine.h:87
Types.h
Aws::Crt::Endpoints::RequestContext::operator=
RequestContext & operator=(RequestContext &&)=delete
Aws::Crt::Vector
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:53
Aws::Crt::basic_string_view
Definition: StringView.h:33
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::Endpoints::RequestContext::operator=
RequestContext & operator=(const RequestContext &)=delete
Aws::Crt::Endpoints::ResolutionOutcome::ResolutionOutcome
ResolutionOutcome(const ResolutionOutcome &)=delete
Aws
Definition: Allocator.h:11
Aws::Crt::Endpoints::RequestContext
Definition: RuleEngine.h:26
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:31
Aws::Crt::Allocator
aws_allocator Allocator
Definition: Allocator.h:14
Aws::Crt::UnorderedMap
std::unordered_map< K, V, std::hash< K >, std::equal_to< K >, StlAllocator< std::pair< const K, V > >> UnorderedMap
Definition: Types.h:50