diff --git a/examples/cli/shvcall/src/appclioptions.cpp b/examples/cli/shvcall/src/appclioptions.cpp index 8f3016e98..06991be34 100644 --- a/examples/cli/shvcall/src/appclioptions.cpp +++ b/examples/cli/shvcall/src/appclioptions.cpp @@ -9,4 +9,6 @@ AppCliOptions::AppCliOptions() addOption("isChainPackOutput").setType(shv::chainpack::RpcValue::Type::Bool).setNames("-x", "--chainpack-output").setComment("ChainPack output"); addOption("shouldSubscribe").setType(shv::chainpack::RpcValue::Type::Bool).setNames("--subscribe").setComment("Whether shvcall should subscribe to a path and print events").setDefaultValue(false); addOption("subscribeFormat").setType(shv::chainpack::RpcValue::Type::String).setNames("--subscribe-format").setComment("Set the format of events. Available placeholders: {TIME}, {PATH}, {METHOD}, {VALUE}. This option is only useful with --subscribe.").setDefaultValue(R"({"timestamp": "{TIME}", "path": "{PATH}", "method": "{METHOD}", "param": {VALUE}})"); + + addOption("shouldEmit").setType(shv::chainpack::RpcValue::Type::Bool).setNames("--emit").setComment("Whether shvcall should emit a signal and quit").setDefaultValue(false); } diff --git a/examples/cli/shvcall/src/appclioptions.h b/examples/cli/shvcall/src/appclioptions.h index a4e74cedf..f74265664 100644 --- a/examples/cli/shvcall/src/appclioptions.h +++ b/examples/cli/shvcall/src/appclioptions.h @@ -1,8 +1,8 @@ #pragma once -#include +#include -class AppCliOptions : public shv::iotqt::rpc::ClientAppCliOptions +class AppCliOptions : public shv::iotqt::rpc::DeviceAppCliOptions { using Super = shv::iotqt::rpc::ClientAppCliOptions; @@ -16,4 +16,6 @@ class AppCliOptions : public shv::iotqt::rpc::ClientAppCliOptions CLIOPTION_GETTER_SETTER(bool, isC, setC, ponOutput) CLIOPTION_GETTER_SETTER(bool, s, setS, houldSubscribe) CLIOPTION_GETTER_SETTER(std::string, s, setS, ubscribeFormat) + + CLIOPTION_GETTER_SETTER(bool, s, setS, houldEmit) }; diff --git a/examples/cli/shvcall/src/application.cpp b/examples/cli/shvcall/src/application.cpp index 330d3f8d4..4a0e5b9a2 100644 --- a/examples/cli/shvcall/src/application.cpp +++ b/examples/cli/shvcall/src/application.cpp @@ -14,7 +14,7 @@ Application::Application(int &argc, char **argv, AppCliOptions *cli_opts) : Super(argc, argv) , m_cliOptions(cli_opts) { - m_rpcConnection = new si::rpc::ClientConnection(this); + m_rpcConnection = new si::rpc::DeviceConnection(this); m_rpcConnection->setCliOptions(cli_opts); @@ -87,6 +87,12 @@ void Application::onShvStateChanged() return; } + if (m_cliOptions->shouldEmit()) { + m_rpcConnection->sendShvSignal(m_cliOptions->path(), m_cliOptions->method(), m_cliOptions->params()); + m_rpcConnection->close(); + return; + } + try { params = m_cliOptions->params().empty() ? cp::RpcValue() : cp::RpcValue::fromCpon(m_cliOptions->params()); } catch (std::exception&) { diff --git a/examples/cli/shvcall/src/application.h b/examples/cli/shvcall/src/application.h index ad76308ae..19aa1c143 100644 --- a/examples/cli/shvcall/src/application.h +++ b/examples/cli/shvcall/src/application.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include class AppCliOptions; @@ -17,7 +17,7 @@ class Application : public QCoreApplication void onShvStateChanged(); AppCliOptions *m_cliOptions; - shv::iotqt::rpc::ClientConnection *m_rpcConnection; + shv::iotqt::rpc::DeviceConnection *m_rpcConnection; int m_subscriptionRpcId; int m_status = EXIT_SUCCESS; };