AWS IoT Device SDK C++ v2 1.44.1
AWS IoT Device SDK C++ v2
Loading...
Searching...
No Matches
DeviceDefender.h
Go to the documentation of this file.
1#pragma once
6
8
12
13#include <aws/iotdevice/device_defender.h>
14
15namespace Aws
16{
17 namespace Crt
18 {
19
20 }
21
23 {
24
25 class ReportTask;
27
31 using OnTaskCancelledHandler = std::function<void(void *)>;
32
33 using ReportFormat = aws_iotdevice_defender_report_format;
34
35 using CustomMetricNumberFunction = std::function<int(double *)>;
39
44
49 {
50 Ready = 0,
53 };
54
59 {
60 friend ReportTaskBuilder;
61
62 public:
64 ReportTask(const ReportTask &) = delete;
65 ReportTask &operator=(const ReportTask &) = delete;
66
70 void StopTask() noexcept;
71
75 int StartTask() noexcept;
76
80 ReportTaskStatus GetStatus() noexcept;
81
83
85
89 int LastError() const noexcept { return m_lastError; }
90
98 void RegisterCustomMetricNumber(
99 const Crt::String metricName,
100 CustomMetricNumberFunction metricFunc) noexcept;
101
110 void RegisterCustomMetricNumberList(
111 const Crt::String metricName,
112 CustomMetricNumberListFunction metricFunc) noexcept;
113
123 void RegisterCustomMetricStringList(
124 const Crt::String metricName,
125 CustomMetricStringListFunction metricFunc) noexcept;
126
135 void RegisterCustomMetricIpAddressList(
136 const Crt::String metricName,
137 CustomMetricIpListFunction metricFunc) noexcept;
138
139 private:
140 Crt::Allocator *m_allocator;
141 ReportTaskStatus m_status;
142 aws_iotdevice_defender_task_config *m_taskConfig;
143 aws_iotdevice_defender_task *m_owningTask;
144 int m_lastError;
145 std::shared_ptr<Crt::Mqtt::MqttConnection> m_mqttConnection;
146 Crt::Io::EventLoopGroup &m_eventLoopGroup;
147
149 Crt::Allocator *allocator,
150 std::shared_ptr<Crt::Mqtt::MqttConnection> mqttConnection,
151 const Crt::String &thingName,
152 Crt::Io::EventLoopGroup &eventLoopGroup,
153 ReportFormat reportFormat,
154 uint32_t taskPeriodSeconds,
155 uint32_t networkConnectionSamplePeriodSeconds,
156 OnTaskCancelledHandler &&onCancelled = NULL,
157 void *cancellationUserdata = nullptr) noexcept;
158
159 static void s_onDefenderV1TaskCancelled(void *userData);
160
161 // Holds all of the custom metrics created for this task. These are pointers that will be
162 // automatically created and cleaned by ReportTask when it is destroyed.
163 Crt::Vector<std::shared_ptr<CustomMetricBase>> storedCustomMetrics;
164 };
165
170 {
171 public:
173 Crt::Allocator *allocator,
174 std::shared_ptr<Crt::Mqtt::MqttConnection> mqttConnection,
175 Crt::Io::EventLoopGroup &eventLoopGroup,
176 const Crt::String &thingName);
177
179 Crt::Allocator *allocator,
180 std::shared_ptr<Crt::Mqtt5::Mqtt5Client> mqtt5Client,
181 Crt::Io::EventLoopGroup &eventLoopGroup,
182 const Crt::String &thingName);
183
187 ReportTaskBuilder &WithReportFormat(ReportFormat reportFormat) noexcept;
188
192 ReportTaskBuilder &WithTaskPeriodSeconds(uint32_t taskPeriodSeconds) noexcept;
193
198 uint32_t networkConnectionSamplePeriodSeconds) noexcept;
199
204
208 ReportTaskBuilder &WithTaskCancellationUserData(void *cancellationUserdata) noexcept;
209
213 std::shared_ptr<ReportTask> Build() noexcept;
214
215 private:
216 Crt::Allocator *m_allocator;
217 std::shared_ptr<Crt::Mqtt::MqttConnection> m_mqttConnection;
218 Crt::String m_thingName;
219 Crt::Io::EventLoopGroup &m_eventLoopGroup;
220 ReportFormat m_reportFormat;
221 uint32_t m_taskPeriodSeconds;
222 uint32_t m_networkConnectionSamplePeriodSeconds;
223 OnTaskCancelledHandler m_onCancelled;
224 void *m_cancellationUserdata;
225 };
226
227 } // namespace Iotdevicedefenderv1
228} // namespace Aws
Definition EventLoopGroup.h:33
Definition DeviceDefender.cpp:24
Definition DeviceDefender.h:170
ReportTaskBuilder & WithReportFormat(ReportFormat reportFormat) noexcept
Definition DeviceDefender.cpp:328
ReportTaskBuilder & WithTaskCancellationUserData(void *cancellationUserdata) noexcept
Definition DeviceDefender.cpp:353
ReportTaskBuilder & WithTaskPeriodSeconds(uint32_t taskPeriodSeconds) noexcept
Definition DeviceDefender.cpp:334
ReportTaskBuilder & WithTaskCancelledHandler(OnTaskCancelledHandler &&onCancelled) noexcept
Definition DeviceDefender.cpp:347
ReportTaskBuilder & WithNetworkConnectionSamplePeriodSeconds(uint32_t networkConnectionSamplePeriodSeconds) noexcept
Definition DeviceDefender.cpp:340
std::shared_ptr< ReportTask > Build() noexcept
Definition DeviceDefender.cpp:359
ReportTaskBuilder(Crt::Allocator *allocator, std::shared_ptr< Crt::Mqtt::MqttConnection > mqttConnection, Crt::Io::EventLoopGroup &eventLoopGroup, const Crt::String &thingName)
Definition DeviceDefender.cpp:300
Definition DeviceDefender.h:59
void * cancellationUserdata
Definition DeviceDefender.h:84
ReportTask(const ReportTask &)=delete
ReportTask & operator=(const ReportTask &)=delete
int StartTask() noexcept
Definition DeviceDefender.cpp:201
ReportTaskStatus GetStatus() noexcept
Definition DeviceDefender.cpp:196
OnTaskCancelledHandler OnTaskCancelled
Definition DeviceDefender.h:82
int LastError() const noexcept
Definition DeviceDefender.h:89
void StopTask() noexcept
Definition DeviceDefender.cpp:228
#define AWS_IOTDEVICEDEFENDER_API
Definition Exports.h:19
Definition Allocator.h:13
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition Types.h:45
std::vector< T, StlAllocator< T > > Vector
Definition Types.h:53
aws_allocator Allocator
Definition Allocator.h:14
Definition DeviceDefender.h:23
std::function< int(Crt::Vector< Crt::String > *)> CustomMetricStringListFunction
Definition DeviceDefender.h:37
ReportTaskStatus
Definition DeviceDefender.h:49
@ Running
Definition DeviceDefender.h:51
@ Stopped
Definition DeviceDefender.h:52
@ Ready
Definition DeviceDefender.h:50
std::function< void(void *)> OnTaskCancelledHandler
Definition DeviceDefender.h:31
std::function< int(Crt::Vector< double > *)> CustomMetricNumberListFunction
Definition DeviceDefender.h:36
std::function< int(Crt::Vector< Crt::String > *)> CustomMetricIpListFunction
Definition DeviceDefender.h:38
std::function< int(double *)> CustomMetricNumberFunction
Definition DeviceDefender.h:35
aws_iotdevice_defender_report_format ReportFormat
Definition DeviceDefender.h:33
Definition Allocator.h:11
Definition StringView.h:862