Skip to content

Gg discovery #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ find_package(aws-crt-cpp REQUIRED)

add_subdirectory(jobs)
add_subdirectory(shadow)
add_subdirectory(discovery)
add_subdirectory(samples/jobs/describe_job_execution)
add_subdirectory(samples/shadow/shadow_sync)
add_subdirectory(samples/greengrass/basic_discovery)


9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ This SDK is built on the AWS Common Runtime, a collection of libraries
([1](https://github.com/awslabs/aws-c-common),
[2](https://github.com/awslabs/aws-c-io),
[3](https://github.com/awslabs/aws-c-mqtt),
[4](https://github.com/awslabs/aws-c-http)...) written in C to be
[4](https://github.com/awslabs/aws-c-http),
[5](https://github.com/awslabs/aws-c-cal)...) written in C to be
cross-platform, high-performance, secure, and reliable. The libraries are bound
to C++ by the [aws-crt-cpp](https://github.com/awslabs/aws-crt-cpp) package.

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

## Build from source
```
git clone --branch v0.2.0 https://github.com/awslabs/aws-crt-cpp.git
git clone --branch v0.3.0 https://github.com/awslabs/aws-crt-cpp.git
git clone https://github.com/awslabs/aws-iot-device-sdk-cpp-v2.git
mkdir aws-crt-cpp-build
cd aws-crt-cpp-build
Expand Down Expand Up @@ -193,6 +194,10 @@ and receive.
</pre>
</details>

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


# License

This library is licensed under the Apache 2.0 License.
113 changes: 113 additions & 0 deletions discovery/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
cmake_minimum_required(VERSION 3.1)
project(Discovery-cpp CXX)

set(RUNTIME_DIRECTORY bin)

if (UNIX AND NOT APPLE)
include(GNUInstallDirs)
elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")

if (${CMAKE_INSTALL_LIBDIR} STREQUAL "lib64")
set(FIND_LIBRARY_USE_LIB64_PATHS true)
endif()
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR}/cmake")

if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

file(GLOB AWS_DISCOVERY_HEADERS
"include/aws/discovery/*.h"
)

file(GLOB AWS_DISCOVERY_SRC
"source/*.cpp"
)

file(GLOB AWS_DISCOVERY_CPP_SRC
${AWS_DISCOVERY_SRC}
)

if (WIN32)
if (MSVC)
source_group("Header Files\\aws\\discovery\\" FILES ${AWS_DISCOVERY_HEADERS})

source_group("Source Files" FILES ${AWS_DISCOVERY_SRC})
endif ()
endif()

add_library(Discovery-cpp ${AWS_DISCOVERY_CPP_SRC})

set_target_properties(Discovery-cpp PROPERTIES LINKER_LANGUAGE CXX)

set(CMAKE_C_FLAGS_DEBUGOPT "")

#set warnings
if (MSVC)
target_compile_options(Discovery-cpp PRIVATE /W4 /WX)
else ()
target_compile_options(Discovery-cpp PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(Discovery-cpp PRIVATE "-DDEBUG_BUILD")
endif ()

if (BUILD_SHARED_LIBS)
target_compile_definitions(Discovery-cpp PUBLIC "-DAWS_DISCOVERY_USE_IMPORT_EXPORT")
target_compile_definitions(Discovery-cpp PRIVATE "-DAWS_DISCOVERY_EXPORTS")

install(TARGETS Discovery-cpp
EXPORT Discovery-cpp-targets
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_SKIP
COMPONENT Runtime
RUNTIME
DESTINATION ${RUNTIME_DIRECTORY}
COMPONENT Runtime)

install(TARGETS Discovery-cpp
EXPORT Discovery-cpp-targets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT Development)
else()
install(TARGETS Discovery-cpp
EXPORT Discovery-cpp-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development)
endif()

target_include_directories(Discovery-cpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

if (NOT IS_SUBDIRECTORY_INCLUDE)
find_package(aws-crt-cpp REQUIRED)
endif()

target_link_libraries(Discovery-cpp AWS::aws-crt-cpp)

install(FILES ${AWS_DISCOVERY_HEADERS} DESTINATION "include/aws/discovery/" COMPONENT Development)


install(EXPORT "Discovery-cpp-targets"
DESTINATION "lib/Discovery-cpp/cmake/"
NAMESPACE AWS::)

configure_file("cmake/Discovery-cpp-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Discovery-cpp-config.cmake"
@ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Discovery-cpp-config.cmake"
DESTINATION "lib/Discovery-cpp/cmake/"
COMPONENT Development)

5 changes: 5 additions & 0 deletions discovery/cmake/Discovery-cpp-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include(CMakeFindDependencyMacro)

find_dependency(aws-crt-cpp)

include(${CMAKE_CURRENT_LIST_DIR}/Discovery-cpp-targets.cmake)
45 changes: 45 additions & 0 deletions discovery/include/aws/discovery/ConnectivityInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.

* This file is generated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most files say This file is generated
Is that a copy/paste error, are these being generated from somewhere?
Or are these files just something that we aspire to generate someday

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these aren't generated.

*/
#include <aws/crt/JsonObject.h>

#include <aws/discovery/Exports.h>

#include <aws/crt/JsonObject.h>
#include <aws/crt/StlAllocator.h>

namespace Aws
{
namespace Discovery
{
class AWS_DISCOVERY_API ConnectivityInfo final
{
public:
ConnectivityInfo() = default;

ConnectivityInfo(const Crt::JsonView &doc);
ConnectivityInfo &operator=(const Crt::JsonView &doc);

Aws::Crt::Optional<Aws::Crt::String> ID;
Aws::Crt::Optional<Aws::Crt::String> HostAddress;
Aws::Crt::Optional<Aws::Crt::String> Metadata;
Aws::Crt::Optional<uint16_t> Port;

private:
static void LoadFromObject(ConnectivityInfo &obj, const Crt::JsonView &doc);
};
} // namespace Discovery
} // namespace Aws
37 changes: 37 additions & 0 deletions discovery/include/aws/discovery/DiscoverResponse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.

* This file is generated
*/
#include <aws/discovery/GGGroup.h>

namespace Aws
{
namespace Discovery
{
class AWS_DISCOVERY_API DiscoverResponse final
{
public:
DiscoverResponse() = default;

DiscoverResponse(const Crt::JsonView &doc);
DiscoverResponse &operator=(const Crt::JsonView &doc);

Aws::Crt::Optional<Aws::Crt::Vector<GGGroup>> GGGroups;

private:
static void LoadFromObject(DiscoverResponse &obj, const Crt::JsonView &doc);
};
} // namespace Discovery
} // namespace Aws
52 changes: 52 additions & 0 deletions discovery/include/aws/discovery/DiscoveryClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.

* This file is generated
*/
#include <aws/discovery/DiscoverResponse.h>

#include <aws/crt/http/HttpConnectionManager.h>

namespace Aws
{
namespace Discovery
{
using OnDiscoverResponse = std::function<void(DiscoverResponse *, int errorCode, int httpResponseCode)>;

struct DiscoveryClientConfig
{
DiscoveryClientConfig() noexcept;
Crt::Allocator *allocator;
Crt::Io::ClientBootstrap *bootstrap;
Crt::Io::TlsContext *tlsContext;
Crt::Io::SocketOptions *socketOptions;
Crt::String region;
size_t maxConnections;
// TODO: when supported add proxy configuration.
};

class DiscoveryClient final
{
public:
DiscoveryClient(const DiscoveryClientConfig &) noexcept;

bool Discover(const Crt::String &thingName, const OnDiscoverResponse &onDiscoverResponse) noexcept;

private:
std::shared_ptr<Crt::Http::HttpClientConnectionManager> m_connectionManager;
Crt::String m_hostName;
Crt::Allocator *m_allocator;
};
} // namespace Discovery
} // namespace Aws
31 changes: 31 additions & 0 deletions discovery/include/aws/discovery/Exports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.

* This file is generated
*/

#if defined(AWS_DISCOVERY_USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32)
# ifdef AWS_DISCOVERY_USE_IMPORT_EXPORT
# ifdef AWS_DISCOVERY_EXPORTS
# define AWS_DISCOVERY_API __declspec(dllexport)
# else
# define AWS_DISCOVERY_API __declspec(dllimport)
# endif /* AWS_DISCOVERY_EXPORTS */
# else
# define AWS_DISCOVERY_API
# endif /* AWS_DISCOVERY_USE_IMPORT_EXPORT */

#else /* defined (AWS_DISCOVERY_USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */
# define AWS_DISCOVERY_API
#endif /* defined (AWS_DISCOVERY_USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */
38 changes: 38 additions & 0 deletions discovery/include/aws/discovery/GGCore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.

* This file is generated
*/
#include <aws/discovery/ConnectivityInfo.h>

namespace Aws
{
namespace Discovery
{
class AWS_DISCOVERY_API GGCore final
{
public:
GGCore() = default;

GGCore(const Crt::JsonView &doc);
GGCore &operator=(const Crt::JsonView &doc);

Aws::Crt::Optional<Aws::Crt::String> ThingArn;
Aws::Crt::Optional<Aws::Crt::Vector<ConnectivityInfo>> Connectivity;

private:
static void LoadFromObject(GGCore &obj, const Crt::JsonView &doc);
};
} // namespace Discovery
} // namespace Aws
Loading