Skip to content

Commit b8dab41

Browse files
committed
Release v2.0.1
2 parents 987b8ba + b03bfe4 commit b8dab41

27 files changed

+642
-68
lines changed

.github/workflows/actions_build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ jobs:
179179
run: |
180180
cmake %GITHUB_WORKSPACE% -A ${{matrix.arch}} -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_INSTALL_PREFIX=install ^
181181
-DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install -DCMAKE_CXX_STANDARD=${{matrix.cpp}} ^
182-
-DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
182+
-DCMAKE_POLICY_DEFAULT_CMP0167=OLD -DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
183183
-DCC_MQTTSN_CUSTOM_CLIENT_CONFIG_FILES="%GITHUB_WORKSPACE%/client/lib/script/BareMetalTestConfig.cmake;%GITHUB_WORKSPACE%/client/lib/script/NoGwDiscoverConfig.cmake;%GITHUB_WORKSPACE%/client/lib/script/Qos1Config.cmake;%GITHUB_WORKSPACE%/client/lib/script/Qos0Config.cmake"
184184
185185
- name: Build Target
@@ -213,7 +213,7 @@ jobs:
213213
if: matrix.arch == 'x64'
214214
shell: cmd
215215
run: |
216-
choco install boost-msvc-14.3
216+
choco install boost-msvc-14.3 --version=1.85.0
217217
218218
- name: Prepare externals
219219
shell: cmd
@@ -236,7 +236,7 @@ jobs:
236236
run: |
237237
cmake %GITHUB_WORKSPACE% -A ${{matrix.arch}} -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_INSTALL_PREFIX=install ^
238238
-DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install -DCMAKE_CXX_STANDARD=${{matrix.cpp}} ^
239-
-DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
239+
-DCMAKE_POLICY_DEFAULT_CMP0167=OLD -DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
240240
-DCC_MQTTSN_CLIENT_APPS=${{env.HAS_BOOST}} -DCC_MQTTSN_GATEWAY_APPS=${{env.HAS_BOOST}} ^
241241
-DCC_MQTTSN_CUSTOM_CLIENT_CONFIG_FILES="%GITHUB_WORKSPACE%/client/lib/script/BareMetalTestConfig.cmake;%GITHUB_WORKSPACE%/client/lib/script/NoGwDiscoverConfig.cmake;%GITHUB_WORKSPACE%/client/lib/script/Qos1Config.cmake;%GITHUB_WORKSPACE%/client/lib/script/Qos0Config.cmake"
242242
env:

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ if ("${CMAKE_CXX_STANDARD}" STREQUAL "")
2626
set(CMAKE_CXX_STANDARD 17)
2727
endif ()
2828

29+
if (("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.30") AND
30+
(NOT DEFINED CMAKE_POLICY_DEFAULT_CMP0167))
31+
# Find boost cmake configuration from the boost installation
32+
cmake_policy(SET CMP0167 NEW)
33+
endif ()
34+
2935
find_package(LibComms REQUIRED)
3036

3137
include (${PROJECT_SOURCE_DIR}/cmake/Compile.cmake)

client/app/common/AppClient.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ std::string toString(CC_MqttsnQoS val)
4646
return Map[idx] + " (" + std::to_string(val) + ')';
4747
}
4848

