refactor: XScreen Classes => ScreenException Classes

This commit is contained in:
sithlord48 2025-08-07 17:12:21 -04:00 committed by Nick Bolton
parent 1b04b1137c
commit e4a9d1eb78
11 changed files with 65 additions and 63 deletions

View file

@ -119,6 +119,8 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
ProtocolUtil.h ProtocolUtil.h
Screen.cpp Screen.cpp
Screen.h Screen.h
ScreenException.cpp
ScreenException.h
ServerApp.cpp ServerApp.cpp
ServerApp.h ServerApp.h
ServerArgs.cpp ServerArgs.cpp
@ -127,8 +129,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
StreamChunker.h StreamChunker.h
XDeskflow.cpp XDeskflow.cpp
XDeskflow.h XDeskflow.h
XScreen.cpp
XScreen.h
languages/LanguageManager.cpp languages/LanguageManager.cpp
languages/LanguageManager.h languages/LanguageManager.h
ipc/DaemonIpcServer.cpp ipc/DaemonIpcServer.cpp

View file

@ -18,7 +18,7 @@
#include "deskflow/ClientArgs.h" #include "deskflow/ClientArgs.h"
#include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolTypes.h"
#include "deskflow/Screen.h" #include "deskflow/Screen.h"
#include "deskflow/XScreen.h" #include "deskflow/ScreenException.h"
#include "net/NetworkAddress.h" #include "net/NetworkAddress.h"
#include "net/SocketException.h" #include "net/SocketException.h"
#include "net/SocketMultiplexer.h" #include "net/SocketMultiplexer.h"
@ -332,11 +332,11 @@ bool ClientApp::startClient()
m_client->connect(m_lastServerAddressIndex); m_client->connect(m_lastServerAddressIndex);
return true; return true;
} catch (XScreenUnavailable &e) { } catch (ScreenUnavailableException &e) {
LOG_WARN("secondary screen unavailable: %s", e.what()); LOG_WARN("secondary screen unavailable: %s", e.what());
closeClientScreen(clientScreen); closeClientScreen(clientScreen);
retryTime = e.getRetryTime(); retryTime = e.getRetryTime();
} catch (XScreenOpenFailure &e) { } catch (ScreenOpenFailureException &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

@ -0,0 +1,37 @@
/*
* 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/ScreenException.h"
//
// ScreenOpenFailureException
//
std::string ScreenOpenFailureException::getWhat() const throw()
{
return format("ScreenOpenFailureException", "unable to open screen");
}
//
// ScreenUnavailableException
//
ScreenUnavailableException::ScreenUnavailableException(double timeUntilRetry) : m_timeUntilRetry(timeUntilRetry)
{
// do nothing
}
double ScreenUnavailableException::getRetryTime() const
{
return m_timeUntilRetry;
}
std::string ScreenUnavailableException::getWhat() const throw()
{
return format("ScreenUnavailableException", "unable to open screen");
}

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
@ -10,19 +11,19 @@
#include "base/XBase.h" #include "base/XBase.h"
/** /**
* @brief The XScreen class, generic screen exception * @brief The ScreenException class, generic screen exception
*/ */
class XScreen : public XBase class ScreenException : public XBase
{ {
using XBase::XBase; using XBase::XBase;
}; };
/** /**
* @brief XScreenOpenFailure - Thrown when a screen cannot be opened or initialized. * @brief ScreenOpenFailureException - Thrown when a screen cannot be opened or initialized.
*/ */
class XScreenOpenFailure : public XScreen class ScreenOpenFailureException : public ScreenException
{ {
using XScreen::XScreen; using ScreenException::ScreenException;
protected: protected:
std::string getWhat() const throw() override; std::string getWhat() const throw() override;
@ -33,15 +34,15 @@ protected:
Thrown when a screen cannot be opened or initialized but retrying later Thrown when a screen cannot be opened or initialized but retrying later
may be successful. may be successful.
*/ */
class XScreenUnavailable : public XScreenOpenFailure class ScreenUnavailableException : public ScreenOpenFailureException
{ {
public: public:
/*! /*!
\c timeUntilRetry is the suggested time the caller should wait until \c timeUntilRetry is the suggested time the caller should wait until
trying to open the screen again. trying to open the screen again.
*/ */
explicit XScreenUnavailable(double timeUntilRetry); explicit ScreenUnavailableException(double timeUntilRetry);
~XScreenUnavailable() throw() override = default; ~ScreenUnavailableException() throw() override = default;
//! @name manipulators //! @name manipulators
//@{ //@{

View file

@ -15,8 +15,8 @@
#include "deskflow/App.h" #include "deskflow/App.h"
#include "deskflow/ArgParser.h" #include "deskflow/ArgParser.h"
#include "deskflow/Screen.h" #include "deskflow/Screen.h"
#include "deskflow/ScreenException.h"
#include "deskflow/ServerArgs.h" #include "deskflow/ServerArgs.h"
#include "deskflow/XScreen.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"
@ -369,12 +369,12 @@ bool ServerApp::initServer()
m_primaryClient = primaryClient; m_primaryClient = primaryClient;
m_serverState = Initialized; m_serverState = Initialized;
return true; return true;
} catch (XScreenUnavailable &e) { } catch (ScreenUnavailableException &e) {
LOG_WARN("primary screen unavailable: %s", e.what()); LOG_WARN("primary screen unavailable: %s", e.what());
closePrimaryClient(primaryClient); closePrimaryClient(primaryClient);
closeServerScreen(serverScreen); closeServerScreen(serverScreen);
retryTime = e.getRetryTime(); retryTime = e.getRetryTime();
} catch (XScreenOpenFailure &e) { } catch (ScreenOpenFailureException &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);

View file

@ -1,36 +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/XScreen.h"
//
// XScreenOpenFailure
//
std::string XScreenOpenFailure::getWhat() const throw()
{
return format("XScreenOpenFailure", "unable to open screen");
}
//
// XScreenUnavailable
//
XScreenUnavailable::XScreenUnavailable(double timeUntilRetry) : m_timeUntilRetry(timeUntilRetry)
{
// do nothing
}
double XScreenUnavailable::getRetryTime() const
{
return m_timeUntilRetry;
}
std::string XScreenUnavailable::getWhat() const throw()
{
return format("XScreenUnavailable", "unable to open screen");
}

View file

@ -16,7 +16,7 @@
#include "common/Constants.h" #include "common/Constants.h"
#include "deskflow/Clipboard.h" #include "deskflow/Clipboard.h"
#include "deskflow/KeyMap.h" #include "deskflow/KeyMap.h"
#include "deskflow/XScreen.h" #include "deskflow/ScreenException.h"
#include "platform/EiEventQueueBuffer.h" #include "platform/EiEventQueueBuffer.h"
#include "platform/EiKeyState.h" #include "platform/EiKeyState.h"
#include "platform/PortalInputCapture.h" #include "platform/PortalInputCapture.h"

View file

@ -13,7 +13,7 @@
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "deskflow/IScreenSaver.h" #include "deskflow/IScreenSaver.h"
#include "deskflow/XScreen.h" #include "deskflow/ScreenException.h"
#include "deskflow/win32/AppUtilWindows.h" #include "deskflow/win32/AppUtilWindows.h"
#include "mt/Lock.h" #include "mt/Lock.h"
#include "mt/Thread.h" #include "mt/Thread.h"
@ -368,7 +368,7 @@ HWND MSWindowsDesks::createWindow(ATOM windowClass, const char *name) const
); );
if (window == nullptr) { if (window == nullptr) {
LOG_ERR("failed to create window: %d", GetLastError()); LOG_ERR("failed to create window: %d", GetLastError());
throw XScreenOpenFailure(); throw ScreenOpenFailureException();
} }
return window; return window;
} }

