Skip to content

Commit efbdf20

Browse files
Addressed PR feedback, still a bit more to go.
1 parent 21ad975 commit efbdf20

20 files changed

+388
-225
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ if (WIN32)
5555
endif()
5656

5757
add_library(${CMAKE_PROJECT_NAME} ${AWS_CRT_CPP_SRC})
58+
59+
if (BUILD_SHARED_LIBS AND WIN32)
60+
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC -DUSE_IMPORT_EXPORT)
61+
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE -DAWS_CRT_CPP_EXPORTS)
62+
endif()
63+
5864
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
5965

6066
set(CMAKE_C_FLAGS_DEBUGOPT "")
@@ -102,4 +108,3 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config.cmake"
102108
enable_testing()
103109
add_subdirectory(tests)
104110
add_subdirectory(samples/mqtt_pub_sub)
105-

include/aws/crt/Api.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* permissions and limitations under the License.
1515
*/
1616
#include <aws/crt/Types.h>
17-
#include <aws/crt/Exports.h>
18-
19-
#include <aws/io/socket.h>
17+
#include <aws/crt/io/Bootstrap.h>
18+
#include <aws/crt/io/EventLoopGroup.h>
19+
#include <aws/crt/io/TlsOptions.h>
20+
#include <aws/crt/mqtt/MqttClient.h>
2021

2122
namespace Aws
2223
{
@@ -34,12 +35,7 @@ namespace Aws
3435
ApiHandle& operator =(ApiHandle&&) = delete;
3536
};
3637

37-
AWS_CRT_CPP_API Allocator* DefaultAllocator() noexcept;
3838
AWS_CRT_CPP_API void LoadErrorStrings() noexcept;
3939
AWS_CRT_CPP_API const char* ErrorDebugString(int error) noexcept;
40-
41-
AWS_CRT_CPP_API ByteBuf ByteBufFromCString(const char* str) noexcept;
42-
AWS_CRT_CPP_API ByteBuf ByteBufFromArray(const uint8_t *array, size_t len) noexcept;
43-
4440
}
45-
}
41+
}

include/aws/crt/Types.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
* express or implied. See the License for the specific language governing
1414
* permissions and limitations under the License.
1515
*/
16+
#include <aws/crt/Exports.h>
17+
18+
#include <aws/common/common.h>
1619
#include <aws/mqtt/mqtt.h>
20+
#include <aws/io/socket.h>
1721

1822
struct aws_allocator;
1923
struct aws_byte_buf;
@@ -28,6 +32,10 @@ namespace Aws
2832
using ByteBuf = aws_byte_buf;
2933
using ByteCursor = aws_byte_cursor;
3034

35+
AWS_CRT_CPP_API Allocator* DefaultAllocator() noexcept;
36+
AWS_CRT_CPP_API ByteBuf ByteBufFromCString(const char* str) noexcept;
37+
AWS_CRT_CPP_API ByteBuf ByteBufFromArray(const uint8_t *array, size_t len) noexcept;
38+
3139
namespace Io
3240
{
3341
using SocketOptions = aws_socket_options;
@@ -39,4 +47,4 @@ namespace Aws
3947
using ReturnCode = aws_mqtt_connect_return_code;
4048
}
4149
}
42-
}
50+
}

include/aws/crt/io/Bootstrap.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414
* permissions and limitations under the License.
1515
*/
1616

17-
#include <aws/crt/Api.h>
1817
#include <aws/crt/Exports.h>
1918
#include <aws/crt/Types.h>
2019
#include <aws/crt/io/EventLoopGroup.h>
2120

2221
#include <aws/io/channel_bootstrap.h>
2322

