refactor: XDeskflow Classes => DeskflowException Classes

This commit is contained in:
sithlord48
2025-08-07 17:17:20 -04:00
committed by Nick Bolton
parent e4a9d1eb78
commit 64786ddcb7
14 changed files with 161 additions and 159 deletions

View File

@ -14,13 +14,13 @@
#include "base/TMethodJob.h"
#include "client/ServerProxy.h"
#include "deskflow/AppUtil.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/IPlatformScreen.h"
#include "deskflow/PacketStreamFilter.h"
#include "deskflow/ProtocolTypes.h"
#include "deskflow/ProtocolUtil.h"
#include "deskflow/Screen.h"
#include "deskflow/StreamChunker.h"
#include "deskflow/XDeskflow.h"
#include "mt/Thread.h"
#include "net/IDataSocket.h"
#include "net/ISocketFactory.h"
@ -68,7 +68,7 @@ Client::Client(
cleanupConnection();
},
[this](int major, int minor) {
sendConnectionFailedEvent(XIncompatibleClient(major, minor).what());
sendConnectionFailedEvent(IncompatibleClientException(major, minor).what());
cleanupTimer();
cleanupConnection();
}

View File

@ -15,11 +15,11 @@
#include "deskflow/AppUtil.h"
#include "deskflow/Clipboard.h"
#include "deskflow/ClipboardChunk.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/OptionTypes.h"
#include "deskflow/ProtocolTypes.h"
#include "deskflow/ProtocolUtil.h"
#include "deskflow/StreamChunker.h"
#include "deskflow/XDeskflow.h"
#include "io/IStream.h"
#include <algorithm>
@ -111,7 +111,7 @@ void ServerProxy::handleData()
case Disconnect:
return;
}
} catch (const XBadClient &e) {
} catch (const BadClientException &e) {
LOG_ERR("protocol error from server: %s", e.what());
ProtocolUtil::writef(m_stream, kMsgEBad);
m_client->disconnect("invalid message from server");

View File

@ -15,8 +15,8 @@
#include "common/Constants.h"
#include "deskflow/ArgsBase.h"
#include "deskflow/Config.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/ProtocolTypes.h"
#include "deskflow/XDeskflow.h"
#if SYSAPI_WIN32
#include "base/IEventQueue.h"
@ -92,7 +92,7 @@ int App::run(int argc, char **argv)
try {
result = appUtil().run(argc, argv);
} catch (XExitApp &e) {
} catch (ExitAppException &e) {
// instead of showing a nasty error, just exit with the error code.
// not sure if i like this behaviour, but it's probably better than
// using the exit(int) function!

View File

@ -7,8 +7,8 @@
#pragma once
#include "deskflow/DeskflowException.h"
#include "deskflow/IAppUtil.h"
#include "deskflow/XDeskflow.h"
class AppUtil : public IAppUtil
{
@ -20,7 +20,7 @@ public:
IApp &app() const override;
virtual void exitApp(int code)
{
throw XExitApp(code);
throw ExitAppException(code);
}
static AppUtil &instance();

View File

@ -85,6 +85,8 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
Config.h
DaemonApp.cpp
DaemonApp.h
DeskflowException.cpp
DeskflowException.h
DisplayInvalidException.h
IApp.h
IAppUtil.h
@ -127,8 +129,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
ServerArgs.h
StreamChunker.cpp
StreamChunker.h
XDeskflow.cpp
XDeskflow.h
languages/LanguageManager.cpp
languages/LanguageManager.h
ipc/DaemonIpcServer.cpp

View File

@ -0,0 +1,112 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "deskflow/DeskflowException.h"
#include "base/String.h"
//
// BadClientException
//
std::string BadClientException::getWhat() const throw()
{
return "BadClientException";
}
//
// InvalidProtocolException
//
std::string InvalidProtocolException::getWhat() const throw()
{
return "InvalidProtocolException";
}
//
// IncompatibleClientException
//
IncompatibleClientException::IncompatibleClientException(int major, int minor) : m_major(major), m_minor(minor)
{
// do nothing
}
int IncompatibleClientException::getMajor() const noexcept
{
return m_major;
}
int IncompatibleClientException::getMinor() const noexcept
{
return m_minor;
}
std::string IncompatibleClientException::getWhat() const throw()
{
return format(
"IncompatibleClientException", "incompatible client %{1}.%{2}", deskflow::string::sprintf("%d", m_major).c_str(),
deskflow::string::sprintf("%d", m_minor).c_str()
);
}
//
// DuplicateClientException
//
DuplicateClientException::DuplicateClientException(const std::string &name) : m_name(name)
{
// do nothing
}
const std::string &DuplicateClientException::getName() const noexcept
{
return m_name;
}
std::string DuplicateClientException::getWhat() const throw()
{
return format("DuplicateClientException", "duplicate client %{1}", m_name.c_str());
}
//
// UnknownClientException
//
UnknownClientException::UnknownClientException(const std::string &name) : m_name(name)
{
// do nothing
}
const std::string &UnknownClientException::getName() const noexcept
{
return m_name;
}
std::string UnknownClientException::getWhat() const throw()
{
return format("UnknownClientException", "unknown client %{1}", m_name.c_str());
}
//
// ExitAppException
//
ExitAppException::ExitAppException(int code) : m_code(code)
{
// do nothing
}
int ExitAppException::getCode() const noexcept
{
return m_code;
}
std::string ExitAppException::getWhat() const throw()
{
return format("ExitAppException", "exiting with code %{1}", deskflow::string::sprintf("%d", m_code).c_str());
}

View File

@ -1,5 +1,6 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -10,30 +11,30 @@
#include "base/XBase.h"
/**
* @brief The XDeskflow class Generic deskflow exception class
* @brief The DeskflowException class Generic deskflow exception class
*/
class XDeskflow : public XBase
class DeskflowException : public XBase
{
using XBase::XBase;
};
/**
* @brief XBadClient - Thrown when the client fails to follow the protocol.
* @brief BadClientException - Thrown when the client fails to follow the protocol.
*/
class XBadClient : public XDeskflow
class BadClientException : public DeskflowException
{
using XDeskflow::XDeskflow;
using DeskflowException::DeskflowException;
protected:
std::string getWhat() const throw() override;
};
/**
* @brief XInvalidProtocol - Thrown when the server protocol is unreconized.
* @brief InvalidProtocolException - Thrown when the server protocol is unreconized.
*/
class XInvalidProtocol : public XDeskflow
class InvalidProtocolException : public DeskflowException
{
using XDeskflow::XDeskflow;
using DeskflowException::DeskflowException;
protected:
std::string getWhat() const throw() override;
@ -43,10 +44,10 @@ protected:
/*!
Thrown when a client attempting to connect has an incompatible version.
*/
class XIncompatibleClient : public XDeskflow
class IncompatibleClientException : public DeskflowException
{
public:
XIncompatibleClient(int major, int minor);
IncompatibleClientException(int major, int minor);
//! @name accessors
//@{
@ -71,11 +72,11 @@ private:
Thrown when a client attempting to connect is using the same name as
a client that is already connected.
*/
class XDuplicateClient : public XDeskflow
class DuplicateClientException : public DeskflowException
{
public:
explicit XDuplicateClient(const std::string &name);
~XDuplicateClient() throw() override = default;
explicit DuplicateClientException(const std::string &name);
~DuplicateClientException() throw() override = default;
//! @name accessors
//@{
@ -97,11 +98,11 @@ private:
Thrown when a client attempting to connect is using a name that is
unknown to the server.
*/
class XUnknownClient : public XDeskflow
class UnknownClientException : public DeskflowException
{
public:
explicit XUnknownClient(const std::string &name);
~XUnknownClient() throw() override = default;
explicit UnknownClientException(const std::string &name);
~UnknownClientException() throw() override = default;
//! @name accessors
//@{
@ -124,11 +125,11 @@ Thrown when we want to abort, with the opportunity to clean up. This is a
little bit of a hack, but it's a better way of exiting, than just calling
exit(int).
*/
class XExitApp : public XDeskflow
class ExitAppException : public DeskflowException
{
public:
explicit XExitApp(int code);
~XExitApp() throw() override = default;
explicit ExitAppException(int code);
~ExitAppException() throw() override = default;
//! Get the exit code
int getCode() const noexcept;

View File

@ -7,8 +7,8 @@
#include "deskflow/ProtocolUtil.h"
#include "base/Log.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/ProtocolTypes.h"
#include "deskflow/XDeskflow.h"
#include "io/IStream.h"
#include <array>
#include <iterator>
@ -193,7 +193,7 @@ void ProtocolUtil::vreadf(deskflow::IStream *stream, const char *fmt, va_list ar
if (len > PROTOCOL_MAX_STRING_LENGTH) {
LOG_ERR("read: string length exceeds maximum allowed size: %u", len);
throw XBadClient("Too long message received");
throw BadClientException("Too long message received");
}
readBytes(stream, len, destination);
@ -507,7 +507,7 @@ uint32_t ProtocolUtil::readVectorSize(deskflow::IStream *stream)
if (size > PROTOCOL_MAX_LIST_LENGTH) {
LOG_ERR("readVectorSize: vector length exceeds maximum allowed size: %u", size);
throw XBadClient("Too long message received");
throw BadClientException("Too long message received");
}
return size;

View File

@ -1,111 +0,0 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "deskflow/XDeskflow.h"
#include "base/String.h"
//
// XBadClient
//
std::string XBadClient::getWhat() const throw()
{
return "XBadClient";
}
//
// XInvalidProtocol
//
std::string XInvalidProtocol::getWhat() const throw()
{
return "XInvalidProtocol";
}
//
// XIncompatibleClient
//
XIncompatibleClient::XIncompatibleClient(int major, int minor) : m_major(major), m_minor(minor)
{
// do nothing
}
int XIncompatibleClient::getMajor() const noexcept
{
return m_major;
}
int XIncompatibleClient::getMinor() const noexcept
{
return m_minor;
}
std::string XIncompatibleClient::getWhat() const throw()
{
return format(
"XIncompatibleClient", "incompatible client %{1}.%{2}", deskflow::string::sprintf("%d", m_major).c_str(),
deskflow::string::sprintf("%d", m_minor).c_str()
);
}
//
// XDuplicateClient
//
XDuplicateClient::XDuplicateClient(const std::string &name) : m_name(name)
{
// do nothing
}
const std::string &XDuplicateClient::getName() const noexcept
{
return m_name;
}
std::string XDuplicateClient::getWhat() const throw()
{
return format("XDuplicateClient", "duplicate client %{1}", m_name.c_str());
}
//
// XUnknownClient
//
XUnknownClient::XUnknownClient(const std::string &name) : m_name(name)
{
// do nothing
}
const std::string &XUnknownClient::getName() const noexcept
{
return m_name;
}
std::string XUnknownClient::getWhat() const throw()
{
return format("XUnknownClient", "unknown client %{1}", m_name.c_str());
}
//
// XExitApp
//
XExitApp::XExitApp(int code) : m_code(code)
{
// do nothing
}
int XExitApp::getCode() const noexcept
{
return m_code;
}
std::string XExitApp::getWhat() const throw()
{
return format("XExitApp", "exiting with code %{1}", deskflow::string::sprintf("%d", m_code).c_str());
}

View File

@ -17,8 +17,8 @@
#include "common/Constants.h"
#include "deskflow/App.h"
#include "deskflow/ArgsBase.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/Screen.h"
#include "deskflow/XDeskflow.h"
#include "platform/MSWindowsScreen.h"
#include <VersionHelpers.h>
@ -77,7 +77,7 @@ void AppUtilWindows::exitApp(int code)
break;
default:
throw XExitApp(code);
throw ExitAppException(code);
}
}

View File

@ -10,8 +10,8 @@
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/ProtocolUtil.h"
#include "deskflow/XDeskflow.h"
#include "io/IStream.h"
#include <cstring>
@ -131,7 +131,7 @@ void ClientProxy1_0::handleData()
while (getStream()->read(nullptr, 4))
;
}
} catch (const XBadClient &e) {
} catch (const BadClientException &e) {
LOG_ERR("protocol error from client \"%s\": %s", getName().c_str(), e.what());
disconnect();
return;

View File

@ -11,9 +11,9 @@
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "deskflow/AppUtil.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/ProtocolTypes.h"
#include "deskflow/ProtocolUtil.h"
#include "deskflow/XDeskflow.h"
#include "io/IOException.h"
#include "io/IStream.h"
#include "server/ClientProxy1_0.h"
@ -189,7 +189,7 @@ void ClientProxyUnknown::initProxy(const std::string &name, int major, int minor
// hangup (with error) if version isn't supported
if (m_proxy == nullptr) {
throw XIncompatibleClient(major, minor);
throw IncompatibleClientException(major, minor);
}
}
@ -203,19 +203,19 @@ void ClientProxyUnknown::handleData()
// limit the maximum length of the hello
if (uint32_t n = m_stream->getSize(); n > kMaxHelloLength) {
LOG_DEBUG1("hello reply too long");
throw XBadClient();
throw BadClientException();
}
// parse the reply to hello
int16_t major;
int16_t minor;
if (std::string protocolName; !ProtocolUtil::readf(m_stream, kMsgHelloBack, &protocolName, &major, &minor, &name)) {
throw XBadClient();
throw BadClientException();
}
// disallow invalid version numbers
if (major <= 0 || minor < 0) {
throw XIncompatibleClient(major, minor);
throw IncompatibleClientException(major, minor);
}
// remove stream event handlers. the proxy we're about to create
@ -233,11 +233,11 @@ void ClientProxyUnknown::handleData()
// wait until the proxy signals that it's ready or has disconnected
addProxyHandlers();
return;
} catch (XIncompatibleClient &e) {
} catch (IncompatibleClientException &e) {
// client is incompatible
LOG_WARN("client \"%s\" has incompatible version %d.%d)", name.c_str(), e.getMajor(), e.getMinor());
ProtocolUtil::writef(m_stream, kMsgEIncompatible, kProtocolMajorVersion, kProtocolMinorVersion);
} catch (XBadClient &) {
} catch (BadClientException &) {
// client not behaving
LOG_WARN("protocol error from client \"%s\"", name.c_str());
ProtocolUtil::writef(m_stream, kMsgEBad);

View File

@ -8,10 +8,10 @@
#include "server/Config.h"
#include "base/IEventQueue.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/KeyMap.h"
#include "deskflow/KeyTypes.h"
#include "deskflow/OptionTypes.h"
#include "deskflow/XDeskflow.h"
#include "net/SocketException.h"
#include "server/Server.h"
@ -1313,7 +1313,7 @@ std::string Config::getOptionValue(OptionID id, OptionValue value)
} else if (enumValue == Barrier) {
return kBarrierProtocolOption;
} else {
throw XInvalidProtocol();
throw InvalidProtocolException();
}
}

View File

@ -13,13 +13,13 @@
#include "base/Log.h"
#include "base/TMethodJob.h"
#include "deskflow/AppUtil.h"
#include "deskflow/DeskflowException.h"
#include "deskflow/IPlatformScreen.h"
#include "deskflow/OptionTypes.h"
#include "deskflow/PacketStreamFilter.h"
#include "deskflow/ProtocolTypes.h"
#include "deskflow/Screen.h"
#include "deskflow/StreamChunker.h"
#include "deskflow/XDeskflow.h"
#include "mt/Thread.h"
#include "net/TCPSocket.h"
#include "server/ClientListener.h"
@ -280,7 +280,7 @@ std::string Server::protocolString() const
} else if (m_protocol == Barrier) {
return kBarrierProtocolName;
}
throw XInvalidProtocol();
throw InvalidProtocolException();
}
uint32_t Server::getNumClients() const
@ -1080,7 +1080,7 @@ void Server::processOptions()
} else if (enumValue == Barrier) {
m_protocol = Barrier;
} else {
throw XInvalidProtocol();
throw InvalidProtocolException();
}
} else if (id == kOptionScreenSwitchDelay) {
m_switchWaitDelay = 1.0e-3 * static_cast<double>(value);