Skip to content

Commit

Permalink
Release v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Mar 26, 2024
2 parents a705f46 + 00507c1 commit 3d14da0
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ build_script:
- cd %BUILD_DIR%
- cmake .. -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G "%CMAKE_GENERATOR%" %PLATFORM_PARAM% -DCMAKE_INSTALL_PREFIX="%COMMON_INSTALL_DIR%" ^
-DCMAKE_PREFIX_PATH="%COMMON_INSTALL_DIR%;%QTDIR%" -DCMAKE_CXX_STANDARD=%CPP_STD% ^
-DOPT_MAJOR_QT_VERSION=%QT_MAJOR%
-DOPT_QT_MAJOR_VERSION=%QT_MAJOR%
- cmake --build . --config %CONFIGURATION% --target install


4 changes: 2 additions & 2 deletions .github/workflows/actions_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install -DCMAKE_CXX_STANDARD=${{matrix.cpp}} \
-DCC_TOOLS_QT_MAJOR_QT_VERSION=${{matrix.qt_ver}}
-DOPT_QT_MAJOR_VERSION=${{matrix.qt_ver}}
env:
CC: gcc-${{matrix.cc_ver}}
CXX: g++-${{matrix.cc_ver}}
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
run: |
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install -DCMAKE_CXX_STANDARD=${{matrix.cpp}} \
-DCC_TOOLS_QT_MAJOR_QT_VERSION=${{matrix.qt_ver}}
-DOPT_QT_MAJOR_VERSION=${{matrix.qt_ver}}
env:
CC: clang-${{matrix.cc_ver}}
CXX: clang++-${{matrix.cc_ver}}
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ option (OPT_WARN_AS_ERR "Treat warning as error" ON)
option (OPT_USE_CCACHE "Use ccache on UNIX systems if it's available" ON)

# Extra configuration variables
# OPT_MAJOR_QT_VERSION - Major Qt version. Defaults to 5
# OPT_QT_MAJOR_VERSION - Major Qt version. Defaults to 5

# Extra standard CMake configuration
# CMAKE_CXX_STANDARD - C++ standard to use, defaults (and min required) to 17
Expand All @@ -17,16 +17,16 @@ if ("${CMAKE_CXX_STANDARD}" STREQUAL "")
set (CMAKE_CXX_STANDARD 17)
endif ()

if ("${OPT_MAJOR_QT_VERSION}" STREQUAL "")
set (OPT_MAJOR_QT_VERSION 5)
if ("${OPT_QT_MAJOR_VERSION}" STREQUAL "")
set (OPT_QT_MAJOR_VERSION 5)
endif ()

find_package(LibComms REQUIRED NO_MODULE)
find_package(cc_tools_qt REQUIRED NO_MODULE)
find_package(cc_mqtt5_client REQUIRED NO_MODULE)
find_package(Qt${OPT_MAJOR_QT_VERSION} REQUIRED COMPONENTS Widgets Core)
find_package(Qt${OPT_QT_MAJOR_VERSION} REQUIRED COMPONENTS Widgets Core)

