| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "serverhandler.h" |
| 6 | #include "tools.h" |
| 7 | |
| 8 | #include <jsonrpccpp/server/connectors/tcpsocketserver.h> |
| 9 | |
| 10 | #include <QApplication> |
| 11 | |
| 12 | #include <iostream> |
| 13 | |
| 14 | namespace OptionNames |
| 15 | { |
| 16 | const QString port {"port" }; |
| 17 | } |
| 18 | |
| 19 | namespace DefaultValues |
| 20 | { |
| 21 | const QString port{"3309" }; |
| 22 | } |
| 23 | |
| 24 | const QList<QCommandLineOption> options |
| 25 | { |
| 26 | { |
| 27 | QCommandLineOption { |
| 28 | OptionNames::port, QString("Server open port, default %0.\n" ).arg(DefaultValues::port), "number" , DefaultValues::port |
| 29 | } |
| 30 | }, |
| 31 | }; |
| 32 | |
| 33 | int main(int argc, char *argv[]) |
| 34 | { |
| 35 | QApplication a(argc, argv); |
| 36 | |
| 37 | QCommandLineParser parser; |
| 38 | |
| 39 | parser.addOptions(options); |
| 40 | parser.addHelpOption(); |
| 41 | parser.process(a); |
| 42 | |
| 43 | auto list = parser.optionNames(); |
| 44 | |
| 45 | quint16 port = DefaultValues::port.toUShort(); |
| 46 | if (list.contains(OptionNames::port)) { |
| 47 | port = parser.value(OptionNames::port).toUShort(); |
| 48 | } |
| 49 | |
| 50 | jsonrpc::TcpSocketServer server("127.0.0.1" , port); |
| 51 | ServerHandler hand(server, new Tools); |
| 52 | |
| 53 | if (hand.StartListening()) { |
| 54 | std::cout << "Server started successfully name: " |
| 55 | << QCoreApplication::applicationName().toStdString() |
| 56 | << "port: " << port |
| 57 | << std::endl; |
| 58 | } else { |
| 59 | std::cout << "Error starting Server name: " |
| 60 | << QCoreApplication::applicationName().toStdString() |
| 61 | << "port: " << port |
| 62 | << std::endl; |
| 63 | } |
| 64 | |
| 65 | return a.exec(); |
| 66 | } |
| 67 | |