Skip to content

Commit 395a1a9

Browse files
Initial work on mqtt bindings for cpp, a sample app, and a simple test setup. We still need unit tests that hit a local mqtt endpoint.
1 parent e135f60 commit 395a1a9

File tree

16 files changed

+1621
-0
lines changed

16 files changed

+1621
-0
lines changed

CMakeLists.txt

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(aws-crt-cpp CXX)
3+
4+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")
5+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
6+
7+
if (NOT CMAKE_CXX_STANDARD)
8+
set(CMAKE_CXX_STANDARD 11)
9+
endif()
10+
11+
file(GLOB AWS_CRT_HEADERS
12+
"include/aws/crt/*.h"
13+
)
14+
15+
file(GLOB AWS_CRT_IO_HEADERS
16+
"include/aws/crt/io/*.h"
17+
)
18+
19+
file(GLOB AWS_CRT_MQTT_HEADERS
20+
"include/aws/crt/mqtt/*.h"
21+
)
22+
23+
file(GLOB AWS_CRT_CPP_HEADERS
24+
${AWS_CRT_HEADERS}
25+
${AWS_CRT_IO_HEADERS}
26+
${AWS_CRT_MQTT_HEADERS}
27+
)
28+
29+
file(GLOB AWS_CRT_SRC
30+
"source/*.cpp"
31+
)
32+
33+
file (GLOB AWS_CRT_IO_SRC
34+
"source/io/*.cpp"
35+
)
36+
37+
file (GLOB AWS_CRT_MQTT_SRC
38+
"source/mqtt/*.cpp"
39+
)
40+
41+
file(GLOB AWS_CRT_CPP_SRC
42+
${AWS_CRT_SRC}
43+
${AWS_CRT_IO_SRC}
44+
${AWS_CRT_MQTT_SRC}
45+
)
46+
47+
if (WIN32)
48+
if (MSVC)
49+
source_group("Header Files\\aws\\crt" FILES ${AWS_CRT_HEADERS})
50+
source_group("Header Files\\aws\\crt\\io" FILES ${AWS_CRT_IO_HEADERS})
51+
source_group("Header Files\\aws\\crt\\mqtt" FILES ${AWS_CRT_MQTT_HEADERS})
52+
source_group("Source Files" FILES ${AWS_CRT_SRC})
53+
source_group("Source Files\\io" FILES ${AWS_CRT_IO_SRC})
54+
source_group("Source Files\\mqtt" FILES ${AWS_CRT_MQTT_SRC})
55+
endif ()
56+
endif()
57+
58+
add_library(${CMAKE_PROJECT_NAME} ${AWS_CRT_CPP_SRC})
59+
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
60+
61+
set(CMAKE_C_FLAGS_DEBUGOPT "")
62+
63+
#set warnings
64+
if (MSVC)
65+
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE /W4 /WX)
66+
else ()
67+
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
68+
endif ()
69+
70+
if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
71+
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "-DDEBUG_BUILD")
72+
endif ()
73+
74+
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
75+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
76+
$<INSTALL_INTERFACE:include>)
77+
78+
find_package(aws-c-common REQUIRED)
79+
find_package(aws-c-io REQUIRED)
80+
81+
if (UNIX AND NOT APPLE)
82+
find_package(s2n REQUIRED)
83+
endif()
84+
85+
find_package(aws-c-mqtt REQUIRED)
86+
target_link_libraries(${CMAKE_PROJECT_NAME} AWS::aws-c-common aws-c-io aws-c-mqtt ${PLATFORM_LIBS})
87+
88+
install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt")
89+
install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "include/aws/crt/io")
90+
install(FILES ${AWS_CRT_MQTT_HEADERS} DESTINATION "include/aws/crt/mqtt")
91+
92+
93+
install(
94+
TARGETS ${CMAKE_PROJECT_NAME} EXPORT ${CMAKE_PROJECT_NAME}-config
95+
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
96+
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
97+
COMPONENT library
98+
)
99+
100+
export(TARGETS ${CMAKE_PROJECT_NAME} FILE ${CMAKE_PROJECT_NAME}-config.cmake)
101+
install(EXPORT ${CMAKE_PROJECT_NAME}-config DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_PROJECT_NAME}/cmake/")
102+
103+
enable_testing()
104+
add_subdirectory(tests)
105+
add_subdirectory(samples/mqtt_pub_sub)
106+

