AWS IoT Device SDK C++ v2  1.33.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 
57  aws_endpoints_request_context *GetNativeHandle() const noexcept { return m_requestContext; }
58 
59  private:
60  Allocator *m_allocator;
61  aws_endpoints_request_context *m_requestContext;
62  };
63 
64  /*
65  * Outcome of Endpoint Resolution.
66  * Outcome can be either endpoint (IsEndpoint) or error (IsError).
67  * Endpoint outcome means that engine was able to resolve context to
68  * an endpoint and outcome can have the following fields defined:
69  * - Url (required) - resolved url
70  * - Headers (optional) - additional headers to be included with request
71  * - Properties (optional) - custom list of properties associated
72  * with request (json blob to be interpreted by the caller.)
73  *
74  * Error outcome means that context could not be resolved to an endpoint.
75  * Outcome will have following fields:
76  * - Error (required) - error message providing more info on why
77  * endpoint could not be resolved.
78  */
80  {
81  public:
83 
84  /* TODO: move/copy semantics */
87  ResolutionOutcome(ResolutionOutcome &&toMove) noexcept;
88  ResolutionOutcome &operator=(ResolutionOutcome &&);
89 
90  bool IsEndpoint() const noexcept;
91  bool IsError() const noexcept;
92 
93  /*
94  * Endpoint properties.
95  * Note: following fields are none if outcome is error.
96  * Headers and Properties are optional and could also be None.
97  */
98  Optional<StringView> GetUrl() const;
99  Optional<StringView> GetProperties() const;
100  Optional<UnorderedMap<StringView, Vector<StringView>>> GetHeaders() const;
101 
102  /*
103  * Error properties.
104  * Note: following fields are none if outcome is error.
105  */
106  Optional<StringView> GetError() const;
107 
111  operator bool() const noexcept { return m_resolvedEndpoint != nullptr; }
112 
114  ResolutionOutcome(aws_endpoints_resolved_endpoint *impl);
115 
116  private:
117  aws_endpoints_resolved_endpoint *m_resolvedEndpoint;
118  };
119 
124  {
125  public:
126  RuleEngine(
127  const ByteCursor &rulesetCursor,
128  const ByteCursor &partitionsCursor,
129  Allocator *allocator = ApiAllocator()) noexcept;
130  ~RuleEngine();
131 
132  RuleEngine(const RuleEngine &) = delete;
133  RuleEngine &operator=(const RuleEngine &) = delete;
134  RuleEngine(RuleEngine &&) = delete;
136 
140  operator bool() const noexcept { return m_ruleEngine != nullptr; }
141 
142  /*
143  * Resolves rules against the provided context.
144  * If successful return will have resolution outcome.
145  * If not, return will be none and Aws::Crt::LastError() can be
146  * used to retrieve CRT error code.
147  */
148  Optional<ResolutionOutcome> Resolve(const RequestContext &context) const;
149 
150  private:
151  aws_endpoints_rule_engine *m_ruleEngine;
152  };
153  } // namespace Endpoints
154  } // namespace Crt
155 } // namespace Aws
Aws::Crt::ApiAllocator
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition: Allocator.cpp:24
Aws::Crt::Endpoints::RuleEngine
Definition: RuleEngine.h:124
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:80
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:32
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