From 0fcb68f8a4e86a3090f9cc3542be9c1a851c8a1d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 13 Feb 2025 11:16:56 +0100 Subject: Move timers to core library Make it clearer what is protocol handling and what is just general plumbing. This is one step of several. --- common/core/CMakeLists.txt | 1 + common/core/Timer.cxx | 179 +++++++++++++++++++++++++++++++++ common/core/Timer.h | 136 +++++++++++++++++++++++++ common/rfb/CMakeLists.txt | 1 - common/rfb/EncodeManager.cxx | 2 +- common/rfb/EncodeManager.h | 8 +- common/rfb/SConnection.cxx | 2 +- common/rfb/SConnection.h | 7 +- common/rfb/Timer.cxx | 182 ---------------------------------- common/rfb/Timer.h | 136 ------------------------- common/rfb/VNCSConnectionST.cxx | 2 +- common/rfb/VNCSConnectionST.h | 13 +-- common/rfb/VNCServerST.cxx | 2 +- common/rfb/VNCServerST.h | 15 +-- tests/unit/CMakeLists.txt | 4 +- tests/unit/emulatemb.cxx | 12 +-- tests/unit/gesturehandler.cxx | 34 +++---- unix/vncconfig/QueryConnectDialog.cxx | 3 +- unix/vncconfig/QueryConnectDialog.h | 9 +- unix/vncconfig/vncconfig.cxx | 4 +- unix/x0vncserver/x0vncserver.cxx | 6 +- unix/xserver/hw/vnc/XserverDesktop.cc | 4 +- unix/xserver/hw/vnc/XserverDesktop.h | 9 +- vncviewer/CConn.cxx | 4 +- vncviewer/EmulateMB.cxx | 4 +- vncviewer/EmulateMB.h | 9 +- vncviewer/GestureHandler.cxx | 2 +- vncviewer/GestureHandler.h | 10 +- vncviewer/vncviewer.cxx | 4 +- win/rfb_win32/SocketManager.cxx | 2 +- 30 files changed, 403 insertions(+), 403 deletions(-) create mode 100644 common/core/Timer.cxx create mode 100644 common/core/Timer.h delete mode 100644 common/rfb/Timer.cxx delete mode 100644 common/rfb/Timer.h diff --git a/common/core/CMakeLists.txt b/common/core/CMakeLists.txt index 78c92652..7f3e9983 100644 --- a/common/core/CMakeLists.txt +++ b/common/core/CMakeLists.txt @@ -6,6 +6,7 @@ add_library(core STATIC Logger_stdio.cxx LogWriter.cxx Region.cxx + Timer.cxx util.cxx) target_link_libraries(core os) diff --git a/common/core/Timer.cxx b/common/core/Timer.cxx new file mode 100644 index 00000000..5c0fcc29 --- /dev/null +++ b/common/core/Timer.cxx @@ -0,0 +1,179 @@ +/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2016-2024 Pierre Ossman for Cendio AB + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +// -=- Timer.cxx + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include + +#include +#include +#include + +using namespace core; + +#ifndef __NO_DEFINE_VLOG__ +static LogWriter vlog("Timer"); +#endif + + +// Millisecond timeout processing helper functions + +inline static timeval addMillis(timeval inTime, int millis) { + int secs = millis / 1000; + millis = millis % 1000; + inTime.tv_sec += secs; + inTime.tv_usec += millis * 1000; + if (inTime.tv_usec >= 1000000) { + inTime.tv_sec++; + inTime.tv_usec -= 1000000; + } + return inTime; +} + +inline static int diffTimeMillis(timeval later, timeval earlier) { + long udiff; + udiff = ((later.tv_sec - earlier.tv_sec) * 1000000) + + (later.tv_usec - earlier.tv_usec); + return (udiff + 999) / 1000; +} + +std::list Timer::pending; + +int Timer::checkTimeouts() { + timeval start; + + if (pending.empty()) + return -1; + + gettimeofday(&start, nullptr); + while (pending.front()->isBefore(start)) { + Timer* timer; + + timer = pending.front(); + pending.pop_front(); + + timer->lastDueTime = timer->dueTime; + timer->cb->handleTimeout(timer); + + if (pending.empty()) + return -1; + } + return getNextTimeout(); +} + +int Timer::getNextTimeout() { + timeval now; + gettimeofday(&now, nullptr); + + if (pending.empty()) + return -1; + + int toWait = pending.front()->getRemainingMs(); + + if (toWait > pending.front()->timeoutMs) { + if (toWait - pending.front()->timeoutMs < 1000) { + vlog.info("gettimeofday is broken..."); + return toWait; + } + // Time has jumped backwards! + vlog.info("Time has moved backwards!"); + pending.front()->dueTime = now; + toWait = 0; + } + + return toWait; +} + +void Timer::insertTimer(Timer* t) { + std::list::iterator i; + for (i=pending.begin(); i!=pending.end(); i++) { + if (t->isBefore((*i)->dueTime)) { + pending.insert(i, t); + return; + } + } + pending.push_back(t); +} + +void Timer::start(int timeoutMs_) { + timeval now; + gettimeofday(&now, nullptr); + stop(); + timeoutMs = timeoutMs_; + dueTime = addMillis(now, timeoutMs); + insertTimer(this); +} + +void Timer::repeat(int timeoutMs_) { + timeval now; + + gettimeofday(&now, nullptr); + + if (isStarted()) { + vlog.error("Incorrectly repeating already running timer"); + stop(); + } + + if (msBetween(&lastDueTime, &dueTime) != 0) + vlog.error("Timer incorrectly modified whilst repeating"); + + if (timeoutMs_ != -1) + timeoutMs = timeoutMs_; + + dueTime = addMillis(lastDueTime, timeoutMs); + if (isBefore(now)) { + // Time has jumped forwards, or we're not getting enough + // CPU time for the timers + dueTime = now; + } + + insertTimer(this); +} + +void Timer::stop() { + pending.remove(this); +} + +bool Timer::isStarted() { + return std::find(pending.begin(), pending.end(), + this) != pending.end(); +} + +int Timer::getTimeoutMs() { + return timeoutMs; +} + +int Timer::getRemainingMs() { + timeval now; + gettimeofday(&now, nullptr); + return __rfbmax(0, diffTimeMillis(dueTime, now)); +} + +bool Timer::isBefore(timeval other) { + return (dueTime.tv_sec < other.tv_sec) || + ((dueTime.tv_sec == other.tv_sec) && + (dueTime.tv_usec < other.tv_usec)); +} diff --git a/common/core/Timer.h b/common/core/Timer.h new file mode 100644 index 00000000..cde672b2 --- /dev/null +++ b/common/core/Timer.h @@ -0,0 +1,136 @@ +/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2018-2024 Pierre Ossman for Cendio AB + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#ifndef __CORE_TIMER_H__ +#define __CORE_TIMER_H__ + +#include +#include + +namespace core { + + /* Timer + + Cross-platform timeout handling. The caller creates instances of + Timer and passes a Callback implementation to each. The Callback + will then be called with a pointer to the Timer instance that + timed-out when the timeout occurs. + + The static methods of Timer are used by the main loop of the + application both to dispatch elapsed Timer callbacks and to + determine how long to wait in select() for the next timeout to + occur. + + For classes that can be derived it's best to use MethodTimer which + can call a specific method on the class, thus avoiding conflicts + when subclassing. + */ + + struct Timer { + + struct Callback { + // handleTimeout + // Passed a pointer to the Timer that has timed out. If the + // handler returns true then the Timer is reset and left + // running, causing another timeout after the appropriate + // interval. + // If the handler returns false then the Timer is cancelled. + virtual void handleTimeout(Timer* t) = 0; + + virtual ~Callback() {} + }; + + // checkTimeouts() + // Dispatches any elapsed Timers, and returns the number of + // milliseconds until the next Timer will timeout. + static int checkTimeouts(); + + // getNextTimeout() + // Returns the number of milliseconds until the next timeout, + // without dispatching any elapsed Timers. + static int getNextTimeout(); + + // Create a Timer with the specified callback handler + Timer(Callback* cb_) {cb = cb_;} + ~Timer() {stop();} + + // start() + // Starts the timer, causing a timeout after the specified number + // of milliseconds. If the timer is already active then it will + // be implicitly cancelled and re-started. + void start(int timeoutMs_); + + // repeat() + // Restarts the timer in a way that repeats that last timeout. + // This allows you to have a periodic timer without the risk of + // accumulating drift caused by processing delays. + // A new interval can be specified, otherwise the previous + // interval is reused. + void repeat(int timeoutMs_=-1); + + // stop() + // Cancels the timer. + void stop(); + + // isStarted() + // Determines whether the timer is started. + bool isStarted(); + + // getTimeoutMs() + // Determines the previously used timeout value, if any. + // Usually used with isStarted() to get the _current_ timeout. + int getTimeoutMs(); + + // getRemainingMs() + // Determines how many milliseconds are left before the Timer + // will timeout. Only valid for an active timer. + int getRemainingMs(); + + // isBefore() + // Determine whether the Timer will timeout before the specified + // time. + bool isBefore(timeval other); + + protected: + timeval dueTime, lastDueTime; + int timeoutMs; + Callback* cb; + + static void insertTimer(Timer* t); + // The list of currently active Timers, ordered by time left until + // timeout. + static std::list pending; + }; + + template class MethodTimer + : public Timer, public Timer::Callback { + public: + MethodTimer(T* obj_, void (T::*cb_)(Timer*)) + : Timer(this), obj(obj_), cb(cb_) {} + + void handleTimeout(Timer* t) override { return (obj->*cb)(t); } + + private: + T* obj; + void (T::*cb)(Timer*); + }; + +}; + +#endif diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index dfdc463b..42f2409d 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -44,7 +44,6 @@ add_library(rfb STATIC SSecurityStack.cxx SSecurityVncAuth.cxx SSecurityVeNCrypt.cxx - Timer.cxx TightDecoder.cxx TightEncoder.cxx TightJPEGEncoder.cxx diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 2d2c7e8a..a482991e 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -298,7 +298,7 @@ void EncodeManager::writeLosslessRefresh(const core::Region& req, {}, {}, pb, renderedCursor); } -void EncodeManager::handleTimeout(Timer* t) +void EncodeManager::handleTimeout(core::Timer* t) { if (t == &recentChangeTimer) { // Any lossy region that wasn't recently updated can diff --git a/common/rfb/EncodeManager.h b/common/rfb/EncodeManager.h index 1bc221aa..959c13d6 100644 --- a/common/rfb/EncodeManager.h +++ b/common/rfb/EncodeManager.h @@ -25,9 +25,9 @@ #include #include +#include #include -#include namespace rfb { @@ -39,7 +39,7 @@ namespace rfb { struct RectInfo; - class EncodeManager : public Timer::Callback { + class EncodeManager : public core::Timer::Callback { public: EncodeManager(SConnection* conn); ~EncodeManager(); @@ -63,7 +63,7 @@ namespace rfb { size_t maxUpdateSize); protected: - void handleTimeout(Timer* t) override; + void handleTimeout(core::Timer* t) override; void doUpdate(bool allowLossy, const core::Region& changed, const core::Region& copied, @@ -126,7 +126,7 @@ namespace rfb { core::Region recentlyChangedRegion; core::Region pendingRefreshRegion; - Timer recentChangeTimer; + core::Timer recentChangeTimer; struct EncoderStats { unsigned rects; diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 876521a8..3017f6ae 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -280,7 +280,7 @@ bool SConnection::processInitMsg() return reader_->readClientInit(); } -void SConnection::handleAuthFailureTimeout(Timer* /*t*/) +void SConnection::handleAuthFailureTimeout(core::Timer* /*t*/) { if (state_ != RFBSTATE_SECURITY_FAILURE) { close("SConnection::handleAuthFailureTimeout: Invalid state"); diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h index df3dfe92..0f4de5a5 100644 --- a/common/rfb/SConnection.h +++ b/common/rfb/SConnection.h @@ -26,10 +26,11 @@ #include +#include + #include #include #include -#include namespace rdr { class InStream; @@ -245,7 +246,7 @@ namespace rfb { bool processSecurityFailure(); bool processInitMsg(); - void handleAuthFailureTimeout(Timer* t); + void handleAuthFailureTimeout(core::Timer* t); int defaultMajorVersion, defaultMinorVersion; @@ -258,7 +259,7 @@ namespace rfb { SecurityServer security; SSecurity* ssecurity; - MethodTimer authFailureTimer; + core::MethodTimer authFailureTimer; std::string authFailureMsg; stateEnum state_; diff --git a/common/rfb/Timer.cxx b/common/rfb/Timer.cxx deleted file mode 100644 index 483be87c..00000000 --- a/common/rfb/Timer.cxx +++ /dev/null @@ -1,182 +0,0 @@ -/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2016-2024 Pierre Ossman for Cendio AB - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ - -// -=- Timer.cxx - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include - -#include -#include - -#include - -// Temporary during transition to new structure: -using namespace core; -using namespace rfb; - -#ifndef __NO_DEFINE_VLOG__ -static LogWriter vlog("Timer"); -#endif - - -// Millisecond timeout processing helper functions - -inline static timeval addMillis(timeval inTime, int millis) { - int secs = millis / 1000; - millis = millis % 1000; - inTime.tv_sec += secs; - inTime.tv_usec += millis * 1000; - if (inTime.tv_usec >= 1000000) { - inTime.tv_sec++; - inTime.tv_usec -= 1000000; - } - return inTime; -} - -inline static int diffTimeMillis(timeval later, timeval earlier) { - long udiff; - udiff = ((later.tv_sec - earlier.tv_sec) * 1000000) + - (later.tv_usec - earlier.tv_usec); - return (udiff + 999) / 1000; -} - -std::list Timer::pending; - -int Timer::checkTimeouts() { - timeval start; - - if (pending.empty()) - return -1; - - gettimeofday(&start, nullptr); - while (pending.front()->isBefore(start)) { - Timer* timer; - - timer = pending.front(); - pending.pop_front(); - - timer->lastDueTime = timer->dueTime; - timer->cb->handleTimeout(timer); - - if (pending.empty()) - return -1; - } - return getNextTimeout(); -} - -int Timer::getNextTimeout() { - timeval now; - gettimeofday(&now, nullptr); - - if (pending.empty()) - return -1; - - int toWait = pending.front()->getRemainingMs(); - - if (toWait > pending.front()->timeoutMs) { - if (toWait - pending.front()->timeoutMs < 1000) { - vlog.info("gettimeofday is broken..."); - return toWait; - } - // Time has jumped backwards! - vlog.info("Time has moved backwards!"); - pending.front()->dueTime = now; - toWait = 0; - } - - return toWait; -} - -void Timer::insertTimer(Timer* t) { - std::list::iterator i; - for (i=pending.begin(); i!=pending.end(); i++) { - if (t->isBefore((*i)->dueTime)) { - pending.insert(i, t); - return; - } - } - pending.push_back(t); -} - -void Timer::start(int timeoutMs_) { - timeval now; - gettimeofday(&now, nullptr); - stop(); - timeoutMs = timeoutMs_; - dueTime = addMillis(now, timeoutMs); - insertTimer(this); -} - -void Timer::repeat(int timeoutMs_) { - timeval now; - - gettimeofday(&now, nullptr); - - if (isStarted()) { - vlog.error("Incorrectly repeating already running timer"); - stop(); - } - - if (msBetween(&lastDueTime, &dueTime) != 0) - vlog.error("Timer incorrectly modified whilst repeating"); - - if (timeoutMs_ != -1) - timeoutMs = timeoutMs_; - - dueTime = addMillis(lastDueTime, timeoutMs); - if (isBefore(now)) { - // Time has jumped forwards, or we're not getting enough - // CPU time for the timers - dueTime = now; - } - - insertTimer(this); -} - -void Timer::stop() { - pending.remove(this); -} - -bool Timer::isStarted() { - return std::find(pending.begin(), pending.end(), - this) != pending.end(); -} - -int Timer::getTimeoutMs() { - return timeoutMs; -} - -int Timer::getRemainingMs() { - timeval now; - gettimeofday(&now, nullptr); - return __rfbmax(0, diffTimeMillis(dueTime, now)); -} - -bool Timer::isBefore(timeval other) { - return (dueTime.tv_sec < other.tv_sec) || - ((dueTime.tv_sec == other.tv_sec) && - (dueTime.tv_usec < other.tv_usec)); -} diff --git a/common/rfb/Timer.h b/common/rfb/Timer.h deleted file mode 100644 index 362cb84e..00000000 --- a/common/rfb/Timer.h +++ /dev/null @@ -1,136 +0,0 @@ -/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2018-2024 Pierre Ossman for Cendio AB - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ - -#ifndef __RFB_TIMER_H__ -#define __RFB_TIMER_H__ - -#include -#include - -namespace rfb { - - /* Timer - - Cross-platform timeout handling. The caller creates instances of - Timer and passes a Callback implementation to each. The Callback - will then be called with a pointer to the Timer instance that - timed-out when the timeout occurs. - - The static methods of Timer are used by the main loop of the - application both to dispatch elapsed Timer callbacks and to - determine how long to wait in select() for the next timeout to - occur. - - For classes that can be derived it's best to use MethodTimer which - can call a specific method on the class, thus avoiding conflicts - when subclassing. - */ - - struct Timer { - - struct Callback { - // handleTimeout - // Passed a pointer to the Timer that has timed out. If the - // handler returns true then the Timer is reset and left - // running, causing another timeout after the appropriate - // interval. - // If the handler returns false then the Timer is cancelled. - virtual void handleTimeout(Timer* t) = 0; - - virtual ~Callback() {} - }; - - // checkTimeouts() - // Dispatches any elapsed Timers, and returns the number of - // milliseconds until the next Timer will timeout. - static int checkTimeouts(); - - // getNextTimeout() - // Returns the number of milliseconds until the next timeout, - // without dispatching any elapsed Timers. - static int getNextTimeout(); - - // Create a Timer with the specified callback handler - Timer(Callback* cb_) {cb = cb_;} - ~Timer() {stop();} - - // start() - // Starts the timer, causing a timeout after the specified number - // of milliseconds. If the timer is already active then it will - // be implicitly cancelled and re-started. - void start(int timeoutMs_); - - // repeat() - // Restarts the timer in a way that repeats that last timeout. - // This allows you to have a periodic timer without the risk of - // accumulating drift caused by processing delays. - // A new interval can be specified, otherwise the previous - // interval is reused. - void repeat(int timeoutMs_=-1); - - // stop() - // Cancels the timer. - void stop(); - - // isStarted() - // Determines whether the timer is started. - bool isStarted(); - - // getTimeoutMs() - // Determines the previously used timeout value, if any. - // Usually used with isStarted() to get the _current_ timeout. - int getTimeoutMs(); - - // getRemainingMs() - // Determines how many milliseconds are left before the Timer - // will timeout. Only valid for an active timer. - int getRemainingMs(); - - // isBefore() - // Determine whether the Timer will timeout before the specified - // time. - bool isBefore(timeval other); - - protected: - timeval dueTime, lastDueTime; - int timeoutMs; - Callback* cb; - - static void insertTimer(Timer* t); - // The list of currently active Timers, ordered by time left until - // timeout. - static std::list pending; - }; - - template class MethodTimer - : public Timer, public Timer::Callback { - public: - MethodTimer(T* obj_, void (T::*cb_)(Timer*)) - : Timer(this), obj(obj_), cb(cb_) {} - - void handleTimeout(Timer* t) override { return (obj->*cb)(t); } - - private: - T* obj; - void (T::*cb)(Timer*); - }; - -}; - -#endif diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 8b47284d..20439d18 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -798,7 +798,7 @@ void VNCSConnectionST::supportsLEDState() writer()->writeLEDState(); } -void VNCSConnectionST::handleTimeout(Timer* t) +void VNCSConnectionST::handleTimeout(core::Timer* t) { try { if ((t == &congestionTimer) || diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index 7335051a..b618923f 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -29,16 +29,17 @@ #include +#include + #include #include #include -#include namespace rfb { class VNCServerST; class VNCSConnectionST : private SConnection, - public Timer::Callback { + public core::Timer::Callback { public: VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse, AccessRights ar); @@ -144,7 +145,7 @@ namespace rfb { void supportsLEDState() override; // Timer callbacks - void handleTimeout(Timer* t) override; + void handleTimeout(core::Timer* t) override; // Internal methods @@ -181,8 +182,8 @@ namespace rfb { uint8_t *fenceData; Congestion congestion; - Timer congestionTimer; - Timer losslessTimer; + core::Timer congestionTimer; + core::Timer losslessTimer; VNCServerST* server; SimpleUpdateTracker updates; @@ -195,7 +196,7 @@ namespace rfb { std::map pressedKeys; - Timer idleTimer; + core::Timer idleTimer; time_t pointerEventTime; core::Point pointerEventPos; diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index b0581513..b45d926d 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -629,7 +629,7 @@ SConnection* VNCServerST::getConnection(network::Socket* sock) { return nullptr; } -void VNCServerST::handleTimeout(Timer* t) +void VNCServerST::handleTimeout(core::Timer* t) { if (t == &frameTimer) { int timeout; diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index 3d6fbeee..5db4513a 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -26,10 +26,11 @@ #include +#include + #include #include #include -#include #include namespace rfb { @@ -42,7 +43,7 @@ namespace rfb { class SDesktop; class VNCServerST : public VNCServer, - public Timer::Callback { + public core::Timer::Callback { public: // -=- Constructors @@ -157,7 +158,7 @@ namespace rfb { protected: // Timer callbacks - void handleTimeout(Timer* t) override; + void handleTimeout(core::Timer* t) override; // - Internal methods @@ -204,12 +205,12 @@ namespace rfb { KeyRemapper* keyRemapper; - Timer idleTimer; - Timer disconnectTimer; - Timer connectTimer; + core::Timer idleTimer; + core::Timer disconnectTimer; + core::Timer connectTimer; uint64_t msc, queuedMsc; - Timer frameTimer; + core::Timer frameTimer; }; }; diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index ac7a91cf..12ba5699 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(convertlf convertlf.cxx) target_link_libraries(convertlf core) add_executable(gesturehandler gesturehandler.cxx ../../vncviewer/GestureHandler.cxx) -target_link_libraries(gesturehandler core rfb) +target_link_libraries(gesturehandler core) add_executable(hostport hostport.cxx) target_link_libraries(hostport network) @@ -24,4 +24,4 @@ target_link_libraries(unicode core) add_executable(emulatemb emulatemb.cxx ../../vncviewer/EmulateMB.cxx) target_include_directories(emulatemb SYSTEM PUBLIC ${GETTEXT_INCLUDE_DIR}) -target_link_libraries(emulatemb core rfb ${GETTEXT_LIBRARIES}) +target_link_libraries(emulatemb core ${GETTEXT_LIBRARIES}) diff --git a/tests/unit/emulatemb.cxx b/tests/unit/emulatemb.cxx index 25b191b7..ac4c8a32 100644 --- a/tests/unit/emulatemb.cxx +++ b/tests/unit/emulatemb.cxx @@ -117,7 +117,7 @@ void testNormalLeftPress() emulateMiddleButton.setParam(true); test.filterPointerEvent({10, 20}, left); usleep(100000); // 0.1s - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.results.size(), 2); @@ -159,7 +159,7 @@ void testNormalRightPress() emulateMiddleButton.setParam(true); test.filterPointerEvent({0, 0}, right); usleep(100000); // 0.1s - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.results.size(), 2); @@ -328,7 +328,7 @@ void testBothPressAfterLeftTimeout() emulateMiddleButton.setParam(true); test.filterPointerEvent({10, 20}, left); usleep(100000); // 0.1s - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.filterPointerEvent({10, 20}, both); ASSERT_EQ(test.results.size(), 3); @@ -357,7 +357,7 @@ void testBothPressAfterRightTimeout() emulateMiddleButton.setParam(true); test.filterPointerEvent({10, 20}, right); usleep(100000); // 0.1s - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.filterPointerEvent({10, 20}, both); ASSERT_EQ(test.results.size(), 3); @@ -386,7 +386,7 @@ void testTimeoutAndDrag() emulateMiddleButton.setParam(true); test.filterPointerEvent({0, 0}, left); usleep(100000); //0.1s - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.filterPointerEvent({10, 10}, left); ASSERT_EQ(test.results.size(), 3); @@ -416,7 +416,7 @@ void testDragAndTimeout() test.filterPointerEvent({10, 10}, left); test.filterPointerEvent({30, 30}, left); usleep(100000); //0.1s - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.results.size(), 3); diff --git a/tests/unit/gesturehandler.cxx b/tests/unit/gesturehandler.cxx index 73b8c62c..f4b5f92e 100644 --- a/tests/unit/gesturehandler.cxx +++ b/tests/unit/gesturehandler.cxx @@ -115,7 +115,7 @@ void testTwoTapSlowBegin() test.handleTouchBegin(1, 20.0, 30.0); usleep(500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchBegin(2, 30.0, 50.0); test.handleTouchEnd(1); @@ -137,7 +137,7 @@ void testTwoTapSlowEnd() test.handleTouchEnd(1); usleep(500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchEnd(2); @@ -156,7 +156,7 @@ void testTwoTapTimeout() test.handleTouchBegin(2, 30.0, 50.0); usleep(1500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchEnd(1); test.handleTouchEnd(2); @@ -213,7 +213,7 @@ void testThreeTapSlowBegin() test.handleTouchBegin(2, 30.0, 50.0); usleep(500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchBegin(3, 40.0, 40.0); test.handleTouchEnd(1); @@ -238,7 +238,7 @@ void testThreeTapSlowEnd() test.handleTouchEnd(2); usleep(500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchEnd(3); @@ -281,7 +281,7 @@ void testThreeTapTimeout() test.handleTouchBegin(3, 40.0, 40.0); usleep(1500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchEnd(1); test.handleTouchEnd(2); @@ -429,7 +429,7 @@ void testLongPressNormal() ASSERT_EQ(test.events.size(), 0); usleep(1500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 1); @@ -463,7 +463,7 @@ void testLongPressDrag() ASSERT_EQ(test.events.size(), 0); usleep(1500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 1); @@ -673,7 +673,7 @@ void testTwoDragFastAlmost() ASSERT_EQ(test.events.size(), 0); usleep(500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 0); @@ -694,7 +694,7 @@ void testTwoDragSlowHoriz() ASSERT_EQ(test.events.size(), 0); usleep(60000); // 60ms - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 2); ASSERT_EQ(test.events[0].type, GestureBegin); @@ -728,7 +728,7 @@ void testTwoDragSlowVert() ASSERT_EQ(test.events.size(), 0); usleep(60000); // 60ms - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 2); ASSERT_EQ(test.events[0].type, GestureBegin); @@ -762,7 +762,7 @@ void testTwoDragSlowDiag() ASSERT_EQ(test.events.size(), 0); usleep(60000); // 60ms - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 2); ASSERT_EQ(test.events[0].type, GestureBegin); @@ -791,7 +791,7 @@ void testTwoDragTooSlow() test.handleTouchBegin(1, 20.0, 30.0); usleep(500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchBegin(2, 30.0, 30.0); test.handleTouchUpdate(2, 50.0, 30.0); @@ -917,7 +917,7 @@ void testPinchFastAlmost() ASSERT_EQ(test.events.size(), 0); usleep(500000); - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 0); @@ -941,7 +941,7 @@ void testPinchSlowIn() ASSERT_EQ(test.events.size(), 0); usleep(60000); // 60ms - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 2); @@ -978,7 +978,7 @@ void testPinchSlowOut() ASSERT_EQ(test.events.size(), 0); usleep(60000); // 60ms - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); ASSERT_EQ(test.events.size(), 2); @@ -1008,7 +1008,7 @@ void testPinchTooSlow() test.handleTouchBegin(1, 0.0, 0.0); usleep(60000); // 60ms - rfb::Timer::checkTimeouts(); + core::Timer::checkTimeouts(); test.handleTouchBegin(2, 130.0, 130.0); test.handleTouchUpdate(2, 100.0, 130.0); diff --git a/unix/vncconfig/QueryConnectDialog.cxx b/unix/vncconfig/QueryConnectDialog.cxx index 8ecb27d5..7beee5f4 100644 --- a/unix/vncconfig/QueryConnectDialog.cxx +++ b/unix/vncconfig/QueryConnectDialog.cxx @@ -74,7 +74,8 @@ void QueryConnectDialog::buttonActivate(TXButton* b) { callback->queryRejected(); } -void QueryConnectDialog::handleTimeout(rfb::Timer* t) { +void QueryConnectDialog::handleTimeout(core::Timer* t) +{ if (timeUntilReject-- == 0) { unmap(); callback->queryTimedOut(); diff --git a/unix/vncconfig/QueryConnectDialog.h b/unix/vncconfig/QueryConnectDialog.h index 5763e1ce..7e9450b0 100644 --- a/unix/vncconfig/QueryConnectDialog.h +++ b/unix/vncconfig/QueryConnectDialog.h @@ -19,7 +19,8 @@ #ifndef __QUERYCONNECTDIALOG_H__ #define __QUERYCONNECTDIALOG_H__ -#include +#include + #include "TXLabel.h" #include "TXButton.h" #include "TXDialog.h" @@ -34,7 +35,7 @@ class QueryResultCallback { class QueryConnectDialog : public TXDialog, public TXEventHandler, public TXButtonCallback, - public rfb::Timer::Callback + public core::Timer::Callback { public: QueryConnectDialog(Display* dpy, const char* address_, @@ -43,14 +44,14 @@ class QueryConnectDialog : public TXDialog, public TXEventHandler, void handleEvent(TXWindow*, XEvent* ) override { } void deleteWindow(TXWindow*) override; void buttonActivate(TXButton* b) override; - void handleTimeout(rfb::Timer* t) override; + void handleTimeout(core::Timer* t) override; private: void refreshTimeout(); TXLabel addressLbl, address, userLbl, user, timeoutLbl, timeout; TXButton accept, reject; QueryResultCallback* callback; int timeUntilReject; - rfb::Timer timer; + core::Timer timer; }; #endif diff --git a/unix/vncconfig/vncconfig.cxx b/unix/vncconfig/vncconfig.cxx index 51d444c3..b1a5232b 100644 --- a/unix/vncconfig/vncconfig.cxx +++ b/unix/vncconfig/vncconfig.cxx @@ -50,8 +50,6 @@ #include "TXLabel.h" #include "QueryConnectDialog.h" -using namespace rfb; - static core::LogWriter vlog("vncconfig"); core::StringParameter displayname("display", "The X display", ""); @@ -352,7 +350,7 @@ int main(int argc, char** argv) TXWindow::handleXEvents(dpy); // Process expired timers and get the time until the next one - int timeoutMs = Timer::checkTimeouts(); + int timeoutMs = core::Timer::checkTimeouts(); if (timeoutMs >= 0) { tv.tv_sec = timeoutMs / 1000; tv.tv_usec = (timeoutMs % 1000) * 1000; diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index b6e33014..a78ea3ed 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -34,11 +34,11 @@ #include #include #include +#include #include #include -#include #include #include @@ -445,7 +445,7 @@ int main(int argc, char** argv) } // Trigger timers and check when the next will expire - nextTimeout = Timer::checkTimeouts(); + nextTimeout = core::Timer::checkTimeouts(); if (nextTimeout >= 0 && (wait_ms == -1 || nextTimeout < wait_ms)) wait_ms = nextTimeout; @@ -479,7 +479,7 @@ int main(int argc, char** argv) } } - Timer::checkTimeouts(); + core::Timer::checkTimeouts(); // Client list could have been changed. server.getSockets(&sockets); diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index de6c0c94..67d4c4f7 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -407,7 +407,7 @@ void XserverDesktop::blockHandler(int* timeout) } // Trigger timers and check when the next will expire - int nextTimeout = Timer::checkTimeouts(); + int nextTimeout = core::Timer::checkTimeouts(); if (nextTimeout >= 0 && (*timeout == -1 || nextTimeout < *timeout)) *timeout = nextTimeout; } catch (std::exception& e) { @@ -548,7 +548,7 @@ void XserverDesktop::keyEvent(uint32_t keysym, uint32_t keycode, bool down) vncKeyboardEvent(keysym, keycode, down); } -void XserverDesktop::handleTimeout(Timer* t) +void XserverDesktop::handleTimeout(core::Timer* t) { if (t == &queryConnectTimer) { server->approveConnection(queryConnectSocket, false, diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index 1d83083b..37f5b1b5 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -31,9 +31,10 @@ #include +#include + #include #include -#include #include @@ -46,7 +47,7 @@ namespace rfb { namespace network { class SocketListener; class Socket; } class XserverDesktop : public rfb::SDesktop, public rfb::FullFramePixelBuffer, - public rfb::Timer::Callback { + public core::Timer::Callback { public: XserverDesktop(int screenIndex, @@ -117,7 +118,7 @@ protected: rfb::VNCServer* sockserv, bool read, bool write); - void handleTimeout(rfb::Timer* t) override; + void handleTimeout(core::Timer* t) override; private: @@ -130,7 +131,7 @@ private: network::Socket* queryConnectSocket; std::string queryConnectAddress; std::string queryConnectUsername; - rfb::Timer queryConnectTimer; + core::Timer queryConnectTimer; OutputIdMap outputIdMap; diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index e91f1972..522b18b3 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -28,6 +28,7 @@ #endif #include +#include #include #include @@ -38,7 +39,6 @@ #include #include #include -#include #include #include @@ -239,7 +239,7 @@ void CConn::socketEvent(FL_SOCKET fd, void *data) // Make sure that the FLTK handling and the timers gets some CPU // time in case of back to back messages Fl::check(); - Timer::checkTimeouts(); + core::Timer::checkTimeouts(); // Also check if we need to stop reading and terminate if (should_disconnect()) diff --git a/vncviewer/EmulateMB.cxx b/vncviewer/EmulateMB.cxx index a5efa7be..89470274 100644 --- a/vncviewer/EmulateMB.cxx +++ b/vncviewer/EmulateMB.cxx @@ -278,7 +278,7 @@ void EmulateMB::filterPointerEvent(const core::Point& pos, } } -void EmulateMB::handleTimeout(rfb::Timer *t) +void EmulateMB::handleTimeout(core::Timer* t) { int action1, action2; uint16_t buttonMask; @@ -334,4 +334,4 @@ int EmulateMB::createButtonMask(uint16_t buttonMask) // Set the left and right buttons according to the action return buttonMask |= emulatedButtonMask; -} \ No newline at end of file +} diff --git a/vncviewer/EmulateMB.h b/vncviewer/EmulateMB.h index 43f2d7da..393655e4 100644 --- a/vncviewer/EmulateMB.h +++ b/vncviewer/EmulateMB.h @@ -20,10 +20,9 @@ #define __EMULATEMB__ #include +#include -#include - -class EmulateMB : public rfb::Timer::Callback { +class EmulateMB : public core::Timer::Callback { public: EmulateMB(); @@ -33,7 +32,7 @@ protected: virtual void sendPointerEvent(const core::Point& pos, uint16_t buttonMask)=0; - void handleTimeout(rfb::Timer *t) override; + void handleTimeout(core::Timer* t) override; private: void sendAction(const core::Point& pos, uint16_t buttonMask, @@ -46,7 +45,7 @@ private: uint16_t emulatedButtonMask; uint16_t lastButtonMask; core::Point lastPos, origPos; - rfb::Timer timer; + core::Timer timer; }; #endif diff --git a/vncviewer/GestureHandler.cxx b/vncviewer/GestureHandler.cxx index 464386a5..f39ec8f2 100644 --- a/vncviewer/GestureHandler.cxx +++ b/vncviewer/GestureHandler.cxx @@ -323,7 +323,7 @@ bool GestureHandler::hasDetectedGesture() return true; } -void GestureHandler::handleTimeout(rfb::Timer* t) +void GestureHandler::handleTimeout(core::Timer* t) { if (t == &longpressTimer) longpressTimeout(); diff --git a/vncviewer/GestureHandler.h b/vncviewer/GestureHandler.h index 2b31703a..1c2134c0 100644 --- a/vncviewer/GestureHandler.h +++ b/vncviewer/GestureHandler.h @@ -23,11 +23,11 @@ #include #include -#include +#include #include "GestureEvent.h" -class GestureHandler : public rfb::Timer::Callback { +class GestureHandler : public core::Timer::Callback { public: GestureHandler(); virtual ~GestureHandler(); @@ -42,7 +42,7 @@ class GestureHandler : public rfb::Timer::Callback { private: bool hasDetectedGesture(); - void handleTimeout(rfb::Timer* t) override; + void handleTimeout(core::Timer* t) override; void longpressTimeout(); void twoTouchTimeout(); @@ -74,8 +74,8 @@ class GestureHandler : public rfb::Timer::Callback { bool waitingRelease; struct timeval releaseStart; - rfb::Timer longpressTimer; - rfb::Timer twoTouchTimer; + core::Timer longpressTimer; + core::Timer twoTouchTimer; }; #endif // __GESTUREHANDLER_H__ diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index a82efe89..13d7b2a7 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -51,11 +51,11 @@ #include #include #include +#include #ifdef HAVE_GNUTLS #include #endif -#include #include @@ -189,7 +189,7 @@ static void mainloop(const char* vncserver, network::Socket* sock) while (!exitMainloop) { int next_timer; - next_timer = Timer::checkTimeouts(); + next_timer = core::Timer::checkTimeouts(); if (next_timer < 0) next_timer = INT_MAX; diff --git a/win/rfb_win32/SocketManager.cxx b/win/rfb_win32/SocketManager.cxx index 819154fb..2f80e28b 100644 --- a/win/rfb_win32/SocketManager.cxx +++ b/win/rfb_win32/SocketManager.cxx @@ -27,13 +27,13 @@ #include #include +#include #include #include #include -#include #include #include -- cgit v1.2.3