include/aws/crt/Api.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
/*
3+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
#include <aws/crt/Types.h>
17+
#include <aws/crt/io/EventLoopGroup.h>
18+
#include <aws/crt/io/TLSOptions.h>
19+
#include <aws/crt/mqtt/MqttClient.h>
20+
21+
#include <aws/io/socket.h>
22+
23+
namespace Aws
24+
{
25+
namespace Crt
26+
{
27+
class AWS_CRT_CPP_API ApiHandle
28+
{
29+
public:
30+
ApiHandle(Allocator* allocator) noexcept;
31+
ApiHandle() noexcept;
32+
~ApiHandle();
33+
ApiHandle(const ApiHandle&) = delete;
34+
ApiHandle(ApiHandle&&) = delete;
35+
ApiHandle& operator =(const ApiHandle&) = delete;
36+
ApiHandle& operator =(ApiHandle&&) = delete;
37+
};
38+
39+
AWS_CRT_CPP_API Allocator* DefaultAllocator() noexcept;
40+
AWS_CRT_CPP_API void LoadErrorStrings() noexcept;
41+
AWS_CRT_CPP_API const char* ErrorDebugString(int error) noexcept;
42+
43+
AWS_CRT_CPP_API ByteBuf ByteBufFromCString(const char* str) noexcept;
44+
AWS_CRT_CPP_API ByteBuf ByteBufFromArray(const uint8_t *array, size_t len) noexcept;
45+
46+
}
47+
}

include/aws/crt/Exports.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
/*
4+
*Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
*icensed under the Apache License, Version 2.0 (the "License").
7+
*You may not use this file except in compliance with the License.
8+
*A copy of the License is located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed
13+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
#if defined(USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32)
19+
# ifdef USE_IMPORT_EXPORT
20+
# ifdef AWS_CRT_CPP_EXPORTS
21+
# define AWS_CRT_CPP_API __declspec(dllexport)
22+
# else
23+
# define AWS_CRT_CPP_API __declspec(dllimport)
24+
# endif /* AWS_CRT_CPP_API */
25+
# else
26+
# define AWS_CRT_CPP_API
27+
# endif // USE_IMPORT_EXPORT
28+
29+
#else // defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32)
30+
# define AWS_CRT_CPP_API
31+
#endif // defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32)

include/aws/crt/Types.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
/*
3+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
#include <aws/mqtt/mqtt.h>
17+
18+
struct aws_allocator;
19+
struct aws_byte_buf;
20+
struct aws_byte_cursor;
21+
struct aws_socket_options;
22+
23+
namespace Aws
24+
{
25+
namespace Crt
26+
{
27+
using Allocator = aws_allocator;
28+
using ByteBuf = aws_byte_buf;
29+
using ByteCursor = aws_byte_cursor;
30+
31+
namespace Io
32+
{
33+
using SocketOptions = aws_socket_options;
34+
}
35+
36+
namespace Mqtt
37+
{
38+
using QOS = aws_mqtt_qos;
39+
using ReturnCode = aws_mqtt_connect_return_code;
40+
}
41+
}
42+
}

include/aws/crt/io/EventLoopGroup.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#pragma once
2+
/*
3+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
#include <aws/io/event_loop.h>
17+
18+
#include <aws/crt/Exports.h>
19+
20+
namespace Aws
21+
{
22+
namespace Crt
23+
{
24+
namespace Io
25+
{
26+
/**
27+
* A collection of event loops, this is used by all APIs that need to
28+
* do any IO. The number of threads used depends on your use-case. IF you
29+
* have a maximum of less than a few hundred connections 1 thread is the ideal
30+
* threadCount.
31+
*
32+
* There should only be one instance of an EventLoopGroup per application and it
33+
* should be passed to all network clients. One exception to this is if you
34+
* want to peg different types of IO to different threads. In that case, you
35+
* may want to have one event loop group dedicated to one IO activity and another
36+
* dedicated to another type.
37+
*/
38+
class AWS_CRT_CPP_API EventLoopGroup final
39+
{
40+
public:
41+
EventLoopGroup() noexcept;
42+
EventLoopGroup(uint16_t threadCount) noexcept;
43+
EventLoopGroup(aws_allocator* allocator, uint16_t threadCount) noexcept;
44+
~EventLoopGroup();
45+
EventLoopGroup(const EventLoopGroup&) = delete;
46+
EventLoopGroup(EventLoopGroup&&) noexcept;
47+
EventLoopGroup&operator =(const EventLoopGroup&) = delete;
48+
EventLoopGroup&operator =(EventLoopGroup&&) noexcept;
49+
50+
operator bool() const;
51+
int LastError() const;
52+
53+
const aws_event_loop_group *GetUnderlyingHandle() const;
54+
55+
private:
56+
aws_event_loop_group m_eventLoopGroup;
57+
int m_lastError;
58+
};
59+
}
60+
61+
}
62+
}
63+
64+
65+
66+

include/aws/crt/io/TLSOptions.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
/*
3+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
#include <aws/crt/Exports.h>
18+
#include <aws/crt/Types.h>
19+
20+
#include <aws/io/tls_channel_handler.h>
21+
22+
struct aws_tls_ctx_options;
23+
24+
namespace Aws
25+
{
26+
namespace Crt
27+
{
28+
namespace Io
29+
{
30+
using TLSCtxOptions = aws_tls_ctx_options;
31+
32+
AWS_CRT_CPP_API void InitDefaultClient(TLSCtxOptions& options) noexcept;
33+
AWS_CRT_CPP_API void InitClientWithMTLS(TLSCtxOptions& options,
34+
const char* cert_path, const char* pkey_path) noexcept;
35+
AWS_CRT_CPP_API void InitClientWithMTLSPkcs12(TLSCtxOptions& options,
36+
const char* pkcs12_path, const char* pkcs12_pwd) noexcept;
37+
AWS_CRT_CPP_API void SetALPNList(TLSCtxOptions& options, const char* alpn_list) noexcept;
38+
AWS_CRT_CPP_API void SetVerifyPeer(TLSCtxOptions& options, bool verify_peer) noexcept;
39+
AWS_CRT_CPP_API void OverrideDefaultTrustStore(TLSCtxOptions& options,
40+
const char* caPath, const char* caFile) noexcept;
41+
42+
AWS_CRT_CPP_API void InitTLSStaticState(Allocator* alloc) noexcept;
43+
AWS_CRT_CPP_API void CleanUpTLSStaticState() noexcept;
44+
45+
AWS_CRT_CPP_API bool IsALPNSupported() noexcept;
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)