if (Qt${OPT_MAJOR_QT_VERSION}_VERSION VERSION_LESS 5.15)
if (Qt${OPT_QT_MAJOR_VERSION}_VERSION VERSION_LESS 5.15)
message(FATAL_ERROR "Minimum supported Qt version is 5.15!")
endif()

Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ This project has the following direct and transitive external dependencies:
- [Qt](https://www.qt.io/) (**direct** dependency) - Qt5/6 libraries.


All these dependencies are expected to be built externally and installation paths to the primary dependencies are expected to be passed
to the `cmake` invocation
using the **CMAKE_PREFIX_PATH** configuration variable:
All these dependencies are expected to be built externally and installation paths to the primary dependencies are
expected to be passed to the `cmake` invocation
using the **CMAKE_PREFIX_PATH** configuration variable. Also the installation directory is expected to be the same as
the one used to install the [CommsChampion Tools](https://github.com/commschamp/cc_tools_qt).
```
cmake -DCMAKE_PREFIX_PATH=/path/to/comms/install\;/path/to/cc_tools_qt/install\;/path/to/cc.mqtt5.libs ...
cmake -DCMAKE_INSTALL_PREFIX=/path/to/cc_tools_qt/install \
-DCMAKE_PREFIX_PATH=/path/to/comms/install\;/path/to/cc_tools_qt/install\;/path/to/cc.mqtt5.libs ...
```

There are [prepare_externals.sh](script/prepare_externals.sh) (for Linux) and [prepare_externals.bat](script/prepare_externals.bat) (for Windows)
There are [prepare_externals.sh](script/prepare_externals.sh) (for Linux) and
[prepare_externals.bat](script/prepare_externals.bat) (for Windows)
scripts that can be used to pull and build all the required dependencies (excluding the [Qt](https://www.qt.io/) libraries).

This project requires minimal **C++17** standard as well as Qt **v5.15** or above to get properly compiled.
Expand Down
2 changes: 1 addition & 1 deletion script/full_debug_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ${SCRIPT_DIR}/prepare_externals.sh

cd ${BUILD_DIR}
cmake .. -DCMAKE_INSTALL_PREFIX=${COMMON_INSTALL_DIR} \
-DCMAKE_BUILD_TYPE=${COMMON_BUILD_TYPE} -DOPT_MAJOR_QT_VERSION=${COMMON_QT_VER} "$@"
-DCMAKE_BUILD_TYPE=${COMMON_BUILD_TYPE} -DOPT_QT_MAJOR_VERSION=${COMMON_QT_VER} "$@"

procs=$(nproc)
if [ -n "${procs}" ]; then
Expand Down
198 changes: 145 additions & 53 deletions src/Mqtt5ClientFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ const QString& aliasSubscribesProp()
return Str;
}

const QString& subscribesRemoveProp()
{
static const QString Str("mqtt5.subscribes_remove");
return Str;
}

const QString& aliasSubscribesRemoveProp()
{
static const QString Str("mqtt.subscribes_remove");
return Str;
}

const QString& subscribesClearProp()
{
static const QString Str("mqtt5.subscribes_clear");
return Str;
}

const QString& aliasSubscribesClearProp()
{
static const QString Str("mqtt.subscribes_clear");
return Str;
}

const QString& keySubProp()
{
static const QString Str("key");
Expand Down Expand Up @@ -695,7 +719,73 @@ void Mqtt5ClientFilter::applyInterPluginConfigImpl(const QVariantMap& props)
updated = true;
}
}
}
}

{
static const QString* SubscribesRemoveProps[] = {
&aliasSubscribesRemoveProp(),
&subscribesRemoveProp(),
};

for (auto* p : SubscribesRemoveProps) {
auto var = props.value(*p);
if ((!var.isValid()) || (!var.canConvert<QVariantList>())) {
continue;
}

auto subList = var.value<QVariantList>();

for (auto idx = 0; idx < subList.size(); ++idx) {
auto& subVar = subList[idx];
if ((!subVar.isValid()) || (!subVar.canConvert<QVariantMap>())) {
continue;
}

auto subMap = subVar.value<QVariantMap>();
auto topicVar = subMap.value(topicSubProp());
if ((!topicVar.isValid()) || (!topicVar.canConvert<QString>())) {
continue;
}

auto topic = topicVar.value<QString>();

auto iter =
std::find_if(
m_config.m_subscribes.begin(), m_config.m_subscribes.end(),
[&topic](const auto& info)
{
return topic == info.m_topic;
});

if (iter != m_config.m_subscribes.end()) {
m_config.m_subscribes.erase(iter);
updated = true;
forceCleanStart();
}
}
}
}

{
static const QString* SubscribesClearProps[] = {
&aliasSubscribesClearProp(),
&subscribesClearProp(),
};

for (auto* p : SubscribesClearProps) {
auto var = props.value(*p);
if ((!var.isValid()) || (!var.canConvert<bool>())) {
continue;
}

if ((!var.value<bool>()) || (m_config.m_subscribes.empty())) {
continue;
}

m_config.m_subscribes.clear();
updated = true;
}
}