49+
50+
std::string toStringInternal(CC_MqttsnGatewayDisconnectReason val)
51+
{
52+
static const std::string Map[] = {
53+
/* CC_MqttsnGatewayDisconnectReason_DisconnectMsg */ "DISCONNECT Message",
54+
/* CC_MqttsnGatewayDisconnectReason_NoGatewayResponse */ "No Response",
55+
};
56+
57+
static constexpr std::size_t MapSize = std::extent<decltype(Map)>::value;
58+
static_assert(MapSize == CC_MqttsnGatewayDisconnectReason_ValuesLimit);
59+
60+
auto idx = static_cast<unsigned>(val);
61+
if (MapSize <= idx) {
62+
assert(false); // Should not happen
63+
return std::to_string(val);
64+
}
65+
66+
return Map[idx] + " (" + std::to_string(val) + ')';
67+
}
68+
4969
void printQos(const char* prefix, CC_MqttsnQoS val)
5070
{
5171
std::cout << "\t" << prefix << ": " << toString(val) << '\n';
@@ -173,6 +193,7 @@ AppClient::AppClient(boost::asio::io_context& io, int& result) :
173193
{
174194
assert(m_client);
175195
::cc_mqttsn_client_set_send_output_data_callback(m_client.get(), &AppClient::sendDataCb, this);
196+
::cc_mqttsn_client_set_gw_disconnect_report_callback(m_client.get(), &AppClient::gwDisconnectedReportCb, this);
176197
::cc_mqttsn_client_set_message_report_callback(m_client.get(), &AppClient::messageReceivedCb, this);
177198
::cc_mqttsn_client_set_error_log_callback(m_client.get(), &AppClient::logMessageCb, this);
178199
::cc_mqttsn_client_set_next_tick_program_callback(m_client.get(), &AppClient::nextTickProgramCb, this);
@@ -278,6 +299,11 @@ void AppClient::disconnectCompleteImpl()
278299
doComplete();
279300
}
280301

302+
void AppClient::gwDisconnectedReportImpl()
303+
{
304+
doTerminate();
305+
}
306+
281307
std::vector<std::uint8_t> AppClient::parseBinaryData(const std::string& val)
282308
{
283309
std::vector<std::uint8_t> result;
@@ -364,7 +390,6 @@ std::string AppClient::toString(CC_MqttsnAsyncOpStatus val)
364390
return Map[idx] + " (" + std::to_string(val) + ')';
365391
}
366392

367-
368393
std::string AppClient::toString(CC_MqttsnReturnCode val)
369394
{
370395
static const std::string Map[] = {
@@ -492,6 +517,12 @@ void AppClient::disconnectCompleteInternal(CC_MqttsnAsyncOpStatus status)
492517
disconnectCompleteImpl();
493518
}
494519

520+
void AppClient::gwDisconnectedReportInternal(CC_MqttsnGatewayDisconnectReason reason)
521+
{
522+
logInfo() << "Gateway disconnected with reason: " << toStringInternal(reason) << std::endl;
523+
gwDisconnectedReportImpl();
524+
}
525+
495526
void AppClient::sendDataCb(void* data, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius)
496527
{
497528
asThis(data)->sendDataInternal(buf, bufLen, broadcastRadius);
@@ -519,12 +550,17 @@ unsigned AppClient::cancelNextTickWaitCb(void* data)
519550

520551
void AppClient::connectCompleteCb(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info)
521552
{
522-
return asThis(data)->connectCompleteInternal(status, info);
553+
asThis(data)->connectCompleteInternal(status, info);
523554
}
524555

525556
void AppClient::disconnectCompleteCb(void* data, CC_MqttsnAsyncOpStatus status)
526557
{
527-
return asThis(data)->disconnectCompleteInternal(status);
558+
asThis(data)->disconnectCompleteInternal(status);
559+
}
560+
561+
void AppClient::gwDisconnectedReportCb(void* data, CC_MqttsnGatewayDisconnectReason reason)
562+
{
563+
asThis(data)->gwDisconnectedReportInternal(reason);
528564
}
529565

530566
} // namespace cc_mqttsn_client_app

client/app/common/AppClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class AppClient
7272
virtual void messageReceivedImpl(const CC_MqttsnMessageInfo* info);
7373
virtual void connectCompleteImpl();
7474
virtual void disconnectCompleteImpl();
75+
virtual void gwDisconnectedReportImpl();
7576

7677
static std::vector<std::uint8_t> parseBinaryData(const std::string& val);
7778

@@ -94,6 +95,7 @@ class AppClient
9495
bool createSession();
9596
void connectCompleteInternal(CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info);
9697
void disconnectCompleteInternal(CC_MqttsnAsyncOpStatus status);
98+
void gwDisconnectedReportInternal(CC_MqttsnGatewayDisconnectReason reason);
9799

98100
static void sendDataCb(void* data, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius);
99101
static void messageReceivedCb(void* data, const CC_MqttsnMessageInfo* info);
@@ -102,6 +104,7 @@ class AppClient
102104
static unsigned cancelNextTickWaitCb(void* data);
103105
static void connectCompleteCb(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info);
104106
static void disconnectCompleteCb(void* data, CC_MqttsnAsyncOpStatus status);
107+
static void gwDisconnectedReportCb(void* data, CC_MqttsnGatewayDisconnectReason reason);
105108

106109
boost::asio::io_context& m_io;
107110
int& m_result;

client/app/common/ProgramOptions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ void ProgramOptions::addPublish()
9292
("pub-qos,q", po::value<unsigned>()->default_value(0U), "Publish QoS value")
9393
("pub-retain", "Publish retained message")
9494
("pub-no-disconnect", "Do not gracefuly disconnect when publish is complete")
95+
("pub-count", po::value<unsigned>()->default_value(1U), "Number of publishes to perform")
96+
("pub-delay", po::value<unsigned>()->default_value(100U), "Delay in ms between publishes")
9597
;
9698

9799
m_desc.add(opts);
@@ -230,6 +232,16 @@ bool ProgramOptions::pubNoDisconnect() const
230232
return m_vm.count("pub-no-disconnect") > 0U;
231233
}
232234

235+
unsigned ProgramOptions::pubCount() const
236+
{
237+
return m_vm["pub-count"].as<unsigned>();
238+
}
239+
240+
unsigned ProgramOptions::pubDelay() const
241+
{
242+
return m_vm["pub-delay"].as<unsigned>();
243+
}
244+
233245
std::vector<std::string> ProgramOptions::subTopics() const
234246
{
235247
std::vector<std::string> result;

client/app/common/ProgramOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class ProgramOptions
7070
std::string pubMessage() const;
7171
unsigned pubQos() const;
7272
bool pubRetain() const;
73-
bool pubNoDisconnect() const;
73+
bool pubNoDisconnect() const;
74+
unsigned pubCount() const;
75+
unsigned pubDelay() const;
7476

7577
// Subscribe Options
7678
std::vector<std::string> subTopics() const;

client/app/pub/Pub.cpp

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Pub.h"
99

1010
#include <algorithm>
11+
#include <chrono>
1112
#include <iostream>
1213
#include <iterator>
1314
#include <type_traits>
@@ -27,7 +28,8 @@ Pub* asThis(void* data)
2728

2829

2930
Pub::Pub(boost::asio::io_context& io, int& result) :
30-
Base(io, result)
31+
Base(io, result),
32+
m_timer(io)
3133
{
3234
opts().addCommon();
3335
opts().addNetwork();
@@ -50,10 +52,21 @@ bool Pub::startImpl()
5052
return false;
5153
}
5254

55+
m_remCount = opts().pubCount();
56+
if (m_remCount == 0U) {
57+
logError() << "Amount of requested publishes needs to be at least 1." << std::endl;
58+
return false;
59+
}
60+
5361
return doConnect();
5462
}
5563

5664
void Pub::connectCompleteImpl()
65+
{
66+
doPublish();
67+
}
68+
69+
void Pub::doPublish()
5770
{
5871
auto config = CC_MqttsnPublishConfig();
5972
cc_mqttsn_client_publish_init_config(&config);
@@ -77,7 +90,17 @@ void Pub::connectCompleteImpl()
7790
}
7891

7992
logError() << "Failed to initiate publish operation with error code: " << toString(ec) << std::endl;
80-
doTerminate();
93+
doTerminate();
94+
}
95+
96+
void Pub::doCompleteInternal()
97+
{
98+
if (opts().pubNoDisconnect()) {
99+
doComplete();
100+
return;
101+
}
102+
103+
doDisconnect();
81104
}
82105