24-
class EventLoopGroup;
25-
2623
namespace Aws
2724
{
2825
namespace Crt
@@ -40,8 +37,8 @@ namespace Aws
4037
ClientBootstrap(ClientBootstrap&&) noexcept;
4138
ClientBootstrap& operator=(ClientBootstrap&&) noexcept;
4239

43-
operator bool() noexcept;
44-
int LastError() noexcept;
40+
operator bool() const noexcept;
41+
int LastError() const noexcept;
4542

4643
const aws_client_bootstrap* GetUnderlyingHandle() const;
4744
private:

include/aws/crt/io/EventLoopGroup.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
* express or implied. See the License for the specific language governing
1414
* permissions and limitations under the License.
1515
*/
16-
#include <aws/crt/Api.h>
16+
#include <aws/crt/Types.h>
1717

1818
#include <aws/io/event_loop.h>
19-
#include <aws/crt/Exports.h>
2019

2120
namespace Aws
2221
{
@@ -44,8 +43,8 @@ namespace Aws
4443
~EventLoopGroup();
4544
EventLoopGroup(const EventLoopGroup&) = delete;
4645
EventLoopGroup(EventLoopGroup&&) noexcept;
47-
EventLoopGroup&operator =(const EventLoopGroup&) = delete;
48-
EventLoopGroup&operator =(EventLoopGroup&&) noexcept;
46+
EventLoopGroup& operator =(const EventLoopGroup&) = delete;
47+
EventLoopGroup& operator =(EventLoopGroup&&) noexcept;
4948

5049
operator bool() const;
5150
int LastError() const;

include/aws/crt/io/TLSOptions.h

Lines changed: 0 additions & 76 deletions
This file was deleted.

include/aws/crt/io/TlsOptions.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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/Types.h>
18+
19+
#include <aws/io/tls_channel_handler.h>
20+
21+
struct aws_tls_ctx_options;
22+
23+
namespace Aws
24+
{
25+
namespace Crt
26+
{
27+
namespace Io
28+
{
29+
using TlsContextOptions = aws_tls_ctx_options;
30+
using TlsConnectionOptions = aws_tls_connection_options;
31+
32+
enum class TLSMode
33+
{
34+
CLIENT,
35+
SERVER,
36+
};
37+
38+
class AWS_CRT_CPP_API TlsContext final
39+
{
40+
public:
41+
TlsContext(TlsContextOptions& options, TLSMode mode, Allocator* allocator = DefaultAllocator()) noexcept;
42+
~TlsContext();
43+
TlsContext(const TlsContext&) = delete;
44+
TlsContext& operator=(const TlsContext&) = delete;
45+
TlsContext(TlsContext&&) noexcept;
46+
TlsContext& operator=(TlsContext&&) noexcept;
47+
48+
TlsConnectionOptions NewConnectionOptions() const noexcept;
49+
50+
operator bool() const noexcept;
51+
int LastError() const noexcept;
52+
53+
private:
54+
aws_tls_ctx* m_ctx;
55+
int m_lastError;
56+
};
57+
58+
AWS_CRT_CPP_API void InitDefaultClient(TlsContextOptions& options) noexcept;
59+
AWS_CRT_CPP_API void InitClientWithMtls(TlsContextOptions &options,
60+
const char *cert_path, const char *pkey_path) noexcept;
61+
AWS_CRT_CPP_API void InitClientWithMtlsPkcs12(TlsContextOptions &options,
62+
const char *pkcs12_path, const char *pkcs12_pwd) noexcept;
63+
AWS_CRT_CPP_API void SetALPNList(TlsContextOptions& options, const char* alpn_list) noexcept;
64+
AWS_CRT_CPP_API void SetVerifyPeer(TlsContextOptions& options, bool verify_peer) noexcept;
65+
AWS_CRT_CPP_API void OverrideDefaultTrustStore(TlsContextOptions& options,
66+
const char* caPath, const char* caFile) noexcept;
67+
68+
AWS_CRT_CPP_API void InitTlsStaticState(Allocator *alloc) noexcept;
69+
AWS_CRT_CPP_API void CleanUpTlsStaticState() noexcept;
70+
71+
AWS_CRT_CPP_API bool IsAlpnSupported() noexcept;
72+
}
73+
}
74+
}

include/aws/crt/mqtt/MqttClient.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
#include <aws/crt/Exports.h>
1717
#include <aws/crt/Types.h>
1818

19-
#include <aws/crt/io/TLSOptions.h>
19+
#include <aws/crt/io/TlsOptions.h>
2020
#include <aws/mqtt/client.h>
2121

2222
#include <functional>
2323
#include <memory>
24-
#include <string>
2524

2625
namespace Aws
2726
{
@@ -51,13 +50,13 @@ namespace Aws
5150
/**
5251
* Invoked when a disconnect message has been sent.
5352
*/
54-
using OnDisconnectHandler = std::function<void(MqttConnection& connection)>;
53+
using OnDisconnectHandler = std::function<bool(MqttConnection& connection)>;
5554

5655
/**
5756
* Invoked upon receipt of a Publish message on a subscribed topic.
5857
*/
5958
using OnPublishReceivedHandler = std::function<void(MqttConnection& connection,
60-
const std::string& topic, const ByteBuf& payload)>;
59+
const ByteBuf& topic, const ByteBuf& payload)>;
6160
using OnOperationCompleteHandler = std::function<void(MqttConnection& connection, uint16_t packetId)>;
6261

6362
/**
@@ -95,20 +94,20 @@ namespace Aws
9594
/**
9695
* Sets LastWill for the connection. The memory backing payload must outlive the connection.
9796
*/
98-
void SetWill(const std::string& topic, QOS qos, bool retain,
97+
void SetWill(const char* topic, QOS qos, bool retain,
9998
const ByteBuf& payload) noexcept;
10099

101100
/**
102101
* Sets login credentials for the connection. The must get set before the Connect call
103102
* if it is to be used.
104103
*/
105-
void SetLogin(const std::string& userName, const std::string& password) noexcept;
104+
void SetLogin(const char* userName, const char* password) noexcept;
106105

107106
/**
108107
* Initiates the connection, OnConnectionFailedHandler and/or OnConnAckHandler will
109108
* be invoked in an event-loop thread.
110109
*/
111-
void Connect(const std::string& clientId, bool cleanSession, uint16_t keepAliveTime) noexcept;
110+
void Connect(const char* clientId, bool cleanSession, uint16_t keepAliveTime) noexcept;
112111

113112
/**
114113
* Initiates disconnect, OnDisconnectHandler will be invoked in an event-loop thread.
@@ -120,22 +119,22 @@ namespace Aws
120119
* thread upon an incoming Publish message. OnOperationCompleteHandler will be invoked
121120
* upon receipt of a suback message.
122121
*/
123-
uint16_t Subscribe(const std::string& topicFilter, QOS qos,
122+
uint16_t Subscribe(const char* topicFilter, QOS qos,
124123
OnPublishReceivedHandler&& onPublish,
125124
OnOperationCompleteHandler&& onOpComplete) noexcept;
126125

127126
/**
128127
* Unsubscribes from topicFilter. OnOperationCompleteHandler will be invoked upon receipt of
129128
* an unsuback message.
130129
*/
131-
uint16_t Unsubscribe(const std::string& topicFilter,
130+
uint16_t Unsubscribe(const char* topicFilter,
132131
OnOperationCompleteHandler&& onOpComplete) noexcept;
133132

134133
/**
135134
* Publishes to topic. The backing memory for payload must stay available until the
136135
* OnOperationCompleteHandler has been invoked.
137136
*/
138-
uint16_t Publish(const std::string& topic, QOS qos, bool retain, const ByteBuf& payload,
137+
uint16_t Publish(const char* topic, QOS qos, bool retain, const ByteBuf& payload,
139138
OnOperationCompleteHandler&& onOpComplete) noexcept;
140139

141140
/**
@@ -144,9 +143,9 @@ namespace Aws
144143
void Ping();
145144

146145
private:
147-
MqttConnection(MqttClient* client, const std::string& hostName, uint16_t port,
146+
MqttConnection(MqttClient* client, const char* hostName, uint16_t port,
148147
const Io::SocketOptions& socketOptions,
149-
Io::TlSConnectionOptions&& tlsConnOptions) noexcept;
148+
Io::TlsConnectionOptions&& tlsConnOptions) noexcept;
150149

151150
MqttClient *m_owningClient;
152151
aws_mqtt_client_connection *m_underlyingConnection;
@@ -162,7 +161,7 @@ namespace Aws
162161
enum aws_mqtt_connect_return_code return_code,
163162
bool session_present,
164163
void* user_data);
165-
static void s_onDisconnect(aws_mqtt_client_connection* connection, int errorCode, void* userData);
164+
static bool s_onDisconnect(aws_mqtt_client_connection* connection, int errorCode, void* userData);
166165
static void s_onPublish(aws_mqtt_client_connection*connection,
167166
const aws_byte_cursor* topic,
168167
const aws_byte_cursor* payload,
@@ -196,8 +195,8 @@ namespace Aws
196195
* Create a new connection object from the client. The client must outlive
197196
* all of its connection instances.
198197
*/
199-
MqttConnection NewConnection(const std::string& hostName, uint16_t port,
200-
const Io::SocketOptions& socketOptions, Io::TlSConnectionOptions&& tlsConnOptions) noexcept;
198+
MqttConnection NewConnection(const char* hostName, uint16_t port,
199+
const Io::SocketOptions& socketOptions, Io::TlsConnectionOptions&& tlsConnOptions) noexcept;
201200

202201
private:
203202
aws_mqtt_client m_client;

0 commit comments

Comments
 (0)