Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libshvbroker: Implement .app:ping #523

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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