83106
void Pub::publishCompleteInternal(CC_MqttsnAsyncOpStatus status, const CC_MqttsnPublishInfo* info)
@@ -98,12 +121,32 @@ void Pub::publishCompleteInternal(CC_MqttsnAsyncOpStatus status, const CC_Mqttsn
98121
logInfo() << "Publish complete" << std::endl;
99122
}
100123

101-
if (opts().pubNoDisconnect()) {
102-
doComplete();
124+
assert(m_remCount > 0U);
125+
--m_remCount;
126+
127+
if (m_remCount == 0U) {
128+
doCompleteInternal();
103129
return;
104130
}
105131

106-
doDisconnect();
132+
auto delay = opts().pubDelay();
133+
if (delay == 0U) {
134+
doPublish();
135+
return;
136+
}
137+
138+
m_timer.expires_after(std::chrono::milliseconds(delay));
139+
m_timer.async_wait(
140+
[this](const boost::system::error_code& ec)
141+
{
142+
if (ec == boost::asio::error::operation_aborted) {
143+
return;
144+
}
145+
146+
assert(!ec);
147+
doPublish();
148+
}
149+
);
107150
}
108151

109152
void Pub::publishCompleteCb(

client/app/pub/Pub.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ class Pub : public AppClient
2626
virtual void connectCompleteImpl() override;
2727

2828
private:
29+
void doPublish();
30+
void doCompleteInternal();
2931
void publishCompleteInternal(CC_MqttsnAsyncOpStatus status, const CC_MqttsnPublishInfo* info);
3032
static void publishCompleteCb(void* data, CC_MqttsnPublishHandle handle, CC_MqttsnAsyncOpStatus status, const CC_MqttsnPublishInfo* info);
33+
34+
boost::asio::steady_timer m_timer;
35+
unsigned m_remCount = 0U;
3136
};
3237

3338
} // namespace cc_mqttsn_client_app

client/lib/include/cc_mqttsn_client/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626

2727
/// @brief Patch level of the library
2828
/// @ingroup global
29-
#define CC_MQTTSN_CLIENT_PATCH_VERSION 0U
29+
#define CC_MQTTSN_CLIENT_PATCH_VERSION 1U
3030

3131
/// @brief Macro to create numeric version as single unsigned number
3232
#define CC_MQTTSN_CLIENT_MAKE_VERSION(major_, minor_, patch_) \

0 commit comments

Comments
 (0)