Skip to content

Commit

Permalink
libshvbroker: Implement .app:ping
Browse files Browse the repository at this point in the history
I'm getting sick of having SHV3 clients ping all the time, and it working even
though all the pings result in an error.
  • Loading branch information
syyyr authored and fvacek committed Oct 30, 2024
1 parent f286bc1 commit da64793
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions libshvbroker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ qt_add_library(libshvbroker
src/aclmanager.cpp
src/aclmanagersqlite.cpp
src/appclioptions.cpp
src/appnode.cpp
src/brokeraclnode.cpp
src/brokerapp.cpp
src/brokerappnode.cpp
Expand Down
25 changes: 25 additions & 0 deletions libshvbroker/src/appnode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "appnode.h"

#include <shv/broker/brokerapp.h>

namespace shv::broker {
AppNode::AppNode(shv::iotqt::node::ShvNode *parent)
: Super("", &m_metaMethods, parent)
, m_metaMethods {
shv::chainpack::methods::DIR,
shv::chainpack::methods::LS,
{shv::chainpack::Rpc::METH_PING, shv::chainpack::MetaMethod::Flag::None, "Null", "Null", shv::chainpack::AccessLevel::Browse, {}, "https://silicon-heaven.github.io/shv-doc/rpcmethods/app.html#appping"},
}
{
}

shv::chainpack::RpcValue AppNode::callMethod(const StringViewList& shv_path, const std::string& method, const shv::chainpack::RpcValue& params, const chainpack::RpcValue& user_id)
{
if (shv_path.empty()) {
if (method == shv::chainpack::Rpc::METH_PING) {
return chainpack::RpcValue(nullptr);
}
}
return Super::callMethod(shv_path, method, params, user_id);
}
}
20 changes: 20 additions & 0 deletions libshvbroker/src/appnode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <shv/iotqt/node/shvnode.h>
#include <shv/chainpack/rpcvalue.h>

namespace shv::broker {

class AppNode : public shv::iotqt::node::MethodsTableNode
{
Q_OBJECT

using Super = shv::iotqt::node::MethodsTableNode;
public:
AppNode(shv::iotqt::node::ShvNode *parent = nullptr);

shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id) override;
private:
std::vector<shv::chainpack::MetaMethod> m_metaMethods;
};
}
2 changes: 2 additions & 0 deletions libshvbroker/src/brokerapp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "aclmanagersqlite.h"
#include "appnode.h"
#include "brokeraclnode.h"
#include "brokerappnode.h"
#include "brokerrootnode.h"
Expand Down Expand Up @@ -295,6 +296,7 @@ BrokerApp::BrokerApp(int &argc, char **argv, AppCliOptions *cli_opts)
connect(m_nodesTree->root(), &shv::iotqt::node::ShvRootNode::sendRpcMessage, this, &BrokerApp::onRootNodeSendRpcMesage);
auto *bn = new BrokerAppNode();
m_nodesTree->mount(cp::Rpc::DIR_BROKER_APP, bn);
m_nodesTree->mount(cp::Rpc::DIR_APP, new AppNode());
m_nodesTree->mount(BROKER_CURRENT_CLIENT_SHV_PATH, new CurrentClientShvNode());
m_nodesTree->mount(std::string(cp::Rpc::DIR_BROKER) + "/clients", new ClientsNode());
m_nodesTree->mount(std::string(cp::Rpc::DIR_BROKER) + "/masters", new MasterBrokersNode());
Expand Down

0 comments on commit da64793

Please sign in to comment.