AWS IoT Device SDK C++ v2: devicedefender/include/aws/iotdevicedefender/DeviceDefender.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

DeviceDefender.h
Go to the documentation of this file.
1#pragma once
7#include <aws/iotdevicedefender/Exports.h>
8
9#include <aws/crt/io/EventLoopGroup.h>
10#include <aws/crt/mqtt/MqttClient.h>
11
12#include <aws/iotdevice/device_defender.h>
13
14namespace Aws
15{
16 namespace Crt
17 {
18
19 }
20
21 namespace Iotdevicedefenderv1
22 {
23
24 class ReportTask;
25 class ReportTaskBuilder;
26
30 using OnTaskCancelledHandler = std::function<void(void *)>;
31
32 using ReportFormat = aws_iotdevice_defender_report_format;
33
37 enum class ReportTaskStatus
38 {
39 Ready = 0,
40 Running = 1,
41 Stopped = 2,
42 };
43
47 class AWS_IOTDEVICEDEFENDER_API ReportTask final
48 {
49 friend ReportTaskBuilder;
50
51 public:
52 ~ReportTask();
53 ReportTask(const ReportTask &) = delete;
54 ReportTask &operator=(const ReportTask &) = delete;
55
59 void StopTask() noexcept;
60
64 int StartTask() noexcept;
65
69 ReportTaskStatus GetStatus() noexcept;
70
71 OnTaskCancelledHandler OnTaskCancelled;
72
73 void *cancellationUserdata;
74
78 int LastError() const noexcept { return m_lastError; }
79
80 private:
81 Crt::Allocator *m_allocator;
82 ReportTaskStatus m_status;
83 aws_iotdevice_defender_task_config *m_taskConfig;
84 aws_iotdevice_defender_task *m_owningTask;
85 int m_lastError;
86 std::shared_ptr<Crt::Mqtt::MqttConnection> m_mqttConnection;
87 Crt::Io::EventLoopGroup &m_eventLoopGroup;
88
89 ReportTask(
90 Crt::Allocator *allocator,
91 std::shared_ptr<Crt::Mqtt::MqttConnection> mqttConnection,
92 const Crt::String &thingName,
93 Crt::Io::EventLoopGroup &eventLoopGroup,
94 ReportFormat reportFormat,
95 uint32_t taskPeriodSeconds,
96 uint32_t networkConnectionSamplePeriodSeconds,
97 OnTaskCancelledHandler &&onCancelled = NULL,
98 void *cancellationUserdata = nullptr) noexcept;
99
100 static void s_onDefenderV1TaskCancelled(void *userData);
101 };
102
106 class AWS_IOTDEVICEDEFENDER_API ReportTaskBuilder final
107 {
108 public:
109 ReportTaskBuilder(
110 Crt::Allocator *allocator,
111 std::shared_ptr<Crt::Mqtt::MqttConnection> mqttConnection,
112 Crt::Io::EventLoopGroup &eventLoopGroup,
113 const Crt::String &thingName);
114
118 ReportTaskBuilder &WithReportFormat(ReportFormat reportFormat) noexcept;
119
123 ReportTaskBuilder &WithTaskPeriodSeconds(uint32_t taskPeriodSeconds) noexcept;
124
128 ReportTaskBuilder &WithNetworkConnectionSamplePeriodSeconds(
129 uint32_t networkConnectionSamplePeriodSeconds) noexcept;
130
134 ReportTaskBuilder &WithTaskCancelledHandler(OnTaskCancelledHandler &&onCancelled) noexcept;
135
139 ReportTaskBuilder &WithTaskCancellationUserData(void *cancellationUserdata) noexcept;
140
144 std::shared_ptr<ReportTask> Build() noexcept;
145
146 private:
147 Crt::Allocator *m_allocator;
148 std::shared_ptr<Crt::Mqtt::MqttConnection> m_mqttConnection;
149 Crt::String m_thingName;
150 Crt::Io::EventLoopGroup &m_eventLoopGroup;
151 ReportFormat m_reportFormat;
152 uint32_t m_taskPeriodSeconds;
153 uint32_t m_networkConnectionSamplePeriodSeconds;
154 OnTaskCancelledHandler m_onCancelled;
155 void *m_cancellationUserdata;
156 };
157
158 } // namespace Iotdevicedefenderv1
159} // namespace Aws
EventLoopGroup.h
Aws::Crt::Io::EventLoopGroup
Definition: EventLoopGroup.h:33
Aws::Iotdevicedefenderv1::ReportTaskBuilder
Definition: DeviceDefender.h:107
Aws::Iotdevicedefenderv1::ReportTask
Definition: DeviceDefender.h:48
Aws::Iotdevicedefenderv1::ReportTask::ReportTask
ReportTask(const ReportTask &)=delete
Aws::Iotdevicedefenderv1::ReportTask::operator=
ReportTask & operator=(const ReportTask &)=delete
MqttClient.h
Exports.h
AWS_IOTDEVICEDEFENDER_API
#define AWS_IOTDEVICEDEFENDER_API
Definition: Exports.h:19
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:47
Aws::Crt::LastError
AWS_CRT_CPP_API int LastError() noexcept
Definition: Api.cpp:315
Aws::Iotdevicedefenderv1::ReportTaskStatus
ReportTaskStatus
Definition: DeviceDefender.h:38
Aws::Iotdevicedefenderv1::ReportTaskStatus::Running
@ Running
Aws::Iotdevicedefenderv1::ReportTaskStatus::Stopped
@ Stopped
Aws::Iotdevicedefenderv1::ReportTaskStatus::Ready
@ Ready
Aws::Iotdevicedefenderv1::ReportFormat
aws_iotdevice_defender_report_format ReportFormat
Definition: DeviceDefender.h:32
Aws::Iotdevicedefenderv1::OnTaskCancelledHandler
std::function< void(void *)> OnTaskCancelledHandler
Definition: DeviceDefender.h:30
Aws
Definition: Api.h:17
Aws::NULL
return NULL
Definition: cJSON.cpp:1188