Skip to content

Commit

Permalink
Initial SHV v3 support, subscribe and unsubscribe works
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Dec 27, 2023
1 parent 334da50 commit d230172
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/libshv
Submodule libshv updated 34 files
+7 −0 .github/actions/cmake/action.yml
+2 −0 .github/workflows/test.yml
+1 −1 3rdparty/necrolog
+6 −2 CMakeLists.txt
+4 −0 libshvbroker/include/shv/broker/ldap/ldap.h
+1 −0 libshvbroker/src/brokerapp.cpp
+42 −0 libshvbroker/src/ldap.cpp
+1 −0 libshvbroker/src/openldap_dynamic.cpp
+1 −0 libshvbroker/src/openldap_dynamic.h
+4 −0 libshvchainpack/include/shv/chainpack/irpcconnection.h
+6 −0 libshvchainpack/include/shv/chainpack/rpc.h
+27 −0 libshvchainpack/src/chainpack/irpcconnection.cpp
+4 −2 libshvcore/include/shv/core/log.h
+4 −10 libshvcore/include/shv/core/utils/abstractshvjournal.h
+2 −2 libshvcore/include/shv/core/utils/shvfilejournal.h
+2 −2 libshvcore/include/shv/core/utils/shvgetlogparams.h
+1 −1 libshvcore/include/shv/core/utils/shvjournalcommon.h
+1 −1 libshvcore/include/shv/core/utils/shvmemoryjournal.h
+9 −0 libshvcore/src/log.cpp
+12 −11 libshvcore/src/utils/shvfilejournal.cpp
+1 −1 libshvcore/src/utils/shvgetlogparams.cpp
+1 −1 libshvcore/src/utils/shvjournalcommon.cpp
+9 −9 libshvcore/src/utils/shvmemoryjournal.cpp
+15 −15 libshvcoreqt/include/shv/coreqt/log.h
+14 −5 libshvcoreqt/src/log.cpp
+2 −0 libshviotqt/include/shv/iotqt/node/shvnodetree.h
+3 −2 libshviotqt/src/node/localfsnode.cpp
+0 −1 libshviotqt/src/node/shvnode.cpp
+16 −0 libshviotqt/src/node/shvnodetree.cpp
+1 −0 libshviotqt/src/rpc/socket.cpp
+2 −0 libshviotqt/tests/serialportsocket/test_serialportsocket.cpp
+0 −2 libshvvisu/src/logview/dlgloginspector.cpp
+1 −2 libshvvisu/src/logview/logmodel.cpp
+10 −15 libshvvisu/src/timeline/channelfilterdialog.cpp
2 changes: 1 addition & 1 deletion 3rdparty/necrolog
Submodule necrolog updated 2 files
+3 −2 CMakeLists.txt
+2 −2 necrolog.pc.in
2 changes: 1 addition & 1 deletion shvspy/src/appversion.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define APP_VERSION "1.5.3"
#define APP_VERSION "1.6.0"

58 changes: 44 additions & 14 deletions shvspy/src/servertreemodel/shvbrokernodeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <shv/core/utils/shvpath.h>
#include <shv/visu/errorlogmodel.h>

