Skip to content

Commit

Permalink
Release v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Aug 26, 2024
2 parents 987b8ba + b03bfe4 commit b8dab41
Show file tree
Hide file tree
Showing 27 changed files with 642 additions and 68 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/actions_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
run: |
cmake %GITHUB_WORKSPACE% -A ${{matrix.arch}} -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_INSTALL_PREFIX=install ^
-DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install -DCMAKE_CXX_STANDARD=${{matrix.cpp}} ^
-DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
-DCMAKE_POLICY_DEFAULT_CMP0167=OLD -DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
-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"
- name: Build Target
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
if: matrix.arch == 'x64'
shell: cmd
run: |
choco install boost-msvc-14.3
choco install boost-msvc-14.3 --version=1.85.0
- name: Prepare externals
shell: cmd
Expand All @@ -236,7 +236,7 @@ jobs:
run: |
cmake %GITHUB_WORKSPACE% -A ${{matrix.arch}} -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_INSTALL_PREFIX=install ^
-DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install -DCMAKE_CXX_STANDARD=${{matrix.cpp}} ^
-DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
-DCMAKE_POLICY_DEFAULT_CMP0167=OLD -DBoost_USE_STATIC_LIBS=ON -DCC_MQTTSN_BUILD_UNIT_TESTS=ON ^
-DCC_MQTTSN_CLIENT_APPS=${{env.HAS_BOOST}} -DCC_MQTTSN_GATEWAY_APPS=${{env.HAS_BOOST}} ^
-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"
env:
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ if ("${CMAKE_CXX_STANDARD}" STREQUAL "")
set(CMAKE_CXX_STANDARD 17)
endif ()

if (("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.30") AND
(NOT DEFINED CMAKE_POLICY_DEFAULT_CMP0167))
# Find boost cmake configuration from the boost installation
cmake_policy(SET CMP0167 NEW)
endif ()

find_package(LibComms REQUIRED)

include (${PROJECT_SOURCE_DIR}/cmake/Compile.cmake)
Expand Down
42 changes: 39 additions & 3 deletions client/app/common/AppClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ std::string toString(CC_MqttsnQoS val)
return Map[idx] + " (" + std::to_string(val) + ')';
}


std::string toStringInternal(CC_MqttsnGatewayDisconnectReason val)
{
static const std::string Map[] = {
/* CC_MqttsnGatewayDisconnectReason_DisconnectMsg */ "DISCONNECT Message",
/* CC_MqttsnGatewayDisconnectReason_NoGatewayResponse */ "No Response",
};

static constexpr std::size_t MapSize = std::extent<decltype(Map)>::value;
static_assert(MapSize == CC_MqttsnGatewayDisconnectReason_ValuesLimit);

auto idx = static_cast<unsigned>(val);
if (MapSize <= idx) {
assert(false); // Should not happen
return std::to_string(val);
}

return Map[idx] + " (" + std::to_string(val) + ')';
}

