refactor: remove ServerArgs

This commit is contained in:
sithlord48 2025-09-25 20:27:24 -04:00 committed by Chris Rizzitello
parent bf7a50ab0e
commit efebe9ca56
10 changed files with 20 additions and 89 deletions

View file

@ -10,7 +10,6 @@
#include "deskflow/App.h" #include "deskflow/App.h"
#include "deskflow/ArgsBase.h" #include "deskflow/ArgsBase.h"
#include "deskflow/ClientArgs.h" #include "deskflow/ClientArgs.h"
#include "deskflow/ServerArgs.h"
#ifdef WINAPI_MSWINDOWS #ifdef WINAPI_MSWINDOWS
#include <VersionHelpers.h> #include <VersionHelpers.h>

View file

@ -126,8 +126,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
ScreenException.h ScreenException.h
ServerApp.cpp ServerApp.cpp
ServerApp.h ServerApp.h
ServerArgs.cpp
ServerArgs.h
StreamChunker.cpp StreamChunker.cpp
StreamChunker.h StreamChunker.h
languages/LanguageManager.cpp languages/LanguageManager.cpp

View file

@ -18,7 +18,6 @@
#include "deskflow/ArgParser.h" #include "deskflow/ArgParser.h"
#include "deskflow/Screen.h" #include "deskflow/Screen.h"
#include "deskflow/ScreenException.h" #include "deskflow/ScreenException.h"
#include "deskflow/ServerArgs.h"
#include "net/SocketException.h" #include "net/SocketException.h"
#include "net/SocketMultiplexer.h" #include "net/SocketMultiplexer.h"
#include "net/TCPSocketFactory.h" #include "net/TCPSocketFactory.h"
@ -70,13 +69,13 @@ using namespace deskflow::server;
// //
ServerApp::ServerApp(IEventQueue *events, const QString &processName) ServerApp::ServerApp(IEventQueue *events, const QString &processName)
: App(events, processName, new deskflow::ServerArgs()) : App(events, processName, new deskflow::ArgsBase())
{ {
m_name = Settings::value(Settings::Core::ScreenName).toString().toStdString(); m_name = Settings::value(Settings::Core::ScreenName).toString().toStdString();
// do nothing // do nothing
} }
void ServerApp::parseArgs(int argc, const char *const *argv) void ServerApp::parseArgs(int, const char *const *)
{ {
if (const auto address = Settings::value(Settings::Core::Interface).toString(); !address.isEmpty()) { if (const auto address = Settings::value(Settings::Core::Interface).toString(); !address.isEmpty()) {
try { try {
@ -105,7 +104,7 @@ void ServerApp::reloadConfig()
LOG_DEBUG("reload configuration"); LOG_DEBUG("reload configuration");
if (loadConfig(Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString())) { if (loadConfig(Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString())) {
if (m_server != nullptr) { if (m_server != nullptr) {
m_server->setConfig(*args().m_config); m_server->setConfig(*m_config);
} }
LOG_NOTE("reloaded configuration"); LOG_NOTE("reloaded configuration");
} }
@ -135,7 +134,7 @@ bool ServerApp::loadConfig(const std::string &pathname)
LOG_ERR("cannot open configuration \"%s\"", pathname.c_str()); LOG_ERR("cannot open configuration \"%s\"", pathname.c_str());
return false; return false;
} }
configStream >> *args().m_config; configStream >> *m_config;
LOG_DEBUG("configuration read successfully"); LOG_DEBUG("configuration read successfully");
return true; return true;
} catch (ServerConfigReadException &e) { } catch (ServerConfigReadException &e) {
@ -316,7 +315,7 @@ bool ServerApp::initServer()
deskflow::Screen *serverScreen = nullptr; deskflow::Screen *serverScreen = nullptr;
PrimaryClient *primaryClient = nullptr; PrimaryClient *primaryClient = nullptr;
try { try {
std::string name = args().m_config->getCanonicalName(m_name); std::string name = m_config->getCanonicalName(m_name);
serverScreen = openServerScreen(); serverScreen = openServerScreen();
primaryClient = openPrimaryClient(name, serverScreen); primaryClient = openPrimaryClient(name, serverScreen);
m_serverScreen = serverScreen; m_serverScreen = serverScreen;
@ -391,8 +390,8 @@ bool ServerApp::startServer()
ClientListener *listener = nullptr; ClientListener *listener = nullptr;
try { try {
listener = openClientListener(args().m_config->getDeskflowAddress()); listener = openClientListener(m_config->getDeskflowAddress());
m_server = openServer(*args().m_config, m_primaryClient); m_server = openServer(*m_config, m_primaryClient);
listener->setServer(m_server); listener->setServer(m_server);
m_server->setListener(listener); m_server->setListener(listener);
m_listener = listener; m_listener = listener;
@ -504,7 +503,7 @@ ClientListener *ServerApp::openClientListener(const NetworkAddress &address)
Server *ServerApp::openServer(ServerConfig &config, PrimaryClient *primaryClient) Server *ServerApp::openServer(ServerConfig &config, PrimaryClient *primaryClient)
{ {
auto *server = new Server(config, primaryClient, m_serverScreen, getEvents(), args()); auto *server = new Server(config, primaryClient, m_serverScreen, getEvents());
try { try {
getEvents()->addHandler(EventTypes::ServerScreenSwitched, server, [this](const auto &) { handleScreenSwitched(); }); getEvents()->addHandler(EventTypes::ServerScreenSwitched, server, [this](const auto &) { handleScreenSwitched(); });
@ -539,21 +538,21 @@ int ServerApp::mainLoop()
// if configuration has no screens then add this system // if configuration has no screens then add this system
// as the default // as the default
if (args().m_config->begin() == args().m_config->end()) { if (m_config->begin() == m_config->end()) {
args().m_config->addScreen(m_name); m_config->addScreen(m_name);
} }
// set the contact address, if provided, in the config. // set the contact address, if provided, in the config.
// otherwise, if the config doesn't have an address, use // otherwise, if the config doesn't have an address, use
// the default. // the default.
if (m_deskflowAddress->isValid()) { if (m_deskflowAddress->isValid()) {
args().m_config->setDeskflowAddress(*m_deskflowAddress); m_config->setDeskflowAddress(*m_deskflowAddress);
} else if (!args().m_config->getDeskflowAddress().isValid()) { } else if (!m_config->getDeskflowAddress().isValid()) {
args().m_config->setDeskflowAddress(NetworkAddress(kDefaultPort)); m_config->setDeskflowAddress(NetworkAddress(kDefaultPort));
} }
// canonicalize the primary screen name // canonicalize the primary screen name
if (std::string primaryName = args().m_config->getCanonicalName(m_name); primaryName.empty()) { if (std::string primaryName = m_config->getCanonicalName(m_name); primaryName.empty()) {
LOG_CRIT("unknown screen name `%s'", m_name.c_str()); LOG_CRIT("unknown screen name `%s'", m_name.c_str());
return s_exitFailed; return s_exitFailed;
} }
@ -621,7 +620,7 @@ int ServerApp::runInner(int argc, char **argv, StartupFunc startup)
{ {
// general initialization // general initialization
m_deskflowAddress = new NetworkAddress; m_deskflowAddress = new NetworkAddress;
args().m_config = std::make_shared<Config>(getEvents()); m_config = std::make_shared<Config>(getEvents());
// run // run
int result = startup(argc, argv); int result = startup(argc, argv);

View file

@ -55,7 +55,7 @@ public:
// IApp overrides // IApp overrides
// //
void parseArgs(int argc, const char *const *argv) override; void parseArgs(int, const char *const *) override;
void help() override; void help() override;
const char *daemonName() const override; const char *daemonName() const override;
const char *daemonInfo() const override; const char *daemonInfo() const override;
@ -105,11 +105,6 @@ public:
return m_server; return m_server;
} }
deskflow::ServerArgs &args() const
{
return (deskflow::ServerArgs &)argsBase();
}
// //
// Static functions // Static functions
// //
@ -134,4 +129,5 @@ private:
EventQueueTimer *m_timer = nullptr; EventQueueTimer *m_timer = nullptr;
NetworkAddress *m_deskflowAddress = nullptr; NetworkAddress *m_deskflowAddress = nullptr;
std::string m_name; std::string m_name;
std::shared_ptr<deskflow::server::Config> m_config;
}; };

View file

@ -1,15 +0,0 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2014 - 2020 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "ServerArgs.h"
namespace deskflow {
ServerArgs::ServerArgs()
{
m_classType = ClassType::Server;
}
} // namespace deskflow

View file

@ -1,33 +0,0 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2014 - 2020 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#pragma once
#include "ArgsBase.h"
#include "server/Config.h"
#include <memory>
namespace deskflow {
class ServerArgs : public ArgsBase
{
using Config = deskflow::server::Config;
public:
ServerArgs();
ServerArgs(ServerArgs const &src) = default;
ServerArgs(ServerArgs &&) = default;
~ServerArgs() override = default;
ServerArgs &operator=(ServerArgs const &) = default;
ServerArgs &operator=(ServerArgs &&) = default;
public:
std::shared_ptr<Config> m_config;
};
} // namespace deskflow

View file

@ -43,17 +43,13 @@ using namespace deskflow::server;
// Server // Server
// //
Server::Server( Server::Server(ServerConfig &config, PrimaryClient *primaryClient, deskflow::Screen *screen, IEventQueue *events)
ServerConfig &config, PrimaryClient *primaryClient, deskflow::Screen *screen, IEventQueue *events,
deskflow::ServerArgs const &args
)
: m_primaryClient(primaryClient), : m_primaryClient(primaryClient),
m_active(primaryClient), m_active(primaryClient),
m_config(&config), m_config(&config),
m_inputFilter(config.getInputFilter()), m_inputFilter(config.getInputFilter()),
m_screen(screen), m_screen(screen),
m_events(events), m_events(events)
m_args(args)
{ {
// must have a primary client and it must have a canonical name // must have a primary client and it must have a canonical name
assert(m_primaryClient != nullptr); assert(m_primaryClient != nullptr);

View file

@ -16,7 +16,6 @@
#include "deskflow/KeyTypes.h" #include "deskflow/KeyTypes.h"
#include "deskflow/MouseTypes.h" #include "deskflow/MouseTypes.h"
#include "deskflow/OptionTypes.h" #include "deskflow/OptionTypes.h"
#include "deskflow/ServerArgs.h"
#include "server/Config.h" #include "server/Config.h"
#include <climits> #include <climits>
@ -120,10 +119,7 @@ public:
client (local screen) \p primaryClient. The client retains client (local screen) \p primaryClient. The client retains
ownership of \p primaryClient. ownership of \p primaryClient.
*/ */
Server( Server(ServerConfig &config, PrimaryClient *primaryClient, deskflow::Screen *screen, IEventQueue *events);
ServerConfig &config, PrimaryClient *primaryClient, deskflow::Screen *screen, IEventQueue *events,
deskflow::ServerArgs const &args
);
Server(Server const &) = delete; Server(Server const &) = delete;
Server(Server &&) = delete; Server(Server &&) = delete;
~Server(); ~Server();
@ -402,8 +398,6 @@ private:
using OldClients = std::map<BaseClientProxy *, EventQueueTimer *>; using OldClients = std::map<BaseClientProxy *, EventQueueTimer *>;
OldClients m_oldClients; OldClients m_oldClients;
deskflow::ServerArgs m_args;
// clipboard cache // clipboard cache
ClipboardInfo m_clipboards[kClipboardEnd]; ClipboardInfo m_clipboards[kClipboardEnd];

View file

@ -9,7 +9,6 @@
#include "deskflow/ArgsBase.h" #include "deskflow/ArgsBase.h"
#include "deskflow/ClientArgs.h" #include "deskflow/ClientArgs.h"
#include "deskflow/ServerArgs.h"
// This file is generated at build time // This file is generated at build time
#include <common/Constants.h> #include <common/Constants.h>

View file

@ -8,12 +8,10 @@
#include "ServerAppTests.h" #include "ServerAppTests.h"
#include "deskflow/ServerApp.h" #include "deskflow/ServerApp.h"
#include "deskflow/ServerArgs.h"
void ServerAppTests::section() void ServerAppTests::section()
{ {
ServerApp app(nullptr); ServerApp app(nullptr);
QVERIFY(!app.args().m_config);
QCOMPARE(app.configSection(), "server"); QCOMPARE(app.configSection(), "server");
} }