#include <shv/chainpack/rpc.h>
#include <shv/chainpack/rpcmessage.h>
#include <shv/core/stringview.h>
#include <shv/core/utils.h>
Expand Down Expand Up @@ -119,7 +120,6 @@ void ShvBrokerNodeItem::setSubscriptionList(const QVariantList &subs)
void ShvBrokerNodeItem::addSubscription(const std::string &shv_path, const std::string &method)
{
int rqid = callSubscribe(shv_path, method);

auto *cb = new shv::iotqt::rpc::RpcResponseCallBack(m_rpcConnection, rqid, this);
cb->start(5000, this, [this, shv_path, method](const cp::RpcResponse &resp) {
if(resp.isError() || (resp.result() == false)){
Expand Down Expand Up @@ -442,17 +442,29 @@ ShvNodeItem* ShvBrokerNodeItem::findNode(const std::string &path_)
return ret;
}

int ShvBrokerNodeItem::callSubscribe(const std::string &shv_path, std::string method)
int ShvBrokerNodeItem::callSubscribe(const std::string &shv_path, const std::string &method)
{
shv::iotqt::rpc::ClientConnection *cc = clientConnection();
int rqid = cc->callMethodSubscribe(shv_path, method);
int rqid;
if(m_shvApiVersion == ShvApiVersion::V3) {
rqid = cc->callMethodSubscribe_v3(shv_path, method);
}
else {
rqid = cc->callMethodSubscribe(shv_path, method);
};
return rqid;
}

int ShvBrokerNodeItem::callUnsubscribe(const std::string &shv_path, std::string method)
int ShvBrokerNodeItem::callUnsubscribe(const std::string &shv_path, const std::string &method)
{
shv::iotqt::rpc::ClientConnection *cc = clientConnection();
int rqid = cc->callMethodUnsubscribe(shv_path, method);
int rqid;
if(m_shvApiVersion == ShvApiVersion::V3) {
rqid = cc->callMethodUnsubscribe_v3(shv_path, method);
}
else {
rqid = cc->callMethodUnsubscribe(shv_path, method);
};
return rqid;
}

Expand Down Expand Up @@ -551,18 +563,36 @@ void ShvBrokerNodeItem::onRpcMessageReceived(const shv::chainpack::RpcMessage &m

void ShvBrokerNodeItem::createSubscriptions()
{
QMetaEnum meta_sub = QMetaEnum::fromType<SubscriptionItem>();
QVariant v = m_brokerPropeties.value(SUBSCRIPTIONS);
if(v.isValid()) {
QVariantList subs = v.toList();
using namespace shv::iotqt::rpc;
using namespace shv::chainpack;
shv::iotqt::rpc::ClientConnection *cc = clientConnection();
auto *rpc = RpcCall::create(cc);
rpc->setShvPath(Rpc::DIR_APP_BROKER_CURRENTCLIENT)
->setMethod(Rpc::METH_DIR)
->setParams(Rpc::METH_DIR);
connect(rpc, &RpcCall::maybeResult, this, [this](const auto &, const auto &err) {
if(err.isValid()) {
//shvError() << "Call check SHV API version error:" << err.toString();
m_shvApiVersion = ShvApiVersion::V2;
}
else {
m_shvApiVersion = ShvApiVersion::V3;
}

QMetaEnum meta_sub = QMetaEnum::fromType<SubscriptionItem>();
QVariant v = m_brokerPropeties.value(SUBSCRIPTIONS);
if(v.isValid()) {
QVariantList subs = v.toList();

for (const auto & sub : subs) {
QVariantMap s = sub.toMap();
for (const auto & sub : subs) {
QVariantMap s = sub.toMap();

if (s.value(meta_sub.valueToKey(SubscriptionItem::IsEnabled)).toBool()){
callSubscribe(s.value(meta_sub.valueToKey(SubscriptionItem::Path)).toString().toStdString(), s.value(meta_sub.valueToKey(SubscriptionItem::Method)).toString().toStdString());
if (s.value(meta_sub.valueToKey(SubscriptionItem::IsEnabled)).toBool()){
callSubscribe(s.value(meta_sub.valueToKey(SubscriptionItem::Path)).toString().toStdString(), s.value(meta_sub.valueToKey(SubscriptionItem::Method)).toString().toStdString());
}
}
}
}
});
rpc->start();
}

7 changes: 4 additions & 3 deletions shvspy/src/servertreemodel/shvbrokernodeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class ShvBrokerNodeItem : public ShvNodeItem
void onBrokerLoginError(const QString &err);
void onRpcMessageReceived(const shv::chainpack::RpcMessage &msg);
void createSubscriptions();
int callSubscribe(const std::string &shv_path, std::string method);
int callUnsubscribe(const std::string &shv_path, std::string method);

int callSubscribe(const std::string &shv_path, const std::string &method);
int callUnsubscribe(const std::string &shv_path, const std::string &method);
private:
int m_brokerId;
QVariantMap m_brokerPropeties;
Expand All @@ -70,5 +69,7 @@ class ShvBrokerNodeItem : public ShvNodeItem
std::map<int, RpcRequestInfo> m_runningRpcRequests;
std::string m_shvRoot;
int m_brokerLoginErrorCount = 0;
enum class ShvApiVersion {V2, V3};
ShvApiVersion m_shvApiVersion = ShvApiVersion::V2;
};

0 comments on commit d230172

Please sign in to comment.