void printQos(const char* prefix, CC_MqttsnQoS val)
{
std::cout << "\t" << prefix << ": " << toString(val) << '\n';
Expand Down Expand Up @@ -173,6 +193,7 @@ AppClient::AppClient(boost::asio::io_context& io, int& result) :
{
assert(m_client);
::cc_mqttsn_client_set_send_output_data_callback(m_client.get(), &AppClient::sendDataCb, this);
::cc_mqttsn_client_set_gw_disconnect_report_callback(m_client.get(), &AppClient::gwDisconnectedReportCb, this);
::cc_mqttsn_client_set_message_report_callback(m_client.get(), &AppClient::messageReceivedCb, this);
::cc_mqttsn_client_set_error_log_callback(m_client.get(), &AppClient::logMessageCb, this);
::cc_mqttsn_client_set_next_tick_program_callback(m_client.get(), &AppClient::nextTickProgramCb, this);
Expand Down Expand Up @@ -278,6 +299,11 @@ void AppClient::disconnectCompleteImpl()
doComplete();
}

void AppClient::gwDisconnectedReportImpl()
{
doTerminate();
}

std::vector<std::uint8_t> AppClient::parseBinaryData(const std::string& val)
{
std::vector<std::uint8_t> result;
Expand Down Expand Up @@ -364,7 +390,6 @@ std::string AppClient::toString(CC_MqttsnAsyncOpStatus val)
return Map[idx] + " (" + std::to_string(val) + ')';
}


std::string AppClient::toString(CC_MqttsnReturnCode val)
{
static const std::string Map[] = {
Expand Down Expand Up @@ -492,6 +517,12 @@ void AppClient::disconnectCompleteInternal(CC_MqttsnAsyncOpStatus status)
disconnectCompleteImpl();
}

void AppClient::gwDisconnectedReportInternal(CC_MqttsnGatewayDisconnectReason reason)
{
logInfo() << "Gateway disconnected with reason: " << toStringInternal(reason) << std::endl;
gwDisconnectedReportImpl();
}

void AppClient::sendDataCb(void* data, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius)
{
asThis(data)->sendDataInternal(buf, bufLen, broadcastRadius);
Expand Down Expand Up @@ -519,12 +550,17 @@ unsigned AppClient::cancelNextTickWaitCb(void* data)

void AppClient::connectCompleteCb(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info)
{
return asThis(data)->connectCompleteInternal(status, info);
asThis(data)->connectCompleteInternal(status, info);
}

void AppClient::disconnectCompleteCb(void* data, CC_MqttsnAsyncOpStatus status)
{
return asThis(data)->disconnectCompleteInternal(status);
asThis(data)->disconnectCompleteInternal(status);
}

void AppClient::gwDisconnectedReportCb(void* data, CC_MqttsnGatewayDisconnectReason reason)
{
asThis(data)->gwDisconnectedReportInternal(reason);
}

} // namespace cc_mqttsn_client_app
3 changes: 3 additions & 0 deletions client/app/common/AppClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AppClient
virtual void messageReceivedImpl(const CC_MqttsnMessageInfo* info);
virtual void connectCompleteImpl();
virtual void disconnectCompleteImpl();
virtual void gwDisconnectedReportImpl();

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

Expand All @@ -94,6 +95,7 @@ class AppClient
bool createSession();
void connectCompleteInternal(CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info);
void disconnectCompleteInternal(CC_MqttsnAsyncOpStatus status);
void gwDisconnectedReportInternal(CC_MqttsnGatewayDisconnectReason reason);

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

boost::asio::io_context& m_io;
int& m_result;
Expand Down
12 changes: 12 additions & 0 deletions client/app/common/ProgramOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void ProgramOptions::addPublish()
("pub-qos,q", po::value<unsigned>()->default_value(0U), "Publish QoS value")
("pub-retain", "Publish retained message")
("pub-no-disconnect", "Do not gracefuly disconnect when publish is complete")
("pub-count", po::value<unsigned>()->default_value(1U), "Number of publishes to perform")
("pub-delay", po::value<unsigned>()->default_value(100U), "Delay in ms between publishes")
;

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

unsigned ProgramOptions::pubCount() const
{
return m_vm["pub-count"].as<unsigned>();
}

unsigned ProgramOptions::pubDelay() const
{
return m_vm["pub-delay"].as<unsigned>();
}

std::vector<std::string> ProgramOptions::subTopics() const
{
std::vector<std::string> result;
Expand Down
4 changes: 3 additions & 1 deletion client/app/common/ProgramOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class ProgramOptions
std::string pubMessage() const;
unsigned pubQos() const;
bool pubRetain() const;
bool pubNoDisconnect() const;
bool pubNoDisconnect() const;
unsigned pubCount() const;
unsigned pubDelay() const;

// Subscribe Options
std::vector<std::string> subTopics() const;
Expand Down
53 changes: 48 additions & 5 deletions client/app/pub/Pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Pub.h"

#include <algorithm>
#include <chrono>
#include <iostream>
#include <iterator>
#include <type_traits>
Expand All @@ -27,7 +28,8 @@ Pub* asThis(void* data)


Pub::Pub(boost::asio::io_context& io, int& result) :
Base(io, result)
Base(io, result),
m_timer(io)
{
opts().addCommon();
opts().addNetwork();
Expand All @@ -50,10 +52,21 @@ bool Pub::startImpl()
return false;
}

m_remCount = opts().pubCount();
if (m_remCount == 0U) {
logError() << "Amount of requested publishes needs to be at least 1." << std::endl;
return false;
}

return doConnect();
}

void Pub::connectCompleteImpl()
{
doPublish();
}

void Pub::doPublish()
{
auto config = CC_MqttsnPublishConfig();
cc_mqttsn_client_publish_init_config(&config);
Expand All @@ -77,7 +90,17 @@ void Pub::connectCompleteImpl()
}

logError() << "Failed to initiate publish operation with error code: " << toString(ec) << std::endl;
doTerminate();
doTerminate();
}

void Pub::doCompleteInternal()
{
if (opts().pubNoDisconnect()) {
doComplete();
return;
}

doDisconnect();
}

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

if (opts().pubNoDisconnect()) {
doComplete();
assert(m_remCount > 0U);
--m_remCount;

if (m_remCount == 0U) {
doCompleteInternal();
return;
}

doDisconnect();
auto delay = opts().pubDelay();
if (delay == 0U) {
doPublish();
return;
}

m_timer.expires_after(std::chrono::milliseconds(delay));
m_timer.async_wait(
[this](const boost::system::error_code& ec)
{
if (ec == boost::asio::error::operation_aborted) {
return;
}

assert(!ec);
doPublish();
}
);
}

void Pub::publishCompleteCb(
Expand Down
5 changes: 5 additions & 0 deletions client/app/pub/Pub.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ class Pub : public AppClient
virtual void connectCompleteImpl() override;

private:
void doPublish();
void doCompleteInternal();
void publishCompleteInternal(CC_MqttsnAsyncOpStatus status, const CC_MqttsnPublishInfo* info);
static void publishCompleteCb(void* data, CC_MqttsnPublishHandle handle, CC_MqttsnAsyncOpStatus status, const CC_MqttsnPublishInfo* info);

boost::asio::steady_timer m_timer;
unsigned m_remCount = 0U;
};

} // namespace cc_mqttsn_client_app
2 changes: 1 addition & 1 deletion client/lib/include/cc_mqttsn_client/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {

/// @brief Patch level of the library
/// @ingroup global
#define CC_MQTTSN_CLIENT_PATCH_VERSION 0U
#define CC_MQTTSN_CLIENT_PATCH_VERSION 1U

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

0 comments on commit b8dab41

Please sign in to comment.