{
static const QString* SubscribesProps[] = {
Expand All @@ -705,61 +795,63 @@ void Mqtt5ClientFilter::applyInterPluginConfigImpl(const QVariantMap& props)

for (auto* p : SubscribesProps) {
auto var = props.value(*p);
if ((var.isValid()) && (var.canConvert<QVariantList>())) {
auto subList = var.value<QVariantList>();

for (auto idx = 0; idx < subList.size(); ++idx) {
auto& subVar = subList[idx];
if ((!subVar.isValid()) || (!subVar.canConvert<QVariantMap>())) {
continue;
}

auto subMap = subVar.value<QVariantMap>();
auto topicVar = subMap.value(topicSubProp());
if ((!topicVar.isValid()) || (!topicVar.canConvert<QString>())) {
continue;
}

auto topic = topicVar.value<QString>();

auto iter =
std::find_if(
m_config.m_subscribes.begin(), m_config.m_subscribes.end(),
[&topic](const auto& info)
{
return topic == info.m_topic;
});

if (iter == m_config.m_subscribes.end()) {
iter = m_config.m_subscribes.insert(m_config.m_subscribes.end(), SubConfig());
iter->m_topic = topic;
}

auto& subConfig = *iter;
auto qosVar = subMap.value(qosSubProp());
if (qosVar.isValid() && qosVar.canConvert<int>()) {
subConfig.m_maxQos = qosVar.value<int>();
}

auto retainHandlingVar = subMap.value(retainHandlingSubProp());
if (retainHandlingVar.isValid() && retainHandlingVar.canConvert<int>()) {
subConfig.m_retainHandling = retainHandlingVar.value<int>();
}

auto noLocalVar = subMap.value(noLocalSubProp());
if (noLocalVar.isValid() && noLocalVar.canConvert<bool>()) {
subConfig.m_noLocal = noLocalVar.value<bool>();
}

auto retainAsPublishedVar = subMap.value(retainAsPublishedSubProp());
if (retainAsPublishedVar.isValid() && retainAsPublishedVar.canConvert<bool>()) {
subConfig.m_retainAsPublished = retainAsPublishedVar.value<bool>();
}
if ((!var.isValid()) || (!var.canConvert<QVariantList>())) {
continue;
}

auto subList = var.value<QVariantList>();

for (auto idx = 0; idx < subList.size(); ++idx) {
auto& subVar = subList[idx];
if ((!subVar.isValid()) || (!subVar.canConvert<QVariantMap>())) {
continue;
}

auto subMap = subVar.value<QVariantMap>();
auto topicVar = subMap.value(topicSubProp());
if ((!topicVar.isValid()) || (!topicVar.canConvert<QString>())) {
continue;
}

auto topic = topicVar.value<QString>();

auto iter =
std::find_if(
m_config.m_subscribes.begin(), m_config.m_subscribes.end(),
[&topic](const auto& info)
{
return topic == info.m_topic;
});

updated = true;
forceCleanStart();
if (iter == m_config.m_subscribes.end()) {
iter = m_config.m_subscribes.insert(m_config.m_subscribes.end(), SubConfig());
iter->m_topic = topic;
}

auto& subConfig = *iter;
auto qosVar = subMap.value(qosSubProp());
if (qosVar.isValid() && qosVar.canConvert<int>()) {
subConfig.m_maxQos = qosVar.value<int>();
}

auto retainHandlingVar = subMap.value(retainHandlingSubProp());
if (retainHandlingVar.isValid() && retainHandlingVar.canConvert<int>()) {
subConfig.m_retainHandling = retainHandlingVar.value<int>();
}

auto noLocalVar = subMap.value(noLocalSubProp());
if (noLocalVar.isValid() && noLocalVar.canConvert<bool>()) {
subConfig.m_noLocal = noLocalVar.value<bool>();
}

auto retainAsPublishedVar = subMap.value(retainAsPublishedSubProp());
if (retainAsPublishedVar.isValid() && retainAsPublishedVar.canConvert<bool>()) {
subConfig.m_retainAsPublished = retainAsPublishedVar.value<bool>();
}
}

updated = true;
forceCleanStart();
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/cc_plugin_mqtt5_client_filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@
" \"retain_as_published\": false, - Retain as published.\n",
" \"retain_handling\": 1 - Retain handling.\n",
" }, {...}",
" ] } - Update subscribes\n",
" ] } - Add or update subscribes\n",
" { \"mqtt5.subscribes_remove\": [\n",
" {\n",
" \"topic\": \"some/topic\" - Subscribe topic.\n",
" }, {...}",
" ] } - Remove subscribes\n",
" { \"mqtt5.subscribes_clear\": true } - Clear all subscribes.\n",
" { \"mqtt.client\": \"client_id\" } - Alias to \"mqtt5.client\".\n",
" { \"mqtt.username\": \"username\" } - Alias to \"mqtt5.username\".\n",
" { \"mqtt.password\": \"password\" } - Alias to \"mqtt5.password\".\n",
" { \"mqtt.pub_topic\": \"pub_topic\" } - Alias to \"mqtt5.pub_topic\".\n",
" { \"mqtt.pub_qos\": 1 } - Alias to \"mqtt5.pub_qos\".\n",
" { \"mqtt.resp_topic\": \"resp_topic\" } - Alias to \"mqtt5.resp_topic\".\n",
" { \"mqtt.subscribes\": [...] - Alias to \"mqtt5.subscribes\". \n",
" { \"mqtt.subscribes_remove\": [...] - Alias to \"mqtt5.subscribes_remove\". \n",
" { \"mqtt.subscribes_clear\": true } - Alias to \"mqtt5.subscribes_clear\". \n",
"\n",
"Supported message overriding properties:\n",
" { \"mqtt5.topic\": \"some/topic\" } - Override publish topic\n",
Expand Down

0 comments on commit 3d14da0

Please sign in to comment.