refactor: XBase Classes => BaseException
This commit is contained in:
@ -1,30 +1,31 @@
|
||||
/*
|
||||
* 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 "base/XBase.h"
|
||||
#include "base/BaseException.h"
|
||||
#include "base/String.h"
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
//
|
||||
// XBase
|
||||
// BaseException
|
||||
//
|
||||
|
||||
XBase::XBase() : std::runtime_error("")
|
||||
BaseException::BaseException() : std::runtime_error("")
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
XBase::XBase(const std::string &msg) : std::runtime_error(msg)
|
||||
BaseException::BaseException(const std::string &msg) : std::runtime_error(msg)
|
||||
{
|
||||
// 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') {
|
||||
return what;
|
||||
@ -34,7 +35,7 @@ const char *XBase::what() const throw()
|
||||
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
|
||||
// fmt to that string if it exists.
|
||||
@ -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
|
||||
@ -14,14 +15,14 @@
|
||||
/*!
|
||||
This is the base class of most exception types.
|
||||
*/
|
||||
class XBase : public std::runtime_error
|
||||
class BaseException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
//! Use getWhat() as the result of what()
|
||||
XBase();
|
||||
BaseException();
|
||||
//! Use \c msg as the result of what()
|
||||
explicit XBase(const std::string &msg);
|
||||
~XBase() throw() override = default;
|
||||
explicit BaseException(const std::string &msg);
|
||||
~BaseException() throw() override = default;
|
||||
|
||||
//! Reason for exception
|
||||
const char *what() const throw() override;
|
||||
@ -4,6 +4,8 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_library(base STATIC
|
||||
BaseException.cpp
|
||||
BaseException.h
|
||||
DirectionTypes.h
|
||||
Event.cpp
|
||||
Event.h
|
||||
@ -38,8 +40,6 @@ add_library(base STATIC
|
||||
TMethodJob.h
|
||||
Unicode.cpp
|
||||
Unicode.h
|
||||
XBase.cpp
|
||||
XBase.h
|
||||
)
|
||||
|
||||
target_link_libraries(base PRIVATE arch)
|
||||
|
||||
@ -128,7 +128,7 @@ void Client::connect(size_t addressIndex)
|
||||
setupConnecting();
|
||||
setupTimer();
|
||||
socket->connect(m_serverAddress);
|
||||
} catch (XBase &e) {
|
||||
} catch (BaseException &e) {
|
||||
cleanupTimer();
|
||||
cleanupConnecting();
|
||||
cleanupStream();
|
||||
@ -639,7 +639,7 @@ void Client::bindNetworkInterface(IDataSocket *socket) const
|
||||
|
||||
socket->bind(bindAddress);
|
||||
}
|
||||
} catch (XBase &e) {
|
||||
} catch (BaseException &e) {
|
||||
LOG_WARN("%s", e.what());
|
||||
LOG_WARN("operating system will select network interface automatically");
|
||||
}
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
|
||||
#include "client/ServerProxy.h"
|
||||
|
||||
#include "base/BaseException.h"
|
||||
#include "base/IEventQueue.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/XBase.h"
|
||||
#include "client/Client.h"
|
||||
#include "deskflow/AppUtil.h"
|
||||
#include "deskflow/Clipboard.h"
|
||||
|
||||
@ -340,7 +340,7 @@ bool ClientApp::startClient()
|
||||
LOG_CRIT("failed to start client: %s", e.what());
|
||||
closeClientScreen(clientScreen);
|
||||
return false;
|
||||
} catch (XBase &e) {
|
||||
} catch (BaseException &e) {
|
||||
LOG_CRIT("failed to start client: %s", e.what());
|
||||
closeClientScreen(clientScreen);
|
||||
return false;
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/XBase.h"
|
||||
#include "base/BaseException.h"
|
||||
|
||||
/**
|
||||
* @brief The DeskflowException class Generic deskflow exception class
|
||||
*/
|
||||
class DeskflowException : public XBase
|
||||
class DeskflowException : public BaseException
|
||||
{
|
||||
using XBase::XBase;
|
||||
using BaseException::BaseException;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -122,7 +122,7 @@ void ProtocolUtil::vwritef(deskflow::IStream *stream, const char *fmt, uint32_t
|
||||
// write buffer
|
||||
stream->write(Buffer.data(), 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);
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -101,6 +101,6 @@ match the format.
|
||||
class XIOReadMismatch : public IOException
|
||||
{
|
||||
public:
|
||||
// XBase overrides
|
||||
// BaseException overrides
|
||||
std::string getWhat() const throw() override;
|
||||
};
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/XBase.h"
|
||||
#include "base/BaseException.h"
|
||||
|
||||
/**
|
||||
* @brief The ScreenException class, generic screen exception
|
||||
*/
|
||||
class ScreenException : public XBase
|
||||
class ScreenException : public BaseException
|
||||
{
|
||||
using XBase::XBase;
|
||||
using BaseException::BaseException;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -379,7 +379,7 @@ bool ServerApp::initServer()
|
||||
closePrimaryClient(primaryClient);
|
||||
closeServerScreen(serverScreen);
|
||||
return false;
|
||||
} catch (XBase &e) {
|
||||
} catch (BaseException &e) {
|
||||
LOG_CRIT("failed to start server: %s", e.what());
|
||||
closePrimaryClient(primaryClient);
|
||||
closeServerScreen(serverScreen);
|
||||
@ -452,7 +452,7 @@ bool ServerApp::startServer()
|
||||
LOG_CRIT("cannot listen for clients: %s", e.what());
|
||||
}
|
||||
closeClientListener(listener);
|
||||
} catch (XBase &e) {
|
||||
} catch (BaseException &e) {
|
||||
LOG_CRIT("failed to start server: %s", e.what());
|
||||
closeClientListener(listener);
|
||||
return false;
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/XBase.h"
|
||||
#include "base/BaseException.h"
|
||||
|
||||
/**
|
||||
* @brief The IOException class Generic i/o exception class
|
||||
*/
|
||||
class IOException : public XBase
|
||||
class IOException : public BaseException
|
||||
{
|
||||
using XBase::XBase;
|
||||
using BaseException::BaseException;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/XBase.h"
|
||||
#include "base/BaseException.h"
|
||||
|
||||
/**
|
||||
* @brief MTException generic multithreading exception
|
||||
*/
|
||||
class MTException : public XBase
|
||||
class MTException : public BaseException
|
||||
{
|
||||
using XBase::XBase;
|
||||
using BaseException::BaseException;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -137,7 +137,7 @@ void *Thread::threadFunc(void *vjob)
|
||||
// client called exit()
|
||||
result = e.m_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());
|
||||
delete job;
|
||||
throw;
|
||||
|
||||
@ -8,16 +8,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/XBase.h"
|
||||
#include "base/BaseException.h"
|
||||
#include "common/Common.h"
|
||||
#include "io/IOException.h"
|
||||
|
||||
/**
|
||||
* @brief SocketException generic socket exception
|
||||
*/
|
||||
class SocketException : public XBase
|
||||
class SocketException : public BaseException
|
||||
{
|
||||
using XBase::XBase;
|
||||
using BaseException::BaseException;
|
||||
};
|
||||
|
||||
//! Socket bad address exception
|
||||
@ -53,7 +53,7 @@ public:
|
||||
//@}
|
||||
|
||||
protected:
|
||||
// XBase overrides
|
||||
// BaseException overrides
|
||||
std::string getWhat() const throw() override;
|
||||
|
||||
private:
|
||||
|
||||
@ -40,7 +40,7 @@ ClientListener::ClientListener(
|
||||
cleanupListenSocket();
|
||||
m_socketFactory.reset();
|
||||
throw;
|
||||
} catch (XBase &) {
|
||||
} catch (BaseException &) {
|
||||
cleanupListenSocket();
|
||||
m_socketFactory.reset();
|
||||
throw;
|
||||
|
||||
@ -241,7 +241,7 @@ void ClientProxyUnknown::handleData()
|
||||
// client not behaving
|
||||
LOG_WARN("protocol error from client \"%s\"", name.c_str());
|
||||
ProtocolUtil::writef(m_stream, kMsgEBad);
|
||||
} catch (XBase &e) {
|
||||
} catch (BaseException &e) {
|
||||
// misc error
|
||||
LOG_WARN("error communicating with client \"%s\": %s", name.c_str(), e.what());
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/BaseException.h"
|
||||
#include "base/String.h"
|
||||
#include "base/XBase.h"
|
||||
#include "deskflow/IPlatformScreen.h"
|
||||
#include "deskflow/OptionTypes.h"
|
||||
#include "deskflow/ProtocolTypes.h"
|
||||
@ -529,7 +529,7 @@ private:
|
||||
/*!
|
||||
Thrown when a configuration stream cannot be parsed.
|
||||
*/
|
||||
class XConfigRead : public XBase
|
||||
class XConfigRead : public BaseException
|
||||
{
|
||||
public:
|
||||
XConfigRead(const ConfigReadContext &context, const std::string &);
|
||||
@ -537,7 +537,7 @@ public:
|
||||
~XConfigRead() throw() override = default;
|
||||
|
||||
protected:
|
||||
// XBase overrides
|
||||
// BaseException overrides
|
||||
std::string getWhat() const throw() override;
|
||||
|
||||
private:
|
||||
|
||||
@ -5,24 +5,24 @@
|
||||
* 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;
|
||||
const char *result = xbase.what();
|
||||
BaseException BaseException;
|
||||
const char *result = BaseException.what();
|
||||
|
||||
QCOMPARE(result, "");
|
||||
}
|
||||
|
||||
void XBaseTests::nonEmpty()
|
||||
void BaseExceptionTests::nonEmpty()
|
||||
{
|
||||
XBase xbase("test");
|
||||
const char *result = xbase.what();
|
||||
BaseException BaseException("test");
|
||||
const char *result = BaseException.what();
|
||||
|
||||
QCOMPARE(result, "test");
|
||||
}
|
||||
|
||||
QTEST_MAIN(XBaseTests)
|
||||
QTEST_MAIN(BaseExceptionTests)
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class XBaseTests : public QObject
|
||||
class BaseExceptionTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
@ -30,10 +30,10 @@ create_test(
|
||||
)
|
||||
|
||||
create_test(
|
||||
NAME XBaseTests
|
||||
NAME BaseExceptionTests
|
||||
DEPENDS base
|
||||
LIBS arch
|
||||
SOURCE XBaseTests.cpp
|
||||
SOURCE BaseExceptionTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/base"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user