Skip to content

Commit 432a204

Browse files
authored
Add client for IoT command service (#790)
1 parent 380b09d commit 432a204

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3466
-89
lines changed

.builder/actions/build_samples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def run(self, env):
1919

2020
steps = []
2121
samples = [
22+
'samples/commands/commands-sandbox',
2223
'samples/deprecated/fleet_provisioning/fleet_provisioning',
2324
'samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning',
2425
'samples/deprecated/jobs/job_execution',

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ add_subdirectory(jobs)
8787
add_subdirectory(shadow)
8888
add_subdirectory(discovery)
8989
add_subdirectory(identity)
90+
add_subdirectory(commands)
9091
add_subdirectory(eventstream_rpc)
9192
add_subdirectory(greengrass_ipc)
9293
if (NOT BYO_CRYPTO)

commands/CMakeLists.txt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# This file is generated
2+
3+
cmake_minimum_required(VERSION 3.9...3.31)
4+
5+
project(IotCommands-cpp LANGUAGES CXX VERSION ${SIMPLE_VERSION})
6+
7+
set(GENERATED_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
8+
set(GENERATED_INCLUDE_DIR "${GENERATED_ROOT_DIR}/include")
9+
set(GENERATED_CONFIG_HEADER "${GENERATED_INCLUDE_DIR}/aws/iotcommands/Config.h")
10+
configure_file(include/aws/iotcommands/Config.h.in ${GENERATED_CONFIG_HEADER} @ONLY)
11+
12+
if (NOT CMAKE_CXX_STANDARD)
13+
set(CMAKE_CXX_STANDARD 11)
14+
endif()
15+
16+
file(GLOB AWS_IOTCOMMANDS_HEADERS
17+
"include/aws/iotcommands/*.h"
18+
${GENERATED_CONFIG_HEADER}
19+
)
20+
21+
file(GLOB AWS_IOTCOMMANDS_SRC
22+
"source/*.cpp"
23+
)
24+
25+
file(GLOB AWS_IOTCOMMANDS_CPP_SRC
26+
${AWS_IOTCOMMANDS_SRC}
27+
)
28+
29+
if (WIN32)
30+
if (MSVC)
31+
source_group("Header Files\\aws\\iotcommands\\" FILES ${AWS_IOTCOMMANDS_HEADERS})
32+
33+
source_group("Source Files" FILES ${AWS_IOTCOMMANDS_SRC})
34+
endif ()
35+
endif()
36+
37+
add_library(IotCommands-cpp ${AWS_IOTCOMMANDS_CPP_SRC})
38+
39+
set_target_properties(IotCommands-cpp PROPERTIES LINKER_LANGUAGE CXX)
40+
41+
set(CMAKE_C_FLAGS_DEBUGOPT "")
42+
43+
#set warnings
44+
if (MSVC)
45+
target_compile_options(IotCommands-cpp PRIVATE /W4 /WX)
46+
else ()
47+
target_compile_options(IotCommands-cpp PRIVATE -Wall -Wno-long-long -pedantic -Werror)
48+
endif ()
49+
50+
target_compile_definitions(IotCommands-cpp PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)
51+
52+
if (BUILD_SHARED_LIBS)
53+
target_compile_definitions(IotCommands-cpp PUBLIC "-DAWS_IOTCOMMANDS_USE_IMPORT_EXPORT")
54+
target_compile_definitions(IotCommands-cpp PRIVATE "-DAWS_IOTCOMMANDS_EXPORTS")
55+
56+
install(TARGETS IotCommands-cpp
57+
EXPORT IotCommands-cpp-targets
58+
ARCHIVE
59+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
60+
COMPONENT Development
61+
LIBRARY
62+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
63+
NAMELINK_SKIP
64+
COMPONENT Runtime
65+
RUNTIME
66+
DESTINATION ${CMAKE_INSTALL_BINDIR}
67+
COMPONENT Runtime)
68+
69+
install(TARGETS IotCommands-cpp
70+
EXPORT IotCommands-cpp-targets
71+
LIBRARY
72+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
73+
NAMELINK_ONLY
74+
COMPONENT Development)
75+
else()
76+
install(TARGETS IotCommands-cpp
77+
EXPORT IotCommands-cpp-targets
78+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
79+
COMPONENT Development)
80+
endif()
81+
82+
target_include_directories(IotCommands-cpp PUBLIC
83+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
84+
$<INSTALL_INTERFACE:include>)
85+
86+
if (BUILD_DEPS)
87+
if (NOT IS_SUBDIRECTORY_INCLUDE)
88+
aws_use_package(aws-crt-cpp)
89+
endif()
90+
endif()
91+
92+
aws_add_sanitizers(IotCommands-cpp)
93+
target_link_libraries(IotCommands-cpp PUBLIC ${DEP_AWS_LIBS})
94+
95+
install(FILES ${AWS_IOTCOMMANDS_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/iotcommands/" COMPONENT Development)
96+
97+
if (BUILD_SHARED_LIBS)
98+
set(TARGET_DIR "shared")
99+
else()
100+
set(TARGET_DIR "static")
101+
endif()
102+
103+
include(CMakePackageConfigHelpers)
104+
if (DEFINED SIMPLE_VERSION)
105+
write_basic_package_version_file(
106+
"${CMAKE_CURRENT_BINARY_DIR}/iotcommands-cpp-config-version.cmake"
107+
COMPATIBILITY SameMajorVersion
108+
)
109+
endif()
110+
111+
install(EXPORT "IotCommands-cpp-targets"
112+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/IotCommands-cpp/${TARGET_DIR}"
113+
NAMESPACE AWS::
114+
COMPONENT Development)
115+
116+
configure_file("cmake/iotcommands-cpp-config.cmake"
117+
"${CMAKE_CURRENT_BINARY_DIR}/iotcommands-cpp-config.cmake"
118+
@ONLY)
119+
120+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/iotcommands-cpp-config.cmake"
121+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/IotCommands-cpp/"
122+
COMPONENT Development)
123+
124+
if(NOT CMAKE_CROSSCOMPILING)
125+
if (BUILD_TESTING AND NOT BYO_CRYPTO)
126+
add_subdirectory(tests)
127+
endif()
128+
endif()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is generated
2+
3+
include(CMakeFindDependencyMacro)
4+
5+
find_dependency(aws-crt-cpp)
6+
7+
macro(aws_load_targets type)
8+
include(${CMAKE_CURRENT_LIST_DIR}/${type}/@PROJECT_NAME@-targets.cmake)
9+
endmacro()
10+
11+
# Allow static or shared lib to be used.
12+
# If both are installed, choose based on BUILD_SHARED_LIBS.
13+
if (BUILD_SHARED_LIBS)
14+
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/shared")
15+
aws_load_targets(shared)
16+
else()
17+
aws_load_targets(static)
18+
endif()
19+
else()
20+
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/static")
21+
aws_load_targets(static)
22+
else()
23+
aws_load_targets(shared)
24+
endif()
25+
endif()
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* This file is generated
7+
*/
8+
9+
#include <aws/iotcommands/Exports.h>
10+
11+
#include <aws/crt/JsonObject.h>
12+
#include <aws/crt/StlAllocator.h>
13+
14+
namespace Aws
15+
{
16+
namespace Iotcommands
17+
{
18+
19+
/**
20+
* Sent whenever a command execution is added for a thing or a client.
21+
*
22+
*/
23+
class AWS_IOTCOMMANDS_API CommandExecutionEvent final
24+
{
25+
public:
26+
CommandExecutionEvent() = default;
27+
28+
CommandExecutionEvent(const Crt::JsonView &doc);
29+
CommandExecutionEvent &operator=(const Crt::JsonView &doc);
30+
31+
void SerializeToObject(Crt::JsonObject &doc) const;
32+
33+
/**
34+
* Opaque data containing instructions sent from the IoT commands service.
35+
*
36+
*/
37+
Aws::Crt::Optional<Aws::Crt::Vector<uint8_t>> Payload;
38+
39+
/**
40+
* Unique ID for the specific execution of a command. A command can have multiple executions, each with a
41+
* unique ID.
42+
*
43+
*/
44+
Aws::Crt::Optional<Aws::Crt::String> ExecutionId;
45+
46+
/**
47+
* Data format of the payload. It is supposed to be a MIME type (IANA media type), but can be an arbitrary
48+
* string.
49+
*
50+
*/
51+
Aws::Crt::Optional<Aws::Crt::String> ContentType;
52+
53+
/**
54+
* Number of seconds before the IoT commands service decides that this command execution is timed out.
55+
*
56+
*/
57+
Aws::Crt::Optional<int32_t> Timeout;
58+
59+
void SetExecutionId(Aws::Crt::ByteCursor value);
60+
61+
void SetPayload(Aws::Crt::ByteCursor payload);
62+
63+
void SetContentType(Aws::Crt::ByteCursor contentType);
64+
65+
void SetTimeout(int32_t messageExpiryInterval);
66+
67+
private:
68+
static void LoadFromObject(CommandExecutionEvent &obj, const Crt::JsonView &doc);
69+
};
70+
} // namespace Iotcommands
71+
} // namespace Aws
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
3+
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* This file is generated
7+
*/
8+
9+
#include <aws/iotcommands/Exports.h>
10+
11+
#include <aws/crt/StlAllocator.h>
12+
#include <aws/crt/Types.h>
13+
14+
namespace Aws
15+
{
16+
namespace Iotcommands
17+
{
18+
19+
/**
20+
* The status of the command execution.
21+
*
22+
*/
23+
enum class CommandExecutionStatus
24+
{
25+
/**
26+
* The device is currently processing the received command.
27+
*/
28+
IN_PROGRESS,
29+
30+
/**
31+
* The device successfully completed the command.
32+
*/
33+
SUCCEEDED,
34+
35+
/**
36+
* The device failed to complete the command.
37+
*/
38+
FAILED,
39+
40+
/**
41+
* The device received an invalid or incomplete request.
42+
*/
43+
REJECTED,
44+
45+
/**
46+
* When the command execution timed out, this status can be used to provide additional information in the
47+
* statusReason field in the UpdateCommandExecutionRequest request.
48+
*/
49+
TIMED_OUT,
50+
51+
};
52+
53+
namespace CommandExecutionStatusMarshaller
54+
{
55+
AWS_IOTCOMMANDS_API const char *ToString(CommandExecutionStatus val);
56+
AWS_IOTCOMMANDS_API CommandExecutionStatus FromString(const Aws::Crt::String &val);
57+
} // namespace CommandExecutionStatusMarshaller
58+
} // namespace Iotcommands
59+
} // namespace Aws
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#pragma once
2+
3+
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* This file is generated
7+
*/
8+
9+
#include <aws/iotcommands/DeviceType.h>
10+
11+
#include <aws/iotcommands/Exports.h>
12+
13+
#include <aws/crt/JsonObject.h>
14+
#include <aws/crt/StlAllocator.h>
15+
16+
namespace Aws
17+
{
18+
namespace Iotcommands
19+
{
20+
21+
/**
22+
* Data needed to subscribe to CommandExecution events.
23+
*
24+
*/
25+
class AWS_IOTCOMMANDS_API CommandExecutionsSubscriptionRequest final
26+
{
27+
public:
28+
CommandExecutionsSubscriptionRequest() = default;
29+
30+
CommandExecutionsSubscriptionRequest(const Crt::JsonView &doc);
31+
CommandExecutionsSubscriptionRequest &operator=(const Crt::JsonView &doc);
32+
33+
void SerializeToObject(Crt::JsonObject &doc) const;
34+
35+
/**
36+
* The type of a target device. Determine if the device should subscribe for commands addressed to an IoT
37+
* Thing or MQTT client.
38+
*
39+
*/
40+
Aws::Crt::Optional<Aws::Iotcommands::DeviceType> DeviceType;
41+
42+
/**
43+
* Depending on device type value, this field is either an IoT Thing name or a client ID.
44+
*
45+
*/
46+
Aws::Crt::Optional<Aws::Crt::String> DeviceId;
47+
48+
private:
49+
static void LoadFromObject(CommandExecutionsSubscriptionRequest &obj, const Crt::JsonView &doc);
50+
};
51+
} // namespace Iotcommands
52+
} // namespace Aws
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*
5+
* This file is generated
6+
*/
7+
8+
#define AWS_IOT_DEVICE_SDK_CPP_V2_IOTCOMMANDS_VERSION "@FULL_VERSION@"
9+
#define AWS_IOT_DEVICE_SDK_CPP_V2_IOTCOMMANDS_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
10+
#define AWS_IOT_DEVICE_SDK_CPP_V2_IOTCOMMANDS_VERSION_MINOR @PROJECT_VERSION_MINOR@
11+
#define AWS_IOT_DEVICE_SDK_CPP_V2_IOTCOMMANDS_VERSION_PATCH @PROJECT_VERSION_PATCH@
12+
#define AWS_IOT_DEVICE_SDK_CPP_V2_IOTCOMMANDS_GIT_HASH "@GIT_HASH@"

0 commit comments

Comments
 (0)