Skip to content

Commit ba362fc

Browse files
Gg discovery (#21)
* GG discovery updates, samples updated to latest test branch in aws-crt-cpp.
1 parent e39db14 commit ba362fc

22 files changed

+1195
-100
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ find_package(aws-crt-cpp REQUIRED)
1818

1919
add_subdirectory(jobs)
2020
add_subdirectory(shadow)
21+
add_subdirectory(discovery)
2122
add_subdirectory(samples/jobs/describe_job_execution)
2223
add_subdirectory(samples/shadow/shadow_sync)
24+
add_subdirectory(samples/greengrass/basic_discovery)
25+
2326

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ This SDK is built on the AWS Common Runtime, a collection of libraries
1313
([1](https://github.com/awslabs/aws-c-common),
1414
[2](https://github.com/awslabs/aws-c-io),
1515
[3](https://github.com/awslabs/aws-c-mqtt),
16-
[4](https://github.com/awslabs/aws-c-http)...) written in C to be
16+
[4](https://github.com/awslabs/aws-c-http),
17+
[5](https://github.com/awslabs/aws-c-cal)...) written in C to be
1718
cross-platform, high-performance, secure, and reliable. The libraries are bound
1819
to C++ by the [aws-crt-cpp](https://github.com/awslabs/aws-crt-cpp) package.
1920

@@ -30,7 +31,7 @@ is provided by code that been generated from a model of the service.
3031

3132
## Build from source
3233
```
33-
git clone --branch v0.2.0 https://github.com/awslabs/aws-crt-cpp.git
34+
git clone --branch v0.3.1 https://github.com/awslabs/aws-crt-cpp.git
3435
git clone https://github.com/awslabs/aws-iot-device-sdk-cpp-v2.git
3536
mkdir aws-crt-cpp-build
3637
cd aws-crt-cpp-build
@@ -193,6 +194,10 @@ and receive.
193194
</pre>
194195
</details>
195196

197+
## Greengrass Discovery
198+
This sample is intended for direct usage with the Greengrass tutorial found [here](https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-gs.html).
199+
200+
196201
# License
197202

198203
This library is licensed under the Apache 2.0 License.

discovery/CMakeLists.txt

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(Discovery-cpp CXX)
3+
4+
set(RUNTIME_DIRECTORY bin)
5+
6+
if (UNIX AND NOT APPLE)
7+
include(GNUInstallDirs)
8+
elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
9+
set(CMAKE_INSTALL_LIBDIR "lib")
10+
11+
if (${CMAKE_INSTALL_LIBDIR} STREQUAL "lib64")
12+
set(FIND_LIBRARY_USE_LIB64_PATHS true)
13+
endif()
14+
endif()
15+
16+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR}/cmake")
17+
18+
if (NOT CMAKE_CXX_STANDARD)
19+
set(CMAKE_CXX_STANDARD 11)
20+
endif()
21+
22+
file(GLOB AWS_DISCOVERY_HEADERS
23+
"include/aws/discovery/*.h"
24+
)
25+
26+
file(GLOB AWS_DISCOVERY_SRC
27+
"source/*.cpp"
28+
)
29+
30+
file(GLOB AWS_DISCOVERY_CPP_SRC
31+
${AWS_DISCOVERY_SRC}
32+
)
33+
34+
if (WIN32)
35+
if (MSVC)
36+
source_group("Header Files\\aws\\discovery\\" FILES ${AWS_DISCOVERY_HEADERS})
37+
38+
source_group("Source Files" FILES ${AWS_DISCOVERY_SRC})
39+
endif ()
40+
endif()
41+
42+
add_library(Discovery-cpp ${AWS_DISCOVERY_CPP_SRC})
43+
44+
set_target_properties(Discovery-cpp PROPERTIES LINKER_LANGUAGE CXX)
45+
46+
set(CMAKE_C_FLAGS_DEBUGOPT "")
47+
48+
#set warnings
49+
if (MSVC)
50+
target_compile_options(Discovery-cpp PRIVATE /W4 /WX)
51+
else ()
52+
target_compile_options(Discovery-cpp PRIVATE -Wall -Wno-long-long -pedantic -Werror)
53+
endif ()
54+
55+
if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
56+
target_compile_definitions(Discovery-cpp PRIVATE "-DDEBUG_BUILD")
57+
endif ()
58+
59+
if (BUILD_SHARED_LIBS)
60+
target_compile_definitions(Discovery-cpp PUBLIC "-DAWS_DISCOVERY_USE_IMPORT_EXPORT")
61+
target_compile_definitions(Discovery-cpp PRIVATE "-DAWS_DISCOVERY_EXPORTS")
62+
63+
install(TARGETS Discovery-cpp
64+
EXPORT Discovery-cpp-targets
65+
ARCHIVE
66+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
67+
COMPONENT Development
68+
LIBRARY
69+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
70+
NAMELINK_SKIP
71+
COMPONENT Runtime
72+
RUNTIME
73+
DESTINATION ${RUNTIME_DIRECTORY}
74+
COMPONENT Runtime)
75+
76+
install(TARGETS Discovery-cpp
77+
EXPORT Discovery-cpp-targets
78+
LIBRARY
79+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
80+
NAMELINK_ONLY
81+
COMPONENT Development)
82+
else()
83+
install(TARGETS Discovery-cpp
84+
EXPORT Discovery-cpp-targets
85+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
86+
COMPONENT Development)
87+
endif()
88+
89+
target_include_directories(Discovery-cpp PUBLIC
90+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
91+
$<INSTALL_INTERFACE:include>)
92+
93+
if (NOT IS_SUBDIRECTORY_INCLUDE)
94+
find_package(aws-crt-cpp REQUIRED)
95+
endif()
96+
97+
target_link_libraries(Discovery-cpp AWS::aws-crt-cpp)
98+
99+
install(FILES ${AWS_DISCOVERY_HEADERS} DESTINATION "include/aws/discovery/" COMPONENT Development)
100+
101+
102+
install(EXPORT "Discovery-cpp-targets"
103+
DESTINATION "lib/Discovery-cpp/cmake/"
104+
NAMESPACE AWS::)
105+
106+
configure_file("cmake/Discovery-cpp-config.cmake"
107+
"${CMAKE_CURRENT_BINARY_DIR}/Discovery-cpp-config.cmake"
108+
@ONLY)
109+
110+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Discovery-cpp-config.cmake"
111+
DESTINATION "lib/Discovery-cpp/cmake/"
112+
COMPONENT Development)
113+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include(CMakeFindDependencyMacro)
2+
3+
find_dependency(aws-crt-cpp)
4+
5+
include(${CMAKE_CURRENT_LIST_DIR}/Discovery-cpp-targets.cmake)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
#include <aws/crt/JsonObject.h>
18+
19+
#include <aws/discovery/Exports.h>
20+
21+
#include <aws/crt/JsonObject.h>
22+
#include <aws/crt/StlAllocator.h>
23+
24+
namespace Aws
25+
{
26+
namespace Discovery
27+
{
28+
class AWS_DISCOVERY_API ConnectivityInfo final
29+
{
30+
public:
31+
ConnectivityInfo() = default;
32+
33+
ConnectivityInfo(const Crt::JsonView &doc);
34+
ConnectivityInfo &operator=(const Crt::JsonView &doc);
35+
36+
Aws::Crt::Optional<Aws::Crt::String> ID;
37+
Aws::Crt::Optional<Aws::Crt::String> HostAddress;
38+
Aws::Crt::Optional<Aws::Crt::String> Metadata;
39+
Aws::Crt::Optional<uint16_t> Port;
40+
41+
private:
42+
static void LoadFromObject(ConnectivityInfo &obj, const Crt::JsonView &doc);
43+
};
44+
} // namespace Discovery
45+
} // namespace Aws
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
#include <aws/discovery/GGGroup.h>
18+
19+
namespace Aws
20+
{
21+
namespace Discovery
22+
{
23+
class AWS_DISCOVERY_API DiscoverResponse final
24+
{
25+
public:
26+
DiscoverResponse() = default;
27+
28+
DiscoverResponse(const Crt::JsonView &doc);
29+
DiscoverResponse &operator=(const Crt::JsonView &doc);
30+
31+
Aws::Crt::Optional<Aws::Crt::Vector<GGGroup>> GGGroups;
32+
33+
private:
34+
static void LoadFromObject(DiscoverResponse &obj, const Crt::JsonView &doc);
35+
};
36+
} // namespace Discovery
37+
} // namespace Aws
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
#include <aws/discovery/DiscoverResponse.h>
18+
19+
#include <aws/crt/http/HttpConnectionManager.h>
20+
21+
namespace Aws
22+
{
23+
namespace Discovery
24+
{
25+
using OnDiscoverResponse = std::function<void(DiscoverResponse *, int errorCode, int httpResponseCode)>;
26+
27+
struct DiscoveryClientConfig
28+
{
29+
DiscoveryClientConfig() noexcept;
30+
Crt::Allocator *allocator;
31+
Crt::Io::ClientBootstrap *bootstrap;
32+
Crt::Io::TlsContext *tlsContext;
33+
Crt::Io::SocketOptions *socketOptions;
34+
Crt::String region;
35+
size_t maxConnections;
36+
// TODO: when supported add proxy configuration.
37+
};
38+
39+
class DiscoveryClient final
40+
{
41+
public:
42+
DiscoveryClient(const DiscoveryClientConfig &) noexcept;
43+
44+
bool Discover(const Crt::String &thingName, const OnDiscoverResponse &onDiscoverResponse) noexcept;
45+
46+
private:
47+
std::shared_ptr<Crt::Http::HttpClientConnectionManager> m_connectionManager;
48+
Crt::String m_hostName;
49+
Crt::Allocator *m_allocator;
50+
};
51+
} // namespace Discovery
52+
} // namespace Aws
53+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
18+
#if defined(AWS_DISCOVERY_USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32)
19+
# ifdef AWS_DISCOVERY_USE_IMPORT_EXPORT
20+
# ifdef AWS_DISCOVERY_EXPORTS
21+
# define AWS_DISCOVERY_API __declspec(dllexport)
22+
# else
23+
# define AWS_DISCOVERY_API __declspec(dllimport)
24+
# endif /* AWS_DISCOVERY_EXPORTS */
25+
# else
26+
# define AWS_DISCOVERY_API
27+
# endif /* AWS_DISCOVERY_USE_IMPORT_EXPORT */
28+
29+
#else /* defined (AWS_DISCOVERY_USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */
30+
# define AWS_DISCOVERY_API
31+
#endif /* defined (AWS_DISCOVERY_USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
#include <aws/discovery/ConnectivityInfo.h>
18+
19+
namespace Aws
20+
{
21+
namespace Discovery
22+
{
23+
class AWS_DISCOVERY_API GGCore final
24+
{
25+
public:
26+
GGCore() = default;
27+
28+
GGCore(const Crt::JsonView &doc);
29+
GGCore &operator=(const Crt::JsonView &doc);
30+
31+
Aws::Crt::Optional<Aws::Crt::String> ThingArn;
32+
Aws::Crt::Optional<Aws::Crt::Vector<ConnectivityInfo>> Connectivity;
33+
34+
private:
35+
static void LoadFromObject(GGCore &obj, const Crt::JsonView &doc);
36+
};
37+
} // namespace Discovery
38+
} // namespace Aws

0 commit comments

Comments
 (0)