View file

@ -8,7 +8,7 @@
#include "platform/MSWindowsHook.h" #include "platform/MSWindowsHook.h"
#include "base/Log.h" #include "base/Log.h"
#include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolTypes.h"
#include "deskflow/XScreen.h" #include "deskflow/ScreenException.h"
static const char *g_name = "dfwhook"; static const char *g_name = "dfwhook";
@ -55,7 +55,7 @@ void MSWindowsHook::loadLibrary()
if (init(GetCurrentThreadId()) == 0) { if (init(GetCurrentThreadId()) == 0) {
LOG_ERR("failed to init %s.dll, another program may be using it", g_name); LOG_ERR("failed to init %s.dll, another program may be using it", g_name);
LOG_INFO("restarting your computer may solve this error"); LOG_INFO("restarting your computer may solve this error");
throw XScreenOpenFailure(); throw ScreenOpenFailureException();
} }
} }

View file

@ -21,7 +21,7 @@
#include "deskflow/ClientApp.h" #include "deskflow/ClientApp.h"
#include "deskflow/Clipboard.h" #include "deskflow/Clipboard.h"
#include "deskflow/KeyMap.h" #include "deskflow/KeyMap.h"
#include "deskflow/XScreen.h" #include "deskflow/ScreenException.h"
#include "platform/MSWindowsClipboard.h" #include "platform/MSWindowsClipboard.h"
#include "platform/MSWindowsDesks.h" #include "platform/MSWindowsDesks.h"
#include "platform/MSWindowsEventQueueBuffer.h" #include "platform/MSWindowsEventQueueBuffer.h"
@ -806,7 +806,7 @@ HWND MSWindowsScreen::createWindow(ATOM windowClass, const char *name) const
); );
if (window == nullptr) { if (window == nullptr) {
LOG_ERR("failed to create window: %d", GetLastError()); LOG_ERR("failed to create window: %d", GetLastError());
throw XScreenOpenFailure(); throw ScreenOpenFailureException();
} }
return window; return window;
} }

