refactor: XBase Classes => BaseException

This commit is contained in:
sithlord48 2025-08-07 17:26:44 -04:00 committed by Nick Bolton
parent 64786ddcb7
commit 9601180e1b
21 changed files with 56 additions and 54 deletions

View file

@ -1,30 +1,31 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/ */
#include "base/XBase.h" #include "base/BaseException.h"
#include "base/String.h" #include "base/String.h"
#include <cstdarg> #include <cstdarg>
// //
// XBase // BaseException
// //
XBase::XBase() : std::runtime_error("") BaseException::BaseException() : std::runtime_error("")
{ {
// do nothing // do nothing
} }
XBase::XBase(const std::string &msg) : std::runtime_error(msg) BaseException::BaseException(const std::string &msg) : std::runtime_error(msg)
{ {
// do nothing // do nothing
} }
const char *XBase::what() const throw() const char *BaseException::what() const throw()
{ {
if (const char *what = std::runtime_error::what(); what != nullptr && what[0] != '\0') { if (const char *what = std::runtime_error::what(); what != nullptr && what[0] != '\0') {
return what; return what;
@ -34,7 +35,7 @@ const char *XBase::what() const throw()
return m_what.c_str(); return m_what.c_str();
} }
std::string XBase::format(const char * /*id*/, const char *fmt, ...) const noexcept std::string BaseException::format(const char * /*id*/, const char *fmt, ...) const noexcept
{ {
// FIXME -- lookup message string using id as an index. set // FIXME -- lookup message string using id as an index. set
// fmt to that string if it exists. // fmt to that string if it exists.

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -14,14 +15,14 @@
/*! /*!
This is the base class of most exception types. This is the base class of most exception types.
*/ */
class XBase : public std::runtime_error class BaseException : public std::runtime_error
{ {
public: public:
//! Use getWhat() as the result of what() //! Use getWhat() as the result of what()
XBase(); BaseException();
//! Use \c msg as the result of what() //! Use \c msg as the result of what()
explicit XBase(const std::string &msg); explicit BaseException(const std::string &msg);
~XBase() throw() override = default; ~BaseException() throw() override = default;
//! Reason for exception //! Reason for exception
const char *what() const throw() override; const char *what() const throw() override;

View file

@ -4,6 +4,8 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
add_library(base STATIC add_library(base STATIC
BaseException.cpp
BaseException.h
DirectionTypes.h DirectionTypes.h
Event.cpp Event.cpp
Event.h Event.h
@ -38,8 +40,6 @@ add_library(base STATIC
TMethodJob.h TMethodJob.h
Unicode.cpp Unicode.cpp
Unicode.h Unicode.h
XBase.cpp
XBase.h
) )
target_link_libraries(base PRIVATE arch) target_link_libraries(base PRIVATE arch)

View file

@ -128,7 +128,7 @@ void Client::connect(size_t addressIndex)
setupConnecting(); setupConnecting();
setupTimer(); setupTimer();
socket->connect(m_serverAddress); socket->connect(m_serverAddress);
} catch (XBase &e) { } catch (BaseException &e) {
cleanupTimer(); cleanupTimer();
cleanupConnecting(); cleanupConnecting();
cleanupStream(); cleanupStream();
@ -639,7 +639,7 @@ void Client::bindNetworkInterface(IDataSocket *socket) const
socket->bind(bindAddress); socket->bind(bindAddress);
} }
} catch (XBase &e) { } catch (BaseException &e) {
LOG_WARN("%s", e.what()); LOG_WARN("%s", e.what());
LOG_WARN("operating system will select network interface automatically"); LOG_WARN("operating system will select network interface automatically");
} }

View file

@ -8,9 +8,9 @@
#include "client/ServerProxy.h" #include "client/ServerProxy.h"
#include "base/BaseException.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/XBase.h"
#include "client/Client.h" #include "client/Client.h"
#include "deskflow/AppUtil.h" #include "deskflow/AppUtil.h"
#include "deskflow/Clipboard.h" #include "deskflow/Clipboard.h"

View file

@ -340,7 +340,7 @@ bool ClientApp::startClient()
LOG_CRIT("failed to start client: %s", e.what()); LOG_CRIT("failed to start client: %s", e.what());
closeClientScreen(clientScreen); closeClientScreen(clientScreen);
return false; return false;
} catch (XBase &e) { } catch (BaseException &e) {
LOG_CRIT("failed to start client: %s", e.what()); LOG_CRIT("failed to start client: %s", e.what());
closeClientScreen(clientScreen); closeClientScreen(clientScreen);
return false; return false;

View file

@ -8,14 +8,14 @@
#pragma once #pragma once
#include "base/XBase.h" #include "base/BaseException.h"
/** /**
* @brief The DeskflowException class Generic deskflow exception class * @brief The DeskflowException class Generic deskflow exception class
*/ */
class DeskflowException : public XBase class DeskflowException : public BaseException
{ {
using XBase::XBase; using BaseException::BaseException;
}; };
/** /**

View file

@ -122,7 +122,7 @@ void ProtocolUtil::vwritef(deskflow::IStream *stream, const char *fmt, uint32_t
// write buffer // write buffer
stream->write(Buffer.data(), size); stream->write(Buffer.data(), size);
LOG_DEBUG2("wrote %d bytes", size); LOG_DEBUG2("wrote %d bytes", size);
} catch (const XBase &exception) { } catch (const BaseException &exception) {
LOG_DEBUG2("exception <%s> during wrote %d bytes into stream", exception.what(), size); LOG_DEBUG2("exception <%s> during wrote %d bytes into stream", exception.what(), size);
throw; throw;
} }

View file

@ -101,6 +101,6 @@ match the format.
class XIOReadMismatch : public IOException class XIOReadMismatch : public IOException
{ {
public: public:
// XBase overrides // BaseException overrides
std::string getWhat() const throw() override; std::string getWhat() const throw() override;
}; };

View file

@ -8,14 +8,14 @@
#pragma once #pragma once
#include "base/XBase.h" #include "base/BaseException.h"
/** /**
* @brief The ScreenException class, generic screen exception * @brief The ScreenException class, generic screen exception
*/ */
class ScreenException : public XBase class ScreenException : public BaseException
{ {
using XBase::XBase; using BaseException::BaseException;
}; };
/** /**

View file

@ -379,7 +379,7 @@ bool ServerApp::initServer()
closePrimaryClient(primaryClient); closePrimaryClient(primaryClient);
closeServerScreen(serverScreen); closeServerScreen(serverScreen);
return false; return false;
} catch (XBase &e) { } catch (BaseException &e) {
LOG_CRIT("failed to start server: %s", e.what()); LOG_CRIT("failed to start server: %s", e.what());
closePrimaryClient(primaryClient); closePrimaryClient(primaryClient);
closeServerScreen(serverScreen); closeServerScreen(serverScreen);
@ -452,7 +452,7 @@ bool ServerApp::startServer()
LOG_CRIT("cannot listen for clients: %s", e.what()); LOG_CRIT("cannot listen for clients: %s", e.what());
} }
closeClientListener(listener); closeClientListener(listener);
} catch (XBase &e) { } catch (BaseException &e) {
LOG_CRIT("failed to start server: %s", e.what()); LOG_CRIT("failed to start server: %s", e.what());
closeClientListener(listener); closeClientListener(listener);
return false; return false;

View file

@ -8,14 +8,14 @@
#pragma once #pragma once
#include "base/XBase.h" #include "base/BaseException.h"
/** /**
* @brief The IOException class Generic i/o exception class * @brief The IOException class Generic i/o exception class
*/ */
class IOException : public XBase class IOException : public BaseException
{ {
using XBase::XBase; using BaseException::BaseException;
}; };
/** /**

View file

@ -8,14 +8,14 @@
#pragma once #pragma once
#include "base/XBase.h" #include "base/BaseException.h"
/** /**
* @brief MTException generic multithreading exception * @brief MTException generic multithreading exception
*/ */
class MTException : public XBase class MTException : public BaseException
{ {
using XBase::XBase; using BaseException::BaseException;
}; };
/** /**

View file

@ -137,7 +137,7 @@ void *Thread::threadFunc(void *vjob)
// client called exit() // client called exit()
result = e.m_result; result = e.m_result;
LOG_DEBUG1("caught exit on thread 0x%08x, result %p", id, result); LOG_DEBUG1("caught exit on thread 0x%08x, result %p", id, result);
} catch (XBase &e) { } catch (BaseException &e) {
LOG_ERR("exception on thread 0x%08x: %s", id, e.what()); LOG_ERR("exception on thread 0x%08x: %s", id, e.what());
delete job; delete job;
throw; throw;

View file

@ -8,16 +8,16 @@
#pragma once #pragma once
#include "base/XBase.h" #include "base/BaseException.h"
#include "common/Common.h" #include "common/Common.h"
#include "io/IOException.h" #include "io/IOException.h"
/** /**
* @brief SocketException generic socket exception * @brief SocketException generic socket exception
*/ */
class SocketException : public XBase class SocketException : public BaseException
{ {
using XBase::XBase; using BaseException::BaseException;
}; };
//! Socket bad address exception //! Socket bad address exception
@ -53,7 +53,7 @@ public:
//@} //@}
protected: protected:
// XBase overrides // BaseException overrides
std::string getWhat() const throw() override; std::string getWhat() const throw() override;
private: private:

View file

@ -40,7 +40,7 @@ ClientListener::ClientListener(
cleanupListenSocket(); cleanupListenSocket();
m_socketFactory.reset(); m_socketFactory.reset();
throw; throw;
} catch (XBase &) { } catch (BaseException &) {
cleanupListenSocket(); cleanupListenSocket();
m_socketFactory.reset(); m_socketFactory.reset();
throw; throw;

View file

@ -241,7 +241,7 @@ void ClientProxyUnknown::handleData()
// client not behaving // client not behaving
LOG_WARN("protocol error from client \"%s\"", name.c_str()); LOG_WARN("protocol error from client \"%s\"", name.c_str());
ProtocolUtil::writef(m_stream, kMsgEBad); ProtocolUtil::writef(m_stream, kMsgEBad);
} catch (XBase &e) { } catch (BaseException &e) {
// misc error // misc error
LOG_WARN("error communicating with client \"%s\": %s", name.c_str(), e.what()); LOG_WARN("error communicating with client \"%s\": %s", name.c_str(), e.what());
} }

View file

@ -7,8 +7,8 @@
#pragma once #pragma once
#include "base/BaseException.h"
#include "base/String.h" #include "base/String.h"
#include "base/XBase.h"
#include "deskflow/IPlatformScreen.h" #include "deskflow/IPlatformScreen.h"
#include "deskflow/OptionTypes.h" #include "deskflow/OptionTypes.h"
#include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolTypes.h"
@ -529,7 +529,7 @@ private:
/*! /*!
Thrown when a configuration stream cannot be parsed. Thrown when a configuration stream cannot be parsed.
*/ */
class XConfigRead : public XBase class XConfigRead : public BaseException
{ {
public: public:
XConfigRead(const ConfigReadContext &context, const std::string &); XConfigRead(const ConfigReadContext &context, const std::string &);
@ -537,7 +537,7 @@ public:
~XConfigRead() throw() override = default; ~XConfigRead() throw() override = default;
protected: protected:
// XBase overrides // BaseException overrides
std::string getWhat() const throw() override; std::string getWhat() const throw() override;
private: private:

View file

@ -5,24 +5,24 @@
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/ */
#include "XBaseTests.h" #include "BaseExceptionTests.h"
#include "base/XBase.h" #include "base/BaseException.h"
void XBaseTests::empty() void BaseExceptionTests::empty()
{ {
XBase xbase; BaseException BaseException;
const char *result = xbase.what(); const char *result = BaseException.what();
QCOMPARE(result, ""); QCOMPARE(result, "");
} }
void XBaseTests::nonEmpty() void BaseExceptionTests::nonEmpty()
{ {
XBase xbase("test"); BaseException BaseException("test");
const char *result = xbase.what(); const char *result = BaseException.what();
QCOMPARE(result, "test"); QCOMPARE(result, "test");
} }
QTEST_MAIN(XBaseTests) QTEST_MAIN(BaseExceptionTests)

View file

@ -6,7 +6,7 @@
#include <QTest> #include <QTest>
class XBaseTests : public QObject class BaseExceptionTests : public QObject
{ {
Q_OBJECT Q_OBJECT
private Q_SLOTS: private Q_SLOTS:

View file

@ -30,10 +30,10 @@ create_test(
) )
create_test( create_test(
NAME XBaseTests NAME BaseExceptionTests
DEPENDS base DEPENDS base
LIBS arch LIBS arch
SOURCE XBaseTests.cpp SOURCE BaseExceptionTests.cpp
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/base" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/base"
) )