1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "client.h"
6
7Client::Client(const std::string &ipToConnect, const unsigned int &port)
8 : QObject ()
9 , tcpSocketClient(ipToConnect, port)
10{
11
12}
13
14void Client::initialzation(int pid)
15{
16 jsonrpc::Client sender(tcpSocketClient);
17 Json::Value params(Json::objectValue);
18 params["processId"] = Json::Value(int(pid));
19 Json::Value orgData(Json::objectValue);
20 orgData["params"] = params;
21 qInfo() << "initialization -->";
22 try {
23 initialzationResult(sender.CallMethod("initialization", orgData));
24 } catch (jsonrpc::JsonRpcException &e) {
25 std::cerr << e.what() << std::endl;
26 }
27}
28
29void Client::pullData()
30{
31 jsonrpc::Client sender(tcpSocketClient);
32 Json::Value params(Json::objectValue);
33 Json::Value orgData(Json::objectValue);
34 orgData["params"] = params;
35 qInfo() << qApp->thread() << QThread::currentThread();
36 qInfo() << "pullData -->";
37 try {
38 Json::Value result = sender.CallMethod("pullData", orgData);
39 if (!result.empty()) {
40 pullDataResult(result);
41 }
42 } catch (jsonrpc::JsonRpcException &e) {
43 std::cerr << e.what() << std::endl;
44 }
45}
46
47void Client::shutdown()
48{
49 jsonrpc::Client sender(tcpSocketClient);
50 Json::Value params(Json::objectValue);
51 Json::Value orgData(Json::objectValue);
52 orgData["params"] = params;
53 qInfo() << "shutdown -->";
54 try {
55 shutdownResult(sender.CallMethod("shutdown", orgData));
56 } catch (jsonrpc::JsonRpcException &e) {
57 std::cerr << e.what() << std::endl;
58 }
59}
60
61void Client::exit()
62{
63 jsonrpc::Client sender(tcpSocketClient);
64 Json::Value params(Json::objectValue);
65 Json::Value orgData(Json::objectValue);
66 orgData["params"] = params;
67 std::cout << "exit -->" << std::endl;
68 try {
69 sender.CallNotification("exit", orgData);
70 } catch (jsonrpc::JsonRpcException &e) {
71 std::cerr << e.what() << std::endl;
72 }
73}
74