View file

@ -19,7 +19,7 @@
#include "deskflow/ClientArgs.h" #include "deskflow/ClientArgs.h"
#include "deskflow/Clipboard.h" #include "deskflow/Clipboard.h"
#include "deskflow/KeyMap.h" #include "deskflow/KeyMap.h"
#include "deskflow/XScreen.h" #include "deskflow/ScreenException.h"
#include "platform/XWindowsClipboard.h" #include "platform/XWindowsClipboard.h"
#include "platform/XWindowsEventQueueBuffer.h" #include "platform/XWindowsEventQueueBuffer.h"
#include "platform/XWindowsKeyState.h" #include "platform/XWindowsKeyState.h"
@ -846,7 +846,7 @@ Display *XWindowsScreen::openDisplay(const char *displayName)
LOG_DEBUG3("calling XOpenDisplay(\"%s\")", displayName); LOG_DEBUG3("calling XOpenDisplay(\"%s\")", displayName);
Display *display = XOpenDisplay(displayName); Display *display = XOpenDisplay(displayName);
if (display == nullptr) { if (display == nullptr) {
throw XScreenUnavailable(60.0); throw ScreenUnavailableException(60.0);
} }
// verify the availability of the XTest extension // verify the availability of the XTest extension
@ -857,7 +857,7 @@ Display *XWindowsScreen::openDisplay(const char *displayName)
if (!XQueryExtension(display, XTestExtensionName, &majorOpcode, &firstEvent, &firstError)) { if (!XQueryExtension(display, XTestExtensionName, &majorOpcode, &firstEvent, &firstError)) {
LOG_ERR("the XTest extension is not available"); LOG_ERR("the XTest extension is not available");
XCloseDisplay(display); XCloseDisplay(display);
throw XScreenOpenFailure(); throw ScreenOpenFailureException();
} }
} }
@ -1028,7 +1028,7 @@ Window XWindowsScreen::openWindow() const
CWDontPropagate | CWEventMask | CWOverrideRedirect | CWCursor, &attr CWDontPropagate | CWEventMask | CWOverrideRedirect | CWCursor, &attr
); );
if (window == None) { if (window == None) {
throw XScreenOpenFailure(); throw ScreenOpenFailureException();
} }
return window; return window;
} }