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/ArgsBase.h"
#include "deskflow/ClientArgs.h"
#include "deskflow/ServerArgs.h"
#ifdef WINAPI_MSWINDOWS
#include <VersionHelpers.h>

View File

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

View File

@ -18,7 +18,6 @@
#include "deskflow/ArgParser.h"
#include "deskflow/Screen.h"
#include "deskflow/ScreenException.h"
#include "deskflow/ServerArgs.h"
#include "net/SocketException.h"
#include "net/SocketMultiplexer.h"
#include "net/TCPSocketFactory.h"
@ -70,13 +69,13 @@ using namespace deskflow::server;
//
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();
// 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()) {
try {
@ -105,7 +104,7 @@ void ServerApp::reloadConfig()
LOG_DEBUG("reload configuration");
if (loadConfig(Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString())) {
if (m_server != nullptr) {
m_server->setConfig(*args().m_config);
m_server->setConfig(*m_config);
}
LOG_NOTE("reloaded configuration");
}
@ -135,7 +134,7 @@ bool ServerApp::loadConfig(const std::string &pathname)
LOG_ERR("cannot open configuration \"%s\"", pathname.c_str());
return false;
}
configStream >> *args().m_config;
configStream >> *m_config;
LOG_DEBUG("configuration read successfully");
return true;
} catch (ServerConfigReadException &e) {
@ -316,7 +315,7 @@ bool ServerApp::initServer()
deskflow::Screen *serverScreen = nullptr;
PrimaryClient *primaryClient = nullptr;
try {
std::string name = args().m_config->getCanonicalName(m_name);
std::string name = m_config->getCanonicalName(m_name);
serverScreen = openServerScreen();
primaryClient = openPrimaryClient(name, serverScreen);
m_serverScreen = serverScreen;
@ -391,8 +390,8 @@ bool ServerApp::startServer()
ClientListener *listener = nullptr;
try {
listener = openClientListener(args().m_config->getDeskflowAddress());
m_server = openServer(*args().m_config, m_primaryClient);
listener = openClientListener(m_config->getDeskflowAddress());
m_server = openServer(*m_config, m_primaryClient);
listener->setServer(m_server);
m_server->setListener(listener);
m_listener = listener;
@ -504,7 +503,7 @@ ClientListener *ServerApp::openClientListener(const NetworkAddress &address)
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 {
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
// as the default
if (args().m_config->begin() == args().m_config->end()) {
args().m_config->addScreen(m_name);
if (m_config->begin() == m_config->end()) {
m_config->addScreen(m_name);
}
// set the contact address, if provided, in the config.
// otherwise, if the config doesn't have an address, use
// the default.
if (m_deskflowAddress->isValid()) {
args().m_config->setDeskflowAddress(*m_deskflowAddress);
} else if (!args().m_config->getDeskflowAddress().isValid()) {
args().m_config->setDeskflowAddress(NetworkAddress(kDefaultPort));
m_config->setDeskflowAddress(*m_deskflowAddress);
} else if (!m_config->getDeskflowAddress().isValid()) {
m_config->setDeskflowAddress(NetworkAddress(kDefaultPort));
}
// 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());
return s_exitFailed;
}
@ -621,7 +620,7 @@ int ServerApp::runInner(int argc, char **argv, StartupFunc startup)
{
// general initialization
m_deskflowAddress = new NetworkAddress;
args().m_config = std::make_shared<Config>(getEvents());
m_config = std::make_shared<Config>(getEvents());
// run
int result = startup(argc, argv);

View File

@ -55,7 +55,7 @@ public:
// IApp overrides
//
void parseArgs(int argc, const char *const *argv) override;
void parseArgs(int, const char *const *) override;
void help() override;
const char *daemonName() const override;
const char *daemonInfo() const override;
@ -105,11 +105,6 @@ public:
return m_server;
}
deskflow::ServerArgs &args() const
{
return (deskflow::ServerArgs &)argsBase();
}
//
// Static functions
//
@ -134,4 +129,5 @@ private:
EventQueueTimer *m_timer = nullptr;
NetworkAddress *m_deskflowAddress = nullptr;
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(
ServerConfig &config, PrimaryClient *primaryClient, deskflow::Screen *screen, IEventQueue *events,
deskflow::ServerArgs const &args
)
Server::Server(ServerConfig &config, PrimaryClient *primaryClient, deskflow::Screen *screen, IEventQueue *events)
: m_primaryClient(primaryClient),
m_active(primaryClient),
m_config(&config),
m_inputFilter(config.getInputFilter()),
m_screen(screen),
m_events(events),
m_args(args)
m_events(events)
{
// must have a primary client and it must have a canonical name
assert(m_primaryClient != nullptr);

View File

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

View File

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

View File

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