Skip to content

Commit

Permalink
shvapi: Add more nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Feb 25, 2024
1 parent 60cb64c commit 53e56d5
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 148 deletions.
3 changes: 1 addition & 2 deletions quickevent/app/quickevent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ if(WITH_QE_SHVAPI)
target_sources(quickevent PRIVATE
plugins/Event/src/services/shvapi/client.cpp
plugins/Event/src/services/shvapi/clientwidget.cpp
plugins/Event/src/services/shvapi/rootnode.cpp
plugins/Event/src/services/shvapi/shvnode.cpp
plugins/Event/src/services/shvapi/dotappnode.cpp
plugins/Event/src/services/shvapi/nodes.cpp
)
endif()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "client.h"
#include "clientwidget.h"
#include "rootnode.h"
#include "nodes.h"

#include "../../eventplugin.h"

Expand All @@ -10,6 +10,7 @@
#include <qf/core/sql/query.h>

#include <shv/iotqt/rpc/deviceconnection.h>
#include <shv/iotqt/node/shvnode.h>

#include <QCoreApplication>
#include <QDir>
Expand Down Expand Up @@ -43,9 +44,27 @@ namespace Event::services::shvapi {
Client::Client(QObject *parent)
: Super(Client::serviceName(), parent)
, m_rpcConnection(nullptr)
, m_rootNode(new RootNode(this))
, m_rootNode(new shv::iotqt::node::ShvRootNode(this))
{
connect(getPlugin<EventPlugin>(), &Event::EventPlugin::dbEventNotify, this, &Client::onDbEventNotify, Qt::QueuedConnection);
auto *event_plugin = getPlugin<EventPlugin>();

new DotAppNode(m_rootNode);
connect(event_plugin, &EventPlugin::eventOpenChanged, this, [this](bool is_open) {
if (is_open) {
auto *event_plugin = getPlugin<EventPlugin>();
auto *event = new EventNode(m_rootNode);
auto *stage = new shv::iotqt::node::ShvNode("stage", event);
for (auto i = 0; i < event_plugin->stageCount(); i++) {
auto *nd = new shv::iotqt::node::ShvNode(std::to_string(i + 1), stage);
new RunNode(i, nd);
}
}
else {
qDeleteAll(m_rootNode->findChildren<EventNode*>());
}
});

connect(event_plugin, &Event::EventPlugin::dbEventNotify, this, &Client::onDbEventNotify, Qt::QueuedConnection);
connect(m_rootNode, &shv::iotqt::node::ShvNode::sendRpcMessage, this, &Client::sendRpcMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class QNetworkAccessManager;

namespace shv::chainpack { class RpcMessage; }
namespace shv::iotqt::rpc { class DeviceConnection; }
namespace shv::iotqt::node { class ShvRootNode; }

namespace Event::services::shvapi {

Expand Down Expand Up @@ -43,7 +44,7 @@ class Client : public Service
void sendRpcMessage(const shv::chainpack::RpcMessage &rpc_msg);
private:
shv::iotqt::rpc::DeviceConnection *m_rpcConnection;
RootNode *m_rootNode;
shv::iotqt::node::ShvRootNode *m_rootNode;
};

}

This file was deleted.

This file was deleted.

106 changes: 106 additions & 0 deletions quickevent/app/quickevent/plugins/Event/src/services/shvapi/nodes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "nodes.h"

#include "../../eventplugin.h"

#include <qf/qmlwidgets/framework/mainwindow.h>
#include <qf/core/exception.h>
#include <qf/core/log.h>

#include <shv/chainpack/rpc.h>

using namespace shv::chainpack;

using qf::qmlwidgets::framework::getPlugin;

namespace Event::services::shvapi {

//=========================================================
// DotAppNode
//=========================================================
static auto METH_NAME = "name";

const std::vector<shv::chainpack::MetaMethod> &DotAppNode::metaMethods()
{
static std::vector<MetaMethod> meta_methods {
{Rpc::METH_DIR, MetaMethod::Signature::RetParam, MetaMethod::Flag::None, Rpc::ROLE_BROWSE},
{Rpc::METH_LS, MetaMethod::Signature::RetParam, MetaMethod::Flag::None, Rpc::ROLE_BROWSE},
{Rpc::METH_PING, MetaMethod::Signature::RetVoid, MetaMethod::Flag::None, Rpc::ROLE_BROWSE},
{METH_NAME, MetaMethod::Signature::RetVoid, MetaMethod::Flag::IsGetter, Rpc::ROLE_BROWSE},
};
return meta_methods;
}

RpcValue DotAppNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id)
{
qfLogFuncFrame() << shv_path.join('/') << method;
//eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString()));
if(shv_path.empty()) {
if(method == Rpc::METH_PING) {
return nullptr;
}
if(method == METH_NAME) {
return "QuickEvent";
}
}
return Super::callMethod(shv_path, method, params, user_id);
}

//=========================================================
// EventNode
//=========================================================
static auto METH_CURRENT_STAGE = "currentStage";

const std::vector<MetaMethod> &EventNode::metaMethods()
{
static std::vector<MetaMethod> meta_methods {
{Rpc::METH_DIR, MetaMethod::Signature::RetParam, MetaMethod::Flag::None, Rpc::ROLE_BROWSE},
{Rpc::METH_LS, MetaMethod::Signature::RetParam, MetaMethod::Flag::None, Rpc::ROLE_BROWSE},
{METH_CURRENT_STAGE, MetaMethod::Signature::RetVoid, MetaMethod::Flag::IsGetter, Rpc::ROLE_READ},
};
return meta_methods;
}

RpcValue EventNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id)
{
qfLogFuncFrame() << shv_path.join('/') << method;
if(shv_path.empty()) {
if(method == METH_CURRENT_STAGE) {
return getPlugin<EventPlugin>()->currentStageId();
}
}
return Super::callMethod(shv_path, method, params, user_id);
}

//=========================================================
// StartListNode
//=========================================================
static auto METH_TABLE = "table";
static auto METH_RECORD = "record";
static auto METH_SET_RECORD = "setRecord";
static auto SIG_REC_CHNG = "recchng";

const std::vector<MetaMethod> &RunNode::metaMethods()
{
static std::vector<MetaMethod> meta_methods {
{Rpc::METH_DIR, MetaMethod::Signature::RetParam, MetaMethod::Flag::None, Rpc::ROLE_BROWSE},
{Rpc::METH_LS, MetaMethod::Signature::RetParam, MetaMethod::Flag::None, Rpc::ROLE_BROWSE},
{METH_TABLE, MetaMethod::Signature::RetVoid, MetaMethod::Flag::None, Rpc::ROLE_READ},
{METH_RECORD, MetaMethod::Signature::RetParam, MetaMethod::Flag::None, Rpc::ROLE_READ},
{METH_SET_RECORD, MetaMethod::Signature::VoidParam, MetaMethod::Flag::None, Rpc::ROLE_WRITE},
{SIG_REC_CHNG, MetaMethod::Signature::VoidParam, MetaMethod::Flag::IsSignal, Rpc::ROLE_READ},
};
return meta_methods;
}

RpcValue RunNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id)
{
qfLogFuncFrame() << shv_path.join('/') << method;
//eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString()));
if(shv_path.empty()) {
if(method == METH_TABLE) {
}
}
return Super::callMethod(shv_path, method, params, user_id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include "shvnode.h"

namespace Event::services::shvapi {

class DotAppNode : public shvapi::ShvNode
{
Q_OBJECT

using Super = shvapi::ShvNode;
public:
explicit DotAppNode(shv::iotqt::node::ShvNode *parent) : Super(".app", parent) {}
private:
//shv::chainpack::RpcValue callMethodRq(const shv::chainpack::RpcRequest &rq) override;
const std::vector<shv::chainpack::MetaMethod> &metaMethods() override;
shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id) override;
};

class EventNode : public shvapi::ShvNode
{
Q_OBJECT

using Super = shvapi::ShvNode;
public:
explicit EventNode(shv::iotqt::node::ShvNode *parent) : Super("event", parent) {}
private:
const std::vector<shv::chainpack::MetaMethod> &metaMethods() override;
shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id) override;
};

class RunNode : public shvapi::ShvNode
{
Q_OBJECT

using Super = shvapi::ShvNode;
public:
explicit RunNode(int stage, shv::iotqt::node::ShvNode *parent)
: Super("startlist", parent)
, m_stage(stage)
{}
private:
const std::vector<shv::chainpack::MetaMethod> &metaMethods() override;
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:
int m_stage;
};

}

This file was deleted.

This file was deleted.

0 comments on commit 53e56d5

Please sign in to comment.