From 63d65bb47bceabf43ffa9889ae94ac4d69e98eba Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sun, 27 Apr 2025 15:39:23 -0400 Subject: [PATCH] chore: use nullptr where possible in place of NULL --- src/apps/deskflow-client/deskflow-client.cpp | 2 +- src/apps/deskflow-core/deskflow-core.cpp | 2 +- src/apps/deskflow-gui/deskflow-gui.cpp | 4 +- src/apps/deskflow-server/deskflow-server.cpp | 2 +- src/lib/arch/Arch.cpp | 6 +- src/lib/arch/IArchDaemon.h | 2 +- src/lib/arch/IArchMultithread.h | 2 +- src/lib/arch/IArchNetwork.h | 4 +- src/lib/arch/IArchString.cpp | 18 +-- src/lib/arch/unix/ArchDaemonUnix.cpp | 2 +- src/lib/arch/unix/ArchMultithreadPosix.cpp | 76 +++++------ src/lib/arch/unix/ArchNetworkBSD.cpp | 48 +++---- src/lib/arch/unix/ArchSleepUnix.cpp | 2 +- src/lib/arch/unix/ArchTimeUnix.cpp | 2 +- src/lib/arch/win32/ArchDaemonWindows.cpp | 92 ++++++------- src/lib/arch/win32/ArchLogWindows.cpp | 16 +-- src/lib/arch/win32/ArchMiscWindows.cpp | 60 ++++---- src/lib/arch/win32/ArchMultithreadWindows.cpp | 70 +++++----- src/lib/arch/win32/ArchNetworkWinsock.cpp | 86 ++++++------ src/lib/arch/win32/ArchSleepWindows.cpp | 2 +- src/lib/arch/win32/ArchTimeWindows.cpp | 16 +-- src/lib/arch/win32/XArchWindows.cpp | 6 +- src/lib/base/Event.cpp | 2 +- src/lib/base/Event.h | 2 +- src/lib/base/EventQueue.cpp | 52 +++---- src/lib/base/EventQueue.h | 2 +- src/lib/base/EventTypes.cpp | 4 +- src/lib/base/FunctionEventJob.cpp | 2 +- src/lib/base/FunctionEventJob.h | 2 +- src/lib/base/FunctionJob.cpp | 2 +- src/lib/base/FunctionJob.h | 2 +- src/lib/base/IEventQueue.h | 6 +- src/lib/base/IEventQueueBuffer.h | 2 +- src/lib/base/Log.cpp | 12 +- src/lib/base/Log.h | 6 +- src/lib/base/LogOutputters.cpp | 6 +- src/lib/base/Path.cpp | 2 +- src/lib/base/String.cpp | 4 +- src/lib/base/TMethodEventJob.h | 4 +- src/lib/base/TMethodJob.h | 4 +- src/lib/base/Unicode.cpp | 16 +-- src/lib/base/Unicode.h | 38 +++--- src/lib/client/Client.cpp | 56 ++++---- src/lib/client/ServerProxy.cpp | 16 +-- src/lib/client/ServerProxy.h | 2 +- src/lib/common/Common.h | 2 +- src/lib/deskflow/App.cpp | 8 +- src/lib/deskflow/ClientApp.cpp | 22 +-- src/lib/deskflow/IClipboard.cpp | 12 +- src/lib/deskflow/IKeyState.cpp | 8 +- src/lib/deskflow/KeyMap.cpp | 60 ++++---- src/lib/deskflow/KeyMap.h | 4 +- src/lib/deskflow/KeyState.cpp | 4 +- src/lib/deskflow/KeyTypes.cpp | 4 +- src/lib/deskflow/KeyTypes.h | 4 +- src/lib/deskflow/PacketStreamFilter.cpp | 2 +- src/lib/deskflow/ProtocolUtil.cpp | 18 +-- src/lib/deskflow/Screen.cpp | 4 +- src/lib/deskflow/ServerApp.cpp | 66 ++++----- src/lib/deskflow/StreamChunker.cpp | 2 +- src/lib/deskflow/unix/AppUtilUnix.cpp | 4 +- src/lib/deskflow/win32/AppUtilWindows.cpp | 6 +- src/lib/gui/ScreenSetupModel.cpp | 2 +- src/lib/gui/widgets/ScreenSetupView.cpp | 2 +- src/lib/io/IStream.h | 2 +- src/lib/io/StreamBuffer.cpp | 6 +- src/lib/mt/CondVar.cpp | 2 +- src/lib/mt/CondVar.h | 2 +- src/lib/mt/Thread.cpp | 6 +- src/lib/mt/Thread.h | 2 +- src/lib/net/IDataSocket.cpp | 2 +- src/lib/net/IListenSocket.h | 2 +- src/lib/net/ISocketMultiplexerJob.h | 2 +- src/lib/net/SecureListenSocket.cpp | 14 +- src/lib/net/SecureSocket.cpp | 34 ++--- src/lib/net/SecureUtils.cpp | 2 +- src/lib/net/SocketMultiplexer.cpp | 30 ++-- src/lib/net/TCPListenSocket.cpp | 22 +-- src/lib/net/TCPSocketFactory.cpp | 2 +- src/lib/net/TSocketMultiplexerMethodJob.h | 4 +- src/lib/platform/EiEventQueueBuffer.cpp | 2 +- src/lib/platform/IOSXKeyResource.cpp | 4 +- src/lib/platform/MSWindowsClipboard.cpp | 12 +- .../MSWindowsClipboardAnyTextConverter.cpp | 8 +- .../MSWindowsClipboardBitmapConverter.cpp | 14 +- src/lib/platform/MSWindowsClipboardFacade.cpp | 2 +- src/lib/platform/MSWindowsDesks.cpp | 70 +++++----- src/lib/platform/MSWindowsDropTarget.cpp | 4 +- .../platform/MSWindowsEventQueueBuffer.cpp | 6 +- src/lib/platform/MSWindowsHook.cpp | 58 ++++---- src/lib/platform/MSWindowsKeyState.cpp | 16 +-- src/lib/platform/MSWindowsKeyState.h | 2 +- src/lib/platform/MSWindowsScreen.cpp | 107 +++++++-------- src/lib/platform/MSWindowsScreen.h | 2 +- src/lib/platform/MSWindowsScreenSaver.cpp | 36 ++--- src/lib/platform/MSWindowsSession.cpp | 4 +- src/lib/platform/MSWindowsUtil.cpp | 4 +- src/lib/platform/OSXClipboard.cpp | 28 ++-- .../platform/OSXClipboardHTMLConverter.cpp | 8 +- .../platform/OSXClipboardTextConverter.cpp | 8 +- src/lib/platform/OSXKeyState.cpp | 10 +- src/lib/platform/OSXScreen.h | 2 +- src/lib/platform/OSXScreen.mm | 109 ++++++++------- src/lib/platform/OSXUchrKeyResource.cpp | 22 +-- src/lib/platform/XWindowsClipboard.h | 4 +- src/lib/platform/XWindowsEventQueueBuffer.cpp | 2 +- src/lib/platform/XWindowsKeyState.cpp | 16 +-- src/lib/platform/XWindowsScreen.cpp | 94 ++++++------- src/lib/platform/XWindowsScreen.h | 2 +- src/lib/platform/XWindowsScreenSaver.cpp | 16 +-- src/lib/platform/XWindowsScreenSaver.h | 2 +- src/lib/platform/XWindowsUtil.cpp | 22 +-- src/lib/platform/XWindowsUtil.h | 6 +- src/lib/server/ClientListener.cpp | 12 +- src/lib/server/ClientListener.h | 2 +- src/lib/server/ClientProxy1_0.cpp | 18 +-- src/lib/server/ClientProxy1_3.cpp | 10 +- src/lib/server/ClientProxy1_4.cpp | 2 +- src/lib/server/ClientProxy1_5.cpp | 2 +- src/lib/server/ClientProxyUnknown.cpp | 28 ++-- src/lib/server/ClientProxyUnknown.h | 2 +- src/lib/server/Config.cpp | 26 ++-- src/lib/server/Config.h | 6 +- src/lib/server/InputFilter.cpp | 47 ++++--- src/lib/server/InputFilter.h | 4 +- src/lib/server/Server.cpp | 128 +++++++++--------- src/lib/server/Server.h | 4 +- src/test/integtests/main.cpp | 2 +- src/test/mock/deskflow/MockApp.h | 2 +- src/test/mock/deskflow/MockArgParser.h | 2 +- src/test/shared/TestEventQueue.cpp | 2 +- .../unittests/deskflow/ArgParserTests.cpp | 8 +- .../deskflow/DeprecatedArgsParsingTests.cpp | 4 +- src/test/unittests/deskflow/KeyStateTests.cpp | 14 +- .../unittests/deskflow/ProtocolUtilTests.cpp | 4 +- src/test/unittests/main.cpp | 2 +- src/test/unittests/net/NetworkTests.cpp | 6 +- .../platform/MSWindowsClipboardTests.cpp | 34 ++--- .../platform/XWindowsKeyStateTests.cpp | 10 +- .../platform/XWindowsScreenSaverTests.cpp | 2 +- 140 files changed, 1116 insertions(+), 1101 deletions(-) diff --git a/src/apps/deskflow-client/deskflow-client.cpp b/src/apps/deskflow-client/deskflow-client.cpp index 33483b7c5..68b374e82 100644 --- a/src/apps/deskflow-client/deskflow-client.cpp +++ b/src/apps/deskflow-client/deskflow-client.cpp @@ -26,7 +26,7 @@ int main(int argc, char **argv) ArchMiscWindows::guardRuntimeVersion(); // record window instance for tray icon, etc - ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); + ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); #endif Arch arch; diff --git a/src/apps/deskflow-core/deskflow-core.cpp b/src/apps/deskflow-core/deskflow-core.cpp index 32c9e37a8..d469c8970 100644 --- a/src/apps/deskflow-core/deskflow-core.cpp +++ b/src/apps/deskflow-core/deskflow-core.cpp @@ -44,7 +44,7 @@ int main(int argc, char **argv) QCoreApplication m(argc, argv); m.deleteLater(); - ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); + ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); #endif Arch arch; diff --git a/src/apps/deskflow-gui/deskflow-gui.cpp b/src/apps/deskflow-gui/deskflow-gui.cpp index bfc6fa15f..075df4973 100644 --- a/src/apps/deskflow-gui/deskflow-gui.cpp +++ b/src/apps/deskflow-gui/deskflow-gui.cpp @@ -123,7 +123,7 @@ int main(int argc, char *argv[]) "Please drag %1 to the Applications folder, " "and open it from there." ); - QMessageBox::information(NULL, kAppName, msgBody.arg(kAppName)); + QMessageBox::information(nullptr, kAppName, msgBody.arg(kAppName)); return 1; } @@ -159,7 +159,7 @@ bool checkMacAssistiveDevices() const void *keys[] = {kAXTrustedCheckOptionPrompt}; const void *trueValue[] = {kCFBooleanTrue}; - CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL); + CFDictionaryRef options = CFDictionaryCreate(nullptr, keys, trueValue, 1, nullptr, nullptr); bool result = AXIsProcessTrustedWithOptions(options); CFRelease(options); diff --git a/src/apps/deskflow-server/deskflow-server.cpp b/src/apps/deskflow-server/deskflow-server.cpp index 5688b72d0..fc95a70fd 100644 --- a/src/apps/deskflow-server/deskflow-server.cpp +++ b/src/apps/deskflow-server/deskflow-server.cpp @@ -26,7 +26,7 @@ int main(int argc, char **argv) ArchMiscWindows::guardRuntimeVersion(); // record window instance for tray icon, etc - ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); + ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); #endif Arch arch; diff --git a/src/lib/arch/Arch.cpp b/src/lib/arch/Arch.cpp index 23f2a5dfc..cca6ccd87 100644 --- a/src/lib/arch/Arch.cpp +++ b/src/lib/arch/Arch.cpp @@ -15,11 +15,11 @@ // Arch // -Arch *Arch::s_instance = NULL; +Arch *Arch::s_instance = nullptr; Arch::Arch() { - assert(s_instance == NULL); + assert(s_instance == nullptr); s_instance = this; } @@ -42,6 +42,6 @@ void Arch::init() Arch *Arch::getInstance() { - assert(s_instance != NULL); + assert(s_instance != nullptr); return s_instance; } diff --git a/src/lib/arch/IArchDaemon.h b/src/lib/arch/IArchDaemon.h index a03a5c659..a730ef576 100644 --- a/src/lib/arch/IArchDaemon.h +++ b/src/lib/arch/IArchDaemon.h @@ -34,7 +34,7 @@ public: \c commandLine should \b not include the name of program as the first argument. If \c allUsers is true then the daemon will be installed to start at boot time, otherwise it will be installed to - start when the current user logs in. If \p dependencies is not NULL + start when the current user logs in. If \p dependencies is not nullptr then it's a concatenation of NUL terminated other daemon names followed by a NUL; the daemon will be configured to startup after the listed daemons. Throws an \c XArchDaemon exception on failure. diff --git a/src/lib/arch/IArchMultithread.h b/src/lib/arch/IArchMultithread.h index b85aa7a49..cc935b519 100644 --- a/src/lib/arch/IArchMultithread.h +++ b/src/lib/arch/IArchMultithread.h @@ -247,7 +247,7 @@ public: //! Set the interrupt handler /*! Sets the function to call on receipt of an external interrupt. - By default and when \p func is NULL, the main thread is cancelled. + By default and when \p func is nullptr, the main thread is cancelled. */ virtual void setSignalHandler(ESignal, SignalFunc func, void *userData) = 0; diff --git a/src/lib/arch/IArchNetwork.h b/src/lib/arch/IArchNetwork.h index 5d59da5f4..8fe3330d0 100644 --- a/src/lib/arch/IArchNetwork.h +++ b/src/lib/arch/IArchNetwork.h @@ -149,10 +149,10 @@ public: /*! Accepts a connection on socket \c s, returning a new socket for the connection and filling in \c addr with the address of the remote - end. \c addr may be NULL if the remote address isn't required. + end. \c addr may be nullptr if the remote address isn't required. The original socket \c s is unaffected and remains in the listening state. The new socket shares most of the properties of \c s except - it's not in the listening state and it's connected. Returns NULL + it's not in the listening state and it's connected. Returns nullptr if there are no pending connection requests. */ virtual ArchSocket acceptSocket(ArchSocket s, ArchNetAddress *addr) = 0; diff --git a/src/lib/arch/IArchString.cpp b/src/lib/arch/IArchString.cpp index 88ca2c99a..d11c5a97c 100644 --- a/src/lib/arch/IArchString.cpp +++ b/src/lib/arch/IArchString.cpp @@ -13,7 +13,7 @@ #include #include -static ArchMutex s_mutex = NULL; +static ArchMutex s_mutex = nullptr; // // use C library non-reentrant multibyte conversion with mutex @@ -21,9 +21,9 @@ static ArchMutex s_mutex = NULL; IArchString::~IArchString() { - if (s_mutex != NULL) { + if (s_mutex != nullptr) { ARCH->closeMutex(s_mutex); - s_mutex = NULL; + s_mutex = nullptr; } } @@ -32,18 +32,18 @@ int IArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, boo ptrdiff_t len = 0; bool dummyErrors; - if (errors == NULL) { + if (errors == nullptr) { errors = &dummyErrors; } *errors = false; - if (s_mutex == NULL) { + if (s_mutex == nullptr) { s_mutex = ARCH->newMutex(); } ARCH->lockMutex(s_mutex); - if (dst == NULL) { + if (dst == nullptr) { char dummy[MB_LEN_MAX]; const wchar_t *scan = src; for (; n > 0; --n) { @@ -90,18 +90,18 @@ int IArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, boo wchar_t dummy; bool dummyErrors; - if (errors == NULL) { + if (errors == nullptr) { errors = &dummyErrors; } *errors = false; - if (s_mutex == NULL) { + if (s_mutex == nullptr) { s_mutex = ARCH->newMutex(); } ARCH->lockMutex(s_mutex); - if (dst == NULL) { + if (dst == nullptr) { const char *scan = src; while (n > 0) { ptrdiff_t mblen = mbtowc(&dummy, scan, n); diff --git a/src/lib/arch/unix/ArchDaemonUnix.cpp b/src/lib/arch/unix/ArchDaemonUnix.cpp index 903b9cccb..175471c26 100644 --- a/src/lib/arch/unix/ArchDaemonUnix.cpp +++ b/src/lib/arch/unix/ArchDaemonUnix.cpp @@ -49,7 +49,7 @@ int execSelfNonDaemonized() bool alreadyDaemonized() { - return getenv("_DESKFLOW_DAEMONIZED") != NULL; + return getenv("_DESKFLOW_DAEMONIZED") != nullptr; } #endif diff --git a/src/lib/arch/unix/ArchMultithreadPosix.cpp b/src/lib/arch/unix/ArchMultithreadPosix.cpp index 9cf05dd3f..ca583a576 100644 --- a/src/lib/arch/unix/ArchMultithreadPosix.cpp +++ b/src/lib/arch/unix/ArchMultithreadPosix.cpp @@ -70,13 +70,13 @@ public: ArchThreadImpl::ArchThreadImpl() : m_refCount(1), m_id(0), - m_func(NULL), - m_userData(NULL), + m_func(nullptr), + m_userData(nullptr), m_cancel(false), m_cancelling(false), m_exited(false), - m_result(NULL), - m_networkData(NULL) + m_result(nullptr), + m_networkData(nullptr) { // do nothing } @@ -85,18 +85,18 @@ ArchThreadImpl::ArchThreadImpl() // ArchMultithreadPosix // -ArchMultithreadPosix *ArchMultithreadPosix::s_instance = NULL; +ArchMultithreadPosix *ArchMultithreadPosix::s_instance = nullptr; ArchMultithreadPosix::ArchMultithreadPosix() : m_newThreadCalled(false), m_nextID(0) { - assert(s_instance == NULL); + assert(s_instance == nullptr); s_instance = this; // no signal handlers for (size_t i = 0; i < kNUM_SIGNALS; ++i) { - m_signalFunc[i] = NULL; - m_signalUserData[i] = NULL; + m_signalFunc[i] = nullptr; + m_signalUserData[i] = nullptr; } // create mutex for thread list @@ -121,25 +121,25 @@ ArchMultithreadPosix::ArchMultithreadPosix() : m_newThreadCalled(false), m_nextI act.sa_flags = 0; #endif act.sa_handler = &threadCancel; - sigaction(SIGWAKEUP, &act, NULL); + sigaction(SIGWAKEUP, &act, nullptr); // set desired signal dispositions. let SIGWAKEUP through but // ignore SIGPIPE (we'll handle EPIPE). sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGWAKEUP); - pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); + pthread_sigmask(SIG_UNBLOCK, &sigset, nullptr); sigemptyset(&sigset); sigaddset(&sigset, SIGPIPE); - pthread_sigmask(SIG_BLOCK, &sigset, NULL); + pthread_sigmask(SIG_BLOCK, &sigset, nullptr); } ArchMultithreadPosix::~ArchMultithreadPosix() { - assert(s_instance != NULL); + assert(s_instance != nullptr); closeMutex(m_threadMutex); - s_instance = NULL; + s_instance = nullptr; } void ArchMultithreadPosix::setNetworkDataForCurrentThread(void *data) @@ -166,7 +166,7 @@ ArchMultithreadPosix *ArchMultithreadPosix::getInstance() ArchCond ArchMultithreadPosix::newCondVar() { ArchCondImpl *cond = new ArchCondImpl; - int status = pthread_cond_init(&cond->m_cond, NULL); + int status = pthread_cond_init(&cond->m_cond, nullptr); (void)status; assert(status == 0); return cond; @@ -214,7 +214,7 @@ bool ArchMultithreadPosix::waitCondVar(ArchCond cond, ArchMutex mutex, double ti // get final time struct timeval now; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); struct timespec finalTime; finalTime.tv_sec = now.tv_sec; finalTime.tv_nsec = now.tv_usec * 1000; @@ -312,7 +312,7 @@ void ArchMultithreadPosix::unlockMutex(ArchMutex mutex) ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data) { - assert(func != NULL); + assert(func != nullptr); // initialize signal handler. we do this here instead of the // constructor so we can avoid daemonizing (using fork()) @@ -336,7 +336,7 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data) thread->m_userData = data; // create the thread. pthread_create() on RedHat 7.2 smp fails - // if passed a NULL attr so use a default attr. + // if passed a nullptr attr so use a default attr. pthread_attr_t attr; int status = pthread_attr_init(&attr); if (status == 0) { @@ -348,7 +348,7 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data) if (status != 0) { // failed to start thread so clean up delete thread; - thread = NULL; + thread = nullptr; } else { // add thread to list insert(thread); @@ -368,18 +368,18 @@ ArchThread ArchMultithreadPosix::newCurrentThread() lockMutex(m_threadMutex); ArchThreadImpl *thread = find(pthread_self()); unlockMutex(m_threadMutex); - assert(thread != NULL); + assert(thread != nullptr); return thread; } void ArchMultithreadPosix::closeThread(ArchThread thread) { - assert(thread != NULL); + assert(thread != nullptr); // decrement ref count and clean up thread if no more references if (--thread->m_refCount == 0) { // detach from thread (unless it's the main thread) - if (thread->m_func != NULL) { + if (thread->m_func != nullptr) { pthread_detach(thread->m_thread); } @@ -402,7 +402,7 @@ ArchThread ArchMultithreadPosix::copyThread(ArchThread thread) void ArchMultithreadPosix::cancelThread(ArchThread thread) { - assert(thread != NULL); + assert(thread != nullptr); // set cancel and wakeup flags if thread can be cancelled bool wakeup = false; @@ -421,7 +421,7 @@ void ArchMultithreadPosix::cancelThread(ArchThread thread) void ArchMultithreadPosix::setPriorityOfThread(ArchThread thread, int /*n*/) { - assert(thread != NULL); + assert(thread != nullptr); // FIXME } @@ -439,7 +439,7 @@ void ArchMultithreadPosix::testCancelThread() bool ArchMultithreadPosix::wait(ArchThread target, double timeout) { - assert(target != NULL); + assert(target != nullptr); lockMutex(m_threadMutex); @@ -528,7 +528,7 @@ void ArchMultithreadPosix::setSignalHandler(ESignal signal, SignalFunc func, voi void ArchMultithreadPosix::raiseSignal(ESignal signal) { lockMutex(m_threadMutex); - if (m_signalFunc[signal] != NULL) { + if (m_signalFunc[signal] != nullptr) { m_signalFunc[signal](signal, m_signalUserData[signal]); pthread_kill(m_mainThread->m_thread, SIGWAKEUP); } else if (signal == kINTERRUPT || signal == kTERMINATE) { @@ -552,20 +552,20 @@ void ArchMultithreadPosix::startSignalHandler() pthread_attr_t attr; int status = pthread_attr_init(&attr); if (status == 0) { - status = pthread_create(&m_signalThread, &attr, &ArchMultithreadPosix::threadSignalHandler, NULL); + status = pthread_create(&m_signalThread, &attr, &ArchMultithreadPosix::threadSignalHandler, nullptr); pthread_attr_destroy(&attr); } if (status != 0) { // can't create thread to wait for signal so don't block // the signals. - pthread_sigmask(SIG_UNBLOCK, &oldsigset, NULL); + pthread_sigmask(SIG_UNBLOCK, &oldsigset, nullptr); } } ArchThreadImpl *ArchMultithreadPosix::find(pthread_t thread) { ArchThreadImpl *impl = findNoRef(thread); - if (impl != NULL) { + if (impl != nullptr) { refThread(impl); } return impl; @@ -579,15 +579,15 @@ ArchThreadImpl *ArchMultithreadPosix::findNoRef(pthread_t thread) return *index; } } - return NULL; + return nullptr; } void ArchMultithreadPosix::insert(ArchThreadImpl *thread) { - assert(thread != NULL); + assert(thread != nullptr); // thread shouldn't already be on the list - assert(findNoRef(thread->m_thread) == NULL); + assert(findNoRef(thread->m_thread) == nullptr); // set thread id. note that we don't worry about m_nextID // wrapping back to 0 and duplicating thread ID's since the @@ -611,14 +611,14 @@ void ArchMultithreadPosix::erase(ArchThreadImpl *thread) void ArchMultithreadPosix::refThread(ArchThreadImpl *thread) { - assert(thread != NULL); - assert(findNoRef(thread->m_thread) != NULL); + assert(thread != nullptr); + assert(findNoRef(thread->m_thread) != nullptr); ++thread->m_refCount; } void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread) { - assert(thread != NULL); + assert(thread != nullptr); // update cancel state lockMutex(m_threadMutex); @@ -642,14 +642,14 @@ void *ArchMultithreadPosix::threadFunc(void *vrep) ArchThreadImpl *thread = static_cast(vrep); // setup pthreads - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, nullptr); // run thread s_instance->doThreadFunc(thread); // terminate the thread - return NULL; + return nullptr; } void ArchMultithreadPosix::doThreadFunc(ArchThread thread) @@ -748,5 +748,5 @@ void *ArchMultithreadPosix::threadSignalHandler(void *) } } - return NULL; + return nullptr; } diff --git a/src/lib/arch/unix/ArchNetworkBSD.cpp b/src/lib/arch/unix/ArchNetworkBSD.cpp index 039f6898a..f7cd77ce7 100644 --- a/src/lib/arch/unix/ArchNetworkBSD.cpp +++ b/src/lib/arch/unix/ArchNetworkBSD.cpp @@ -131,7 +131,7 @@ ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type) ArchSocket ArchNetworkBSD::copySocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // ref the socket and return it ARCH->lockMutex(m_mutex); @@ -142,7 +142,7 @@ ArchSocket ArchNetworkBSD::copySocket(ArchSocket s) void ArchNetworkBSD::closeSocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // unref the socket and note if it should be released ARCH->lockMutex(m_mutex); @@ -165,7 +165,7 @@ void ArchNetworkBSD::closeSocket(ArchSocket s) void ArchNetworkBSD::closeSocketForRead(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); if (shutdown(s->m_fd, 0) == -1) { if (errno != ENOTCONN) { @@ -176,7 +176,7 @@ void ArchNetworkBSD::closeSocketForRead(ArchSocket s) void ArchNetworkBSD::closeSocketForWrite(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); if (shutdown(s->m_fd, 1) == -1) { if (errno != ENOTCONN) { @@ -187,8 +187,8 @@ void ArchNetworkBSD::closeSocketForWrite(ArchSocket s) void ArchNetworkBSD::bindSocket(ArchSocket s, ArchNetAddress addr) { - assert(s != NULL); - assert(addr != NULL); + assert(s != nullptr); + assert(addr != nullptr); if (bind(s->m_fd, TYPED_ADDR(struct sockaddr, addr), addr->m_len) == -1) { throwError(errno); @@ -197,7 +197,7 @@ void ArchNetworkBSD::bindSocket(ArchSocket s, ArchNetAddress addr) void ArchNetworkBSD::listenOnSocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // hardcoding backlog if (listen(s->m_fd, 3) == -1) { @@ -207,9 +207,9 @@ void ArchNetworkBSD::listenOnSocket(ArchSocket s) ArchSocket ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress *addr) { - assert(s != NULL); + assert(s != nullptr); - // if user passed NULL in addr then use scratch space + // if user passed nullptr in addr then use scratch space ArchNetAddress dummy; if (addr == nullptr) { addr = &dummy; @@ -258,8 +258,8 @@ ArchSocket ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress *addr) bool ArchNetworkBSD::connectSocket(ArchSocket s, ArchNetAddress addr) { - assert(s != NULL); - assert(addr != NULL); + assert(s != nullptr); + assert(addr != nullptr); if (connect(s->m_fd, TYPED_ADDR(struct sockaddr, addr), addr->m_len) == -1) { if (errno == EISCONN) { @@ -372,7 +372,7 @@ void ArchNetworkBSD::unblockPollSocket(ArchThread thread) size_t ArchNetworkBSD::readSocket(ArchSocket s, void *buf, size_t len) { - assert(s != NULL); + assert(s != nullptr); ssize_t n = read(s->m_fd, buf, len); if (n == -1) { @@ -386,7 +386,7 @@ size_t ArchNetworkBSD::readSocket(ArchSocket s, void *buf, size_t len) size_t ArchNetworkBSD::writeSocket(ArchSocket s, const void *buf, size_t len) { - assert(s != NULL); + assert(s != nullptr); ssize_t n = write(s->m_fd, buf, len); if (n == -1) { @@ -400,7 +400,7 @@ size_t ArchNetworkBSD::writeSocket(ArchSocket s, const void *buf, size_t len) void ArchNetworkBSD::throwErrorOnSocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // get the error from the socket layer int err = 0; @@ -435,7 +435,7 @@ void ArchNetworkBSD::setBlockingOnSocket(int fd, bool blocking) bool ArchNetworkBSD::setNoDelayOnSocket(ArchSocket s, bool noDelay) { - assert(s != NULL); + assert(s != nullptr); // get old state int oflag; @@ -455,7 +455,7 @@ bool ArchNetworkBSD::setNoDelayOnSocket(ArchSocket s, bool noDelay) bool ArchNetworkBSD::setReuseAddrOnSocket(ArchSocket s, bool reuse) { - assert(s != NULL); + assert(s != nullptr); // get old state int oflag; @@ -518,7 +518,7 @@ ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family) ArchNetAddress ArchNetworkBSD::copyAddr(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); // allocate and copy address return new ArchNetAddressImpl(*addr); @@ -572,14 +572,14 @@ std::vector ArchNetworkBSD::nameToAddr(const std::string &name) void ArchNetworkBSD::closeAddr(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); delete addr; } std::string ArchNetworkBSD::addrToName(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); // mutexed name lookup (ugh) ARCH->lockMutex(m_mutex); @@ -603,7 +603,7 @@ std::string ArchNetworkBSD::addrToName(ArchNetAddress addr) std::string ArchNetworkBSD::addrToString(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { @@ -631,7 +631,7 @@ std::string ArchNetworkBSD::addrToString(ArchNetAddress addr) IArchNetwork::EAddressFamily ArchNetworkBSD::getAddrFamily(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (addr->m_addr.ss_family) { case AF_INET: @@ -646,7 +646,7 @@ IArchNetwork::EAddressFamily ArchNetworkBSD::getAddrFamily(ArchNetAddress addr) void ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { @@ -669,7 +669,7 @@ void ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port) int ArchNetworkBSD::getAddrPort(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { @@ -690,7 +690,7 @@ int ArchNetworkBSD::getAddrPort(ArchNetAddress addr) bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { diff --git a/src/lib/arch/unix/ArchSleepUnix.cpp b/src/lib/arch/unix/ArchSleepUnix.cpp index 590753477..7d345140a 100644 --- a/src/lib/arch/unix/ArchSleepUnix.cpp +++ b/src/lib/arch/unix/ArchSleepUnix.cpp @@ -70,7 +70,7 @@ void ArchSleepUnix::sleep(double timeout) timeout2.tv_sec = static_cast(timeLeft); timeout2.tv_usec = static_cast(1.0e+6 * (timeLeft - timeout2.tv_sec)); select( - (SELECT_TYPE_ARG1)0, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL, + (SELECT_TYPE_ARG1)0, SELECT_TYPE_ARG234 nullptr, SELECT_TYPE_ARG234 nullptr, SELECT_TYPE_ARG234 nullptr, SELECT_TYPE_ARG5 & timeout2 ); ARCH->testCancelThread(); diff --git a/src/lib/arch/unix/ArchTimeUnix.cpp b/src/lib/arch/unix/ArchTimeUnix.cpp index 86ad6c122..dc47be4c1 100644 --- a/src/lib/arch/unix/ArchTimeUnix.cpp +++ b/src/lib/arch/unix/ArchTimeUnix.cpp @@ -35,6 +35,6 @@ ArchTimeUnix::~ArchTimeUnix() double ArchTimeUnix::time() { struct timeval t; - gettimeofday(&t, NULL); + gettimeofday(&t, nullptr); return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec; } diff --git a/src/lib/arch/win32/ArchDaemonWindows.cpp b/src/lib/arch/win32/ArchDaemonWindows.cpp index 334f2b465..fd91c6031 100644 --- a/src/lib/arch/win32/ArchDaemonWindows.cpp +++ b/src/lib/arch/win32/ArchDaemonWindows.cpp @@ -16,7 +16,7 @@ // ArchDaemonWindows // -ArchDaemonWindows *ArchDaemonWindows::s_daemon = NULL; +ArchDaemonWindows *ArchDaemonWindows::s_daemon = nullptr; ArchDaemonWindows::ArchDaemonWindows() : m_daemonThreadID(0) { @@ -30,20 +30,20 @@ ArchDaemonWindows::~ArchDaemonWindows() int ArchDaemonWindows::runDaemon(RunFunc runFunc) { - assert(s_daemon != NULL); + assert(s_daemon != nullptr); return s_daemon->doRunDaemon(runFunc); } void ArchDaemonWindows::daemonRunning(bool running) { - if (s_daemon != NULL) { + if (s_daemon != nullptr) { s_daemon->doDaemonRunning(running); } } UINT ArchDaemonWindows::getDaemonQuitMessage() { - if (s_daemon != NULL) { + if (s_daemon != nullptr) { return s_daemon->doGetDaemonQuitMessage(); } else { return 0; @@ -52,7 +52,7 @@ UINT ArchDaemonWindows::getDaemonQuitMessage() void ArchDaemonWindows::daemonFailed(int result) { - assert(s_daemon != NULL); + assert(s_daemon != nullptr); throw XArchDaemonRunFailed(result); } @@ -63,8 +63,8 @@ void ArchDaemonWindows::installDaemon( LOG_DEBUG("installing windows service: %s", name); // open service manager - SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_WRITE); - if (mgr == NULL) { + SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_WRITE); + if (mgr == nullptr) { // can't open service manager throw XArchDaemonInstallFailed(new XArchEvalWindows); } @@ -72,10 +72,10 @@ void ArchDaemonWindows::installDaemon( // create the service SC_HANDLE service = CreateService( mgr, name, name, 0, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, - SERVICE_ERROR_NORMAL, pathname, NULL, NULL, dependencies, NULL, NULL + SERVICE_ERROR_NORMAL, pathname, nullptr, nullptr, dependencies, nullptr, nullptr ); - if (service == NULL) { + if (service == nullptr) { // can't create service DWORD err = GetLastError(); if (err != ERROR_SERVICE_EXISTS) { @@ -93,7 +93,7 @@ void ArchDaemonWindows::installDaemon( // open the registry key for this service HKEY key = openNTServicesKey(); key = ArchMiscWindows::addKey(key, name); - if (key == NULL) { + if (key == nullptr) { // can't open key DWORD err = GetLastError(); try { @@ -109,7 +109,7 @@ void ArchDaemonWindows::installDaemon( // set command line key = ArchMiscWindows::addKey(key, _T("Parameters")); - if (key == NULL) { + if (key == nullptr) { // can't open key DWORD err = GetLastError(); ArchMiscWindows::closeKey(key); @@ -133,21 +133,21 @@ void ArchDaemonWindows::uninstallDaemon(const char *name) // remove parameters for this service. ignore failures. HKEY key = openNTServicesKey(); key = ArchMiscWindows::openKey(key, name); - if (key != NULL) { + if (key != nullptr) { ArchMiscWindows::deleteKey(key, _T("Parameters")); ArchMiscWindows::closeKey(key); } // open service manager - SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_WRITE); - if (mgr == NULL) { + SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_WRITE); + if (mgr == nullptr) { // can't open service manager throw XArchDaemonUninstallFailed(new XArchEvalWindows); } // open the service. oddly, you must open a service to delete it. SC_HANDLE service = OpenService(mgr, name, DELETE | SERVICE_STOP); - if (service == NULL) { + if (service == nullptr) { DWORD err = GetLastError(); CloseServiceHandle(mgr); if (err != ERROR_SERVICE_DOES_NOT_EXIST) { @@ -194,8 +194,8 @@ void ArchDaemonWindows::uninstallDaemon(const char *name) int ArchDaemonWindows::daemonize(const char *name, DaemonFunc func) { - assert(name != NULL); - assert(func != NULL); + assert(name != nullptr); + assert(func != nullptr); // save daemon function m_daemonFunc = func; @@ -204,27 +204,27 @@ int ArchDaemonWindows::daemonize(const char *name, DaemonFunc func) SERVICE_TABLE_ENTRY entry[2]; entry[0].lpServiceName = const_cast(name); entry[0].lpServiceProc = &ArchDaemonWindows::serviceMainEntry; - entry[1].lpServiceName = NULL; - entry[1].lpServiceProc = NULL; + entry[1].lpServiceName = nullptr; + entry[1].lpServiceProc = nullptr; // hook us up to the service control manager. this won't return // (if successful) until the processes have terminated. s_daemon = this; if (StartServiceCtrlDispatcher(entry) == 0) { // StartServiceCtrlDispatcher failed - s_daemon = NULL; + s_daemon = nullptr; throw XArchDaemonFailed(new XArchEvalWindows); } - s_daemon = NULL; + s_daemon = nullptr; return m_daemonResult; } bool ArchDaemonWindows::canInstallDaemon(const char * /*name*/) { // check if we can open service manager for write - SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_WRITE); - if (mgr == NULL) { + SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_WRITE); + if (mgr == nullptr) { return false; } CloseServiceHandle(mgr); @@ -233,14 +233,14 @@ bool ArchDaemonWindows::canInstallDaemon(const char * /*name*/) HKEY key = openNTServicesKey(); ArchMiscWindows::closeKey(key); - return (key != NULL); + return (key != nullptr); } bool ArchDaemonWindows::isDaemonInstalled(const char *name) { // open service manager - SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_READ); - if (mgr == NULL) { + SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_READ); + if (mgr == nullptr) { return false; } @@ -248,17 +248,17 @@ bool ArchDaemonWindows::isDaemonInstalled(const char *name) SC_HANDLE service = OpenService(mgr, name, GENERIC_READ); // clean up - if (service != NULL) { + if (service != nullptr) { CloseServiceHandle(service); } CloseServiceHandle(mgr); - return (service != NULL); + return (service != nullptr); } HKEY ArchDaemonWindows::openNTServicesKey() { - static const char *s_keyNames[] = {_T("SYSTEM"), _T("CurrentControlSet"), _T("Services"), NULL}; + static const char *s_keyNames[] = {_T("SYSTEM"), _T("CurrentControlSet"), _T("Services"), nullptr}; return ArchMiscWindows::addKey(HKEY_LOCAL_MACHINE, s_keyNames); } @@ -279,12 +279,12 @@ bool ArchDaemonWindows::isRunState(DWORD state) int ArchDaemonWindows::doRunDaemon(RunFunc run) { // should only be called from DaemonFunc - assert(m_serviceMutex != NULL); - assert(run != NULL); + assert(m_serviceMutex != nullptr); + assert(run != nullptr); // create message queue for this thread MSG dummy; - PeekMessage(&dummy, NULL, 0, 0, PM_NOREMOVE); + PeekMessage(&dummy, nullptr, 0, 0, PM_NOREMOVE); int result = 0; ARCH->lockMutex(m_serviceMutex); @@ -348,7 +348,7 @@ void ArchDaemonWindows::setStatus(DWORD state) void ArchDaemonWindows::setStatus(DWORD state, DWORD step, DWORD waitHint) { - assert(s_daemon != NULL); + assert(s_daemon != nullptr); LOG_DEBUG("setting service status: state=%d, step=%d, waitHint=%d", state, step, waitHint); @@ -365,7 +365,7 @@ void ArchDaemonWindows::setStatus(DWORD state, DWORD step, DWORD waitHint) void ArchDaemonWindows::setStatusError(DWORD error) { - assert(s_daemon != NULL); + assert(s_daemon != nullptr); SERVICE_STATUS status; status.dwServiceType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS; @@ -413,7 +413,7 @@ void ArchDaemonWindows::serviceMain(DWORD argc, LPTSTR *argvIn) HKEY key = openNTServicesKey(); key = ArchMiscWindows::openKey(key, argvIn[0]); key = ArchMiscWindows::openKey(key, _T("Parameters")); - if (key != NULL) { + if (key != nullptr) { commandLine = ArchMiscWindows::readValueString(key, _T("CommandLine")); } @@ -498,14 +498,14 @@ void WINAPI ArchDaemonWindows::serviceMainEntry(DWORD argc, LPTSTR *argv) void ArchDaemonWindows::serviceHandler(DWORD ctrl) { - assert(m_serviceMutex != NULL); - assert(m_serviceCondVar != NULL); + assert(m_serviceMutex != nullptr); + assert(m_serviceCondVar != nullptr); ARCH->lockMutex(m_serviceMutex); // ignore request if service is already stopped - if (s_daemon == NULL || m_serviceState == SERVICE_STOPPED) { - if (s_daemon != NULL) { + if (s_daemon == nullptr || m_serviceState == SERVICE_STOPPED) { + if (s_daemon != nullptr) { setStatus(m_serviceState); } ARCH->unlockMutex(m_serviceMutex); @@ -560,21 +560,21 @@ void WINAPI ArchDaemonWindows::serviceHandlerEntry(DWORD ctrl) void ArchDaemonWindows::start(const char *name) { // open service manager - SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_READ); - if (mgr == NULL) { + SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_READ); + if (mgr == nullptr) { throw XArchDaemonFailed(new XArchEvalWindows()); } // open the service SC_HANDLE service = OpenService(mgr, name, SERVICE_START); - if (service == NULL) { + if (service == nullptr) { CloseServiceHandle(mgr); throw XArchDaemonFailed(new XArchEvalWindows()); } // start the service - if (!StartService(service, 0, NULL)) { + if (!StartService(service, 0, nullptr)) { throw XArchDaemonFailed(new XArchEvalWindows()); } } @@ -582,15 +582,15 @@ void ArchDaemonWindows::start(const char *name) void ArchDaemonWindows::stop(const char *name) { // open service manager - SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_READ); - if (mgr == NULL) { + SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_READ); + if (mgr == nullptr) { throw XArchDaemonFailed(new XArchEvalWindows()); } // open the service SC_HANDLE service = OpenService(mgr, name, SERVICE_STOP | SERVICE_QUERY_STATUS); - if (service == NULL) { + if (service == nullptr) { CloseServiceHandle(mgr); throw XArchDaemonFailed(new XArchEvalWindows()); } diff --git a/src/lib/arch/win32/ArchLogWindows.cpp b/src/lib/arch/win32/ArchLogWindows.cpp index adc4d69cf..9a8d29657 100644 --- a/src/lib/arch/win32/ArchLogWindows.cpp +++ b/src/lib/arch/win32/ArchLogWindows.cpp @@ -14,7 +14,7 @@ // ArchLogWindows // -ArchLogWindows::ArchLogWindows() : m_eventLog(NULL) +ArchLogWindows::ArchLogWindows() : m_eventLog(nullptr) { // do nothing } @@ -26,16 +26,16 @@ ArchLogWindows::~ArchLogWindows() void ArchLogWindows::openLog(const char *name) { - if (m_eventLog == NULL) { - m_eventLog = RegisterEventSource(NULL, name); + if (m_eventLog == nullptr) { + m_eventLog = RegisterEventSource(nullptr, name); } } void ArchLogWindows::closeLog() { - if (m_eventLog != NULL) { + if (m_eventLog != nullptr) { DeregisterEventSource(m_eventLog); - m_eventLog = NULL; + m_eventLog = nullptr; } } @@ -46,7 +46,7 @@ void ArchLogWindows::showLog(bool) void ArchLogWindows::writeLog(ELevel level, const char *msg) { - if (m_eventLog != NULL) { + if (m_eventLog != nullptr) { // convert priority WORD type; switch (level) { @@ -72,9 +72,9 @@ void ArchLogWindows::writeLog(ELevel level, const char *msg) ReportEvent( m_eventLog, type, static_cast(level), 0, // event ID - NULL, 0, + nullptr, 0, (DWORD)strlen(msg) + 1, // raw data size - NULL, + nullptr, const_cast(msg) ); // raw data } diff --git a/src/lib/arch/win32/ArchMiscWindows.cpp b/src/lib/arch/win32/ArchMiscWindows.cpp index affec1585..cdc30da31 100644 --- a/src/lib/arch/win32/ArchMiscWindows.cpp +++ b/src/lib/arch/win32/ArchMiscWindows.cpp @@ -31,7 +31,7 @@ void errorMessageBox(const char *message, const char *title = "Fatal Error"); std::string getBinaryName() { std::array buffer; - if (!GetModuleFileNameA(NULL, buffer.data(), MAX_PATH)) { + if (!GetModuleFileNameA(nullptr, buffer.data(), MAX_PATH)) { errorMessageBox("Failed to get binary name."); abort(); } @@ -52,10 +52,10 @@ const std::string s_binaryName = getBinaryName(); // DWORD ArchMiscWindows::s_busyState = 0; -ArchMiscWindows::STES_t ArchMiscWindows::s_stes = NULL; -HICON ArchMiscWindows::s_largeIcon = NULL; -HICON ArchMiscWindows::s_smallIcon = NULL; -HINSTANCE ArchMiscWindows::s_instanceWin32 = NULL; +ArchMiscWindows::STES_t ArchMiscWindows::s_stes = nullptr; +HICON ArchMiscWindows::s_largeIcon = nullptr; +HICON ArchMiscWindows::s_smallIcon = nullptr; +HINSTANCE ArchMiscWindows::s_instanceWin32 = nullptr; void ArchMiscWindows::init() { @@ -105,9 +105,9 @@ HKEY ArchMiscWindows::addKey(HKEY key, const TCHAR *const *keyNames) HKEY ArchMiscWindows::openKey(HKEY key, const TCHAR *keyName, bool create) { - // ignore if parent is NULL - if (key == NULL) { - return NULL; + // ignore if parent is nullptr + if (key == nullptr) { + return nullptr; } // open next key @@ -115,11 +115,11 @@ HKEY ArchMiscWindows::openKey(HKEY key, const TCHAR *keyName, bool create) LSTATUS result = RegOpenKeyEx(key, keyName, 0, KEY_WRITE | KEY_QUERY_VALUE, &newKey); if (result != ERROR_SUCCESS && create) { DWORD disp; - result = RegCreateKeyEx(key, keyName, 0, NULL, 0, KEY_WRITE | KEY_QUERY_VALUE, NULL, &newKey, &disp); + result = RegCreateKeyEx(key, keyName, 0, nullptr, 0, KEY_WRITE | KEY_QUERY_VALUE, nullptr, &newKey, &disp); } if (result != ERROR_SUCCESS) { RegCloseKey(key); - return NULL; + return nullptr; } // switch to new key @@ -129,7 +129,7 @@ HKEY ArchMiscWindows::openKey(HKEY key, const TCHAR *keyName, bool create) HKEY ArchMiscWindows::openKey(HKEY key, const TCHAR *const *keyNames, bool create) { - for (size_t i = 0; key != NULL && keyNames[i] != NULL; ++i) { + for (size_t i = 0; key != nullptr && keyNames[i] != nullptr; ++i) { // open next key key = openKey(key, keyNames[i], create); } @@ -138,17 +138,17 @@ HKEY ArchMiscWindows::openKey(HKEY key, const TCHAR *const *keyNames, bool creat void ArchMiscWindows::closeKey(HKEY key) { - assert(key != NULL); - if (key == NULL) + assert(key != nullptr); + if (key == nullptr) return; RegCloseKey(key); } void ArchMiscWindows::deleteKey(HKEY key, const TCHAR *name) { - assert(key != NULL); - assert(name != NULL); - if (key == NULL || name == NULL) + assert(key != nullptr); + assert(name != nullptr); + if (key == nullptr || name == nullptr) return; RegDeleteKey(key, name); } @@ -156,7 +156,7 @@ void ArchMiscWindows::deleteKey(HKEY key, const TCHAR *name) ArchMiscWindows::EValueType ArchMiscWindows::typeOfValue(HKEY key, const TCHAR *name) { DWORD type; - LONG result = RegQueryValueEx(key, name, 0, &type, NULL, NULL); + LONG result = RegQueryValueEx(key, name, 0, &type, nullptr, nullptr); if (result != ERROR_SUCCESS) { return kNO_VALUE; } @@ -177,8 +177,8 @@ ArchMiscWindows::EValueType ArchMiscWindows::typeOfValue(HKEY key, const TCHAR * void ArchMiscWindows::setValue(HKEY key, const TCHAR *name, const std::string &value) { - assert(key != NULL); - if (key == NULL) { + assert(key != nullptr); + if (key == nullptr) { // TODO: throw exception return; } @@ -187,8 +187,8 @@ void ArchMiscWindows::setValue(HKEY key, const TCHAR *name, const std::string &v void ArchMiscWindows::setValue(HKEY key, const TCHAR *name, DWORD value) { - assert(key != NULL); - if (key == NULL) { + assert(key != nullptr); + if (key == nullptr) { // TODO: throw exception return; } @@ -200,7 +200,7 @@ std::string ArchMiscWindows::readBinaryOrString(HKEY key, const TCHAR *name, DWO // get the size of the string DWORD actualType; DWORD size = 0; - LONG result = RegQueryValueEx(key, name, 0, &actualType, NULL, &size); + LONG result = RegQueryValueEx(key, name, 0, &actualType, nullptr, &size); if (result != ERROR_SUCCESS || actualType != type) { return std::string(); } @@ -263,12 +263,12 @@ void ArchMiscWindows::removeBusyState(DWORD busyModes) void ArchMiscWindows::setThreadExecutionState(DWORD busyModes) { // look up function dynamically so we work on older systems - if (s_stes == NULL) { + if (s_stes == nullptr) { HINSTANCE kernel = LoadLibrary("kernel32.dll"); - if (kernel != NULL) { + if (kernel != nullptr) { s_stes = reinterpret_cast(GetProcAddress(kernel, "SetThreadExecutionState")); } - if (s_stes == NULL) { + if (s_stes == nullptr) { s_stes = &ArchMiscWindows::dummySetThreadExecutionState; } } @@ -301,12 +301,12 @@ void ArchMiscWindows::wakeupDisplay() // We can't use ::setThreadExecutionState here because it sets // ES_CONTINUOUS, which we don't want. - if (s_stes == NULL) { + if (s_stes == nullptr) { HINSTANCE kernel = LoadLibrary("kernel32.dll"); - if (kernel != NULL) { + if (kernel != nullptr) { s_stes = reinterpret_cast(GetProcAddress(kernel, "SetThreadExecutionState")); } - if (s_stes == NULL) { + if (s_stes == nullptr) { s_stes = &ArchMiscWindows::dummySetThreadExecutionState; } } @@ -394,13 +394,13 @@ BOOL WINAPI ArchMiscWindows::getProcessEntry(PROCESSENTRY32 &entry, DWORD proces HINSTANCE ArchMiscWindows::instanceWin32() { - assert(s_instanceWin32 != NULL); + assert(s_instanceWin32 != nullptr); return s_instanceWin32; } void ArchMiscWindows::setInstanceWin32(HINSTANCE instance) { - assert(instance != NULL); + assert(instance != nullptr); s_instanceWin32 = instance; } diff --git a/src/lib/arch/win32/ArchMultithreadWindows.cpp b/src/lib/arch/win32/ArchMultithreadWindows.cpp index f44af37b1..74cdf0008 100644 --- a/src/lib/arch/win32/ArchMultithreadWindows.cpp +++ b/src/lib/arch/win32/ArchMultithreadWindows.cpp @@ -50,16 +50,16 @@ public: ArchThreadImpl::ArchThreadImpl() : m_refCount(1), - m_thread(NULL), + m_thread(nullptr), m_id(0), - m_func(NULL), - m_userData(NULL), + m_func(nullptr), + m_userData(nullptr), m_cancelling(false), - m_result(NULL), - m_networkData(NULL) + m_result(nullptr), + m_networkData(nullptr) { - m_exit = CreateEvent(NULL, TRUE, FALSE, NULL); - m_cancel = CreateEvent(NULL, TRUE, FALSE, NULL); + m_exit = CreateEvent(nullptr, TRUE, FALSE, nullptr); + m_cancel = CreateEvent(nullptr, TRUE, FALSE, nullptr); } ArchThreadImpl::~ArchThreadImpl() @@ -72,17 +72,17 @@ ArchThreadImpl::~ArchThreadImpl() // ArchMultithreadWindows // -ArchMultithreadWindows *ArchMultithreadWindows::s_instance = NULL; +ArchMultithreadWindows *ArchMultithreadWindows::s_instance = nullptr; ArchMultithreadWindows::ArchMultithreadWindows() { - assert(s_instance == NULL); + assert(s_instance == nullptr); s_instance = this; // no signal handlers for (size_t i = 0; i < kNUM_SIGNALS; ++i) { - m_signalFunc[i] = NULL; - m_signalUserData[i] = NULL; + m_signalFunc[i] = nullptr; + m_signalUserData[i] = nullptr; } // create mutex for thread list @@ -91,14 +91,14 @@ ArchMultithreadWindows::ArchMultithreadWindows() // create thread for calling (main) thread and add it to our // list. no need to lock the mutex since we're the only thread. m_mainThread = new ArchThreadImpl; - m_mainThread->m_thread = NULL; + m_mainThread->m_thread = nullptr; m_mainThread->m_id = GetCurrentThreadId(); insert(m_mainThread); } ArchMultithreadWindows::~ArchMultithreadWindows() { - s_instance = NULL; + s_instance = nullptr; // clean up thread list for (ThreadList::iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) { @@ -142,8 +142,8 @@ ArchMultithreadWindows *ArchMultithreadWindows::getInstance() ArchCond ArchMultithreadWindows::newCondVar() { ArchCondImpl *cond = new ArchCondImpl; - cond->m_events[ArchCondImpl::kSignal] = CreateEvent(NULL, FALSE, FALSE, NULL); - cond->m_events[ArchCondImpl::kBroadcast] = CreateEvent(NULL, TRUE, FALSE, NULL); + cond->m_events[ArchCondImpl::kSignal] = CreateEvent(nullptr, FALSE, FALSE, nullptr); + cond->m_events[ArchCondImpl::kBroadcast] = CreateEvent(nullptr, TRUE, FALSE, nullptr); cond->m_waitCountMutex = newMutex(); cond->m_waitCount = 0; return cond; @@ -272,14 +272,14 @@ ArchThread ArchMultithreadWindows::newThread(ThreadFunc func, void *data) // create thread unsigned int id = 0; - thread->m_thread = reinterpret_cast(_beginthreadex(NULL, 0, threadFunc, (void *)thread, 0, &id)); + thread->m_thread = reinterpret_cast(_beginthreadex(nullptr, 0, threadFunc, (void *)thread, 0, &id)); thread->m_id = static_cast(id); // check if thread was started if (thread->m_thread == 0) { // failed to start thread so clean up delete thread; - thread = NULL; + thread = nullptr; } else { // add thread to list insert(thread); @@ -299,18 +299,18 @@ ArchThread ArchMultithreadWindows::newCurrentThread() lockMutex(m_threadMutex); ArchThreadImpl *thread = find(GetCurrentThreadId()); unlockMutex(m_threadMutex); - assert(thread != NULL); + assert(thread != nullptr); return thread; } void ArchMultithreadWindows::closeThread(ArchThread thread) { - assert(thread != NULL); + assert(thread != nullptr); // decrement ref count and clean up thread if no more references if (--thread->m_refCount == 0) { - // close the handle (main thread has a NULL handle) - if (thread->m_thread != NULL) { + // close the handle (main thread has a nullptr handle) + if (thread->m_thread != nullptr) { CloseHandle(thread->m_thread); } @@ -333,7 +333,7 @@ ArchThread ArchMultithreadWindows::copyThread(ArchThread thread) void ArchMultithreadWindows::cancelThread(ArchThread thread) { - assert(thread != NULL); + assert(thread != nullptr); // set cancel flag SetEvent(thread->m_cancel); @@ -380,7 +380,7 @@ void ArchMultithreadWindows::setPriorityOfThread(ArchThread thread, int n) #endif static const size_t s_pBase = 8; // index of normal priority - assert(thread != NULL); + assert(thread != nullptr); size_t index; if (n > 0 && s_pBase < (size_t)n) { @@ -410,7 +410,7 @@ void ArchMultithreadWindows::testCancelThread() bool ArchMultithreadWindows::wait(ArchThread target, double timeout) { - assert(target != NULL); + assert(target != nullptr); lockMutex(m_threadMutex); @@ -502,7 +502,7 @@ void ArchMultithreadWindows::setSignalHandler(ESignal signal, SignalFunc func, v void ArchMultithreadWindows::raiseSignal(ESignal signal) { lockMutex(m_threadMutex); - if (m_signalFunc[signal] != NULL) { + if (m_signalFunc[signal] != nullptr) { m_signalFunc[signal](signal, m_signalUserData[signal]); ARCH->unblockPollSocket(m_mainThread); } else if (signal == kINTERRUPT || signal == kTERMINATE) { @@ -514,7 +514,7 @@ void ArchMultithreadWindows::raiseSignal(ESignal signal) ArchThreadImpl *ArchMultithreadWindows::find(DWORD id) { ArchThreadImpl *impl = findNoRef(id); - if (impl != NULL) { + if (impl != nullptr) { refThread(impl); } return impl; @@ -523,13 +523,13 @@ ArchThreadImpl *ArchMultithreadWindows::find(DWORD id) ArchThreadImpl *ArchMultithreadWindows::findNoRef(DWORD id) { ArchThreadImpl *impl = findNoRefOrCreate(id); - if (impl == NULL) { + if (impl == nullptr) { // create thread for calling thread which isn't in our list and // add it to the list. this won't normally happen but it can if // the system calls us under a new thread, like it does when we // run as a service. impl = new ArchThreadImpl; - impl->m_thread = NULL; + impl->m_thread = nullptr; impl->m_id = GetCurrentThreadId(); insert(impl); } @@ -544,15 +544,15 @@ ArchThreadImpl *ArchMultithreadWindows::findNoRefOrCreate(DWORD id) return *index; } } - return NULL; + return nullptr; } void ArchMultithreadWindows::insert(ArchThreadImpl *thread) { - assert(thread != NULL); + assert(thread != nullptr); // thread shouldn't already be on the list - assert(findNoRefOrCreate(thread->m_id) == NULL); + assert(findNoRefOrCreate(thread->m_id) == nullptr); // append to list m_threadList.push_back(thread); @@ -570,14 +570,14 @@ void ArchMultithreadWindows::erase(ArchThreadImpl *thread) void ArchMultithreadWindows::refThread(ArchThreadImpl *thread) { - assert(thread != NULL); - assert(findNoRefOrCreate(thread->m_id) != NULL); + assert(thread != nullptr); + assert(findNoRefOrCreate(thread->m_id) != nullptr); ++thread->m_refCount; } void ArchMultithreadWindows::testCancelThreadImpl(ArchThreadImpl *thread) { - assert(thread != NULL); + assert(thread != nullptr); // poll cancel event. return if not set. const DWORD result = WaitForSingleObject(thread->m_cancel, 0); @@ -616,7 +616,7 @@ void ArchMultithreadWindows::doThreadFunc(ArchThread thread) lockMutex(m_threadMutex); unlockMutex(m_threadMutex); - void *result = NULL; + void *result = nullptr; try { // go result = (*thread->m_func)(thread->m_userData); diff --git a/src/lib/arch/win32/ArchNetworkWinsock.cpp b/src/lib/arch/win32/ArchNetworkWinsock.cpp index 0a79cebe8..35d68667b 100644 --- a/src/lib/arch/win32/ArchNetworkWinsock.cpp +++ b/src/lib/arch/win32/ArchNetworkWinsock.cpp @@ -58,7 +58,7 @@ static int(PASCAL FAR *WSAEnumNetworkEvents_winsock)(SOCKET, WSAEVENT, LPWSANETW #define setfunc(var, name, type) var = (type)netGetProcAddress(module, #name) -static HMODULE s_networkModule = NULL; +static HMODULE s_networkModule = nullptr; static FARPROC netGetProcAddress(HMODULE module, LPCSTR name) { @@ -81,20 +81,20 @@ ArchNetAddressImpl *ArchNetAddressImpl::alloc(size_t size) // ArchNetworkWinsock // -ArchNetworkWinsock::ArchNetworkWinsock() : m_mutex(NULL) +ArchNetworkWinsock::ArchNetworkWinsock() : m_mutex(nullptr) { } ArchNetworkWinsock::~ArchNetworkWinsock() { - if (s_networkModule != NULL) { + if (s_networkModule != nullptr) { WSACleanup_winsock(); ::FreeLibrary(s_networkModule); - WSACleanup_winsock = NULL; - s_networkModule = NULL; + WSACleanup_winsock = nullptr; + s_networkModule = nullptr; } - if (m_mutex != NULL) { + if (m_mutex != nullptr) { ARCH->closeMutex(m_mutex); } @@ -108,8 +108,8 @@ void ArchNetworkWinsock::init() { static const char *s_library[] = {"ws2_32.dll"}; - assert(WSACleanup_winsock == NULL); - assert(s_networkModule == NULL); + assert(WSACleanup_winsock == nullptr); + assert(s_networkModule == nullptr); // try each winsock library for (size_t i = 0; i < sizeof(s_library) / sizeof(s_library[0]); ++i) { @@ -128,7 +128,7 @@ void ArchNetworkWinsock::init() void ArchNetworkWinsock::initModule(HMODULE module) { - if (module == NULL) { + if (module == nullptr) { throw XArchNetworkSupport(""); } @@ -229,7 +229,7 @@ ArchSocket ArchNetworkWinsock::newSocket(EAddressFamily family, ESocketType type ArchSocket ArchNetworkWinsock::copySocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // ref the socket and return it ARCH->lockMutex(m_mutex); @@ -240,7 +240,7 @@ ArchSocket ArchNetworkWinsock::copySocket(ArchSocket s) void ArchNetworkWinsock::closeSocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // unref the socket and note if it should be released ARCH->lockMutex(m_mutex); @@ -264,7 +264,7 @@ void ArchNetworkWinsock::closeSocket(ArchSocket s) void ArchNetworkWinsock::closeSocketForRead(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); if (shutdown_winsock(s->m_socket, SD_RECEIVE) == SOCKET_ERROR) { if (getsockerror_winsock() != WSAENOTCONN) { @@ -275,7 +275,7 @@ void ArchNetworkWinsock::closeSocketForRead(ArchSocket s) void ArchNetworkWinsock::closeSocketForWrite(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); if (shutdown_winsock(s->m_socket, SD_SEND) == SOCKET_ERROR) { if (getsockerror_winsock() != WSAENOTCONN) { @@ -286,8 +286,8 @@ void ArchNetworkWinsock::closeSocketForWrite(ArchSocket s) void ArchNetworkWinsock::bindSocket(ArchSocket s, ArchNetAddress addr) { - assert(s != NULL); - assert(addr != NULL); + assert(s != nullptr); + assert(addr != nullptr); if (bind_winsock(s->m_socket, TYPED_ADDR(struct sockaddr, addr), addr->m_len) == SOCKET_ERROR) { throwError(getsockerror_winsock()); @@ -296,7 +296,7 @@ void ArchNetworkWinsock::bindSocket(ArchSocket s, ArchNetAddress addr) void ArchNetworkWinsock::listenOnSocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // hardcoding backlog if (listen_winsock(s->m_socket, 3) == SOCKET_ERROR) { @@ -306,7 +306,7 @@ void ArchNetworkWinsock::listenOnSocket(ArchSocket s) ArchSocket ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress *const addr) { - assert(s != NULL); + assert(s != nullptr); // create new socket and temporary address ArchSocketImpl *socket = new ArchSocketImpl; @@ -319,10 +319,10 @@ ArchSocket ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress *const delete socket; free(tmp); if (addr) { - *addr = NULL; + *addr = nullptr; } if (err == WSAEWOULDBLOCK) { - return NULL; + return nullptr; } throwError(err); } @@ -334,7 +334,7 @@ ArchSocket ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress *const delete socket; free(tmp); if (addr) { - *addr = NULL; + *addr = nullptr; } throw; } @@ -346,7 +346,7 @@ ArchSocket ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress *const socket->m_pollWrite = true; // copy address if requested - if (addr != NULL) { + if (addr != nullptr) { *addr = ARCH->copyAddr(tmp); } @@ -356,8 +356,8 @@ ArchSocket ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress *const bool ArchNetworkWinsock::connectSocket(ArchSocket s, ArchNetAddress addr) { - assert(s != NULL); - assert(addr != NULL); + assert(s != nullptr); + assert(addr != nullptr); if (connect_winsock(s->m_socket, TYPED_ADDR(struct sockaddr, addr), addr->m_len) == SOCKET_ERROR) { if (getsockerror_winsock() == WSAEISCONN) { @@ -384,7 +384,7 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout) pe[i].m_revents = 0; // set invalid flag if socket is bogus then go to next socket - if (pe[i].m_socket == NULL) { + if (pe[i].m_socket == nullptr) { pe[i].m_revents |= kPOLLNVAL; continue; } @@ -428,7 +428,7 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout) ArchThread thread = mt->newCurrentThread(); WSAEVENT *unblockEvent = (WSAEVENT *)mt->getNetworkDataForThread(thread); ARCH->closeThread(thread); - if (unblockEvent == NULL) { + if (unblockEvent == nullptr) { unblockEvent = new WSAEVENT; m_unblockEvents.push_back(unblockEvent); *unblockEvent = WSACreateEvent_winsock(); @@ -467,7 +467,7 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout) } for (i = 0, n = 0; i < num; ++i) { // skip events we didn't check - if (pe[i].m_socket == NULL || (pe[i].m_events & (kPOLLIN | kPOLLOUT)) == 0) { + if (pe[i].m_socket == nullptr || (pe[i].m_events & (kPOLLIN | kPOLLOUT)) == 0) { continue; } @@ -522,14 +522,14 @@ void ArchNetworkWinsock::unblockPollSocket(ArchThread thread) // set the unblock event ArchMultithreadWindows *mt = ArchMultithreadWindows::getInstance(); WSAEVENT *unblockEvent = (WSAEVENT *)mt->getNetworkDataForThread(thread); - if (unblockEvent != NULL) { + if (unblockEvent != nullptr) { WSASetEvent_winsock(*unblockEvent); } } size_t ArchNetworkWinsock::readSocket(ArchSocket s, void *buf, size_t len) { - assert(s != NULL); + assert(s != nullptr); int n = recv_winsock(s->m_socket, buf, (int)len, 0); if (n == SOCKET_ERROR) { @@ -544,7 +544,7 @@ size_t ArchNetworkWinsock::readSocket(ArchSocket s, void *buf, size_t len) size_t ArchNetworkWinsock::writeSocket(ArchSocket s, const void *buf, size_t len) { - assert(s != NULL); + assert(s != nullptr); int n = send_winsock(s->m_socket, buf, (int)len, 0); if (n == SOCKET_ERROR) { @@ -563,7 +563,7 @@ size_t ArchNetworkWinsock::writeSocket(ArchSocket s, const void *buf, size_t len void ArchNetworkWinsock::throwErrorOnSocket(ArchSocket s) { - assert(s != NULL); + assert(s != nullptr); // get the error from the socket layer int err = 0; @@ -590,7 +590,7 @@ void ArchNetworkWinsock::setBlockingOnSocket(SOCKET s, bool blocking) bool ArchNetworkWinsock::setNoDelayOnSocket(ArchSocket s, bool noDelay) { - assert(s != NULL); + assert(s != nullptr); // get old state BOOL oflag; @@ -611,7 +611,7 @@ bool ArchNetworkWinsock::setNoDelayOnSocket(ArchSocket s, bool noDelay) bool ArchNetworkWinsock::setReuseAddrOnSocket(ArchSocket s, bool reuse) { - assert(s != NULL); + assert(s != nullptr); // get old state BOOL oflag; @@ -643,7 +643,7 @@ std::string ArchNetworkWinsock::getHostName() ArchNetAddress ArchNetworkWinsock::newAnyAddr(EAddressFamily family) { - ArchNetAddressImpl *addr = NULL; + ArchNetAddressImpl *addr = nullptr; switch (family) { case kINET: { addr = ArchNetAddressImpl::alloc(sizeof(struct sockaddr_in)); @@ -671,7 +671,7 @@ ArchNetAddress ArchNetworkWinsock::newAnyAddr(EAddressFamily family) ArchNetAddress ArchNetworkWinsock::copyAddr(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); ArchNetAddressImpl *copy = ArchNetAddressImpl::alloc(addr->m_len); memcpy(TYPED_ADDR(void, copy), TYPED_ADDR(void, addr), addr->m_len); @@ -690,7 +690,7 @@ std::vector ArchNetworkWinsock::nameToAddr(const std::string &na int ret = -1; ARCH->lockMutex(m_mutex); - if ((ret = getaddrinfo(name.c_str(), NULL, &hints, &pResult)) != 0) { + if ((ret = getaddrinfo(name.c_str(), nullptr, &hints, &pResult)) != 0) { ARCH->unlockMutex(m_mutex); throwNameError(ret); } @@ -713,21 +713,21 @@ std::vector ArchNetworkWinsock::nameToAddr(const std::string &na void ArchNetworkWinsock::closeAddr(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); free(addr); } std::string ArchNetworkWinsock::addrToName(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); char host[1024]; char service[20]; int ret = getnameinfo(TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host), service, sizeof(service), 0); - if (ret != NULL) { + if (ret != 0) { throwNameError(ret); } @@ -738,7 +738,7 @@ std::string ArchNetworkWinsock::addrToName(ArchNetAddress addr) std::string ArchNetworkWinsock::addrToString(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { @@ -761,7 +761,7 @@ std::string ArchNetworkWinsock::addrToString(ArchNetAddress addr) IArchNetwork::EAddressFamily ArchNetworkWinsock::getAddrFamily(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (addr->m_addr.ss_family) { case AF_INET: @@ -777,7 +777,7 @@ IArchNetwork::EAddressFamily ArchNetworkWinsock::getAddrFamily(ArchNetAddress ad void ArchNetworkWinsock::setAddrPort(ArchNetAddress addr, int port) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { @@ -800,7 +800,7 @@ void ArchNetworkWinsock::setAddrPort(ArchNetAddress addr, int port) int ArchNetworkWinsock::getAddrPort(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { @@ -821,7 +821,7 @@ int ArchNetworkWinsock::getAddrPort(ArchNetAddress addr) bool ArchNetworkWinsock::isAnyAddr(ArchNetAddress addr) { - assert(addr != NULL); + assert(addr != nullptr); switch (getAddrFamily(addr)) { case kINET: { diff --git a/src/lib/arch/win32/ArchSleepWindows.cpp b/src/lib/arch/win32/ArchSleepWindows.cpp index 84053d4b1..3baf6c732 100644 --- a/src/lib/arch/win32/ArchSleepWindows.cpp +++ b/src/lib/arch/win32/ArchSleepWindows.cpp @@ -35,7 +35,7 @@ void ArchSleepWindows::sleep(double timeout) // this is windows so that's pretty certain; we'll get a // link error if we're not, though. ArchMultithreadWindows *mt = ArchMultithreadWindows::getInstance(); - if (mt != NULL) { + if (mt != nullptr) { HANDLE cancelEvent = mt->getCancelEventForCurrentThread(); WaitForSingleObject(cancelEvent, (DWORD)(1000.0 * timeout)); if (timeout == 0.0) { diff --git a/src/lib/arch/win32/ArchTimeWindows.cpp b/src/lib/arch/win32/ArchTimeWindows.cpp index b64201aa4..71fa2558a 100644 --- a/src/lib/arch/win32/ArchTimeWindows.cpp +++ b/src/lib/arch/win32/ArchTimeWindows.cpp @@ -25,8 +25,8 @@ typedef WINMMAPI DWORD(WINAPI *PTimeGetTime)(void); static double s_freq = 0.0; -static HINSTANCE s_mmInstance = NULL; -static PTimeGetTime s_tgt = NULL; +static HINSTANCE s_mmInstance = nullptr; +static PTimeGetTime s_tgt = nullptr; // // ArchTimeWindows @@ -34,7 +34,7 @@ static PTimeGetTime s_tgt = NULL; ArchTimeWindows::ArchTimeWindows() { - assert(s_freq == 0.0 || s_mmInstance == NULL); + assert(s_freq == 0.0 || s_mmInstance == nullptr); LARGE_INTEGER freq; if (QueryPerformanceFrequency(&freq) && freq.QuadPart != 0) { @@ -42,7 +42,7 @@ ArchTimeWindows::ArchTimeWindows() } else { // load winmm.dll and get timeGetTime s_mmInstance = LoadLibrary("winmm"); - if (s_mmInstance != NULL) { + if (s_mmInstance != nullptr) { s_tgt = (PTimeGetTime)GetProcAddress(s_mmInstance, "timeGetTime"); } } @@ -51,10 +51,10 @@ ArchTimeWindows::ArchTimeWindows() ArchTimeWindows::~ArchTimeWindows() { s_freq = 0.0; - if (s_mmInstance == NULL) { + if (s_mmInstance == nullptr) { FreeLibrary(static_cast(s_mmInstance)); - s_tgt = NULL; - s_mmInstance = NULL; + s_tgt = nullptr; + s_mmInstance = nullptr; } } @@ -65,7 +65,7 @@ double ArchTimeWindows::time() LARGE_INTEGER c; QueryPerformanceCounter(&c); return s_freq * static_cast(c.QuadPart); - } else if (s_tgt != NULL) { + } else if (s_tgt != nullptr) { return 0.001 * static_cast(s_tgt()); } else { return 0.001 * static_cast(GetTickCount()); diff --git a/src/lib/arch/win32/XArchWindows.cpp b/src/lib/arch/win32/XArchWindows.cpp index 388d3e794..4c0ec2dc7 100644 --- a/src/lib/arch/win32/XArchWindows.cpp +++ b/src/lib/arch/win32/XArchWindows.cpp @@ -18,9 +18,9 @@ std::string XArchEvalWindows::eval() const throw() char *cmsg; if (FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, 0, m_error, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&cmsg, 0, NULL + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&cmsg, 0, nullptr ) == 0) { - cmsg = NULL; + cmsg = nullptr; return deskflow::string::sprintf("Unknown error, code %d", m_error); } std::string smsg(cmsg); @@ -200,7 +200,7 @@ std::string XArchEvalWinsock::eval() const throw() {WSANO_DATA, "The requested name is valid but does not have an IP address"}, // end - {0, NULL} + {0, nullptr} }; for (unsigned int i = 0; s_netErrorCodes[i].m_code != 0; ++i) { diff --git a/src/lib/base/Event.cpp b/src/lib/base/Event.cpp index f90fea09f..abceff296 100644 --- a/src/lib/base/Event.cpp +++ b/src/lib/base/Event.cpp @@ -11,7 +11,7 @@ // Event // -Event::Event() : m_type(kUnknown), m_target(NULL), m_data(NULL), m_flags(0), m_dataObject(nullptr) +Event::Event() : m_type(kUnknown), m_target(nullptr), m_data(nullptr), m_flags(0), m_dataObject(nullptr) { // do nothing } diff --git a/src/lib/base/Event.h b/src/lib/base/Event.h index 07304ed13..c36de4120 100644 --- a/src/lib/base/Event.h +++ b/src/lib/base/Event.h @@ -56,7 +56,7 @@ public: \p target is the intended recipient of the event. \p flags is any combination of \c Flags. */ - Event(Type type, void *target = NULL, void *data = NULL, Flags flags = kNone); + Event(Type type, void *target = nullptr, void *data = nullptr, Flags flags = kNone); //! Create \c Event with non-POD data /*! diff --git a/src/lib/base/EventQueue.cpp b/src/lib/base/EventQueue.cpp index c50e7f465..43b8a0aa8 100644 --- a/src/lib/base/EventQueue.cpp +++ b/src/lib/base/EventQueue.cpp @@ -48,23 +48,23 @@ static void interrupt(Arch::ESignal, void *data) EventQueue::EventQueue() : m_systemTarget(0), m_nextType(Event::kLast), - m_typesForClient(NULL), - m_typesForIStream(NULL), - m_typesForIDataSocket(NULL), - m_typesForIListenSocket(NULL), - m_typesForISocket(NULL), - m_typesForOSXScreen(NULL), - m_typesForClientListener(NULL), - m_typesForClientProxy(NULL), - m_typesForClientProxyUnknown(NULL), - m_typesForServer(NULL), - m_typesForServerApp(NULL), - m_typesForIKeyState(NULL), - m_typesForIPrimaryScreen(NULL), - m_typesForIScreen(NULL), - m_typesForClipboard(NULL), - m_typesForFile(NULL), - m_typesForEi(NULL), + m_typesForClient(nullptr), + m_typesForIStream(nullptr), + m_typesForIDataSocket(nullptr), + m_typesForIListenSocket(nullptr), + m_typesForISocket(nullptr), + m_typesForOSXScreen(nullptr), + m_typesForClientListener(nullptr), + m_typesForClientProxy(nullptr), + m_typesForClientProxyUnknown(nullptr), + m_typesForServer(nullptr), + m_typesForServerApp(nullptr), + m_typesForIKeyState(nullptr), + m_typesForIPrimaryScreen(nullptr), + m_typesForIScreen(nullptr), + m_typesForClipboard(nullptr), + m_typesForFile(nullptr), + m_typesForEi(nullptr), m_readyMutex(new Mutex), m_readyCondVar(new CondVar(m_readyMutex, false)) { @@ -80,8 +80,8 @@ EventQueue::~EventQueue() delete m_readyCondVar; delete m_readyMutex; - ARCH->setSignalHandler(Arch::kINTERRUPT, NULL, NULL); - ARCH->setSignalHandler(Arch::kTERMINATE, NULL, NULL); + ARCH->setSignalHandler(Arch::kINTERRUPT, nullptr, nullptr); + ARCH->setSignalHandler(Arch::kTERMINATE, nullptr, nullptr); ARCH->closeMutex(m_mutex); } @@ -169,7 +169,7 @@ void EventQueue::adoptBuffer(IEventQueueBuffer *buffer) // use new buffer m_buffer = buffer; - if (m_buffer == NULL) { + if (m_buffer == nullptr) { m_buffer = new SimpleEventQueueBuffer; } } @@ -235,10 +235,10 @@ bool EventQueue::dispatchEvent(const Event &event) { void *target = event.getTarget(); IEventJob *job = getHandler(event.getType(), target); - if (job == NULL) { + if (job == nullptr) { job = getHandler(Event::kUnknown, target); } - if (job != NULL) { + if (job != nullptr) { job->run(event); return true; } @@ -288,7 +288,7 @@ EventQueueTimer *EventQueue::newTimer(double duration, void *target) assert(duration > 0.0); EventQueueTimer *timer = m_buffer->newTimer(duration, false); - if (target == NULL) { + if (target == nullptr) { target = timer; } ArchMutexLock lock(m_mutex); @@ -305,7 +305,7 @@ EventQueueTimer *EventQueue::newOneShotTimer(double duration, void *target) assert(duration > 0.0); EventQueueTimer *timer = m_buffer->newTimer(duration, true); - if (target == NULL) { + if (target == nullptr) { target = timer; } ArchMutexLock lock(m_mutex); @@ -343,7 +343,7 @@ void EventQueue::adoptHandler(Event::Type type, void *target, IEventJob *handler void EventQueue::removeHandler(Event::Type type, void *target) { - IEventJob *handler = NULL; + IEventJob *handler = nullptr; { ArchMutexLock lock(m_mutex); HandlerTable::iterator index = m_handlers.find(target); @@ -397,7 +397,7 @@ IEventJob *EventQueue::getHandler(Event::Type type, void *target) const return index2->second; } } - return NULL; + return nullptr; } uint32_t EventQueue::saveEvent(const Event &event) diff --git a/src/lib/base/EventQueue.h b/src/lib/base/EventQueue.h index 251d02a5b..b64402fed 100644 --- a/src/lib/base/EventQueue.h +++ b/src/lib/base/EventQueue.h @@ -171,7 +171,7 @@ private: type_##Events& \ EventQueue::for##type_() \ { \ - if (m_typesFor##type_ == NULL) { \ + if (m_typesFor##type_ == nullptr) { \ m_typesFor##type_ = new type_##Events(); \ m_typesFor##type_->setEvents(dynamic_cast(this)); \ } \ diff --git a/src/lib/base/EventTypes.cpp b/src/lib/base/EventTypes.cpp index 28483ae77..8e8cdb5b5 100644 --- a/src/lib/base/EventTypes.cpp +++ b/src/lib/base/EventTypes.cpp @@ -9,13 +9,13 @@ #include -EventTypes::EventTypes() : m_events(NULL) +EventTypes::EventTypes() : m_events(nullptr) { } IEventQueue *EventTypes::getEvents() const { - assert(m_events != NULL); + assert(m_events != nullptr); return m_events; } diff --git a/src/lib/base/FunctionEventJob.cpp b/src/lib/base/FunctionEventJob.cpp index f0d89c708..d4fd7018f 100644 --- a/src/lib/base/FunctionEventJob.cpp +++ b/src/lib/base/FunctionEventJob.cpp @@ -23,7 +23,7 @@ FunctionEventJob::~FunctionEventJob() void FunctionEventJob::run(const Event &event) { - if (m_func != NULL) { + if (m_func != nullptr) { m_func(event, m_arg); } } diff --git a/src/lib/base/FunctionEventJob.h b/src/lib/base/FunctionEventJob.h index 23b241c48..bf3304bec 100644 --- a/src/lib/base/FunctionEventJob.h +++ b/src/lib/base/FunctionEventJob.h @@ -17,7 +17,7 @@ class FunctionEventJob : public IEventJob { public: //! run() invokes \c func(arg) - FunctionEventJob(void (*func)(const Event &, void *), void *arg = NULL); + FunctionEventJob(void (*func)(const Event &, void *), void *arg = nullptr); ~FunctionEventJob() override; // IEventJob overrides diff --git a/src/lib/base/FunctionJob.cpp b/src/lib/base/FunctionJob.cpp index 0032a52b6..d356604a3 100644 --- a/src/lib/base/FunctionJob.cpp +++ b/src/lib/base/FunctionJob.cpp @@ -23,7 +23,7 @@ FunctionJob::~FunctionJob() void FunctionJob::run() { - if (m_func != NULL) { + if (m_func != nullptr) { m_func(m_arg); } } diff --git a/src/lib/base/FunctionJob.h b/src/lib/base/FunctionJob.h index 2f1ab19a4..99432f132 100644 --- a/src/lib/base/FunctionJob.h +++ b/src/lib/base/FunctionJob.h @@ -17,7 +17,7 @@ class FunctionJob : public IJob { public: //! run() invokes \c func(arg) - FunctionJob(void (*func)(void *), void *arg = NULL); + FunctionJob(void (*func)(void *), void *arg = nullptr); ~FunctionJob() override; // IJob overrides diff --git a/src/lib/base/IEventQueue.h b/src/lib/base/IEventQueue.h index 9882a3565..3a3a2d149 100644 --- a/src/lib/base/IEventQueue.h +++ b/src/lib/base/IEventQueue.h @@ -98,7 +98,7 @@ public: is returned the data points to a \c TimerEvent. The client must pass the returned timer to \c deleteTimer() (whether or not the timer has expired) to release the timer. The returned timer event uses the - given \p target. If \p target is NULL it uses the returned timer as + given \p target. If \p target is nullptr it uses the returned timer as the target. Events for a single timer don't accumulate in the queue, even if the @@ -117,7 +117,7 @@ public: The c_count member of the \c TimerEvent is always 1. The client must pass the returned timer to \c deleteTimer() (whether or not the timer has expired) to release the timer. The returned timer event - uses the given \p target. If \p target is NULL it uses the returned + uses the given \p target. If \p target is nullptr it uses the returned timer as the target. */ virtual EventQueueTimer *newOneShotTimer(double duration, void *target) = 0; @@ -181,7 +181,7 @@ public: //! Get an event handler /*! Finds and returns the event handler for the \p type, \p target pair - if it exists, otherwise it returns NULL. + if it exists, otherwise it returns nullptr. */ virtual IEventJob *getHandler(Event::Type type, void *target) const = 0; diff --git a/src/lib/base/IEventQueueBuffer.h b/src/lib/base/IEventQueueBuffer.h index e822bda78..2df1bf78a 100644 --- a/src/lib/base/IEventQueueBuffer.h +++ b/src/lib/base/IEventQueueBuffer.h @@ -77,7 +77,7 @@ public: /*! Create and return a timer object. The object is opaque and is used only by the buffer but it must be a valid object (i.e. - not NULL). + not nullptr). */ virtual EventQueueTimer *newTimer(double duration, bool oneShot) const = 0; diff --git a/src/lib/base/Log.cpp b/src/lib/base/Log.cpp index 3a5339c28..a7962f88e 100644 --- a/src/lib/base/Log.cpp +++ b/src/lib/base/Log.cpp @@ -115,12 +115,12 @@ std::vector makeMessage(const char *filename, int lineNumber, const char * // Log // -Log *Log::s_log = NULL; +Log *Log::s_log = nullptr; Log::Log(bool singleton) { if (singleton) { - assert(s_log == NULL); + assert(s_log == nullptr); } // create mutex for multithread safe operation @@ -154,7 +154,7 @@ Log::~Log() Log *Log::getInstance() { - assert(s_log != NULL); + assert(s_log != nullptr); return s_log; } @@ -210,7 +210,7 @@ void Log::print(const char *file, int line, const char *fmt, ...) void Log::insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead) { - assert(adoptedOutputter != NULL); + assert(adoptedOutputter != nullptr); ArchMutexLock lock(m_mutex); if (alwaysAtHead) { @@ -241,7 +241,7 @@ void Log::pop_front(bool alwaysAtHead) bool Log::setFilter(const char *maxPriority) { - if (maxPriority != NULL) { + if (maxPriority != nullptr) { for (int i = 0; i < g_numPriority; ++i) { if (strcmp(maxPriority, g_priority[i]) == 0) { setFilter(i); @@ -268,7 +268,7 @@ int Log::getFilter() const void Log::output(ELevel priority, char *msg) { assert(priority >= -1 && priority < g_numPriority); - assert(msg != NULL); + assert(msg != nullptr); if (!msg) return; diff --git a/src/lib/base/Log.h b/src/lib/base/Log.h index 3c1dadbd4..412409927 100644 --- a/src/lib/base/Log.h +++ b/src/lib/base/Log.h @@ -79,7 +79,7 @@ public: Set the filter. Messages below this priority are discarded. The default priority is 4 (INFO) (unless built without NDEBUG in which case it's 5 (DEBUG)). setFilter(const char*) returns - true if the priority \c name was recognized; if \c name is NULL + true if the priority \c name was recognized; if \c name is nullptr then it simply returns true. */ bool setFilter(const char *name); @@ -94,7 +94,7 @@ public: //! Print a log message /*! Print a log message using the printf-like \c format and arguments - preceded by the filename and line number. If \c file is NULL then + preceded by the filename and line number. If \c file is nullptr then neither the file nor the line are printed. */ void print(const char *file, int line, const char *format, ...); @@ -182,7 +182,7 @@ otherwise it expands to a call that doesn't. #define LOGC(_a1, _a2) \ if (_a1) \ CLOG->print _a2 -#define CLOG_TRACE NULL, 0, +#define CLOG_TRACE nullptr, 0, #else #define LOG(_a1) CLOG->print _a1 #define LOGC(_a1, _a2) \ diff --git a/src/lib/base/LogOutputters.cpp b/src/lib/base/LogOutputters.cpp index 3e9e29460..eb59883fa 100644 --- a/src/lib/base/LogOutputters.cpp +++ b/src/lib/base/LogOutputters.cpp @@ -128,7 +128,7 @@ bool SystemLogOutputter::write(ELevel level, const char *msg) // SystemLogger // -SystemLogger::SystemLogger(const char *title, bool blockConsole) : m_stop(NULL) +SystemLogger::SystemLogger(const char *title, bool blockConsole) : m_stop(nullptr) { // redirect log messages if (blockConsole) { @@ -144,7 +144,7 @@ SystemLogger::~SystemLogger() { CLOG->remove(m_syslog); delete m_syslog; - if (m_stop != NULL) { + if (m_stop != nullptr) { CLOG->remove(m_stop); delete m_stop; } @@ -165,7 +165,7 @@ FileLogOutputter::~FileLogOutputter() void FileLogOutputter::setLogFilename(const char *logFile) { - assert(logFile != NULL); + assert(logFile != nullptr); m_fileName = logFile; } diff --git a/src/lib/base/Path.cpp b/src/lib/base/Path.cpp index 36809e87a..546c7ab8a 100644 --- a/src/lib/base/Path.cpp +++ b/src/lib/base/Path.cpp @@ -20,7 +20,7 @@ std::wstring path(const std::string &filePath) { std::wstring result; - auto length = MultiByteToWideChar(CP_UTF8, 0, filePath.c_str(), static_cast(filePath.length()), NULL, 0); + auto length = MultiByteToWideChar(CP_UTF8, 0, filePath.c_str(), static_cast(filePath.length()), nullptr, 0); if (length > 0) { result.resize(length); MultiByteToWideChar(CP_UTF8, 0, filePath.c_str(), static_cast(filePath.length()), &result[0], length); diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index 1ac7468e6..10d179488 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -109,7 +109,7 @@ std::string sprintf(const char *fmt, ...) char *buffer = tmp; int len = (int)(sizeof(tmp) / sizeof(tmp[0])); std::string result; - while (buffer != NULL) { + while (buffer != nullptr) { // try printing into the buffer va_list args; va_start(args, fmt); @@ -131,7 +131,7 @@ std::string sprintf(const char *fmt, ...) if (buffer != tmp) { delete[] buffer; } - buffer = NULL; + buffer = nullptr; } } diff --git a/src/lib/base/TMethodEventJob.h b/src/lib/base/TMethodEventJob.h index 6295e5859..bebcadd3a 100644 --- a/src/lib/base/TMethodEventJob.h +++ b/src/lib/base/TMethodEventJob.h @@ -17,7 +17,7 @@ template class TMethodEventJob : public IEventJob { public: //! run(event) invokes \c object->method(event, arg) - TMethodEventJob(T *object, void (T::*method)(const Event &, void *), void *arg = NULL); + TMethodEventJob(T *object, void (T::*method)(const Event &, void *), void *arg = nullptr); ~TMethodEventJob() override; // IJob overrides @@ -45,7 +45,7 @@ template inline TMethodEventJob::~TMethodEventJob() template inline void TMethodEventJob::run(const Event &event) { - if (m_object != NULL) { + if (m_object != nullptr) { (m_object->*m_method)(event, m_arg); } } diff --git a/src/lib/base/TMethodJob.h b/src/lib/base/TMethodJob.h index 2adff585c..9d82cb2f5 100644 --- a/src/lib/base/TMethodJob.h +++ b/src/lib/base/TMethodJob.h @@ -17,7 +17,7 @@ template class TMethodJob : public IJob { public: //! run() invokes \c object->method(arg) - TMethodJob(T *object, void (T::*method)(void *), void *arg = NULL); + TMethodJob(T *object, void (T::*method)(void *), void *arg = nullptr); ~TMethodJob() override; // IJob overrides @@ -45,7 +45,7 @@ template inline TMethodJob::~TMethodJob() template inline void TMethodJob::run() { - if (m_object != NULL) { + if (m_object != nullptr) { (m_object->*m_method)(m_arg); } } diff --git a/src/lib/base/Unicode.cpp b/src/lib/base/Unicode.cpp index c7115f2f7..1bdc1e242 100644 --- a/src/lib/base/Unicode.cpp +++ b/src/lib/base/Unicode.cpp @@ -52,14 +52,14 @@ inline static uint32_t decode32(const uint8_t *n, bool byteSwapped) inline static void resetError(bool *errors) { - if (errors != NULL) { + if (errors != nullptr) { *errors = false; } } inline static void setError(bool *errors) { - if (errors != NULL) { + if (errors != nullptr) { *errors = true; } } @@ -204,7 +204,7 @@ std::string Unicode::UTF8ToText(const std::string &src, bool *errors) wchar_t *tmp = UTF8ToWideChar(src, size, errors); // convert string to multibyte - int len = ARCH->convStringWCToMB(NULL, tmp, size, errors); + int len = ARCH->convStringWCToMB(nullptr, tmp, size, errors); char *mbs = new char[len + 1]; ARCH->convStringWCToMB(mbs, tmp, size, errors); std::string text(mbs, len); @@ -263,7 +263,7 @@ std::string Unicode::textToUTF8(const std::string &src, bool *errors, IArchStrin // convert string to wide characters uint32_t n = (uint32_t)src.size(); - int len = ARCH->convStringMBToWC(NULL, src.c_str(), n, errors); + int len = ARCH->convStringMBToWC(nullptr, src.c_str(), n, errors); wchar_t *wcs = new wchar_t[len + 1]; ARCH->convStringMBToWC(wcs, src.c_str(), n, errors); @@ -445,7 +445,7 @@ std::string Unicode::doUTF16ToUTF8(const uint8_t *data, uint32_t n, bool *errors } else if (n == 1) { // error -- missing second word setError(errors); - toUTF8(dst, s_replacement, NULL); + toUTF8(dst, s_replacement, nullptr); } else if (c >= 0x0000d800 && c <= 0x0000dbff) { data += 2; --n; @@ -453,7 +453,7 @@ std::string Unicode::doUTF16ToUTF8(const uint8_t *data, uint32_t n, bool *errors if (c2 < 0x0000dc00 || c2 > 0x0000dfff) { // error -- [d800,dbff] not followed by [dc00,dfff] setError(errors); - toUTF8(dst, s_replacement, NULL); + toUTF8(dst, s_replacement, nullptr); } else { c = (((c - 0x0000d800) << 10) | (c2 - 0x0000dc00)) + 0x00010000; toUTF8(dst, c, errors); @@ -461,7 +461,7 @@ std::string Unicode::doUTF16ToUTF8(const uint8_t *data, uint32_t n, bool *errors } else { // error -- [dc00,dfff] without leading [d800,dbff] setError(errors); - toUTF8(dst, s_replacement, NULL); + toUTF8(dst, s_replacement, nullptr); } data += 2; --n; @@ -512,7 +512,7 @@ std::string Unicode::doUTF32ToUTF8(const uint8_t *data, uint32_t n, bool *errors uint32_t Unicode::fromUTF8(const uint8_t *&data, uint32_t &n) { - assert(data != NULL); + assert(data != nullptr); assert(n != 0); // compute character encoding length, checking for overlong diff --git a/src/lib/base/Unicode.h b/src/lib/base/Unicode.h index 0b518014b..66144f8f0 100644 --- a/src/lib/base/Unicode.h +++ b/src/lib/base/Unicode.h @@ -31,76 +31,76 @@ public: //! Convert from UTF-8 to UCS-2 encoding /*! - Convert from UTF-8 to UCS-2. If errors is not NULL then *errors + Convert from UTF-8 to UCS-2. If errors is not nullptr then *errors is set to true iff any character could not be encoded in UCS-2. Decoding errors do not set *errors. */ - static std::string UTF8ToUCS2(const std::string &, bool *errors = NULL); + static std::string UTF8ToUCS2(const std::string &, bool *errors = nullptr); //! Convert from UTF-8 to UCS-4 encoding /*! - Convert from UTF-8 to UCS-4. If errors is not NULL then *errors + Convert from UTF-8 to UCS-4. If errors is not nullptr then *errors is set to true iff any character could not be encoded in UCS-4. Decoding errors do not set *errors. */ - static std::string UTF8ToUCS4(const std::string &, bool *errors = NULL); + static std::string UTF8ToUCS4(const std::string &, bool *errors = nullptr); //! Convert from UTF-8 to UTF-16 encoding /*! - Convert from UTF-8 to UTF-16. If errors is not NULL then *errors + Convert from UTF-8 to UTF-16. If errors is not nullptr then *errors is set to true iff any character could not be encoded in UTF-16. Decoding errors do not set *errors. */ - static std::string UTF8ToUTF16(const std::string &, bool *errors = NULL); + static std::string UTF8ToUTF16(const std::string &, bool *errors = nullptr); //! Convert from UTF-8 to UTF-32 encoding /*! - Convert from UTF-8 to UTF-32. If errors is not NULL then *errors + Convert from UTF-8 to UTF-32. If errors is not nullptr then *errors is set to true iff any character could not be encoded in UTF-32. Decoding errors do not set *errors. */ - static std::string UTF8ToUTF32(const std::string &, bool *errors = NULL); + static std::string UTF8ToUTF32(const std::string &, bool *errors = nullptr); //! Convert from UTF-8 to the current locale encoding /*! Convert from UTF-8 to the current locale encoding. If errors is not - NULL then *errors is set to true iff any character could not be encoded. + nullptr then *errors is set to true iff any character could not be encoded. Decoding errors do not set *errors. */ - static std::string UTF8ToText(const std::string &, bool *errors = NULL); + static std::string UTF8ToText(const std::string &, bool *errors = nullptr); //! Convert from UCS-2 to UTF-8 /*! - Convert from UCS-2 to UTF-8. If errors is not NULL then *errors is + Convert from UCS-2 to UTF-8. If errors is not nullptr then *errors is set to true iff any character could not be decoded. */ - static std::string UCS2ToUTF8(const std::string &, bool *errors = NULL); + static std::string UCS2ToUTF8(const std::string &, bool *errors = nullptr); //! Convert from UCS-4 to UTF-8 /*! - Convert from UCS-4 to UTF-8. If errors is not NULL then *errors is + Convert from UCS-4 to UTF-8. If errors is not nullptr then *errors is set to true iff any character could not be decoded. */ - static std::string UCS4ToUTF8(const std::string &, bool *errors = NULL); + static std::string UCS4ToUTF8(const std::string &, bool *errors = nullptr); //! Convert from UTF-16 to UTF-8 /*! - Convert from UTF-16 to UTF-8. If errors is not NULL then *errors is + Convert from UTF-16 to UTF-8. If errors is not nullptr then *errors is set to true iff any character could not be decoded. */ - static std::string UTF16ToUTF8(const std::string &, bool *errors = NULL); + static std::string UTF16ToUTF8(const std::string &, bool *errors = nullptr); //! Convert from UTF-32 to UTF-8 /*! - Convert from UTF-32 to UTF-8. If errors is not NULL then *errors is + Convert from UTF-32 to UTF-8. If errors is not nullptr then *errors is set to true iff any character could not be decoded. */ - static std::string UTF32ToUTF8(const std::string &, bool *errors = NULL); + static std::string UTF32ToUTF8(const std::string &, bool *errors = nullptr); //! Convert from the current locale encoding to UTF-8 /*! Convert from the current locale encoding to UTF-8. If errors is not - NULL then *errors is set to true iff any character could not be decoded. + nullptr then *errors is set to true iff any character could not be decoded. */ static std::string textToUTF8( const std::string &, bool *errors = nullptr, diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 00b474cb5..2ac5c5d63 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -55,9 +55,9 @@ Client::Client( m_serverAddress(address), m_socketFactory(socketFactory), m_screen(screen), - m_stream(NULL), - m_timer(NULL), - m_server(NULL), + m_stream(nullptr), + m_timer(nullptr), + m_server(nullptr), m_ready(false), m_active(false), m_suspended(false), @@ -70,8 +70,8 @@ Client::Client( m_enableClipboard(true), m_maximumClipboardSize(INT_MAX) { - assert(m_socketFactory != NULL); - assert(m_screen != NULL); + assert(m_socketFactory != nullptr); + assert(m_screen != nullptr); // register suspend/resume event handlers m_events->adoptHandler( @@ -123,7 +123,7 @@ Client::~Client() void Client::connect(size_t addressIndex) { - if (m_stream != NULL) { + if (m_stream != nullptr) { return; } if (m_suspended) { @@ -179,7 +179,7 @@ void Client::disconnect(const char *msg) if (msg) { sendConnectionFailedEvent(msg); } else { - sendEvent(m_events->forClient().disconnected(), NULL); + sendEvent(m_events->forClient().disconnected(), nullptr); } } @@ -199,17 +199,17 @@ void Client::handshakeComplete() { m_ready = true; m_screen->enable(); - sendEvent(m_events->forClient().connected(), NULL); + sendEvent(m_events->forClient().connected(), nullptr); } bool Client::isConnected() const { - return (m_server != NULL); + return (m_server != nullptr); } bool Client::isConnecting() const { - return (m_timer != NULL); + return (m_timer != nullptr); } NetworkAddress Client::getServerAddress() const @@ -373,8 +373,8 @@ std::string Client::getName() const void Client::sendClipboard(ClipboardID id) { // note -- m_mutex must be locked on entry - assert(m_screen != NULL); - assert(m_server != NULL); + assert(m_screen != nullptr); + assert(m_server != nullptr); // get clipboard data. set the clipboard time to the last // clipboard time before getting the data from the screen @@ -427,7 +427,7 @@ void Client::sendFileChunk(const void *data) { FileChunk *chunk = static_cast(const_cast(data)); LOG((CLOG_DEBUG1 "send file chunk")); - assert(m_server != NULL); + assert(m_server != nullptr); // relay m_server->fileChunkSending(chunk->m_chunk[0], &chunk->m_chunk[1], chunk->m_dataSize); @@ -435,7 +435,7 @@ void Client::sendFileChunk(const void *data) void Client::setupConnecting() { - assert(m_stream != NULL); + assert(m_stream != nullptr); if (m_args.m_enableCrypto) { m_events->adoptHandler( @@ -457,7 +457,7 @@ void Client::setupConnecting() void Client::setupConnection() { - assert(m_stream != NULL); + assert(m_stream != nullptr); m_events->adoptHandler( m_events->forISocket().disconnected(), m_stream->getEventTarget(), @@ -488,7 +488,7 @@ void Client::setupConnection() void Client::setupScreen() { - assert(m_server == NULL); + assert(m_server == nullptr); m_ready = false; m_server = new ServerProxy(this, m_stream, m_events); @@ -504,8 +504,8 @@ void Client::setupScreen() void Client::setupTimer() { - assert(m_timer == NULL); - m_timer = m_events->newOneShotTimer(2.0, NULL); + assert(m_timer == nullptr); + m_timer = m_events->newOneShotTimer(2.0, nullptr); m_events->adoptHandler(Event::kTimer, m_timer, new TMethodEventJob(this, &Client::handleConnectTimeout)); } @@ -520,7 +520,7 @@ void Client::cleanup() void Client::cleanupConnecting() { - if (m_stream != NULL) { + if (m_stream != nullptr) { m_events->removeHandler(m_events->forIDataSocket().connected(), m_stream->getEventTarget()); m_events->removeHandler(m_events->forIDataSocket().connectionFailed(), m_stream->getEventTarget()); } @@ -528,7 +528,7 @@ void Client::cleanupConnecting() void Client::cleanupConnection() { - if (m_stream != NULL) { + if (m_stream != nullptr) { m_events->removeHandler(m_events->forIStream().inputReady(), m_stream->getEventTarget()); m_events->removeHandler(m_events->forIStream().outputError(), m_stream->getEventTarget()); m_events->removeHandler(m_events->forIStream().inputShutdown(), m_stream->getEventTarget()); @@ -541,7 +541,7 @@ void Client::cleanupConnection() void Client::cleanupScreen() { - if (m_server != NULL) { + if (m_server != nullptr) { if (m_ready) { m_screen->disable(); m_ready = false; @@ -549,23 +549,23 @@ void Client::cleanupScreen() m_events->removeHandler(m_events->forIScreen().shapeChanged(), getEventTarget()); m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(), getEventTarget()); delete m_server; - m_server = NULL; + m_server = nullptr; } } void Client::cleanupTimer() { - if (m_timer != NULL) { + if (m_timer != nullptr) { m_events->removeHandler(Event::kTimer, m_timer); m_events->deleteTimer(m_timer); - m_timer = NULL; + m_timer = nullptr; } } void Client::cleanupStream() { delete m_stream; - m_stream = NULL; + m_stream = nullptr; } void Client::handleConnected(const Event &, void *) @@ -610,7 +610,7 @@ void Client::handleOutputError(const Event &, void *) cleanupScreen(); cleanupConnection(); LOG((CLOG_WARN "error sending to server")); - sendEvent(m_events->forClient().disconnected(), NULL); + sendEvent(m_events->forClient().disconnected(), nullptr); } void Client::handleDisconnected(const Event &, void *) @@ -619,7 +619,7 @@ void Client::handleDisconnected(const Event &, void *) cleanupScreen(); cleanupConnection(); LOG((CLOG_DEBUG1 "disconnected")); - sendEvent(m_events->forClient().disconnected(), NULL); + sendEvent(m_events->forClient().disconnected(), nullptr); } void Client::handleShapeChanged(const Event &, void *) @@ -673,7 +673,7 @@ void Client::handleSuspend(const Event &, void *) LOG((CLOG_INFO "suspend")); m_suspended = true; bool wasConnected = isConnected(); - disconnect(NULL); + disconnect(nullptr); m_connectOnResume = wasConnected; } } diff --git a/src/lib/client/ServerProxy.cpp b/src/lib/client/ServerProxy.cpp index d23edd8ba..9705a701d 100644 --- a/src/lib/client/ServerProxy.cpp +++ b/src/lib/client/ServerProxy.cpp @@ -43,12 +43,12 @@ ServerProxy::ServerProxy(Client *client, deskflow::IStream *stream, IEventQueue m_dyMouse(0), m_ignoreMouse(false), m_keepAliveAlarm(0.0), - m_keepAliveAlarmTimer(NULL), + m_keepAliveAlarmTimer(nullptr), m_parser(&ServerProxy::parseHandshakeMessage), m_events(events) { - assert(m_client != NULL); - assert(m_stream != NULL); + assert(m_client != nullptr); + assert(m_stream != nullptr); // initialize modifier translation table for (KeyModifierID id = 0; id < kKeyModifierIDLast; ++id) @@ -77,13 +77,13 @@ ServerProxy::~ServerProxy() void ServerProxy::resetKeepAliveAlarm() { - if (m_keepAliveAlarmTimer != NULL) { + if (m_keepAliveAlarmTimer != nullptr) { m_events->removeHandler(Event::kTimer, m_keepAliveAlarmTimer); m_events->deleteTimer(m_keepAliveAlarmTimer); - m_keepAliveAlarmTimer = NULL; + m_keepAliveAlarmTimer = nullptr; } if (m_keepAliveAlarm > 0.0) { - m_keepAliveAlarmTimer = m_events->newOneShotTimer(m_keepAliveAlarm, NULL); + m_keepAliveAlarmTimer = m_events->newOneShotTimer(m_keepAliveAlarm, nullptr); m_events->adoptHandler( Event::kTimer, m_keepAliveAlarmTimer, new TMethodEventJob(this, &ServerProxy::handleKeepAliveAlarm) ); @@ -177,7 +177,7 @@ ServerProxy::EResult ServerProxy::parseHandshakeMessage(const uint8_t *code) else if (memcmp(code, kMsgCClose, 4) == 0) { // server wants us to hangup LOG((CLOG_DEBUG1 "recv close")); - m_client->disconnect(NULL); + m_client->disconnect(nullptr); return kDisconnect; } @@ -324,7 +324,7 @@ ServerProxy::EResult ServerProxy::parseMessage(const uint8_t *code) else if (memcmp(code, kMsgCClose, 4) == 0) { // server wants us to hangup LOG((CLOG_DEBUG1 "recv close")); - m_client->disconnect(NULL); + m_client->disconnect(nullptr); return kDisconnect; } else if (memcmp(code, kMsgEBad, 4) == 0) { LOG((CLOG_ERR "server disconnected due to a protocol error")); diff --git a/src/lib/client/ServerProxy.h b/src/lib/client/ServerProxy.h index 2e50a1623..37de1e519 100644 --- a/src/lib/client/ServerProxy.h +++ b/src/lib/client/ServerProxy.h @@ -60,7 +60,7 @@ public: #ifdef TEST_ENV void handleDataForTest() { - handleData(Event(), NULL); + handleData(Event(), nullptr); } #endif diff --git a/src/lib/common/Common.h b/src/lib/common/Common.h index cf937eec0..ddc622a99 100644 --- a/src/lib/common/Common.h +++ b/src/lib/common/Common.h @@ -16,7 +16,7 @@ #error "config.h missing" #endif -// define NULL +// define nullptr #include // make assert available since we use it a lot diff --git a/src/lib/deskflow/App.cpp b/src/lib/deskflow/App.cpp index 09d256b13..4b75c1d0d 100644 --- a/src/lib/deskflow/App.cpp +++ b/src/lib/deskflow/App.cpp @@ -131,7 +131,7 @@ int App::daemonMainLoop(int, const char **) void App::setupFileLogging() { - if (argsBase().m_logFile != NULL) { + if (argsBase().m_logFile != nullptr) { m_fileLog = new FileLogOutputter(argsBase().m_logFile); // NOSONAR - Adopted by `Log` CLOG->insert(m_fileLog); LOG((CLOG_DEBUG1 "logging to file (%s) enabled", argsBase().m_logFile)); @@ -141,7 +141,7 @@ void App::setupFileLogging() void App::loggingFilterWarning() { if (CLOG->getFilter() > CLOG->getConsoleMaxLevel()) { - if (argsBase().m_logFile == NULL) { + if (argsBase().m_logFile == nullptr) { LOG( (CLOG_WARN "log messages above %s are NOT sent to console (use file logging)", CLOG->getFilterName(CLOG->getConsoleMaxLevel())) @@ -206,7 +206,7 @@ void App::runEventsLoop(void *) // MinimalApp // -MinimalApp::MinimalApp() : App(NULL, new deskflow::ArgsBase()) +MinimalApp::MinimalApp() : App(nullptr, new deskflow::ArgsBase()) { m_arch.init(); setEvents(m_events); @@ -242,7 +242,7 @@ int MinimalApp::foregroundStartup(int argc, char **argv) deskflow::Screen *MinimalApp::createScreen() { - return NULL; + return nullptr; } void MinimalApp::loadConfig() diff --git a/src/lib/deskflow/ClientApp.cpp b/src/lib/deskflow/ClientApp.cpp index 23f4f6193..3a3cf6766 100644 --- a/src/lib/deskflow/ClientApp.cpp +++ b/src/lib/deskflow/ClientApp.cpp @@ -62,9 +62,9 @@ ClientApp::ClientApp(IEventQueue *events) : App(events, new deskflow::ClientArgs()), - m_client(NULL), - m_clientScreen(NULL), - m_serverAddress(NULL) + m_client(nullptr), + m_clientScreen(nullptr), + m_serverAddress(nullptr) { } @@ -258,7 +258,7 @@ deskflow::Screen *ClientApp::openClientScreen() void ClientApp::closeClientScreen(deskflow::Screen *screen) { - if (screen != NULL) { + if (screen != nullptr) { m_events->removeHandler(m_events->forIScreen().error(), screen->getEventTarget()); delete screen; } @@ -279,7 +279,7 @@ void ClientApp::scheduleClientRestart(double retryTime) { // install a timer and handler to retry later LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); - EventQueueTimer *timer = m_events->newOneShotTimer(retryTime, NULL); + EventQueueTimer *timer = m_events->newOneShotTimer(retryTime, nullptr); m_events->adoptHandler( Event::kTimer, timer, new TMethodEventJob(this, &ClientApp::handleClientRestart, timer) ); @@ -370,7 +370,7 @@ Client *ClientApp::openClient(const std::string &name, const NetworkAddress &add void ClientApp::closeClient(Client *client) { - if (client == NULL) { + if (client == nullptr) { return; } @@ -392,9 +392,9 @@ int ClientApp::foregroundStartup(int argc, char **argv) bool ClientApp::startClient() { double retryTime; - deskflow::Screen *clientScreen = NULL; + deskflow::Screen *clientScreen = nullptr; try { - if (m_clientScreen == NULL) { + if (m_clientScreen == nullptr) { clientScreen = openClientScreen(); m_client = openClient(args().m_name, *m_serverAddress, clientScreen); m_clientScreen = clientScreen; @@ -433,8 +433,8 @@ void ClientApp::stopClient() { closeClient(m_client); closeClientScreen(m_clientScreen); - m_client = NULL; - m_clientScreen = NULL; + m_client = nullptr; + m_clientScreen = nullptr; } int ClientApp::mainLoop() @@ -454,7 +454,7 @@ int ClientApp::mainLoop() #if WINAPI_CARBON - Thread thread(new TMethodJob(this, &ClientApp::runEventsLoop, NULL)); + Thread thread(new TMethodJob(this, &ClientApp::runEventsLoop, nullptr)); // wait until carbon loop is ready OSXScreen *screen = dynamic_cast(m_clientScreen->getPlatformScreen()); diff --git a/src/lib/deskflow/IClipboard.cpp b/src/lib/deskflow/IClipboard.cpp index d2d5a7a43..5f000df94 100644 --- a/src/lib/deskflow/IClipboard.cpp +++ b/src/lib/deskflow/IClipboard.cpp @@ -15,7 +15,7 @@ void IClipboard::unmarshall(IClipboard *clipboard, const std::string &data, Time time) { - assert(clipboard != NULL); + assert(clipboard != nullptr); const char *index = data.data(); @@ -60,7 +60,7 @@ std::string IClipboard::marshall(const IClipboard *clipboard) // n bytes => clipboard data // back to the second 4 bytes if there is another format - assert(clipboard != NULL); + assert(clipboard != nullptr); std::string data; @@ -100,16 +100,16 @@ std::string IClipboard::marshall(const IClipboard *clipboard) bool IClipboard::copy(IClipboard *dst, const IClipboard *src) { - assert(dst != NULL); - assert(src != NULL); + assert(dst != nullptr); + assert(src != nullptr); return copy(dst, src, src->getTime()); } bool IClipboard::copy(IClipboard *dst, const IClipboard *src, Time time) { - assert(dst != NULL); - assert(src != NULL); + assert(dst != nullptr); + assert(src != nullptr); bool success = false; if (src->open(time)) { diff --git a/src/lib/deskflow/IKeyState.cpp b/src/lib/deskflow/IKeyState.cpp index d4ab532bb..9b47d8ca6 100644 --- a/src/lib/deskflow/IKeyState.cpp +++ b/src/lib/deskflow/IKeyState.cpp @@ -30,7 +30,7 @@ IKeyState::KeyInfo *IKeyState::KeyInfo::alloc(KeyID id, KeyModifierMask mask, Ke info->m_mask = mask; info->m_button = button; info->m_count = count; - info->m_screens = NULL; + info->m_screens = nullptr; info->m_screensBuffer[0] = '\0'; return info; } @@ -61,14 +61,14 @@ IKeyState::KeyInfo *IKeyState::KeyInfo::alloc(const KeyInfo &x) info->m_mask = x.m_mask; info->m_button = x.m_button; info->m_count = x.m_count; - info->m_screens = x.m_screens ? info->m_screensBuffer : NULL; + info->m_screens = x.m_screens ? info->m_screensBuffer : nullptr; memcpy(info->m_screensBuffer, x.m_screensBuffer, bufferLen + 1); return info; } bool IKeyState::KeyInfo::isDefault(const char *screens) { - return (screens == NULL || screens[0] == '\0'); + return (screens == nullptr || screens[0] == '\0'); } bool IKeyState::KeyInfo::contains(const char *screens, const std::string &name) @@ -87,7 +87,7 @@ bool IKeyState::KeyInfo::contains(const char *screens, const std::string &name) match += ":"; match += name; match += ":"; - return (strstr(screens, match.c_str()) != NULL); + return (strstr(screens, match.c_str()) != nullptr); } bool IKeyState::KeyInfo::equal(const KeyInfo *a, const KeyInfo *b) diff --git a/src/lib/deskflow/KeyMap.cpp b/src/lib/deskflow/KeyMap.cpp index a9c7d3509..04f944a0b 100644 --- a/src/lib/deskflow/KeyMap.cpp +++ b/src/lib/deskflow/KeyMap.cpp @@ -17,10 +17,10 @@ namespace deskflow { -KeyMap::NameToKeyMap *KeyMap::s_nameToKeyMap = NULL; -KeyMap::NameToModifierMap *KeyMap::s_nameToModifierMap = NULL; -KeyMap::KeyToNameMap *KeyMap::s_keyToNameMap = NULL; -KeyMap::ModifierToNameMap *KeyMap::s_modifierToNameMap = NULL; +KeyMap::NameToKeyMap *KeyMap::s_nameToKeyMap = nullptr; +KeyMap::NameToModifierMap *KeyMap::s_nameToModifierMap = nullptr; +KeyMap::KeyToNameMap *KeyMap::s_keyToNameMap = nullptr; +KeyMap::ModifierToNameMap *KeyMap::s_modifierToNameMap = nullptr; KeyMap::KeyMap() : m_numGroups(0), m_composeAcrossGroups(false) { @@ -104,7 +104,7 @@ void KeyMap::addKeyAliasEntry( ) { // if we can already generate the target as desired then we're done. - if (findCompatibleKey(targetID, group, targetRequired, targetSensitive) != NULL) { + if (findCompatibleKey(targetID, group, targetRequired, targetSensitive) != nullptr) { return; } @@ -112,7 +112,7 @@ void KeyMap::addKeyAliasEntry( for (int32_t gd = 0, n = getNumGroups(); gd < n; ++gd) { int32_t eg = getEffectiveGroup(group, gd); const KeyItemList *sourceEntry = findCompatibleKey(sourceID, eg, sourceRequired, sourceSensitive); - if (sourceEntry != NULL && sourceEntry->size() == 1) { + if (sourceEntry != nullptr && sourceEntry->size() == 1) { KeyMap::KeyItem targetItem = sourceEntry->back(); targetItem.m_id = targetID; targetItem.m_group = eg; @@ -243,10 +243,10 @@ const KeyMap::KeyItem *KeyMap::mapKey( // handle group change if (id == kKeyNextGroup) { keys.push_back(Keystroke(1, false, false)); - return NULL; + return nullptr; } else if (id == kKeyPrevGroup) { keys.push_back(Keystroke(-1, false, false)); - return NULL; + return nullptr; } const KeyItem *item; @@ -271,7 +271,7 @@ const KeyMap::KeyItem *KeyMap::mapKey( case kKeySetModifiers: if (!keysForModifierState(0, group, activeModifiers, currentState, desiredMask, desiredMask, 0, keys)) { LOG((CLOG_DEBUG1 "unable to set modifiers %04x", desiredMask)); - return NULL; + return nullptr; } return &m_modifierKeyItem; @@ -280,7 +280,7 @@ const KeyMap::KeyItem *KeyMap::mapKey( 0, group, activeModifiers, currentState, currentState & ~desiredMask, desiredMask, 0, keys )) { LOG((CLOG_DEBUG1 "unable to clear modifiers %04x", desiredMask)); - return NULL; + return nullptr; } return &m_modifierKeyItem; @@ -293,7 +293,7 @@ const KeyMap::KeyItem *KeyMap::mapKey( break; } - if (item != NULL) { + if (item != nullptr) { LOG((CLOG_DEBUG1 "mapped to %03x, new state %04x", item->m_button, currentState)); } return item; @@ -336,7 +336,7 @@ KeyMap::findCompatibleKey(KeyID id, int32_t group, KeyModifierMask required, Key KeyIDMap::const_iterator i = m_keyIDMap.find(id); if (i == m_keyIDMap.end()) { - return NULL; + return nullptr; } const KeyEntryList &entries = i->second[group]; @@ -347,7 +347,7 @@ KeyMap::findCompatibleKey(KeyID id, int32_t group, KeyModifierMask required, Key } } - return NULL; + return nullptr; } bool KeyMap::isHalfDuplex(KeyID key, KeyButton button) const @@ -487,12 +487,12 @@ const KeyMap::KeyItem *KeyMap::mapCommandKey( if (i == m_keyIDMap.end()) { // unknown key LOG((CLOG_DEBUG1 "key %04x is not on keyboard", id)); - return NULL; + return nullptr; } const KeyGroupTable &keyGroupTable = i->second; // find the first key that generates this KeyID - const KeyItem *keyItem = NULL; + const KeyItem *keyItem = nullptr; int32_t numGroups = getNumGroups(); for (int32_t groupOffset = 0; groupOffset < numGroups; ++groupOffset) { int32_t effectiveGroup = getEffectiveGroup(group, groupOffset); @@ -518,14 +518,14 @@ const KeyMap::KeyItem *KeyMap::mapCommandKey( break; } } - if (keyItem != NULL) { + if (keyItem != nullptr) { break; } } - if (keyItem == NULL) { + if (keyItem == nullptr) { // no mapping for this keysym LOG((CLOG_DEBUG1 "no mapping for key %04x", id)); - return NULL; + return nullptr; } // make working copy of modifiers @@ -542,14 +542,14 @@ const KeyMap::KeyItem *KeyMap::mapCommandKey( )) { LOG((CLOG_DEBUG1 "can't map key")); keys.clear(); - return NULL; + return nullptr; } // add keystrokes to restore modifier keys if (!keysToRestoreModifiers(*keyItem, group, newModifiers, newState, activeModifiers, keys)) { LOG((CLOG_DEBUG1 "modifiers were not restored")); keys.clear(); - return NULL; + return nullptr; } // save new modifiers @@ -589,7 +589,7 @@ const KeyMap::KeyItem *KeyMap::mapCharacterKey( // unknown key LOG((CLOG_DEBUG1 "key %04x is not on keyboard", id)); - return NULL; + return nullptr; } // get keys to press for key @@ -597,7 +597,7 @@ const KeyMap::KeyItem *KeyMap::mapCharacterKey( if (!itemList || itemList->empty()) { // no mapping for this keysym LOG((CLOG_DEBUG1 "no mapping for key %04x", id)); - return NULL; + return nullptr; } const KeyItem &keyItem = itemList->back(); @@ -612,7 +612,7 @@ const KeyMap::KeyItem *KeyMap::mapCharacterKey( if (!keysForKeyItem(itemList->at(j), newGroup, newModifiers, newState, desiredMask, 0, isAutoRepeat, keys, lang)) { LOG((CLOG_DEBUG1 "can't map key")); keys.clear(); - return NULL; + return nullptr; } } @@ -620,7 +620,7 @@ const KeyMap::KeyItem *KeyMap::mapCharacterKey( if (!keysToRestoreModifiers(keyItem, group, newModifiers, newState, activeModifiers, keys)) { LOG((CLOG_DEBUG1 "modifiers were not restored")); keys.clear(); - return NULL; + return nullptr; } // save new modifiers @@ -691,7 +691,7 @@ const KeyMap::KeyItem *KeyMap::keyForModifier(KeyButton button, int32_t group, i return (*i); } } - return NULL; + return nullptr; } bool KeyMap::keysForKeyItem( @@ -852,7 +852,7 @@ bool KeyMap::keysForModifierState( // get the KeyItem for the modifier in the group const KeyItem *keyItem = keyForModifier(button, group, bit); - if (keyItem == NULL) { + if (keyItem == nullptr) { if ((mask & notRequiredMask) == 0) { LOG((CLOG_DEBUG1 "no key for modifier %04x", mask)); return false; @@ -1199,18 +1199,18 @@ bool KeyMap::parseModifiers(std::string &x, KeyModifierMask &mask) void KeyMap::initKeyNameMaps() { // initialize tables - if (s_nameToKeyMap == NULL) { + if (s_nameToKeyMap == nullptr) { s_nameToKeyMap = new NameToKeyMap; s_keyToNameMap = new KeyToNameMap; - for (const KeyNameMapEntry *i = kKeyNameMap; i->m_name != NULL; ++i) { + for (const KeyNameMapEntry *i = kKeyNameMap; i->m_name != nullptr; ++i) { (*s_nameToKeyMap)[i->m_name] = i->m_id; (*s_keyToNameMap)[i->m_id] = i->m_name; } } - if (s_nameToModifierMap == NULL) { + if (s_nameToModifierMap == nullptr) { s_nameToModifierMap = new NameToModifierMap; s_modifierToNameMap = new ModifierToNameMap; - for (const KeyModifierNameMapEntry *i = kModifierNameMap; i->m_name != NULL; ++i) { + for (const KeyModifierNameMapEntry *i = kModifierNameMap; i->m_name != nullptr; ++i) { (*s_nameToModifierMap)[i->m_name] = i->m_mask; (*s_modifierToNameMap)[i->m_mask] = i->m_name; } diff --git a/src/lib/deskflow/KeyMap.h b/src/lib/deskflow/KeyMap.h index 250a2a189..2232a9b21 100644 --- a/src/lib/deskflow/KeyMap.h +++ b/src/lib/deskflow/KeyMap.h @@ -211,7 +211,7 @@ public: modifiers as given in \p currentState and the desired modifiers in \p desiredMask into the keystrokes necessary to synthesize that key event in \p keys. It returns the \c KeyItem of the key being - pressed/repeated, or NULL if the key cannot be mapped. + pressed/repeated, or nullptr if the key cannot be mapped. */ virtual const KeyItem *mapKey( Keystrokes &keys, KeyID id, int32_t group, ModifierToKeys &activeModifiers, KeyModifierMask ¤tState, @@ -235,7 +235,7 @@ public: //! Find key entry compatible with modifiers /*! Returns the \c KeyItemList for the first entry for \p id in group - \p group that is compatible with the given modifiers, or NULL + \p group that is compatible with the given modifiers, or nullptr if there isn't one. A button list is compatible with a modifiers if it is either insensitive to all modifiers in \p sensitive or it requires the modifiers to be in the state indicated by \p required diff --git a/src/lib/deskflow/KeyState.cpp b/src/lib/deskflow/KeyState.cpp index c5df245d9..e7840ee49 100644 --- a/src/lib/deskflow/KeyState.cpp +++ b/src/lib/deskflow/KeyState.cpp @@ -855,7 +855,7 @@ bool KeyState::fakeKeyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyB ModifierToKeys oldActiveModifiers = m_activeModifiers; const deskflow::KeyMap::KeyItem *keyItem = m_keyMap.mapKey(keys, id, pollActiveGroup(), m_activeModifiers, getActiveModifiersRValue(), mask, true, lang); - if (keyItem == NULL) { + if (keyItem == nullptr) { return false; } KeyButton localID = (KeyButton)(keyItem->m_button & kButtonMask); @@ -996,7 +996,7 @@ bool KeyState::isIgnoredKey(KeyID key, KeyModifierMask) const KeyButton KeyState::getButton(KeyID id, int32_t group) const { const deskflow::KeyMap::KeyItemList *items = m_keyMap.findCompatibleKey(id, group, 0, 0); - if (items == NULL) { + if (items == nullptr) { return 0; } else { return items->back().m_button; diff --git a/src/lib/deskflow/KeyTypes.cpp b/src/lib/deskflow/KeyTypes.cpp index e9f069723..c1eb2ad5f 100644 --- a/src/lib/deskflow/KeyTypes.cpp +++ b/src/lib/deskflow/KeyTypes.cpp @@ -180,7 +180,7 @@ const KeyNameMapEntry kKeyNameMap[] = { {"Bar", 0x007c}, {"BraceR", 0x007d}, {"Tilde", 0x007e}, - {NULL, 0}, + {nullptr, 0}, }; const KeyModifierNameMapEntry kModifierNameMap[] = { @@ -193,5 +193,5 @@ const KeyModifierNameMapEntry kModifierNameMap[] = { // { "ScrollLock", KeyModifierScrollLock }, {"Shift", KeyModifierShift}, {"Super", KeyModifierSuper}, - {NULL, 0}, + {nullptr, 0}, }; diff --git a/src/lib/deskflow/KeyTypes.h b/src/lib/deskflow/KeyTypes.h index 6650fbf73..1e4612fc4 100644 --- a/src/lib/deskflow/KeyTypes.h +++ b/src/lib/deskflow/KeyTypes.h @@ -310,13 +310,13 @@ struct KeyModifierNameMapEntry /*! A table of key names to the corresponding KeyID. Only the keys listed above plus non-alphanumeric ASCII characters are in the table. The end -of the table is the first pair with a NULL m_name. +of the table is the first pair with a nullptr m_name. */ extern const struct KeyNameMapEntry kKeyNameMap[]; //! Modifier key name to KeyModifierMask table /*! A table of modifier key names to the corresponding KeyModifierMask. -The end of the table is the first pair with a NULL m_name. +The end of the table is the first pair with a nullptr m_name. */ extern const struct KeyModifierNameMapEntry kModifierNameMap[]; diff --git a/src/lib/deskflow/PacketStreamFilter.cpp b/src/lib/deskflow/PacketStreamFilter.cpp index 3bcd5bbda..86d549058 100644 --- a/src/lib/deskflow/PacketStreamFilter.cpp +++ b/src/lib/deskflow/PacketStreamFilter.cpp @@ -59,7 +59,7 @@ uint32_t PacketStreamFilter::read(void *buffer, uint32_t n) } // read it - if (buffer != NULL) { + if (buffer != nullptr) { memcpy(buffer, m_buffer.peek(n), n); } m_buffer.pop(n); diff --git a/src/lib/deskflow/ProtocolUtil.cpp b/src/lib/deskflow/ProtocolUtil.cpp index 56625dad1..a689c8a1f 100644 --- a/src/lib/deskflow/ProtocolUtil.cpp +++ b/src/lib/deskflow/ProtocolUtil.cpp @@ -58,7 +58,7 @@ template void writeVectorInt(const std::vector *VectorData, std: void writeString(const std::string *StringData, std::vector &Buffer) { - const uint32_t len = (StringData != NULL) ? (uint32_t)StringData->size() : 0; + const uint32_t len = (StringData != nullptr) ? (uint32_t)StringData->size() : 0; writeInt(len, sizeof(len), Buffer); if (len != 0) { std::copy(StringData->begin(), StringData->end(), std::back_inserter(Buffer)); @@ -69,8 +69,8 @@ void writeString(const std::string *StringData, std::vector &Buffer) void ProtocolUtil::writef(deskflow::IStream *stream, const char *fmt, ...) { - assert(stream != NULL); - assert(fmt != NULL); + assert(stream != nullptr); + assert(fmt != nullptr); LOG((CLOG_DEBUG2 "writef(%s)", fmt)); va_list args; @@ -106,8 +106,8 @@ bool ProtocolUtil::readf(deskflow::IStream *stream, const char *fmt, ...) void ProtocolUtil::vwritef(deskflow::IStream *stream, const char *fmt, uint32_t size, va_list args) { - assert(stream != NULL); - assert(fmt != NULL); + assert(stream != nullptr); + assert(fmt != nullptr); // done if nothing to write if (size == 0) { @@ -130,8 +130,8 @@ void ProtocolUtil::vwritef(deskflow::IStream *stream, const char *fmt, uint32_t void ProtocolUtil::vreadf(deskflow::IStream *stream, const char *fmt, va_list args) { - assert(stream != NULL); - assert(fmt != NULL); + assert(stream != nullptr); + assert(fmt != nullptr); // begin scanning while (*fmt) { @@ -415,8 +415,8 @@ uint32_t ProtocolUtil::eatLength(const char **pfmt) void ProtocolUtil::read(deskflow::IStream *stream, void *vbuffer, uint32_t count) { - assert(stream != NULL); - assert(vbuffer != NULL); + assert(stream != nullptr); + assert(vbuffer != nullptr); uint8_t *buffer = static_cast(vbuffer); while (count > 0) { diff --git a/src/lib/deskflow/Screen.cpp b/src/lib/deskflow/Screen.cpp index a9c92acc9..ea73ef58e 100644 --- a/src/lib/deskflow/Screen.cpp +++ b/src/lib/deskflow/Screen.cpp @@ -29,7 +29,7 @@ Screen::Screen(IPlatformScreen *platformScreen, IEventQueue *events) m_mock(false), m_enableDragDrop(false) { - assert(m_screen != NULL); + assert(m_screen != nullptr); // reset options resetOptions(); @@ -179,7 +179,7 @@ void Screen::setClipboard(ClipboardID id, const IClipboard *clipboard) void Screen::grabClipboard(ClipboardID id) { - m_screen->setClipboard(id, NULL); + m_screen->setClipboard(id, nullptr); } void Screen::screensaver(bool) const diff --git a/src/lib/deskflow/ServerApp.cpp b/src/lib/deskflow/ServerApp.cpp index 20049debc..400547f9d 100644 --- a/src/lib/deskflow/ServerApp.cpp +++ b/src/lib/deskflow/ServerApp.cpp @@ -70,13 +70,13 @@ using namespace deskflow::server; ServerApp::ServerApp(IEventQueue *events) : App(events, new deskflow::ServerArgs()), - m_server(NULL), + m_server(nullptr), m_serverState(kUninitialized), - m_serverScreen(NULL), - m_primaryClient(NULL), - m_listener(NULL), - m_timer(NULL), - m_deskflowAddress(NULL) + m_serverScreen(nullptr), + m_primaryClient(nullptr), + m_listener(nullptr), + m_timer(nullptr), + m_deskflowAddress(nullptr) { } @@ -166,7 +166,7 @@ void ServerApp::reloadConfig(const Event &, void *) { LOG((CLOG_DEBUG "reload configuration")); if (loadConfig(args().m_configFile)) { - if (m_server != NULL) { + if (m_server != nullptr) { m_server->setConfig(*args().m_config); } LOG((CLOG_NOTE "reloaded configuration")); @@ -209,7 +209,7 @@ bool ServerApp::loadConfig(const std::string &pathname) void ServerApp::forceReconnect(const Event &, void *) { - if (m_server != NULL) { + if (m_server != nullptr) { m_server->disconnect(); } } @@ -218,7 +218,7 @@ void ServerApp::handleClientConnected(const Event &, void *vlistener) { ClientListener *listener = static_cast(vlistener); ClientProxy *client = listener->getNextClient(); - if (client != NULL) { + if (client != nullptr) { m_server->adoptClient(client); updateStatus(); } @@ -231,7 +231,7 @@ void ServerApp::handleClientsDisconnected(const Event &, void *) void ServerApp::closeServer(Server *server) { - if (server == NULL) { + if (server == nullptr) { return; } @@ -240,7 +240,7 @@ void ServerApp::closeServer(Server *server) // wait for clients to disconnect for up to timeout seconds double timeout = 3.0; - EventQueueTimer *timer = m_events->newOneShotTimer(timeout, NULL); + EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr); m_events->adoptHandler( Event::kTimer, timer, new TMethodEventJob(this, &ServerApp::handleClientsDisconnected) ); @@ -261,10 +261,10 @@ void ServerApp::closeServer(Server *server) void ServerApp::stopRetryTimer() { - if (m_timer != NULL) { + if (m_timer != nullptr) { m_events->removeHandler(Event::kTimer, m_timer); m_events->deleteTimer(m_timer); - m_timer = NULL; + m_timer = nullptr; } } @@ -279,7 +279,7 @@ void ServerApp::updateStatus(const std::string &msg) void ServerApp::closeClientListener(ClientListener *listen) { - if (listen != NULL) { + if (listen != nullptr) { m_events->removeHandler(m_events->forClientListener().connected(), listen); delete listen; } @@ -290,15 +290,15 @@ void ServerApp::stopServer() if (m_serverState == kStarted) { closeServer(m_server); closeClientListener(m_listener); - m_server = NULL; - m_listener = NULL; + m_server = nullptr; + m_listener = nullptr; m_serverState = kInitialized; } else if (m_serverState == kStarting) { stopRetryTimer(); m_serverState = kInitialized; } - assert(m_server == NULL); - assert(m_listener == NULL); + assert(m_server == nullptr); + assert(m_listener == nullptr); } void ServerApp::closePrimaryClient(PrimaryClient *primaryClient) @@ -308,7 +308,7 @@ void ServerApp::closePrimaryClient(PrimaryClient *primaryClient) void ServerApp::closeServerScreen(deskflow::Screen *screen) { - if (screen != NULL) { + if (screen != nullptr) { m_events->removeHandler(m_events->forIScreen().error(), screen->getEventTarget()); m_events->removeHandler(m_events->forIScreen().suspend(), screen->getEventTarget()); m_events->removeHandler(m_events->forIScreen().resume(), screen->getEventTarget()); @@ -322,22 +322,22 @@ void ServerApp::cleanupServer() if (m_serverState == kInitialized) { closePrimaryClient(m_primaryClient); closeServerScreen(m_serverScreen); - m_primaryClient = NULL; - m_serverScreen = NULL; + m_primaryClient = nullptr; + m_serverScreen = nullptr; m_serverState = kUninitialized; } else if (m_serverState == kInitializing || m_serverState == kInitializingToStart) { stopRetryTimer(); m_serverState = kUninitialized; } - assert(m_primaryClient == NULL); - assert(m_serverScreen == NULL); + assert(m_primaryClient == nullptr); + assert(m_serverScreen == nullptr); assert(m_serverState == kUninitialized); } void ServerApp::retryHandler(const Event &, void *) { // discard old timer - assert(m_timer != NULL); + assert(m_timer != nullptr); stopRetryTimer(); // try initializing/starting the server again @@ -387,8 +387,8 @@ bool ServerApp::initServer() } double retryTime; - deskflow::Screen *serverScreen = NULL; - PrimaryClient *primaryClient = NULL; + deskflow::Screen *serverScreen = nullptr; + PrimaryClient *primaryClient = nullptr; try { std::string name = args().m_config->getCanonicalName(args().m_name); serverScreen = openServerScreen(); @@ -418,9 +418,9 @@ bool ServerApp::initServer() if (args().m_restartable) { // install a timer and handler to retry later - assert(m_timer == NULL); + assert(m_timer == nullptr); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); - m_timer = m_events->newOneShotTimer(retryTime, NULL); + m_timer = m_events->newOneShotTimer(retryTime, nullptr); m_events->adoptHandler(Event::kTimer, m_timer, new TMethodEventJob(this, &ServerApp::retryHandler)); m_serverState = kInitializing; return true; @@ -470,7 +470,7 @@ bool ServerApp::startServer() assert(m_serverState == kInitialized); } - ClientListener *listener = NULL; + ClientListener *listener = nullptr; try { listener = openClientListener(args().m_config->getDeskflowAddress()); m_server = openServer(*args().m_config, m_primaryClient); @@ -497,10 +497,10 @@ bool ServerApp::startServer() if (args().m_restartable) { // install a timer and handler to retry later - assert(m_timer == NULL); + assert(m_timer == nullptr); const auto retryTime = 10.0; LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); - m_timer = m_events->newOneShotTimer(retryTime, NULL); + m_timer = m_events->newOneShotTimer(retryTime, nullptr); m_events->adoptHandler(Event::kTimer, m_timer, new TMethodEventJob(this, &ServerApp::retryHandler)); m_serverState = kStarting; return true; @@ -655,7 +655,7 @@ int ServerApp::mainLoop() appUtil().startNode(); // handle hangup signal by reloading the server's configuration - ARCH->setSignalHandler(Arch::kHANGUP, &reloadSignalHandler, NULL); + ARCH->setSignalHandler(Arch::kHANGUP, &reloadSignalHandler, nullptr); m_events->adoptHandler( m_events->forServerApp().reloadConfig(), m_events->getSystemTarget(), new TMethodEventJob(this, &ServerApp::reloadConfig) @@ -682,7 +682,7 @@ int ServerApp::mainLoop() #if WINAPI_CARBON - Thread thread(new TMethodJob(this, &ServerApp::runEventsLoop, NULL)); + Thread thread(new TMethodJob(this, &ServerApp::runEventsLoop, nullptr)); // wait until carbon loop is ready OSXScreen *screen = dynamic_cast(m_serverScreen->getPlatformScreen()); diff --git a/src/lib/deskflow/StreamChunker.cpp b/src/lib/deskflow/StreamChunker.cpp index 01178747f..87ed44bbd 100644 --- a/src/lib/deskflow/StreamChunker.cpp +++ b/src/lib/deskflow/StreamChunker.cpp @@ -27,7 +27,7 @@ static const size_t g_chunkSize = 512 * 1024; // 512kb bool StreamChunker::s_isChunkingFile = false; bool StreamChunker::s_interruptFile = false; -Mutex *StreamChunker::s_interruptMutex = NULL; +Mutex *StreamChunker::s_interruptMutex = nullptr; void StreamChunker::sendFile(char *filename, IEventQueue *events, void *eventTarget) { diff --git a/src/lib/deskflow/unix/AppUtilUnix.cpp b/src/lib/deskflow/unix/AppUtilUnix.cpp index df76a0f0a..09b4984cf 100644 --- a/src/lib/deskflow/unix/AppUtilUnix.cpp +++ b/src/lib/deskflow/unix/AppUtilUnix.cpp @@ -60,7 +60,9 @@ std::vector AppUtilUnix::getKeyboardLayoutList() #elif WINAPI_CARBON CFStringRef keys[] = {kTISPropertyInputSourceCategory}; CFStringRef values[] = {kTISCategoryKeyboardInputSource}; - AutoCFDictionary dict(CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL), CFRelease); + AutoCFDictionary dict( + CFDictionaryCreate(nullptr, (const void **)keys, (const void **)values, 1, nullptr, nullptr), CFRelease + ); AutoCFArray kbds(TISCreateInputSourceList(dict.get(), false), CFRelease); for (CFIndex i = 0; i < CFArrayGetCount(kbds.get()); ++i) { diff --git a/src/lib/deskflow/win32/AppUtilWindows.cpp b/src/lib/deskflow/win32/AppUtilWindows.cpp index ee86463ef..1b0bb701d 100644 --- a/src/lib/deskflow/win32/AppUtilWindows.cpp +++ b/src/lib/deskflow/win32/AppUtilWindows.cpp @@ -109,7 +109,7 @@ int AppUtilWindows::run(int argc, char **argv) } // record window instance for tray icon, etc - ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); + ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); MSWindowsScreen::init(ArchMiscWindows::instanceWin32()); Thread::getCurrentThread().setPriority(-14); @@ -139,7 +139,7 @@ std::vector AppUtilWindows::getKeyboardLayoutList() { std::vector layoutLangCodes; { - auto uLayouts = GetKeyboardLayoutList(0, NULL); + auto uLayouts = GetKeyboardLayoutList(0, nullptr); auto lpList = (HKL *)LocalAlloc(LPTR, (uLayouts * sizeof(HKL))); uLayouts = GetKeyboardLayoutList(uLayouts, lpList); @@ -178,7 +178,7 @@ HKL AppUtilWindows::getCurrentKeyboardLayout() const GUITHREADINFO gti = {sizeof(GUITHREADINFO)}; if (GetGUIThreadInfo(0, >i) && gti.hwndActive) { - layout = GetKeyboardLayout(GetWindowThreadProcessId(gti.hwndActive, NULL)); + layout = GetKeyboardLayout(GetWindowThreadProcessId(gti.hwndActive, nullptr)); } else { LOG((CLOG_WARN "failed to determine current keyboard layout")); } diff --git a/src/lib/gui/ScreenSetupModel.cpp b/src/lib/gui/ScreenSetupModel.cpp index 7811d8088..474790b0d 100644 --- a/src/lib/gui/ScreenSetupModel.cpp +++ b/src/lib/gui/ScreenSetupModel.cpp @@ -17,7 +17,7 @@ const QString ScreenSetupModel::m_MimeType = "application/x-deskflow-screen"; ScreenSetupModel::ScreenSetupModel(ScreenList &screens, int numColumns, int numRows) - : QAbstractTableModel(NULL), + : QAbstractTableModel(nullptr), m_Screens(screens), m_NumColumns(numColumns), m_NumRows(numRows) diff --git a/src/lib/gui/widgets/ScreenSetupView.cpp b/src/lib/gui/widgets/ScreenSetupView.cpp index e854d2396..0cd25582a 100644 --- a/src/lib/gui/widgets/ScreenSetupView.cpp +++ b/src/lib/gui/widgets/ScreenSetupView.cpp @@ -122,7 +122,7 @@ void ScreenSetupView::startDrag(Qt::DropActions) return; QMimeData *pData = model()->mimeData(indexes); - if (pData == NULL) + if (pData == nullptr) return; const QPixmap &pixmap = model()->screen(indexes[0]).pixmap(); diff --git a/src/lib/io/IStream.h b/src/lib/io/IStream.h index ee2b5db42..4cb1061ff 100644 --- a/src/lib/io/IStream.h +++ b/src/lib/io/IStream.h @@ -44,7 +44,7 @@ public: /*! Read up to \p n bytes into \p buffer, returning the number read (zero if no data is available or input is shutdown). \p buffer - may be NULL in which case the data is discarded. + may be nullptr in which case the data is discarded. */ virtual uint32_t read(void *buffer, uint32_t n) = 0; diff --git a/src/lib/io/StreamBuffer.cpp b/src/lib/io/StreamBuffer.cpp index d84369d3e..91626b3ad 100644 --- a/src/lib/io/StreamBuffer.cpp +++ b/src/lib/io/StreamBuffer.cpp @@ -28,10 +28,10 @@ const void *StreamBuffer::peek(uint32_t n) { assert(n <= m_size); - // if requesting no data then return NULL so we don't try to access + // if requesting no data then return nullptr so we don't try to access // an empty list. if (n == 0) { - return NULL; + return nullptr; } // reserve space in first chunk @@ -80,7 +80,7 @@ void StreamBuffer::pop(uint32_t n) void StreamBuffer::write(const void *vdata, uint32_t n) { - assert(vdata != NULL); + assert(vdata != nullptr); // ignore if no data, otherwise update size if (n == 0) { diff --git a/src/lib/mt/CondVar.cpp b/src/lib/mt/CondVar.cpp index eaff25b1d..74d1d8cd5 100644 --- a/src/lib/mt/CondVar.cpp +++ b/src/lib/mt/CondVar.cpp @@ -15,7 +15,7 @@ CondVarBase::CondVarBase(Mutex *mutex) : m_mutex(mutex) { - assert(m_mutex != NULL); + assert(m_mutex != nullptr); m_cond = ARCH->newCondVar(); } diff --git a/src/lib/mt/CondVar.h b/src/lib/mt/CondVar.h index 1972b60cf..4c4f67ace 100644 --- a/src/lib/mt/CondVar.h +++ b/src/lib/mt/CondVar.h @@ -23,7 +23,7 @@ class CondVarBase { public: /*! - \c mutex must not be NULL. All condition variables have an + \c mutex must not be nullptr. All condition variables have an associated mutex. The mutex needn't be unique to one condition variable. */ diff --git a/src/lib/mt/Thread.cpp b/src/lib/mt/Thread.cpp index 5f953580e..d7cabf2c5 100644 --- a/src/lib/mt/Thread.cpp +++ b/src/lib/mt/Thread.cpp @@ -21,7 +21,7 @@ Thread::Thread(IJob *job) { m_thread = ARCH->newThread(&Thread::threadFunc, job); - if (m_thread == NULL) { + if (m_thread == nullptr) { // couldn't create thread delete job; throw XMTThreadUnavailable(); @@ -95,7 +95,7 @@ void *Thread::getResult() const if (wait()) return ARCH->getResultOfThread(m_thread); else - return NULL; + return nullptr; } IArchMultithread::ThreadID Thread::getID() const @@ -127,7 +127,7 @@ void *Thread::threadFunc(void *vjob) IJob *job = static_cast(vjob); // run job - void *result = NULL; + void *result = nullptr; try { // go LOG((CLOG_DEBUG1 "thread 0x%08x entry", id)); diff --git a/src/lib/mt/Thread.h b/src/lib/mt/Thread.h index 72a150996..acfb9e03d 100644 --- a/src/lib/mt/Thread.h +++ b/src/lib/mt/Thread.h @@ -160,7 +160,7 @@ public: //! Get the exit result /*! Returns the exit result. This does an implicit wait(). It returns - NULL immediately if called by a thread on itself or on a thread that + nullptr immediately if called by a thread on itself or on a thread that was cancelled. (cancellation point) diff --git a/src/lib/net/IDataSocket.cpp b/src/lib/net/IDataSocket.cpp index 76472676f..95cddc63a 100644 --- a/src/lib/net/IDataSocket.cpp +++ b/src/lib/net/IDataSocket.cpp @@ -22,5 +22,5 @@ void *IDataSocket::getEventTarget() const { // this is here to work around a VC++6 bug. see the header file. assert(0 && "bad call"); - return NULL; + return nullptr; } diff --git a/src/lib/net/IListenSocket.h b/src/lib/net/IListenSocket.h index e0155f39f..1089bd718 100644 --- a/src/lib/net/IListenSocket.h +++ b/src/lib/net/IListenSocket.h @@ -26,7 +26,7 @@ public: //! Accept connection /*! Accept a connection, returning a socket representing the full-duplex - data stream. Returns NULL if no socket is waiting to be accepted. + data stream. Returns nullptr if no socket is waiting to be accepted. This is only valid after a call to \c bind(). */ virtual IDataSocket *accept() = 0; diff --git a/src/lib/net/ISocketMultiplexerJob.h b/src/lib/net/ISocketMultiplexerJob.h index 2ff562655..bff5c1acf 100644 --- a/src/lib/net/ISocketMultiplexerJob.h +++ b/src/lib/net/ISocketMultiplexerJob.h @@ -25,7 +25,7 @@ public: Called by a socket multiplexer when the socket becomes readable, writable, or has an error. It should return itself if the same job can continue to service events, a new job if the socket must - be serviced differently, or NULL if the socket should no longer + be serviced differently, or nullptr if the socket should no longer be serviced. The socket is readable if \p readable is true, writable if \p writable is true, and in error if \p error is true. diff --git a/src/lib/net/SecureListenSocket.cpp b/src/lib/net/SecureListenSocket.cpp index 5ec1e9be5..c13a27894 100644 --- a/src/lib/net/SecureListenSocket.cpp +++ b/src/lib/net/SecureListenSocket.cpp @@ -33,12 +33,12 @@ SecureListenSocket::SecureListenSocket( IDataSocket *SecureListenSocket::accept() { - SecureSocket *socket = NULL; + SecureSocket *socket = nullptr; try { - socket = new SecureSocket(m_events, m_socketMultiplexer, ARCH->acceptSocket(m_socket, NULL), m_securityLevel); + socket = new SecureSocket(m_events, m_socketMultiplexer, ARCH->acceptSocket(m_socket, nullptr), m_securityLevel); socket->initSsl(true); - if (socket != NULL) { + if (socket != nullptr) { setListeningJob(); } @@ -53,20 +53,20 @@ IDataSocket *SecureListenSocket::accept() bool loaded = socket->loadCertificates(certificateFilename); if (!loaded) { delete socket; - return NULL; + return nullptr; } socket->secureAccept(); return dynamic_cast(socket); } catch (XArchNetwork &) { - if (socket != NULL) { + if (socket != nullptr) { delete socket; setListeningJob(); } - return NULL; + return nullptr; } catch (std::exception &ex) { - if (socket != NULL) { + if (socket != nullptr) { delete socket; setListeningJob(); } diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index 388ec26ab..75fade29f 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -104,7 +104,7 @@ ISocketMultiplexerJob *SecureSocket::newJob() // after TCP connection is established, SecureSocket will pick up // connected event and do secureConnect if (m_connected && !m_secureReady) { - return NULL; + return nullptr; } return TCPSocket::newJob(); @@ -184,7 +184,7 @@ TCPSocket::EJobResult SecureSocket::doWrite() static bool s_retry = false; static int s_retrySize = 0; static int s_staticBufferSize = 0; - static void *s_staticBuffer = NULL; + static void *s_staticBuffer = nullptr; // write data int bufferSize = 0; @@ -236,7 +236,7 @@ int SecureSocket::secureRead(void *buffer, int size, int &read) { std::lock_guard ssl_lock{ssl_mutex_}; - if (m_ssl->m_ssl != NULL) { + if (m_ssl->m_ssl != nullptr) { LOG((CLOG_DEBUG2 "reading secure socket")); read = SSL_read(m_ssl->m_ssl, buffer, size); @@ -263,7 +263,7 @@ int SecureSocket::secureWrite(const void *buffer, int size, int &wrote) { std::lock_guard ssl_lock{ssl_mutex_}; - if (m_ssl->m_ssl != NULL) { + if (m_ssl->m_ssl != nullptr) { LOG((CLOG_DEBUG2 "writing secure socket: %p", this)); wrote = SSL_write(m_ssl->m_ssl, buffer, size); @@ -297,8 +297,8 @@ void SecureSocket::initSsl(bool server) std::lock_guard ssl_lock{ssl_mutex_}; m_ssl = new Ssl(); - m_ssl->m_context = NULL; - m_ssl->m_ssl = NULL; + m_ssl->m_context = nullptr; + m_ssl->m_ssl = nullptr; initContext(server); } @@ -372,7 +372,7 @@ void SecureSocket::initContext(bool server) // be vulnerable SSL_CTX_set_options(m_ssl->m_context, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1); - if (m_ssl->m_context == NULL) { + if (m_ssl->m_context == nullptr) { SslLogger::logError(); } @@ -388,8 +388,8 @@ void SecureSocket::createSSL() { // I assume just one instance is needed // get new SSL state with context - if (m_ssl->m_ssl == NULL) { - assert(m_ssl->m_context != NULL); + if (m_ssl->m_ssl == nullptr) { + assert(m_ssl->m_context != nullptr); m_ssl->m_ssl = SSL_new(m_ssl->m_context); } } @@ -402,17 +402,17 @@ void SecureSocket::freeSSL() // take socket from multiplexer ASAP otherwise the race condition // could cause events to get called on a dead object. TCPSocket // will do this, too, but the double-call is harmless - setJob(NULL); + setJob(nullptr); if (m_ssl) { - if (m_ssl->m_ssl != NULL) { + if (m_ssl->m_ssl != nullptr) { SSL_shutdown(m_ssl->m_ssl); SSL_free(m_ssl->m_ssl); - m_ssl->m_ssl = NULL; + m_ssl->m_ssl = nullptr; } - if (m_ssl->m_context != NULL) { + if (m_ssl->m_context != nullptr) { SSL_CTX_free(m_ssl->m_context); - m_ssl->m_context = NULL; + m_ssl->m_context = nullptr; } delete m_ssl; m_ssl = nullptr; @@ -546,7 +546,7 @@ bool SecureSocket::showCertificate() const // get the server's certificate cert = SSL_get_peer_certificate(m_ssl->m_ssl); - if (cert != NULL) { + if (cert != nullptr) { line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0); LOG((CLOG_INFO "server tls certificate info: %s", line)); OPENSSL_free(line); @@ -704,7 +704,7 @@ ISocketMultiplexerJob *SecureSocket::serviceConnect(ISocketMultiplexerJob *job, // If status < 0, error happened if (status < 0) { - return NULL; + return nullptr; } // If status > 0, success @@ -731,7 +731,7 @@ ISocketMultiplexerJob *SecureSocket::serviceAccept(ISocketMultiplexerJob *job, b #endif // If status < 0, error happened if (status < 0) { - return NULL; + return nullptr; } // If status > 0, success diff --git a/src/lib/net/SecureUtils.cpp b/src/lib/net/SecureUtils.cpp index 3c7907554..590b569f4 100644 --- a/src/lib/net/SecureUtils.cpp +++ b/src/lib/net/SecureUtils.cpp @@ -136,7 +136,7 @@ int getCertLength(const std::string &path) return -1; } - EVP_PKEY *privateKey = PEM_read_PrivateKey(fp, NULL, NULL, NULL); + EVP_PKEY *privateKey = PEM_read_PrivateKey(fp, nullptr, nullptr, nullptr); fclose(fp); diff --git a/src/lib/net/SocketMultiplexer.cpp b/src/lib/net/SocketMultiplexer.cpp index 723a8da44..7fcd487ba 100644 --- a/src/lib/net/SocketMultiplexer.cpp +++ b/src/lib/net/SocketMultiplexer.cpp @@ -25,15 +25,15 @@ SocketMultiplexer::SocketMultiplexer() : m_mutex(new Mutex), - m_thread(NULL), + m_thread(nullptr), m_update(false), m_jobsReady(new CondVar(m_mutex, false)), m_jobListLock(new CondVar(m_mutex, false)), m_jobListLockLocked(new CondVar(m_mutex, false)), - m_jobListLocker(NULL), - m_jobListLockLocker(NULL) + m_jobListLocker(nullptr), + m_jobListLockLocker(nullptr) { - // this pointer just has to be unique and not NULL. it will + // this pointer just has to be unique and not nullptr. it will // never be dereferenced. it's used to identify cursor nodes // in the jobs list. // TODO: Remove this evilness @@ -64,8 +64,8 @@ SocketMultiplexer::~SocketMultiplexer() void SocketMultiplexer::addSocket(ISocket *socket, ISocketMultiplexerJob *job) { - assert(socket != NULL); - assert(job != NULL); + assert(socket != nullptr); + assert(job != nullptr); // prevent other threads from locking the job list lockJobListLock(); @@ -100,7 +100,7 @@ void SocketMultiplexer::addSocket(ISocket *socket, ISocketMultiplexerJob *job) void SocketMultiplexer::removeSocket(ISocket *socket) { - assert(socket != NULL); + assert(socket != nullptr); // prevent other threads from locking the job list lockJobListLock(); @@ -111,14 +111,14 @@ void SocketMultiplexer::removeSocket(ISocket *socket) // lock the job list lockJobList(); - // remove job. rather than removing it from the map we put NULL + // remove job. rather than removing it from the map we put nullptr // in the list instead so the order of jobs in the list continues // to match the order of jobs in pfds in serviceThread(). SocketJobMap::iterator i = m_socketJobMap.find(socket); if (i != m_socketJobMap.end()) { - if (*(i->second) != NULL) { + if (*(i->second) != nullptr) { delete *(i->second); - *(i->second) = NULL; + *(i->second) = nullptr; m_update = true; } } @@ -158,7 +158,7 @@ void SocketMultiplexer::serviceThread(void *) JobCursor jobCursor = nextCursor(cursor); while (jobCursor != m_socketJobs.end()) { ISocketMultiplexerJob *job = *jobCursor; - if (job != NULL) { + if (job != nullptr) { pfd.m_socket = job->getSocket(); pfd.m_events = 0; if (job->isReadable()) { @@ -194,7 +194,7 @@ void SocketMultiplexer::serviceThread(void *) JobCursor cursor = newCursor(); JobCursor jobCursor = nextCursor(cursor); while (i < pfds.size() && jobCursor != m_socketJobs.end()) { - if (*jobCursor != NULL) { + if (*jobCursor != nullptr) { // get poll state unsigned short revents = pfds[i].m_revents; bool read = ((revents & IArchNetwork::kPOLLIN) != 0); @@ -223,7 +223,7 @@ void SocketMultiplexer::serviceThread(void *) // delete any removed socket jobs for (SocketJobMap::iterator i = m_socketJobMap.begin(); i != m_socketJobMap.end();) { - if (*(i->second) == NULL) { + if (*(i->second) == nullptr) { m_socketJobs.erase(i->second); m_socketJobMap.erase(i++); m_update = true; @@ -296,7 +296,7 @@ void SocketMultiplexer::lockJobList() // take ownership of the lock *m_jobListLock = true; m_jobListLocker = m_jobListLockLocker; - m_jobListLockLocker = NULL; + m_jobListLockLocker = nullptr; // release the lock on the lock *m_jobListLockLocked = false; @@ -312,7 +312,7 @@ void SocketMultiplexer::unlockJobList() // release the lock delete m_jobListLocker; - m_jobListLocker = NULL; + m_jobListLocker = nullptr; *m_jobListLock = false; m_jobListLock->signal(); diff --git a/src/lib/net/TCPListenSocket.cpp b/src/lib/net/TCPListenSocket.cpp index 47c69e2bc..6c5bb7cb6 100644 --- a/src/lib/net/TCPListenSocket.cpp +++ b/src/lib/net/TCPListenSocket.cpp @@ -41,7 +41,7 @@ TCPListenSocket::TCPListenSocket( TCPListenSocket::~TCPListenSocket() { try { - if (m_socket != NULL) { + if (m_socket != nullptr) { m_socketMultiplexer->removeSocket(this); ARCH->closeSocket(m_socket); } @@ -74,13 +74,13 @@ void TCPListenSocket::bind(const NetworkAddress &addr) void TCPListenSocket::close() { Lock lock(m_mutex); - if (m_socket == NULL) { + if (m_socket == nullptr) { throw XIOClosed(); } try { m_socketMultiplexer->removeSocket(this); ARCH->closeSocket(m_socket); - m_socket = NULL; + m_socket = nullptr; } catch (XArchNetwork &e) { throw XSocketIOClose(e.what()); } @@ -93,21 +93,21 @@ void *TCPListenSocket::getEventTarget() const IDataSocket *TCPListenSocket::accept() { - IDataSocket *socket = NULL; + IDataSocket *socket = nullptr; try { - socket = new TCPSocket(m_events, m_socketMultiplexer, ARCH->acceptSocket(m_socket, NULL)); - if (socket != NULL) { + socket = new TCPSocket(m_events, m_socketMultiplexer, ARCH->acceptSocket(m_socket, nullptr)); + if (socket != nullptr) { setListeningJob(); } return socket; } catch (XArchNetwork &) { - if (socket != NULL) { + if (socket != nullptr) { delete socket; setListeningJob(); } - return NULL; + return nullptr; } catch (std::exception &ex) { - if (socket != NULL) { + if (socket != nullptr) { delete socket; setListeningJob(); } @@ -127,12 +127,12 @@ ISocketMultiplexerJob *TCPListenSocket::serviceListening(ISocketMultiplexerJob * { if (error) { close(); - return NULL; + return nullptr; } if (read) { m_events->addEvent(Event(m_events->forIListenSocket().connecting(), this)); // stop polling on this socket until the client accepts - return NULL; + return nullptr; } return job; } diff --git a/src/lib/net/TCPSocketFactory.cpp b/src/lib/net/TCPSocketFactory.cpp index 29d5e50b3..4e6cfbc1b 100644 --- a/src/lib/net/TCPSocketFactory.cpp +++ b/src/lib/net/TCPSocketFactory.cpp @@ -43,7 +43,7 @@ IDataSocket *TCPSocketFactory::create(IArchNetwork::EAddressFamily family, Secur IListenSocket *TCPSocketFactory::createListen(IArchNetwork::EAddressFamily family, SecurityLevel securityLevel) const { - IListenSocket *socket = NULL; + IListenSocket *socket = nullptr; if (securityLevel != SecurityLevel::PlainText) { socket = new SecureListenSocket(m_events, m_socketMultiplexer, family, securityLevel); } else { diff --git a/src/lib/net/TSocketMultiplexerMethodJob.h b/src/lib/net/TSocketMultiplexerMethodJob.h index c6ed9bbd5..f8ad8c25b 100644 --- a/src/lib/net/TSocketMultiplexerMethodJob.h +++ b/src/lib/net/TSocketMultiplexerMethodJob.h @@ -63,10 +63,10 @@ template inline TSocketMultiplexerMethodJob::~TSocketMultiplexerMet template inline ISocketMultiplexerJob *TSocketMultiplexerMethodJob::run(bool read, bool write, bool error) { - if (m_object != NULL) { + if (m_object != nullptr) { return (m_object->*m_method)(this, read, write, error); } - return NULL; + return nullptr; } template inline ArchSocket TSocketMultiplexerMethodJob::getSocket() const diff --git a/src/lib/platform/EiEventQueueBuffer.cpp b/src/lib/platform/EiEventQueueBuffer.cpp index cb8af224f..1143a3674 100644 --- a/src/lib/platform/EiEventQueueBuffer.cpp +++ b/src/lib/platform/EiEventQueueBuffer.cpp @@ -68,7 +68,7 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms) std::lock_guard lock(mutex_); // libei doesn't allow ei_event_ref() because events are - // supposed to be short-lived only. So instead, we create an NULL-data + // supposed to be short-lived only. So instead, we create an nullptr-data // kSystemEvent whenever there's data on the fd, shove that event // into our event queue and once we process the event (see // getEvent()), the EiScreen will call ei_dispatch() and process diff --git a/src/lib/platform/IOSXKeyResource.cpp b/src/lib/platform/IOSXKeyResource.cpp index 164edf921..0e3dc6b4f 100644 --- a/src/lib/platform/IOSXKeyResource.cpp +++ b/src/lib/platform/IOSXKeyResource.cpp @@ -107,10 +107,10 @@ KeyID IOSXKeyResource::getKeyID(uint8_t c) // convert to unicode CFStringRef cfString = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, str, encoding, kCFAllocatorNull); - // sometimes CFStringCreate...() returns NULL (e.g. Apple Korean + // sometimes CFStringCreate...() returns nullptr (e.g. Apple Korean // encoding with char value 214). if it did then make no key, // otherwise CFStringCreateMutableCopy() will crash. - if (cfString == NULL) { + if (cfString == nullptr) { return kKeyNone; } diff --git a/src/lib/platform/MSWindowsClipboard.cpp b/src/lib/platform/MSWindowsClipboard.cpp index 7b4fb5bd6..cd2b56292 100644 --- a/src/lib/platform/MSWindowsClipboard.cpp +++ b/src/lib/platform/MSWindowsClipboard.cpp @@ -74,7 +74,7 @@ bool MSWindowsClipboard::empty() // mark clipboard as being owned by deskflow HGLOBAL data = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, 1); - if (NULL == SetClipboardData(getOwnershipFormat(), data)) { + if (nullptr == SetClipboardData(getOwnershipFormat(), data)) { LOG((CLOG_WARN "failed to set clipboard data")); GlobalFree(data); return false; @@ -98,7 +98,7 @@ void MSWindowsClipboard::add(EFormat format, const std::string &data) // skip converters for other formats if (converter->getFormat() == format) { HANDLE win32Data = converter->fromIClipboard(data); - if (win32Data != NULL) { + if (win32Data != nullptr) { LOG((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format)); m_facade->write(win32Data, converter->getWin32Format()); isSucceeded = true; @@ -155,25 +155,25 @@ bool MSWindowsClipboard::has(EFormat format) const std::string MSWindowsClipboard::get(EFormat format) const { // find the converter for the first clipboard format we can handle - IMSWindowsClipboardConverter *converter = NULL; + IMSWindowsClipboardConverter *converter = nullptr; for (ConverterList::const_iterator index = m_converters.begin(); index != m_converters.end(); ++index) { converter = *index; if (converter->getFormat() == format) { break; } - converter = NULL; + converter = nullptr; } // if no converter then we don't recognize any formats - if (converter == NULL) { + if (converter == nullptr) { LOG((CLOG_WARN "no converter for format %d", format)); return std::string(); } // get a handle to the clipboard data HANDLE win32Data = GetClipboardData(converter->getWin32Format()); - if (win32Data == NULL) { + if (win32Data == nullptr) { // nb: can't cause this using integ tests; this is only caused when // the selected converter returns an invalid format -- which you // cannot cause using public functions. diff --git a/src/lib/platform/MSWindowsClipboardAnyTextConverter.cpp b/src/lib/platform/MSWindowsClipboardAnyTextConverter.cpp index b118e5287..8a676c68c 100644 --- a/src/lib/platform/MSWindowsClipboardAnyTextConverter.cpp +++ b/src/lib/platform/MSWindowsClipboardAnyTextConverter.cpp @@ -35,15 +35,15 @@ MSWindowsClipboardAnyTextConverter::fromIClipboard(const std::string &data) cons // copy to memory handle HGLOBAL gData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size); - if (gData != NULL) { + if (gData != nullptr) { // get a pointer to the allocated memory char *dst = (char *)GlobalLock(gData); - if (dst != NULL) { + if (dst != nullptr) { memcpy(dst, text.data(), size); GlobalUnlock(gData); } else { GlobalFree(gData); - gData = NULL; + gData = nullptr; } } @@ -55,7 +55,7 @@ std::string MSWindowsClipboardAnyTextConverter::toIClipboard(HANDLE data) const // get datator const char *src = (const char *)GlobalLock(data); uint32_t srcSize = (uint32_t)GlobalSize(data); - if (src == NULL || srcSize <= 1) { + if (src == nullptr || srcSize <= 1) { return std::string(); } diff --git a/src/lib/platform/MSWindowsClipboardBitmapConverter.cpp b/src/lib/platform/MSWindowsClipboardBitmapConverter.cpp index dc73e9dc9..41f9eaa23 100644 --- a/src/lib/platform/MSWindowsClipboardBitmapConverter.cpp +++ b/src/lib/platform/MSWindowsClipboardBitmapConverter.cpp @@ -38,15 +38,15 @@ MSWindowsClipboardBitmapConverter::fromIClipboard(const std::string &data) const { // copy to memory handle HGLOBAL gData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, data.size()); - if (gData != NULL) { + if (gData != nullptr) { // get a pointer to the allocated memory char *dst = (char *)GlobalLock(gData); - if (dst != NULL) { + if (dst != nullptr) { memcpy(dst, data.data(), data.size()); GlobalUnlock(gData); } else { GlobalFree(gData); - gData = NULL; + gData = nullptr; } } @@ -57,7 +57,7 @@ std::string MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const { // get datator LPVOID src = GlobalLock(data); - if (src == NULL) { + if (src == nullptr) { return std::string(); } uint32_t srcSize = (uint32_t)GlobalSize(data); @@ -94,8 +94,8 @@ std::string MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const info.biYPelsPerMeter = 1000; info.biClrUsed = 0; info.biClrImportant = 0; - HDC dc = GetDC(NULL); - HBITMAP dst = CreateDIBSection(dc, (BITMAPINFO *)&info, DIB_RGB_COLORS, &raw, NULL, 0); + HDC dc = GetDC(nullptr); + HBITMAP dst = CreateDIBSection(dc, (BITMAPINFO *)&info, DIB_RGB_COLORS, &raw, nullptr, 0); // find the start of the pixel data const char *srcBits = (const char *)bitmap + bitmap->bmiHeader.biSize; @@ -125,7 +125,7 @@ std::string MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const // clean up GDI DeleteObject(dst); - ReleaseDC(NULL, dc); + ReleaseDC(nullptr, dc); // release handle GlobalUnlock(data); diff --git a/src/lib/platform/MSWindowsClipboardFacade.cpp b/src/lib/platform/MSWindowsClipboardFacade.cpp index 8c8c4494d..7f7448b66 100644 --- a/src/lib/platform/MSWindowsClipboardFacade.cpp +++ b/src/lib/platform/MSWindowsClipboardFacade.cpp @@ -11,7 +11,7 @@ void MSWindowsClipboardFacade::write(HANDLE win32Data, UINT win32Format) { - if (SetClipboardData(win32Format, win32Data) == NULL) { + if (SetClipboardData(win32Format, win32Data) == nullptr) { // free converted data if we couldn't put it on // the clipboard. // nb: couldn't cause this in integ tests. diff --git a/src/lib/platform/MSWindowsDesks.cpp b/src/lib/platform/MSWindowsDesks.cpp index 72deb1336..091ec1b33 100644 --- a/src/lib/platform/MSWindowsDesks.cpp +++ b/src/lib/platform/MSWindowsDesks.cpp @@ -119,10 +119,10 @@ MSWindowsDesks::MSWindowsDesks( m_xCenter(0), m_yCenter(0), m_multimon(false), - m_timer(NULL), + m_timer(nullptr), m_screensaver(screensaver), m_screensaverNotify(false), - m_activeDesk(NULL), + m_activeDesk(nullptr), m_activeDeskName(), m_mutex(), m_deskReady(&m_mutex, false), @@ -155,7 +155,7 @@ void MSWindowsDesks::enable() // which desk is active and reinstalls the hooks as necessary. // we wouldn't need this if windows notified us of a desktop // change but as far as i can tell it doesn't. - m_timer = m_events->newTimer(0.2, NULL); + m_timer = m_events->newTimer(0.2, nullptr); m_events->adoptHandler( Event::kTimer, m_timer, new TMethodEventJob(this, &MSWindowsDesks::handleCheckDesk) ); @@ -166,10 +166,10 @@ void MSWindowsDesks::enable() void MSWindowsDesks::disable() { // remove timer - if (m_timer != NULL) { + if (m_timer != nullptr) { m_events->removeHandler(Event::kTimer, m_timer); m_events->deleteTimer(m_timer); - m_timer = NULL; + m_timer = nullptr; } // destroy desks @@ -321,7 +321,7 @@ void MSWindowsDesks::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const void MSWindowsDesks::sendMessage(UINT msg, WPARAM wParam, LPARAM lParam) const { - if (m_activeDesk != NULL && m_activeDesk->m_window != NULL) { + if (m_activeDesk != nullptr && m_activeDesk->m_window != nullptr) { PostThreadMessage(m_activeDesk->m_threadID, msg, wParam, lParam); waitForDesk(); } @@ -345,7 +345,7 @@ MSWindowsDesks::createBlankCursor() const void MSWindowsDesks::destroyCursor(HCURSOR cursor) const { - if (cursor != NULL) { + if (cursor != nullptr) { DestroyCursor(cursor); } } @@ -359,12 +359,12 @@ ATOM MSWindowsDesks::createDeskWindowClass(bool isPrimary) const classInfo.cbClsExtra = 0; classInfo.cbWndExtra = 0; classInfo.hInstance = MSWindowsScreen::getWindowInstance(); - classInfo.hIcon = NULL; + classInfo.hIcon = nullptr; classInfo.hCursor = m_cursor; - classInfo.hbrBackground = NULL; - classInfo.lpszMenuName = NULL; + classInfo.hbrBackground = nullptr; + classInfo.lpszMenuName = nullptr; classInfo.lpszClassName = "DeskflowDesk"; - classInfo.hIconSm = NULL; + classInfo.hIconSm = nullptr; return RegisterClassEx(&classInfo); } @@ -378,10 +378,10 @@ void MSWindowsDesks::destroyClass(ATOM windowClass) const HWND MSWindowsDesks::createWindow(ATOM windowClass, const char *name) const { HWND window = CreateWindowEx( - WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, MAKEINTATOM(windowClass), name, WS_POPUP, 0, 0, 1, 1, NULL, NULL, - MSWindowsScreen::getWindowInstance(), NULL + WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, MAKEINTATOM(windowClass), name, WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, + MSWindowsScreen::getWindowInstance(), nullptr ); - if (window == NULL) { + if (window == nullptr) { LOG((CLOG_ERR "failed to create window: %d", GetLastError())); throw XScreenOpenFailure(); } @@ -390,7 +390,7 @@ HWND MSWindowsDesks::createWindow(ATOM windowClass, const char *name) const void MSWindowsDesks::destroyWindow(HWND hwnd) const { - if (hwnd != NULL) { + if (hwnd != nullptr) { DestroyWindow(hwnd); } } @@ -481,13 +481,13 @@ void MSWindowsDesks::deskEnter(Desk *desk) // (mouse over activation) but i've no idea how to do that. // the obvious workaround of using SetWindowPos() to move it back // after being raised doesn't work. - DWORD thisThread = GetWindowThreadProcessId(desk->m_window, NULL); - DWORD thatThread = GetWindowThreadProcessId(desk->m_foregroundWindow, NULL); + DWORD thisThread = GetWindowThreadProcessId(desk->m_window, nullptr); + DWORD thatThread = GetWindowThreadProcessId(desk->m_foregroundWindow, nullptr); AttachThreadInput(thatThread, thisThread, TRUE); SetForegroundWindow(desk->m_foregroundWindow); AttachThreadInput(thatThread, thisThread, FALSE); EnableWindow(desk->m_window, desk->m_lowLevel ? FALSE : TRUE); - desk->m_foregroundWindow = NULL; + desk->m_foregroundWindow = nullptr; } void MSWindowsDesks::deskLeave(Desk *desk, HKL keyLayout) @@ -537,11 +537,11 @@ void MSWindowsDesks::deskLeave(Desk *desk, HKL keyLayout) // need to disable the window on deskEnter. else { desk->m_foregroundWindow = getForegroundWindow(); - if (desk->m_foregroundWindow != NULL) { + if (desk->m_foregroundWindow != nullptr) { EnableWindow(desk->m_window, TRUE); SetActiveWindow(desk->m_window); - DWORD thisThread = GetWindowThreadProcessId(desk->m_window, NULL); - DWORD thatThread = GetWindowThreadProcessId(desk->m_foregroundWindow, NULL); + DWORD thisThread = GetWindowThreadProcessId(desk->m_window, nullptr); + DWORD thatThread = GetWindowThreadProcessId(desk->m_foregroundWindow, nullptr); AttachThreadInput(thatThread, thisThread, TRUE); SetForegroundWindow(desk->m_window); @@ -571,11 +571,11 @@ void MSWindowsDesks::deskThread(void *vdesk) // use given desktop for this thread Desk *desk = static_cast(vdesk); desk->m_threadID = GetCurrentThreadId(); - desk->m_window = NULL; - desk->m_foregroundWindow = NULL; - if (desk->m_desk != NULL && SetThreadDesktop(desk->m_desk) != 0) { + desk->m_window = nullptr; + desk->m_foregroundWindow = nullptr; + if (desk->m_desk != nullptr && SetThreadDesktop(desk->m_desk) != 0) { // create a message queue - PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); + PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE); // create a window. we use this window to hide the cursor. try { @@ -594,7 +594,7 @@ void MSWindowsDesks::deskThread(void *vdesk) m_deskReady.broadcast(); } - while (GetMessage(&msg, NULL, 0, 0)) { + while (GetMessage(&msg, nullptr, 0, 0)) { switch (msg.message) { default: TranslateMessage(&msg); @@ -705,10 +705,10 @@ void MSWindowsDesks::deskThread(void *vdesk) // clean up deskEnter(desk); - if (desk->m_window != NULL) { + if (desk->m_window != nullptr) { DestroyWindow(desk->m_window); } - if (desk->m_desk != NULL) { + if (desk->m_desk != nullptr) { closeDesktop(desk->m_desk); } } @@ -735,7 +735,7 @@ void MSWindowsDesks::removeDesks() delete desk; } m_desks.clear(); - m_activeDesk = NULL; + m_activeDesk = nullptr; m_activeDeskName = ""; } @@ -805,7 +805,7 @@ void MSWindowsDesks::checkDesk() bool MSWindowsDesks::isDeskAccessible(const Desk *desk) const { - return (desk != NULL && desk->m_desk != NULL); + return (desk != nullptr && desk->m_desk != nullptr); } void MSWindowsDesks::waitForDesk() const @@ -840,18 +840,18 @@ MSWindowsDesks::openInputDesktop() void MSWindowsDesks::closeDesktop(HDESK desk) { - if (desk != NULL) { + if (desk != nullptr) { CloseDesktop(desk); } } std::string MSWindowsDesks::getDesktopName(HDESK desk) { - if (desk == NULL) { + if (desk == nullptr) { return std::string(); } else { DWORD size; - GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size); + GetUserObjectInformation(desk, UOI_NAME, nullptr, 0, &size); TCHAR *name = (TCHAR *)alloca(size + sizeof(TCHAR)); GetUserObjectInformation(desk, UOI_NAME, name, size, &size); std::string result(name); @@ -861,12 +861,12 @@ std::string MSWindowsDesks::getDesktopName(HDESK desk) HWND MSWindowsDesks::getForegroundWindow() const { - // Ideally we'd return NULL as much as possible, only returning + // Ideally we'd return nullptr as much as possible, only returning // the actual foreground window when we know it's going to mess // up our keyboard input. For now we'll just let the user // decide. if (m_leaveForegroundOption) { - return NULL; + return nullptr; } return GetForegroundWindow(); } diff --git a/src/lib/platform/MSWindowsDropTarget.cpp b/src/lib/platform/MSWindowsDropTarget.cpp index d65236701..41931659e 100644 --- a/src/lib/platform/MSWindowsDropTarget.cpp +++ b/src/lib/platform/MSWindowsDropTarget.cpp @@ -14,7 +14,7 @@ void getDropData(IDataObject *pDataObject); -MSWindowsDropTarget *MSWindowsDropTarget::s_instance = NULL; +MSWindowsDropTarget *MSWindowsDropTarget::s_instance = nullptr; MSWindowsDropTarget::MSWindowsDropTarget() : m_refCount(1), m_allowDrop(false) { @@ -27,7 +27,7 @@ MSWindowsDropTarget::~MSWindowsDropTarget() MSWindowsDropTarget &MSWindowsDropTarget::instance() { - assert(s_instance != NULL); + assert(s_instance != nullptr); return *s_instance; } diff --git a/src/lib/platform/MSWindowsEventQueueBuffer.cpp b/src/lib/platform/MSWindowsEventQueueBuffer.cpp index b9a6a2efc..bec7afbc2 100644 --- a/src/lib/platform/MSWindowsEventQueueBuffer.cpp +++ b/src/lib/platform/MSWindowsEventQueueBuffer.cpp @@ -36,7 +36,7 @@ MSWindowsEventQueueBuffer::MSWindowsEventQueueBuffer(IEventQueue *events) : m_ev // make sure this thread has a message queue MSG dummy; - PeekMessage(&dummy, NULL, WM_USER, WM_USER, PM_NOREMOVE); + PeekMessage(&dummy, nullptr, WM_USER, WM_USER, PM_NOREMOVE); } MSWindowsEventQueueBuffer::~MSWindowsEventQueueBuffer() @@ -77,12 +77,12 @@ IEventQueueBuffer::Type MSWindowsEventQueueBuffer::getEvent(Event &event, uint32 // if a message has been sent to our window but GetMessage will // dispatch that message behind our backs and block. PeekMessage // will also dispatch behind our backs but won't block. - if (!PeekMessage(&m_event, NULL, 0, 0, PM_NOREMOVE) && !PeekMessage(&m_event, (HWND)-1, 0, 0, PM_NOREMOVE)) { + if (!PeekMessage(&m_event, nullptr, 0, 0, PM_NOREMOVE) && !PeekMessage(&m_event, (HWND)-1, 0, 0, PM_NOREMOVE)) { return kNone; } // BOOL. yeah, right. - BOOL result = GetMessage(&m_event, NULL, 0, 0); + BOOL result = GetMessage(&m_event, nullptr, 0, 0); if (result == -1) { return kNone; } else if (result == 0) { diff --git a/src/lib/platform/MSWindowsHook.cpp b/src/lib/platform/MSWindowsHook.cpp index c974208e0..3d8070482 100644 --- a/src/lib/platform/MSWindowsHook.cpp +++ b/src/lib/platform/MSWindowsHook.cpp @@ -14,9 +14,9 @@ static const char *g_name = "dfwhook"; static DWORD g_processID = 0; static DWORD g_threadID = 0; -static HHOOK g_getMessage = NULL; -static HHOOK g_keyboardLL = NULL; -static HHOOK g_mouseLL = NULL; +static HHOOK g_getMessage = nullptr; +static HHOOK g_keyboardLL = nullptr; +static HHOOK g_mouseLL = nullptr; static bool g_screenSaver = false; static EHookMode g_mode = kHOOK_DISABLE; static uint32_t g_zoneSides = 0; @@ -69,7 +69,7 @@ int MSWindowsHook::init(DWORD threadID) // still running or if it died without cleaning up. if (g_processID != 0 && g_processID != GetCurrentProcessId()) { HANDLE process = OpenProcess(STANDARD_RIGHTS_REQUIRED, FALSE, g_processID); - if (process != NULL) { + if (process != nullptr) { // old process (probably) still exists so refuse to // reinitialize this DLL (and thus steal it from the // old process). @@ -83,9 +83,9 @@ int MSWindowsHook::init(DWORD threadID) // removed the hooks so we just need to reset our state. g_processID = GetCurrentProcessId(); g_threadID = 0; - g_getMessage = NULL; - g_keyboardLL = NULL; - g_mouseLL = NULL; + g_getMessage = nullptr; + g_keyboardLL = nullptr; + g_mouseLL = nullptr; g_screenSaver = false; } @@ -589,7 +589,7 @@ static LRESULT CALLBACK mouseLLHook(int code, WPARAM wParam, LPARAM lParam) EHookResult MSWindowsHook::install() { - assert(g_getMessage == NULL || g_screenSaver); + assert(g_getMessage == nullptr || g_screenSaver); // must be initialized if (g_threadID == 0) { @@ -604,32 +604,32 @@ EHookResult MSWindowsHook::install() g_fakeServerInput = false; // install low-level hooks. we require that they both get installed. - g_mouseLL = SetWindowsHookEx(WH_MOUSE_LL, &mouseLLHook, NULL, 0); + g_mouseLL = SetWindowsHookEx(WH_MOUSE_LL, &mouseLLHook, nullptr, 0); #if !NO_GRAB_KEYBOARD - g_keyboardLL = SetWindowsHookEx(WH_KEYBOARD_LL, &keyboardLLHook, NULL, 0); - if (g_mouseLL == NULL || g_keyboardLL == NULL) { - if (g_keyboardLL != NULL) { + g_keyboardLL = SetWindowsHookEx(WH_KEYBOARD_LL, &keyboardLLHook, nullptr, 0); + if (g_mouseLL == nullptr || g_keyboardLL == nullptr) { + if (g_keyboardLL != nullptr) { UnhookWindowsHookEx(g_keyboardLL); - g_keyboardLL = NULL; + g_keyboardLL = nullptr; } - if (g_mouseLL != NULL) { + if (g_mouseLL != nullptr) { UnhookWindowsHookEx(g_mouseLL); - g_mouseLL = NULL; + g_mouseLL = nullptr; } } #endif // check that we got all the hooks we wanted - if ((g_mouseLL == NULL) || + if ((g_mouseLL == nullptr) || #if !NO_GRAB_KEYBOARD - (g_keyboardLL == NULL) + (g_keyboardLL == nullptr) #endif ) { uninstall(); return kHOOK_FAILED; } - if (g_keyboardLL != NULL || g_mouseLL != NULL) { + if (g_keyboardLL != nullptr || g_mouseLL != nullptr) { g_hookThread = GetCurrentThreadId(); return kHOOK_OKAY_LL; } @@ -644,17 +644,17 @@ int MSWindowsHook::uninstall() g_deadLParam = 0; // uninstall hooks - if (g_keyboardLL != NULL) { + if (g_keyboardLL != nullptr) { UnhookWindowsHookEx(g_keyboardLL); - g_keyboardLL = NULL; + g_keyboardLL = nullptr; } - if (g_mouseLL != NULL) { + if (g_mouseLL != nullptr) { UnhookWindowsHookEx(g_mouseLL); - g_mouseLL = NULL; + g_mouseLL = nullptr; } - if (g_getMessage != NULL && !g_screenSaver) { + if (g_getMessage != nullptr && !g_screenSaver) { UnhookWindowsHookEx(g_getMessage); - g_getMessage = NULL; + g_getMessage = nullptr; } return 1; @@ -686,19 +686,19 @@ int MSWindowsHook::installScreenSaver() g_screenSaver = true; // install hook unless it's already installed - if (g_getMessage == NULL) { - g_getMessage = SetWindowsHookEx(WH_GETMESSAGE, &getMessageHook, NULL, 0); + if (g_getMessage == nullptr) { + g_getMessage = SetWindowsHookEx(WH_GETMESSAGE, &getMessageHook, nullptr, 0); } - return (g_getMessage != NULL) ? 1 : 0; + return (g_getMessage != nullptr) ? 1 : 0; } int MSWindowsHook::uninstallScreenSaver() { // uninstall hook unless the mouse wheel hook is installed - if (g_getMessage != NULL) { + if (g_getMessage != nullptr) { UnhookWindowsHookEx(g_getMessage); - g_getMessage = NULL; + g_getMessage = nullptr; } // screen saver hook is no longer installed diff --git a/src/lib/platform/MSWindowsKeyState.cpp b/src/lib/platform/MSWindowsKeyState.cpp index fe8e0423a..c13b6e853 100644 --- a/src/lib/platform/MSWindowsKeyState.cpp +++ b/src/lib/platform/MSWindowsKeyState.cpp @@ -562,7 +562,7 @@ MSWindowsKeyState::MSWindowsKeyState( m_eventTarget(eventTarget), m_desks(desks), m_keyLayout(GetKeyboardLayout(0)), - m_fixTimer(NULL), + m_fixTimer(nullptr), m_lastDown(0), m_useSavedModifiers(false), m_savedModifiers(0), @@ -580,7 +580,7 @@ MSWindowsKeyState::MSWindowsKeyState( m_eventTarget(eventTarget), m_desks(desks), m_keyLayout(GetKeyboardLayout(0)), - m_fixTimer(NULL), + m_fixTimer(nullptr), m_lastDown(0), m_useSavedModifiers(false), m_savedModifiers(0), @@ -604,10 +604,10 @@ void MSWindowsKeyState::init() void MSWindowsKeyState::disable() { - if (m_fixTimer != NULL) { + if (m_fixTimer != nullptr) { m_events->removeHandler(Event::kTimer, m_fixTimer); m_events->deleteTimer(m_fixTimer); - m_fixTimer = NULL; + m_fixTimer = nullptr; } m_lastDown = 0; } @@ -672,7 +672,7 @@ KeyID MSWindowsKeyState::mapKeyFromEvent(WPARAM charAndVirtKey, LPARAM info, Key } // set modifier mask - if (maskOut != NULL) { + if (maskOut != nullptr) { KeyModifierMask active = getActiveModifiers(); if (!noAltGr && (active & s_controlAlt) == s_controlAlt) { // if !noAltGr then we're only interested in matching the @@ -813,7 +813,7 @@ int32_t MSWindowsKeyState::pollActiveGroup() const { // determine the thread that'll receive this event HWND targetWindow = GetForegroundWindow(); - DWORD targetThread = GetWindowThreadProcessId(targetWindow, NULL); + DWORD targetThread = GetWindowThreadProcessId(targetWindow, nullptr); // get keyboard layout for the thread HKL hkl = GetKeyboardLayout(targetThread); @@ -822,7 +822,7 @@ int32_t MSWindowsKeyState::pollActiveGroup() const // GetKeyboardLayout failed. Maybe targetWindow is a console window. // We're getting the keyboard layout of the desktop instead. targetWindow = GetDesktopWindow(); - targetThread = GetWindowThreadProcessId(targetWindow, NULL); + targetThread = GetWindowThreadProcessId(targetWindow, nullptr); hkl = GetKeyboardLayout(targetThread); } @@ -1225,7 +1225,7 @@ KeyModifierMask &MSWindowsKeyState::getActiveModifiersRValue() bool MSWindowsKeyState::getGroups(GroupList &groups) const { // get keyboard layouts - uint32_t newNumLayouts = GetKeyboardLayoutList(0, NULL); + uint32_t newNumLayouts = GetKeyboardLayoutList(0, nullptr); if (newNumLayouts == 0) { LOG((CLOG_DEBUG1 "can't get keyboard layouts")); return false; diff --git a/src/lib/platform/MSWindowsKeyState.h b/src/lib/platform/MSWindowsKeyState.h index 559eb1f84..94b21d83c 100644 --- a/src/lib/platform/MSWindowsKeyState.h +++ b/src/lib/platform/MSWindowsKeyState.h @@ -216,7 +216,7 @@ private: KeyModifierMask m_savedModifiers; KeyModifierMask m_originalSavedModifiers; - // pointer to ToUnicodeEx. on win95 family this will be NULL. + // pointer to ToUnicodeEx. on win95 family this will be nullptr. typedef int(WINAPI *ToUnicodeEx_t)( UINT wVirtKey, UINT wScanCode, PBYTE lpKeyState, LPWSTR pwszBuff, int cchBuff, UINT wFlags, HKL dwhkl ); diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index eb158a39b..26842661e 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -78,8 +78,8 @@ // MSWindowsScreen // -HINSTANCE MSWindowsScreen::s_windowInstance = NULL; -MSWindowsScreen *MSWindowsScreen::s_screen = NULL; +HINSTANCE MSWindowsScreen::s_windowInstance = nullptr; +MSWindowsScreen *MSWindowsScreen::s_screen = nullptr; MSWindowsScreen::MSWindowsScreen( bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync, @@ -102,24 +102,24 @@ MSWindowsScreen::MSWindowsScreen( m_sequenceNumber(0), m_mark(0), m_markReceived(0), - m_fixTimer(NULL), - m_keyLayout(NULL), - m_screensaver(NULL), + m_fixTimer(nullptr), + m_keyLayout(nullptr), + m_screensaver(nullptr), m_screensaverNotify(false), m_screensaverActive(false), - m_window(NULL), + m_window(nullptr), m_clipboardSequenceNumber(0), m_ownClipboard(false), - m_desks(NULL), - m_keyState(NULL), + m_desks(nullptr), + m_keyState(nullptr), m_hasMouse(GetSystemMetrics(SM_MOUSEPRESENT) != 0), m_showingMouse(false), m_events(events), - m_dropWindow(NULL), + m_dropWindow(nullptr), m_dropWindowSize(20) { - assert(s_windowInstance != NULL); - assert(s_screen == NULL); + assert(s_windowInstance != nullptr); + assert(s_screen == nullptr); s_screen = this; try { @@ -145,7 +145,7 @@ MSWindowsScreen::MSWindowsScreen( // SHGetFolderPath is deprecated in vista, but use it for xp support. char desktopPath[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktopPath))) { + if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_DESKTOP, nullptr, 0, desktopPath))) { m_desktopPath = std::string(desktopPath); LOG((CLOG_DEBUG "using desktop for file drag-drop target: %s", m_desktopPath.c_str())); } else { @@ -166,7 +166,7 @@ MSWindowsScreen::MSWindowsScreen( delete m_screensaver; destroyWindow(m_window); destroyClass(m_class); - s_screen = NULL; + s_screen = nullptr; throw; } @@ -182,10 +182,10 @@ MSWindowsScreen::MSWindowsScreen( MSWindowsScreen::~MSWindowsScreen() { - assert(s_screen != NULL); + assert(s_screen != nullptr); disable(); - m_events->adoptBuffer(NULL); + m_events->adoptBuffer(nullptr); m_events->removeHandler(Event::kSystem, m_events->getSystemTarget()); delete m_keyState; delete m_desks; @@ -198,13 +198,13 @@ MSWindowsScreen::~MSWindowsScreen() OleUninitialize(); destroyWindow(m_dropWindow); - s_screen = NULL; + s_screen = nullptr; } void MSWindowsScreen::init(HINSTANCE windowInstance) { - assert(s_windowInstance == NULL); - assert(windowInstance != NULL); + assert(s_windowInstance == nullptr); + assert(windowInstance != nullptr); s_windowInstance = windowInstance; } @@ -220,7 +220,7 @@ void MSWindowsScreen::enable() assert(m_isOnScreen == m_isPrimary); // we need to poll some things to fix them - m_fixTimer = m_events->newTimer(1.0, NULL); + m_fixTimer = m_events->newTimer(1.0, nullptr); m_events->adoptHandler( Event::kTimer, m_fixTimer, new TMethodEventJob(this, &MSWindowsScreen::handleFixes) ); @@ -264,10 +264,10 @@ void MSWindowsScreen::disable() } // uninstall fix timer - if (m_fixTimer != NULL) { + if (m_fixTimer != nullptr) { m_events->removeHandler(Event::kTimer, m_fixTimer); m_events->deleteTimer(m_fixTimer); - m_fixTimer = NULL; + m_fixTimer = nullptr; } m_isOnScreen = m_isPrimary; @@ -293,7 +293,7 @@ void MSWindowsScreen::enter() // and that the screen is not in powersave mode. ArchMiscWindows::wakeupDisplay(); - if (m_screensaver != NULL && m_screensaverActive) { + if (m_screensaver != nullptr && m_screensaverActive) { m_screensaver->deactivate(); m_screensaverActive = 0; } @@ -386,7 +386,7 @@ void MSWindowsScreen::sendDragThread(void *) bool MSWindowsScreen::setClipboard(ClipboardID, const IClipboard *src) { MSWindowsClipboard dst(m_window); - if (src != NULL) { + if (src != nullptr) { // save clipboard data return Clipboard::copy(&dst, src); } else { @@ -423,7 +423,7 @@ void MSWindowsScreen::checkClipboards() void MSWindowsScreen::openScreensaver(bool notify) { - assert(m_screensaver != NULL); + assert(m_screensaver != nullptr); m_screensaverNotify = notify; if (m_screensaverNotify) { @@ -435,7 +435,7 @@ void MSWindowsScreen::openScreensaver(bool notify) void MSWindowsScreen::closeScreensaver() { - if (m_screensaver != NULL) { + if (m_screensaver != nullptr) { if (m_screensaverNotify) { m_desks->installScreensaverHooks(false); } else { @@ -447,8 +447,8 @@ void MSWindowsScreen::closeScreensaver() void MSWindowsScreen::screensaver(bool activate) { - assert(m_screensaver != NULL); - if (m_screensaver == NULL) + assert(m_screensaver != nullptr); + if (m_screensaver == nullptr) return; if (activate) { @@ -557,7 +557,7 @@ void MSWindowsScreen::updateDesktopThread() LOG_DEBUG("updating desktop thread"); HDESK hDesk = OpenInputDesktop(0, true, GENERIC_ALL); - if (hDesk == NULL) { + if (hDesk == nullptr) { XArchEvalWindows error1; LOG_DEBUG("could not open input desktop, error: %s", error1.eval().c_str()); return; @@ -589,7 +589,7 @@ void MSWindowsScreen::warpCursor(int32_t x, int32_t y) // remove all input events before and including warp MSG msg; - while (PeekMessage(&msg, NULL, DESKFLOW_MSG_INPUT_FIRST, DESKFLOW_MSG_INPUT_LAST, PM_REMOVE)) { + while (PeekMessage(&msg, nullptr, DESKFLOW_MSG_INPUT_FIRST, DESKFLOW_MSG_INPUT_LAST, PM_REMOVE)) { // do nothing } @@ -660,7 +660,7 @@ uint32_t MSWindowsScreen::registerHotKey(KeyID key, KeyModifierMask mask) err = (m_hotKeyToIDMap.count(HotKeyItem(vk, modifiers)) > 0); } else { // register with OS - err = (RegisterHotKey(NULL, id, modifiers, vk) == 0); + err = (RegisterHotKey(nullptr, id, modifiers, vk) == 0); } if (!err) { @@ -694,7 +694,7 @@ void MSWindowsScreen::unregisterHotKey(uint32_t id) // unregister with OS bool err; if (i->second.getVirtualKey() != 0) { - err = !UnregisterHotKey(NULL, id); + err = !UnregisterHotKey(nullptr, id); } else { err = false; } @@ -844,7 +844,7 @@ MSWindowsScreen::createBlankCursor() const void MSWindowsScreen::destroyCursor(HCURSOR cursor) const { - if (cursor != NULL) { + if (cursor != nullptr) { DestroyCursor(cursor); } } @@ -858,12 +858,12 @@ ATOM MSWindowsScreen::createWindowClass() const classInfo.cbClsExtra = 0; classInfo.cbWndExtra = 0; classInfo.hInstance = s_windowInstance; - classInfo.hIcon = NULL; - classInfo.hCursor = NULL; - classInfo.hbrBackground = NULL; - classInfo.lpszMenuName = NULL; + classInfo.hIcon = nullptr; + classInfo.hCursor = nullptr; + classInfo.hbrBackground = nullptr; + classInfo.lpszMenuName = nullptr; classInfo.lpszClassName = kAppName; - classInfo.hIconSm = NULL; + classInfo.hIconSm = nullptr; return RegisterClassEx(&classInfo); } @@ -877,10 +877,10 @@ void MSWindowsScreen::destroyClass(ATOM windowClass) const HWND MSWindowsScreen::createWindow(ATOM windowClass, const char *name) const { HWND window = CreateWindowEx( - WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, MAKEINTATOM(windowClass), name, WS_POPUP, 0, 0, 1, 1, NULL, - NULL, s_windowInstance, NULL + WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, MAKEINTATOM(windowClass), name, WS_POPUP, 0, 0, 1, 1, + nullptr, nullptr, s_windowInstance, nullptr ); - if (window == NULL) { + if (window == nullptr) { LOG((CLOG_ERR "failed to create window: %d", GetLastError())); throw XScreenOpenFailure(); } @@ -891,10 +891,10 @@ HWND MSWindowsScreen::createDropWindow(ATOM windowClass, const char *name) const { HWND window = CreateWindowEx( WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_ACCEPTFILES, MAKEINTATOM(m_class), name, WS_POPUP, 0, 0, - m_dropWindowSize, m_dropWindowSize, NULL, NULL, s_windowInstance, NULL + m_dropWindowSize, m_dropWindowSize, nullptr, nullptr, s_windowInstance, nullptr ); - if (window == NULL) { + if (window == nullptr) { LOG((CLOG_ERR "failed to create drop window: %d", GetLastError())); throw XScreenOpenFailure(); } @@ -904,7 +904,7 @@ HWND MSWindowsScreen::createDropWindow(ATOM windowClass, const char *name) const void MSWindowsScreen::destroyWindow(HWND hwnd) const { - if (hwnd != NULL) { + if (hwnd != nullptr) { DestroyWindow(hwnd); } } @@ -917,7 +917,7 @@ void MSWindowsScreen::sendEvent(Event::Type type, void *data) void MSWindowsScreen::sendClipboardEvent(Event::Type type, ClipboardID id) { ClipboardInfo *info = (ClipboardInfo *)malloc(sizeof(ClipboardInfo)); - if (info == NULL) { + if (info == nullptr) { LOG((CLOG_ERR "malloc failed on %s:%s", __FILE__, __LINE__)); return; } @@ -929,7 +929,7 @@ void MSWindowsScreen::sendClipboardEvent(Event::Type type, ClipboardID id) void MSWindowsScreen::handleSystemEvent(const Event &event, void *) { MSG *msg = static_cast(event.getData()); - assert(msg != NULL); + assert(msg != nullptr); if (onPreDispatch(msg->hwnd, msg->message, msg->wParam, msg->lParam)) { return; @@ -1006,7 +1006,7 @@ bool MSWindowsScreen::onPreDispatchPrimary(HWND, UINT message, WPARAM wParam, LP // event. MSG msg; do { - GetMessage(&msg, NULL, DESKFLOW_MSG_MOUSE_MOVE, DESKFLOW_MSG_POST_WARP); + GetMessage(&msg, nullptr, DESKFLOW_MSG_MOUSE_MOVE, DESKFLOW_MSG_POST_WARP); } while (msg.message != DESKFLOW_MSG_POST_WARP); } return true; @@ -1050,7 +1050,7 @@ bool MSWindowsScreen::onEvent(HWND, UINT msg, WPARAM wParam, LPARAM lParam, LRES /* On windows 10 we don't receive WM_POWERBROADCAST after sleep. We receive only WM_TIMECHANGE hence this message is used to resume.*/ case WM_TIMECHANGE: - m_events->addEvent(Event(m_events->forIScreen().resume(), getEventTarget(), NULL, Event::kDeliverImmediately)); + m_events->addEvent(Event(m_events->forIScreen().resume(), getEventTarget(), nullptr, Event::kDeliverImmediately)); break; case WM_POWERBROADCAST: @@ -1058,11 +1058,12 @@ bool MSWindowsScreen::onEvent(HWND, UINT msg, WPARAM wParam, LPARAM lParam, LRES case PBT_APMRESUMEAUTOMATIC: case PBT_APMRESUMECRITICAL: case PBT_APMRESUMESUSPEND: - m_events->addEvent(Event(m_events->forIScreen().resume(), getEventTarget(), NULL, Event::kDeliverImmediately)); + m_events->addEvent(Event(m_events->forIScreen().resume(), getEventTarget(), nullptr, Event::kDeliverImmediately)); break; case PBT_APMSUSPEND: - m_events->addEvent(Event(m_events->forIScreen().suspend(), getEventTarget(), NULL, Event::kDeliverImmediately)); + m_events->addEvent(Event(m_events->forIScreen().suspend(), getEventTarget(), nullptr, Event::kDeliverImmediately) + ); break; } *result = TRUE; @@ -1383,7 +1384,7 @@ bool MSWindowsScreen::onScreensaver(bool activated) // send SC_SCREENSAVE until the screen saver starts, even if // the screen saver is disabled! MSG msg; - if (PeekMessage(&msg, NULL, DESKFLOW_MSG_SCREEN_SAVER, DESKFLOW_MSG_SCREEN_SAVER, PM_NOREMOVE)) { + if (PeekMessage(&msg, nullptr, DESKFLOW_MSG_SCREEN_SAVER, DESKFLOW_MSG_SCREEN_SAVER, PM_NOREMOVE)) { return true; } @@ -1553,12 +1554,12 @@ void MSWindowsScreen::fixClipboardViewer() // recursion in the WM_DRAWCLIPBOARD handler. either we're sending // the message to our own window or some window farther down the chain // forwards the message to our window or a window farther up the chain. - // i'm not sure how that could happen. the m_nextClipboardWindow = NULL + // i'm not sure how that could happen. the m_nextClipboardWindow = nullptr // was not in the code that infinite loops and may fix the bug but i // doubt it. /* ChangeClipboardChain(m_window, m_nextClipboardWindow); - m_nextClipboardWindow = NULL; + m_nextClipboardWindow = nullptr; m_nextClipboardWindow = SetClipboardViewer(m_window); */ } @@ -1735,7 +1736,7 @@ void MSWindowsScreen::updateForceShowCursor() LRESULT CALLBACK MSWindowsScreen::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - assert(s_screen != NULL); + assert(s_screen != nullptr); LRESULT result = 0; if (!s_screen->onEvent(hwnd, msg, wParam, lParam, &result)) { diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h index 04b864574..7cd194492 100644 --- a/src/lib/platform/MSWindowsScreen.h +++ b/src/lib/platform/MSWindowsScreen.h @@ -152,7 +152,7 @@ private: // convenience function to send events public: // HACK - void sendEvent(Event::Type type, void * = NULL); + void sendEvent(Event::Type type, void * = nullptr); private: // HACK void sendClipboardEvent(Event::Type type, ClipboardID id); diff --git a/src/lib/platform/MSWindowsScreenSaver.cpp b/src/lib/platform/MSWindowsScreenSaver.cpp index 2f111dd50..f2b9cf7b0 100644 --- a/src/lib/platform/MSWindowsScreenSaver.cpp +++ b/src/lib/platform/MSWindowsScreenSaver.cpp @@ -23,7 +23,7 @@ static const TCHAR *g_isSecureNT = "ScreenSaverIsSecure"; static const TCHAR *g_isSecure9x = "ScreenSaveUsePassword"; -static const TCHAR *const g_pathScreenSaverIsSecure[] = {"Control Panel", "Desktop", NULL}; +static const TCHAR *const g_pathScreenSaverIsSecure[] = {"Control Panel", "Desktop", nullptr}; // // MSWindowsScreenSaver @@ -32,8 +32,8 @@ static const TCHAR *const g_pathScreenSaverIsSecure[] = {"Control Panel", "Deskt MSWindowsScreenSaver::MSWindowsScreenSaver() : m_wasSecure(false), m_wasSecureAnInt(false), - m_process(NULL), - m_watch(NULL), + m_process(nullptr), + m_watch(nullptr), m_threadID(0), m_msg(0), m_wParam(0), @@ -116,11 +116,11 @@ void MSWindowsScreenSaver::activate() if (!isActive()) { // activate HWND hwnd = GetForegroundWindow(); - if (hwnd != NULL) { + if (hwnd != nullptr) { PostMessage(hwnd, WM_SYSCOMMAND, SC_SCREENSAVE, 0); } else { // no foreground window. pretend we got the event instead. - DefWindowProc(NULL, WM_SYSCOMMAND, SC_SCREENSAVE, 0); + DefWindowProc(nullptr, WM_SYSCOMMAND, SC_SCREENSAVE, 0); } } } @@ -131,7 +131,7 @@ void MSWindowsScreenSaver::deactivate() // NT runs screen saver in another desktop HDESK desktop = OpenDesktop("Screen-saver", 0, FALSE, DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS); - if (desktop != NULL) { + if (desktop != nullptr) { EnumDesktopWindows(desktop, &MSWindowsScreenSaver::killScreenSaverFunc, reinterpret_cast(&killed)); CloseDesktop(desktop); } @@ -139,12 +139,12 @@ void MSWindowsScreenSaver::deactivate() // if above failed or wasn't tried, try the windows 95 way if (!killed) { // find screen saver window and close it - HWND hwnd = FindWindow("WindowsScreenSaverClass", NULL); - if (hwnd == NULL) { + HWND hwnd = FindWindow("WindowsScreenSaverClass", nullptr); + if (hwnd == nullptr) { // win2k may use a different class - hwnd = FindWindow("Default Screen Saver", NULL); + hwnd = FindWindow("Default Screen Saver", nullptr); } - if (hwnd != NULL) { + if (hwnd != nullptr) { PostMessage(hwnd, WM_CLOSE, 0, 0); } } @@ -191,7 +191,7 @@ void MSWindowsScreenSaver::watchProcess(HANDLE process) unwatchProcess(); // watch new process in another thread - if (process != NULL) { + if (process != nullptr) { LOG((CLOG_DEBUG "watching screen saver process")); m_process = process; m_active = true; @@ -201,24 +201,24 @@ void MSWindowsScreenSaver::watchProcess(HANDLE process) void MSWindowsScreenSaver::unwatchProcess() { - if (m_watch != NULL) { + if (m_watch != nullptr) { LOG((CLOG_DEBUG "stopped watching screen saver process/desktop")); m_watch->cancel(); m_watch->wait(); delete m_watch; - m_watch = NULL; + m_watch = nullptr; m_active = false; } - if (m_process != NULL) { + if (m_process != nullptr) { CloseHandle(m_process); - m_process = NULL; + m_process = nullptr; } } void MSWindowsScreenSaver::watchDesktopThread(void *) { DWORD reserved = 0; - TCHAR *name = NULL; + TCHAR *name = nullptr; for (;;) { // wait a bit @@ -256,7 +256,7 @@ void MSWindowsScreenSaver::watchProcessThread(void *) void MSWindowsScreenSaver::setSecure(bool secure, bool saveSecureAsInt) { HKEY hkey = ArchMiscWindows::addKey(HKEY_CURRENT_USER, g_pathScreenSaverIsSecure); - if (hkey == NULL) { + if (hkey == nullptr) { return; } @@ -273,7 +273,7 @@ bool MSWindowsScreenSaver::isSecure(bool *wasSecureFlagAnInt) const { // get the password protection setting key HKEY hkey = ArchMiscWindows::openKey(HKEY_CURRENT_USER, g_pathScreenSaverIsSecure); - if (hkey == NULL) { + if (hkey == nullptr) { return false; } diff --git a/src/lib/platform/MSWindowsSession.cpp b/src/lib/platform/MSWindowsSession.cpp index 4119708a8..e8691839e 100644 --- a/src/lib/platform/MSWindowsSession.cpp +++ b/src/lib/platform/MSWindowsSession.cpp @@ -20,7 +20,7 @@ MSWindowsSession::~MSWindowsSession() { } -bool MSWindowsSession::isProcessInSession(const char *name, PHANDLE process = NULL) +bool MSWindowsSession::isProcessInSession(const char *name, PHANDLE process = nullptr) { // first we need to take a snapshot of the running processes HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); @@ -91,7 +91,7 @@ bool MSWindowsSession::isProcessInSession(const char *name, PHANDLE process = NU CloseHandle(snapshot); if (pid) { - if (process != NULL) { + if (process != nullptr) { // now get the process, which we'll use to get the process token. LOG((CLOG_DEBUG "found %s in session %i", name, m_activeSessionId)); *process = OpenProcess(MAXIMUM_ALLOWED, FALSE, pid); diff --git a/src/lib/platform/MSWindowsUtil.cpp b/src/lib/platform/MSWindowsUtil.cpp index 8b02f9637..d52914d4a 100644 --- a/src/lib/platform/MSWindowsUtil.cpp +++ b/src/lib/platform/MSWindowsUtil.cpp @@ -17,7 +17,7 @@ std::string MSWindowsUtil::getString(HINSTANCE instance, DWORD id) { - char *msg = NULL; + char *msg = nullptr; int n = LoadString(instance, id, reinterpret_cast(&msg), 0); if (n <= 0) { @@ -32,7 +32,7 @@ std::string MSWindowsUtil::getErrorString(HINSTANCE hinstance, DWORD error, DWOR char *buffer; if (FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, 0, error, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buffer, 0, NULL + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buffer, 0, nullptr ) == 0) { std::string errorString = deskflow::string::sprintf("%d", error); return deskflow::string::format(getString(hinstance, id).c_str(), errorString.c_str()); diff --git a/src/lib/platform/OSXClipboard.cpp b/src/lib/platform/OSXClipboard.cpp index 5c79ff009..d19c78821 100644 --- a/src/lib/platform/OSXClipboard.cpp +++ b/src/lib/platform/OSXClipboard.cpp @@ -20,7 +20,7 @@ // OSXClipboard // -OSXClipboard::OSXClipboard() : m_time(0), m_pboard(NULL) +OSXClipboard::OSXClipboard() : m_time(0), m_pboard(nullptr) { m_converters.push_back(new OSXClipboardHTMLConverter); m_converters.push_back(new OSXClipboardBMPConverter); @@ -32,7 +32,7 @@ OSXClipboard::OSXClipboard() : m_time(0), m_pboard(NULL) if (createErr != noErr) { LOG((CLOG_WARN "failed to create clipboard reference: error %i", createErr)); LOG((CLOG_ERR "unable to connect to pasteboard, clipboard sharing disabled", createErr)); - m_pboard = NULL; + m_pboard = nullptr; return; } @@ -50,7 +50,7 @@ OSXClipboard::~OSXClipboard() bool OSXClipboard::empty() { LOG((CLOG_DEBUG "emptying clipboard")); - if (m_pboard == NULL) + if (m_pboard == nullptr) return false; OSStatus err = PasteboardClear(m_pboard); @@ -64,7 +64,7 @@ bool OSXClipboard::empty() bool OSXClipboard::synchronize() { - if (m_pboard == NULL) + if (m_pboard == nullptr) return false; PasteboardSyncFlags flags = PasteboardSynchronize(m_pboard); @@ -78,7 +78,7 @@ bool OSXClipboard::synchronize() void OSXClipboard::add(EFormat format, const std::string &data) { - if (m_pboard == NULL) + if (m_pboard == nullptr) return; LOG((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format)); @@ -113,7 +113,7 @@ void OSXClipboard::add(EFormat format, const std::string &data) bool OSXClipboard::open(Time time) const { - if (m_pboard == NULL) + if (m_pboard == nullptr) return false; LOG((CLOG_DEBUG "opening clipboard")); @@ -134,7 +134,7 @@ IClipboard::Time OSXClipboard::getTime() const bool OSXClipboard::has(EFormat format) const { - if (m_pboard == NULL) + if (m_pboard == nullptr) return false; PasteboardItemID item; @@ -163,13 +163,13 @@ std::string OSXClipboard::get(EFormat format) const PasteboardItemID item; std::string result; - if (m_pboard == NULL) + if (m_pboard == nullptr) return result; PasteboardGetItemIdentifier(m_pboard, (CFIndex)1, &item); // find the converter for the first clipboard format we can handle - IOSXClipboardConverter *converter = NULL; + IOSXClipboardConverter *converter = nullptr; for (ConverterList::const_iterator index = m_converters.begin(); index != m_converters.end(); ++index) { converter = *index; @@ -179,17 +179,17 @@ std::string OSXClipboard::get(EFormat format) const if (converter->getFormat() == format && PasteboardGetItemFlavorFlags(m_pboard, item, type, &flags) == noErr) { break; } - converter = NULL; + converter = nullptr; } // if no converter then we don't recognize any formats - if (converter == NULL) { + if (converter == nullptr) { LOG((CLOG_DEBUG "unable to find converter for data")); return result; } // get the clipboard data. - CFDataRef buffer = NULL; + CFDataRef buffer = nullptr; try { OSStatus err = PasteboardCopyItemFlavorData(m_pboard, item, type, &buffer); @@ -205,7 +205,7 @@ std::string OSXClipboard::get(EFormat format) const RETHROW_XTHREAD } - if (buffer != NULL) + if (buffer != nullptr) CFRelease(buffer); return converter->toIClipboard(result); @@ -213,7 +213,7 @@ std::string OSXClipboard::get(EFormat format) const void OSXClipboard::clearConverters() { - if (m_pboard == NULL) + if (m_pboard == nullptr) return; for (ConverterList::iterator index = m_converters.begin(); index != m_converters.end(); ++index) { diff --git a/src/lib/platform/OSXClipboardHTMLConverter.cpp b/src/lib/platform/OSXClipboardHTMLConverter.cpp index 619315778..dd172ac88 100644 --- a/src/lib/platform/OSXClipboardHTMLConverter.cpp +++ b/src/lib/platform/OSXClipboardHTMLConverter.cpp @@ -35,23 +35,23 @@ std::string OSXClipboardHTMLConverter::convertString( { CFStringRef stringRef = CFStringCreateWithCString(kCFAllocatorDefault, data.c_str(), fromEncoding); - if (stringRef == NULL) { + if (stringRef == nullptr) { return std::string(); } CFIndex buffSize; CFRange entireString = CFRangeMake(0, CFStringGetLength(stringRef)); - CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, NULL, 0, &buffSize); + CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, nullptr, 0, &buffSize); char *buffer = new char[buffSize]; - if (buffer == NULL) { + if (buffer == nullptr) { CFRelease(stringRef); return std::string(); } - CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, (uint8_t *)buffer, buffSize, NULL); + CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, (uint8_t *)buffer, buffSize, nullptr); std::string result(buffer, buffSize); diff --git a/src/lib/platform/OSXClipboardTextConverter.cpp b/src/lib/platform/OSXClipboardTextConverter.cpp index 5bda1a280..40c2d83f1 100644 --- a/src/lib/platform/OSXClipboardTextConverter.cpp +++ b/src/lib/platform/OSXClipboardTextConverter.cpp @@ -34,23 +34,23 @@ std::string OSXClipboardTextConverter::convertString( { CFStringRef stringRef = CFStringCreateWithCString(kCFAllocatorDefault, data.c_str(), fromEncoding); - if (stringRef == NULL) { + if (stringRef == nullptr) { return std::string(); } CFIndex buffSize; CFRange entireString = CFRangeMake(0, CFStringGetLength(stringRef)); - CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, NULL, 0, &buffSize); + CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, nullptr, 0, &buffSize); char *buffer = new char[buffSize]; - if (buffer == NULL) { + if (buffer == nullptr) { CFRelease(stringRef); return std::string(); } - CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, (uint8_t *)buffer, buffSize, NULL); + CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, (uint8_t *)buffer, buffSize, nullptr); std::string result(buffer, buffSize); diff --git a/src/lib/platform/OSXKeyState.cpp b/src/lib/platform/OSXKeyState.cpp index 40d94582f..c90bb6b2c 100644 --- a/src/lib/platform/OSXKeyState.cpp +++ b/src/lib/platform/OSXKeyState.cpp @@ -269,7 +269,7 @@ KeyButton OSXKeyState::mapKeyFromEvent(KeyIDs &ids, KeyModifierMask *maskOut, CG ids.clear(); // map modifier key - if (maskOut != NULL) { + if (maskOut != nullptr) { KeyModifierMask activeMask = getActiveModifiers(); activeMask &= ~KeyModifierAltGr; *maskOut = activeMask; @@ -331,7 +331,7 @@ KeyButton OSXKeyState::mapKeyFromEvent(KeyIDs &ids, KeyModifierMask *maskOut, CG // translate via uchr resource CFDataRef ref = (CFDataRef)TISGetInputSourceProperty(currentKeyboardLayout.get(), kTISPropertyUnicodeKeyLayoutData); const UCKeyboardLayout *layout = (const UCKeyboardLayout *)CFDataGetBytePtr(ref); - const bool layoutValid = (layout != NULL); + const bool layoutValid = (layout != nullptr); if (layoutValid) { // translate key @@ -485,7 +485,7 @@ void OSXKeyState::getKeyMap(deskflow::KeyMap &keyMap) TISInputSourceRef keyboardLayout = (TISInputSourceRef)CFArrayGetValueAtIndex(m_groups.get(), g); CFDataRef resourceRef = (CFDataRef)TISGetInputSourceProperty(keyboardLayout, kTISPropertyUnicodeKeyLayoutData); - layoutValid = resourceRef != NULL; + layoutValid = resourceRef != nullptr; if (layoutValid) resource = CFDataGetBytePtr(resourceRef); @@ -852,7 +852,9 @@ bool OSXKeyState::getGroups(AutoCFArray &groups) const // get number of layouts CFStringRef keys[] = {kTISPropertyInputSourceCategory}; CFStringRef values[] = {kTISCategoryKeyboardInputSource}; - AutoCFDictionary dict(CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL), CFRelease); + AutoCFDictionary dict( + CFDictionaryCreate(nullptr, (const void **)keys, (const void **)values, 1, nullptr, nullptr), CFRelease + ); AutoCFArray kbds(TISCreateInputSourceList(dict.get(), false), CFRelease); if (CFArrayGetCount(kbds.get()) > 0) { diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h index 81c641e51..cbcc53f57 100644 --- a/src/lib/platform/OSXScreen.h +++ b/src/lib/platform/OSXScreen.h @@ -116,7 +116,7 @@ private: void postMouseEvent(CGPoint &) const; // convenience function to send events - void sendEvent(Event::Type type, void * = NULL) const; + void sendEvent(Event::Type type, void * = nullptr) const; void sendClipboardEvent(Event::Type type, ClipboardID id) const; // message handlers diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 499c4172d..9b8a15f3f 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -86,18 +86,18 @@ OSXScreen::OSXScreen( MouseButtonEventMap(NumButtonIDs), m_cursorHidden(false), m_dragNumButtonsDown(0), - m_dragTimer(NULL), - m_keyState(NULL), + m_dragTimer(nullptr), + m_keyState(nullptr), m_sequenceNumber(0), - m_screensaver(NULL), + m_screensaver(nullptr), m_screensaverNotify(false), m_ownClipboard(false), - m_clipboardTimer(NULL), - m_hiddenWindow(NULL), - m_userInputWindow(NULL), + m_clipboardTimer(nullptr), + m_hiddenWindow(nullptr), + m_userInputWindow(nullptr), m_switchEventHandlerRef(0), m_pmMutex(new Mutex), - m_pmWatchThread(NULL), + m_pmWatchThread(nullptr), m_pmThreadReady(new CondVar(m_pmMutex, false)), m_pmRootPort(0), m_activeModifierHotKey(0), @@ -110,7 +110,7 @@ OSXScreen::OSXScreen( m_lastSingleClickYCursor(0), m_events(events), m_getDropTargetThread(nullptr), - m_impl(NULL) + m_impl(nullptr) { m_displayID = CGMainDisplayID(); if (!updateScreenShape(m_displayID, 0)) { @@ -186,7 +186,7 @@ OSXScreen::~OSXScreen() { disable(); - m_events->adoptBuffer(NULL); + m_events->adoptBuffer(nullptr); m_events->removeHandler(Event::kSystem, m_events->getSystemTarget()); if (m_pmWatchThread) { @@ -203,7 +203,7 @@ OSXScreen::~OSXScreen() CFRunLoopStop(m_pmRunloop); m_pmWatchThread->wait(); delete m_pmWatchThread; - m_pmWatchThread = NULL; + m_pmWatchThread = nullptr; } delete m_pmThreadReady; delete m_pmMutex; @@ -242,7 +242,7 @@ void OSXScreen::getShape(int32_t &x, int32_t &y, int32_t &w, int32_t &h) const void OSXScreen::getCursorPos(int32_t &x, int32_t &y) const { - CGEventRef event = CGEventCreate(NULL); + CGEventRef event = CGEventCreate(nullptr); CGPoint mouse = CGEventGetLocation(event); x = mouse.x; y = mouse.y; @@ -321,7 +321,7 @@ uint32_t OSXScreen::registerHotKey(KeyID key, KeyModifierMask mask) } // if this hot key has modifiers only then we'll handle it specially - EventHotKeyRef ref = NULL; + EventHotKeyRef ref = nullptr; bool okay; if (key == kKeyNone) { if (m_modifierHotKeys.count(mask) > 0) { @@ -367,7 +367,7 @@ void OSXScreen::unregisterHotKey(uint32_t id) // unregister with OS bool okay; - if (i->second.getRef() != NULL) { + if (i->second.getRef() != nullptr) { okay = (UnregisterEventHotKey(i->second.getRef()) == noErr); } else { okay = false; @@ -421,7 +421,7 @@ void OSXScreen::postMouseEvent(CGPoint &pos) const // check if cursor position is valid on the client display configuration // stkamp@users.sourceforge.net CGDisplayCount displayCount = 0; - CGGetDisplaysWithPoint(pos, 0, NULL, &displayCount); + CGGetDisplaysWithPoint(pos, 0, nullptr, &displayCount); if (displayCount == 0) { // cursor position invalid - clamp to bounds of last valid display. // find the last valid display using the last cursor position. @@ -451,7 +451,7 @@ void OSXScreen::postMouseEvent(CGPoint &pos) const type = thisButtonType[kMouseButtonDragged]; } - CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, static_cast(button)); + CGEventRef event = CGEventCreateMouseEvent(nullptr, type, pos, static_cast(button)); // Dragging events also need the click state CGEventSetIntegerValueField(event, kCGMouseEventClickState, m_clickState); @@ -535,7 +535,7 @@ void OSXScreen::fakeMouseButton(ButtonID id, bool press) MouseButtonEventMapType thisButtonMap = MouseButtonEventMap[index]; CGEventType type = thisButtonMap[state]; - CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, static_cast(index)); + CGEventRef event = CGEventCreateMouseEvent(nullptr, type, pos, static_cast(index)); CGEventSetIntegerValueField(event, kCGMouseEventClickState, m_clickState); @@ -569,7 +569,7 @@ void OSXScreen::getDropTargetThread(void *) char *cstr = CFStringRefToUTF8String(cfstr); CFRelease(cfstr); - if (cstr != NULL) { + if (cstr != nullptr) { LOG((CLOG_DEBUG "drop target: %s", cstr)); m_dropTarget = cstr; free(cstr); @@ -616,7 +616,7 @@ void OSXScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const // we can do. // get current position - CGEventRef event = CGEventCreate(NULL); + CGEventRef event = CGEventCreate(nullptr); CGPoint oldPos = CGEventGetLocation(event); CFRelease(event); @@ -638,7 +638,7 @@ void OSXScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const // create a scroll event, post it and release it. not sure if kCGScrollEventUnitLine // is the right choice here over kCGScrollEventUnitPixel CGEventRef scrollEvent = CGEventCreateScrollWheelEvent( - NULL, kCGScrollEventUnitLine, 2, mapScrollWheelFromDeskflow(yDelta), mapScrollWheelFromDeskflow(xDelta) + nullptr, kCGScrollEventUnitLine, 2, mapScrollWheelFromDeskflow(yDelta), mapScrollWheelFromDeskflow(xDelta) ); // Fix for sticky keys @@ -654,7 +654,7 @@ void OSXScreen::showCursor() { LOG((CLOG_DEBUG "showing cursor")); - CFStringRef propertyString = CFStringCreateWithCString(NULL, "SetsCursorInBackground", kCFStringEncodingMacRoman); + CFStringRef propertyString = CFStringCreateWithCString(nullptr, "SetsCursorInBackground", kCFStringEncodingMacRoman); CGSSetConnectionProperty(_CGSDefaultConnection(), _CGSDefaultConnection(), propertyString, kCFBooleanTrue); @@ -677,7 +677,7 @@ void OSXScreen::hideCursor() { LOG((CLOG_DEBUG "hiding cursor")); - CFStringRef propertyString = CFStringCreateWithCString(NULL, "SetsCursorInBackground", kCFStringEncodingMacRoman); + CFStringRef propertyString = CFStringCreateWithCString(nullptr, "SetsCursorInBackground", kCFStringEncodingMacRoman); CGSSetConnectionProperty(_CGSDefaultConnection(), _CGSDefaultConnection(), propertyString, kCFBooleanTrue); @@ -699,7 +699,7 @@ void OSXScreen::hideCursor() void OSXScreen::enable() { // watch the clipboard - m_clipboardTimer = m_events->newTimer(1.0, NULL); + m_clipboardTimer = m_events->newTimer(1.0, nullptr); m_events->adoptHandler( Event::kTimer, m_clipboardTimer, new TMethodEventJob(this, &OSXScreen::handleClipboardCheck) ); @@ -765,10 +765,10 @@ void OSXScreen::disable() enableDragTimer(false); // uninstall clipboard timer - if (m_clipboardTimer != NULL) { + if (m_clipboardTimer != nullptr) { m_events->removeHandler(Event::kTimer, m_clipboardTimer); m_events->deleteTimer(m_clipboardTimer); - m_clipboardTimer = NULL; + m_clipboardTimer = nullptr; } m_isOnScreen = m_isPrimary; @@ -842,7 +842,7 @@ void OSXScreen::leave() bool OSXScreen::setClipboard(ClipboardID, const IClipboard *src) { - if (src != NULL) { + if (src != nullptr) { LOG((CLOG_DEBUG "setting clipboard")); Clipboard::copy(&m_pasteboard, src); } @@ -919,7 +919,7 @@ void OSXScreen::sendClipboardEvent(Event::Type type, ClipboardID id) const void OSXScreen::handleSystemEvent(const Event &event, void *) { EventRef *carbonEvent = static_cast(event.getData()); - assert(carbonEvent != NULL); + assert(carbonEvent != nullptr); uint32_t eventClass = GetEventClass(*carbonEvent); @@ -932,11 +932,15 @@ void OSXScreen::handleSystemEvent(const Event &event, void *) long yScroll; // get scroll amount - r = GetEventParameter(*carbonEvent, kDeskflowMouseScrollAxisX, typeSInt32, NULL, sizeof(xScroll), NULL, &xScroll); + r = GetEventParameter( + *carbonEvent, kDeskflowMouseScrollAxisX, typeSInt32, nullptr, sizeof(xScroll), nullptr, &xScroll + ); if (r != noErr) { xScroll = 0; } - r = GetEventParameter(*carbonEvent, kDeskflowMouseScrollAxisY, typeSInt32, NULL, sizeof(yScroll), NULL, &yScroll); + r = GetEventParameter( + *carbonEvent, kDeskflowMouseScrollAxisY, typeSInt32, nullptr, sizeof(yScroll), nullptr, &yScroll + ); if (r != noErr) { yScroll = 0; } @@ -961,8 +965,8 @@ void OSXScreen::handleSystemEvent(const Event &event, void *) case kEventClassWindow: // 2nd param was formerly GetWindowEventTarget(m_userInputWindow) which is 32-bit only, // however as m_userInputWindow is never initialized to anything we can take advantage of - // the fact that GetWindowEventTarget(NULL) == NULL - SendEventToEventTarget(*carbonEvent, NULL); + // the fact that GetWindowEventTarget(nullptr) == nullptr + SendEventToEventTarget(*carbonEvent, nullptr); switch (GetEventKind(*carbonEvent)) { case kEventWindowActivated: LOG((CLOG_DEBUG1 "window activated")); @@ -1265,7 +1269,7 @@ bool OSXScreen::onHotKey(EventRef event) const { // get the hotkey id EventHotKeyID hkid; - GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(EventHotKeyID), NULL, &hkid); + GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, nullptr, sizeof(EventHotKeyID), nullptr, &hkid); uint32_t id = hkid.id; // determine event type @@ -1337,7 +1341,7 @@ double OSXScreen::getScrollSpeed() const CFSTR("com.apple.scrollwheel.scaling"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost ); - if (pref != NULL) { + if (pref != nullptr) { CFTypeID id = CFGetTypeID(pref); if (id == CFNumberGetTypeID()) { CFNumberRef value = static_cast(pref); @@ -1355,24 +1359,24 @@ double OSXScreen::getScrollSpeed() const void OSXScreen::enableDragTimer(bool enable) { - if (enable && m_dragTimer == NULL) { - m_dragTimer = m_events->newTimer(0.01, NULL); + if (enable && m_dragTimer == nullptr) { + m_dragTimer = m_events->newTimer(0.01, nullptr); m_events->adoptHandler(Event::kTimer, m_dragTimer, new TMethodEventJob(this, &OSXScreen::handleDrag)); - CGEventRef event = CGEventCreate(NULL); + CGEventRef event = CGEventCreate(nullptr); CGPoint mouse = CGEventGetLocation(event); m_dragLastPoint.h = (short)mouse.x; m_dragLastPoint.v = (short)mouse.y; CFRelease(event); - } else if (!enable && m_dragTimer != NULL) { + } else if (!enable && m_dragTimer != nullptr) { m_events->removeHandler(Event::kTimer, m_dragTimer); m_events->deleteTimer(m_dragTimer); - m_dragTimer = NULL; + m_dragTimer = nullptr; } } void OSXScreen::handleDrag(const Event &, void *) { - CGEventRef event = CGEventCreate(NULL); + CGEventRef event = CGEventCreate(nullptr); CGPoint p = CGEventGetLocation(event); CFRelease(event); @@ -1405,7 +1409,7 @@ bool OSXScreen::updateScreenShape() // get info for each display CGDisplayCount displayCount = 0; - if (CGGetActiveDisplayList(0, NULL, &displayCount) != CGDisplayNoErr) { + if (CGGetActiveDisplayList(0, nullptr, &displayCount) != CGDisplayNoErr) { return false; } @@ -1414,7 +1418,7 @@ bool OSXScreen::updateScreenShape() } CGDirectDisplayID *displays = new CGDirectDisplayID[displayCount]; - if (displays == NULL) { + if (displays == nullptr) { return false; } @@ -1597,7 +1601,8 @@ void OSXScreen::handleConfirmSleep(const Event &event, void *) Lock lock(m_pmMutex); if (m_pmRootPort != 0) { // deliver suspend event immediately. - m_events->addEvent(Event(m_events->forIScreen().suspend(), getEventTarget(), NULL, Event::kDeliverImmediately)); + m_events->addEvent(Event(m_events->forIScreen().suspend(), getEventTarget(), nullptr, Event::kDeliverImmediately) + ); LOG((CLOG_DEBUG "system will sleep")); IOAllowPowerChange(m_pmRootPort, messageArg); @@ -1650,7 +1655,7 @@ static CGSSetGlobalHotKeyOperatingMode_t s_CGSSetGlobalHotKeyOperatingMode; #endif #define LOOKUP(name_) \ - s_##name_ = NULL; \ + s_##name_ = nullptr; \ if (NSIsSymbolNameDefinedWithHint("_" #name_, "CoreGraphics")) { \ s_##name_ = (name_##_t)NSAddressOfSymbol(NSLookupAndBindSymbolWithHint("_" #name_, "CoreGraphics")); \ } @@ -1663,9 +1668,9 @@ OSXScreen::isGlobalHotKeyOperatingModeAvailable() LOOKUP(_CGSDefaultConnection); LOOKUP(CGSGetGlobalHotKeyOperatingMode); LOOKUP(CGSSetGlobalHotKeyOperatingMode); - s_hasGHOM = (s__CGSDefaultConnection != NULL && - s_CGSGetGlobalHotKeyOperatingMode != NULL && - s_CGSSetGlobalHotKeyOperatingMode != NULL); + s_hasGHOM = (s__CGSDefaultConnection != nullptr && + s_CGSGetGlobalHotKeyOperatingMode != nullptr && + s_CGSSetGlobalHotKeyOperatingMode != nullptr); } return s_hasGHOM; } @@ -1708,7 +1713,7 @@ OSXScreen::getGlobalHotKeysEnabled() // OSXScreen::HotKeyItem // -OSXScreen::HotKeyItem::HotKeyItem(uint32_t keycode, uint32_t mask) : m_ref(NULL), m_keycode(keycode), m_mask(mask) +OSXScreen::HotKeyItem::HotKeyItem(uint32_t keycode, uint32_t mask) : m_ref(nullptr), m_keycode(keycode), m_mask(mask) { // do nothing } @@ -1823,7 +1828,7 @@ CGEventRef OSXScreen::handleCGInputEvent(CGEventTapProxy proxy, CGEventType type if (screen->m_isOnScreen) { return event; } else { - return NULL; + return nullptr; } } @@ -1867,8 +1872,8 @@ int8_t OSXScreen::MouseButtonState::getFirstButtonDown() const char *OSXScreen::CFStringRefToUTF8String(CFStringRef aString) { - if (aString == NULL) { - return NULL; + if (aString == nullptr) { + return nullptr; } CFIndex length = CFStringGetLength(aString); @@ -1877,7 +1882,7 @@ char *OSXScreen::CFStringRefToUTF8String(CFStringRef aString) if (!CFStringGetCString(aString, buffer, maxSize, kCFStringEncodingUTF8)) { free(buffer); - buffer = NULL; + buffer = nullptr; } return buffer; @@ -1903,7 +1908,7 @@ std::string &OSXScreen::getDraggingFilename() char *info = CFStringRefToUTF8String(dragInfo); CFRelease(dragInfo); - if (info != NULL) { + if (info != nullptr) { LOG((CLOG_DEBUG "drag info: %s", info)); m_draggingFilename = info; free(info); @@ -1966,7 +1971,7 @@ int getSecureInputEventPID() std::unique_ptr::type, decltype(&CFRelease)> consoleUsers( IORegistryEntrySearchCFProperty( - service_root, kIOServicePlane, CFSTR("IOConsoleUsers"), NULL, + service_root, kIOServicePlane, CFSTR("IOConsoleUsers"), nullptr, kIORegistryIterateParents | kIORegistryIterateRecursively ), CFRelease diff --git a/src/lib/platform/OSXUchrKeyResource.cpp b/src/lib/platform/OSXUchrKeyResource.cpp index ed278cb5f..3e5678e7e 100644 --- a/src/lib/platform/OSXUchrKeyResource.cpp +++ b/src/lib/platform/OSXUchrKeyResource.cpp @@ -13,19 +13,19 @@ // OSXUchrKeyResource::OSXUchrKeyResource(const void *resource, uint32_t keyboardType) - : m_m(NULL), - m_cti(NULL), - m_sdi(NULL), - m_sri(NULL), - m_st(NULL) + : m_m(nullptr), + m_cti(nullptr), + m_sdi(nullptr), + m_sri(nullptr), + m_st(nullptr) { m_resource = static_cast(resource); - if (m_resource == NULL) { + if (m_resource == nullptr) { return; } // find the keyboard info for the current keyboard type - const UCKeyboardTypeHeader *th = NULL; + const UCKeyboardTypeHeader *th = nullptr; const UCKeyboardLayout *r = m_resource; for (ItemCount i = 0; i < r->keyboardTypeCount; ++i) { if (keyboardType >= r->keyboardTypeList[i].keyboardTypeFirst && @@ -38,7 +38,7 @@ OSXUchrKeyResource::OSXUchrKeyResource(const void *resource, uint32_t keyboardTy th = r->keyboardTypeList + i; } } - if (th == NULL) { + if (th == nullptr) { // cannot find a suitable keyboard type return; } @@ -74,7 +74,7 @@ OSXUchrKeyResource::OSXUchrKeyResource(const void *resource, uint32_t keyboardTy bool OSXUchrKeyResource::isValid() const { - return (m_m != NULL); + return (m_m != nullptr); } uint32_t OSXUchrKeyResource::getNumModifierCombinations() const @@ -138,7 +138,7 @@ KeyID OSXUchrKeyResource::getKey(uint32_t table, uint32_t button) const bool OSXUchrKeyResource::getDeadKey(KeySequence &keys, uint16_t index) const { - if (m_sri == NULL || index >= m_sri->keyStateRecordCount) { + if (m_sri == nullptr || index >= m_sri->keyStateRecordCount) { // XXX -- should we be using some other fallback? return false; } @@ -218,7 +218,7 @@ bool OSXUchrKeyResource::getKeyRecord(KeySequence &keys, uint16_t index, uint16_ } if (!found) { // use a terminator - if (m_st != NULL && state < m_st->keyStateTerminatorCount) { + if (m_st != nullptr && state < m_st->keyStateTerminatorCount) { if (!addSequence(keys, m_st->keyStateTerminators[state - 1])) { return false; } diff --git a/src/lib/platform/XWindowsClipboard.h b/src/lib/platform/XWindowsClipboard.h index f327bec57..949e5a187 100644 --- a/src/lib/platform/XWindowsClipboard.h +++ b/src/lib/platform/XWindowsClipboard.h @@ -92,9 +92,9 @@ private: // remove all converters from our list void clearConverters(); - // get the converter for a clipboard format. returns NULL if no + // get the converter for a clipboard format. returns nullptr if no // suitable converter. iff onlyIfNotAdded is true then also - // return NULL if a suitable converter was found but we already + // return nullptr if a suitable converter was found but we already // have data of the converter's clipboard format. IXWindowsClipboardConverter *getConverter(Atom target, bool onlyIfNotAdded = false) const; diff --git a/src/lib/platform/XWindowsEventQueueBuffer.cpp b/src/lib/platform/XWindowsEventQueueBuffer.cpp index a48e893e4..97f504bca 100644 --- a/src/lib/platform/XWindowsEventQueueBuffer.cpp +++ b/src/lib/platform/XWindowsEventQueueBuffer.cpp @@ -37,7 +37,7 @@ XWindowsEventQueueBuffer::XWindowsEventQueueBuffer(Display *display, Window wind m_window(window), m_waiting(false) { - assert(m_display != NULL); + assert(m_display != nullptr); assert(m_window != None); m_userEvent = XInternAtom(m_display, "DESKFLOW_USER_EVENT", False); diff --git a/src/lib/platform/XWindowsKeyState.cpp b/src/lib/platform/XWindowsKeyState.cpp index 08d9db929..ab4c5b525 100644 --- a/src/lib/platform/XWindowsKeyState.cpp +++ b/src/lib/platform/XWindowsKeyState.cpp @@ -59,7 +59,7 @@ XWindowsKeyState::XWindowsKeyState(Display *display, bool useXKB, IEventQueue *e XWindowsKeyState::~XWindowsKeyState() { #if HAVE_XKB_EXTENSION - if (m_xkb != NULL) { + if (m_xkb != nullptr) { XkbFreeKeyboard(m_xkb, 0, True); } #endif @@ -72,7 +72,7 @@ void XWindowsKeyState::init(Display *display, bool useXKB) if (useXKB) { m_xkb = XkbGetMap(m_display, XkbKeyActionsMask | XkbKeyBehaviorsMask | XkbAllClientInfoMask, XkbUseCoreKbd); } else { - m_xkb = NULL; + m_xkb = nullptr; } #endif setActiveGroup(kGroupPoll); @@ -173,7 +173,7 @@ int32_t XWindowsKeyState::pollActiveGroup() const } #if HAVE_XKB_EXTENSION - if (m_xkb != NULL) { + if (m_xkb != nullptr) { XkbStateRec state; XSync(m_display, False); if (XkbGetState(m_display, XkbUseCoreKbd, &state) == Success) { @@ -208,7 +208,7 @@ void XWindowsKeyState::getKeyMap(deskflow::KeyMap &keyMap) m_keyboardState.global_auto_repeat = oldGlobalAutoRepeat; #if HAVE_XKB_EXTENSION - if (m_xkb != NULL) { + if (m_xkb != nullptr) { if (XkbGetUpdatedMap(m_display, XkbKeyActionsMask | XkbKeyBehaviorsMask | XkbAllClientInfoMask, m_xkb) == Success) { updateKeysymMapXKB(keyMap); return; @@ -294,7 +294,7 @@ void XWindowsKeyState::fakeKey(const Keystroke &keystroke) } #endif #if HAVE_XKB_EXTENSION - if (m_xkb != NULL) { + if (m_xkb != nullptr) { if (XkbLockGroup(m_display, XkbUseCoreKbd, keystroke.m_data.m_group.m_group) == False) { LOG((CLOG_DEBUG1 "xkb lock group request not sent")); } @@ -311,7 +311,7 @@ void XWindowsKeyState::fakeKey(const Keystroke &keystroke) } #endif #if HAVE_XKB_EXTENSION - if (m_xkb != NULL) { + if (m_xkb != nullptr) { if (XkbLockGroup( m_display, XkbUseCoreKbd, getEffectiveGroup(pollActiveGroup(), keystroke.m_data.m_group.m_group) ) == False) { @@ -637,7 +637,7 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap) // set required modifiers for this item item.m_required = mapEntry->mods.mask; - if ((item.m_required & LockMask) != 0 && j != -1 && type->preserve != NULL && + if ((item.m_required & LockMask) != 0 && j != -1 && type->preserve != nullptr && (type->preserve[j].mask & LockMask) != 0) { // sensitive caps lock and we preserve caps-lock. // preserving caps-lock means we Xlib functions would @@ -847,7 +847,7 @@ int XWindowsKeyState::getEffectiveGroup(KeyCode keycode, int group) const uint32_t XWindowsKeyState::getGroupFromState(unsigned int state) const { #if HAVE_XKB_EXTENSION - if (m_xkb != NULL) { + if (m_xkb != nullptr) { return XkbGroupForCoreState(state); } #endif diff --git a/src/lib/platform/XWindowsScreen.cpp b/src/lib/platform/XWindowsScreen.cpp index 7b7d81dbd..49749df6f 100644 --- a/src/lib/platform/XWindowsScreen.cpp +++ b/src/lib/platform/XWindowsScreen.cpp @@ -83,7 +83,7 @@ static int xi_opcode; // display and the X11 event queue buffer, ignore any calls that try // to use the display, and wait to be destroyed. -XWindowsScreen *XWindowsScreen::s_screen = NULL; +XWindowsScreen *XWindowsScreen::s_screen = nullptr; XWindowsScreen::XWindowsScreen( const char *displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, IEventQueue *events, @@ -92,7 +92,7 @@ XWindowsScreen::XWindowsScreen( : PlatformScreen(events, scrollDirection), m_isPrimary(isPrimary), m_mouseScrollDelta(mouseScrollDelta), - m_display(NULL), + m_display(nullptr), m_root(None), m_window(None), m_isOnScreen(m_isPrimary), @@ -104,14 +104,14 @@ XWindowsScreen::XWindowsScreen( m_yCenter(0), m_xCursor(0), m_yCursor(0), - m_keyState(NULL), + m_keyState(nullptr), m_lastFocus(None), m_lastFocusRevert(RevertToNone), - m_im(NULL), - m_ic(NULL), + m_im(nullptr), + m_ic(nullptr), m_lastKeycode(0), m_sequenceNumber(0), - m_screensaver(NULL), + m_screensaver(nullptr), m_screensaverNotify(false), m_xtestIsXineramaUnaware(true), m_preserveFocus(false), @@ -120,7 +120,7 @@ XWindowsScreen::XWindowsScreen( m_xrandr(false), m_events(events) { - assert(s_screen == NULL); + assert(s_screen == nullptr); if (mouseScrollDelta == 0) m_mouseScrollDelta = 120; @@ -147,7 +147,7 @@ XWindowsScreen::XWindowsScreen( LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_xinerama ? "(xinerama)" : "")); LOG((CLOG_DEBUG "window is 0x%08x", m_window)); } catch (...) { - if (m_display != NULL) { + if (m_display != nullptr) { XCloseDisplay(m_display); } throw; @@ -195,32 +195,32 @@ XWindowsScreen::XWindowsScreen( XWindowsScreen::~XWindowsScreen() { - assert(s_screen != NULL); - assert(m_display != NULL); + assert(s_screen != nullptr); + assert(m_display != nullptr); - m_events->adoptBuffer(NULL); + m_events->adoptBuffer(nullptr); m_events->removeHandler(Event::kSystem, m_events->getSystemTarget()); for (ClipboardID id = 0; id < kClipboardEnd; ++id) { delete m_clipboard[id]; } delete m_keyState; delete m_screensaver; - m_keyState = NULL; - m_screensaver = NULL; - if (m_display != NULL) { + m_keyState = nullptr; + m_screensaver = nullptr; + if (m_display != nullptr) { // FIXME -- is it safe to clean up the IC and IM without a display? - if (m_ic != NULL) { + if (m_ic != nullptr) { XDestroyIC(m_ic); } - if (m_im != NULL) { + if (m_im != nullptr) { XCloseIM(m_im); } XDestroyWindow(m_display, m_window); XCloseDisplay(m_display); } - XSetIOErrorHandler(NULL); + XSetIOErrorHandler(nullptr); - s_screen = NULL; + s_screen = nullptr; } void XWindowsScreen::enable() @@ -247,7 +247,7 @@ void XWindowsScreen::enable() void XWindowsScreen::disable() { // release input context focus - if (m_ic != NULL) { + if (m_ic != nullptr) { XUnsetICFocus(m_ic); } @@ -266,7 +266,7 @@ void XWindowsScreen::enter() screensaver(false); // release input context focus - if (m_ic != NULL) { + if (m_ic != nullptr) { XUnsetICFocus(m_ic); } @@ -368,7 +368,7 @@ void XWindowsScreen::leave() } // set input context focus to our window - if (m_ic != NULL) { + if (m_ic != nullptr) { XmbResetIC(m_ic); XSetICFocus(m_ic); m_filtered.clear(); @@ -381,14 +381,14 @@ void XWindowsScreen::leave() bool XWindowsScreen::setClipboard(ClipboardID id, const IClipboard *clipboard) { // fail if we don't have the requested clipboard - if (m_clipboard[id] == NULL) { + if (m_clipboard[id] == nullptr) { return false; } // get the actual time. ICCCM does not allow CurrentTime. Time timestamp = XWindowsUtil::getCurrentTime(m_display, m_clipboard[id]->getWindow()); - if (clipboard != NULL) { + if (clipboard != nullptr) { // save clipboard data return Clipboard::copy(m_clipboard[id], clipboard, timestamp); } else { @@ -473,10 +473,10 @@ void *XWindowsScreen::getEventTarget() const bool XWindowsScreen::getClipboard(ClipboardID id, IClipboard *clipboard) const { - assert(clipboard != NULL); + assert(clipboard != nullptr); // fail if we don't have the requested clipboard - if (m_clipboard[id] == NULL) { + if (m_clipboard[id] == nullptr) { return false; } @@ -857,9 +857,9 @@ void XWindowsScreen::fakeMouseWheel(int32_t, int32_t yDelta) const Display *XWindowsScreen::openDisplay(const char *displayName) { // get the DISPLAY - if (displayName == NULL) { + if (displayName == nullptr) { displayName = getenv("DISPLAY"); - if (displayName == NULL) { + if (displayName == nullptr) { displayName = ":0.0"; } } @@ -867,7 +867,7 @@ Display *XWindowsScreen::openDisplay(const char *displayName) // open the display LOG((CLOG_DEBUG3 "calling XOpenDisplay(\"%s\")", displayName)); Display *display = XOpenDisplay(displayName); - if (display == NULL) { + if (display == nullptr) { throw XScreenUnavailable(60.0); } @@ -942,7 +942,7 @@ void XWindowsScreen::saveShape() int numScreens; XineramaScreenInfo *screens; screens = XineramaQueryScreens(m_display, &numScreens); - if (screens != NULL) { + if (screens != nullptr) { if (numScreens > 1) { m_xinerama = true; m_xCenter = screens[0].x_org + (screens[0].width >> 1); @@ -1049,8 +1049,8 @@ Window XWindowsScreen::openWindow() const void XWindowsScreen::openIM() { // open the input methods - XIM im = XOpenIM(m_display, NULL, NULL, NULL); - if (im == NULL) { + XIM im = XOpenIM(m_display, nullptr, nullptr, nullptr); + if (im == nullptr) { LOG((CLOG_INFO "no support for IM")); return; } @@ -1058,7 +1058,7 @@ void XWindowsScreen::openIM() // find the appropriate style. deskflow supports XIMPreeditNothing // only at the moment. XIMStyles *styles; - if (XGetIMValues(im, XNQueryInputStyle, &styles, NULL) != NULL || styles == NULL) { + if (XGetIMValues(im, XNQueryInputStyle, &styles, nullptr) != nullptr || styles == nullptr) { LOG((CLOG_WARN "cannot get IM styles")); XCloseIM(im); return; @@ -1080,8 +1080,8 @@ void XWindowsScreen::openIM() } // create an input context for the style and tell it about our window - XIC ic = XCreateIC(im, XNInputStyle, style, XNClientWindow, m_window, NULL); - if (ic == NULL) { + XIC ic = XCreateIC(im, XNInputStyle, style, XNClientWindow, m_window, nullptr); + if (ic == nullptr) { LOG((CLOG_WARN "cannot create IC")); XCloseIM(im); return; @@ -1089,7 +1089,7 @@ void XWindowsScreen::openIM() // find out the events we must select for and do so unsigned long mask; - if (XGetICValues(ic, XNFilterEvents, &mask, NULL) != NULL) { + if (XGetICValues(ic, XNFilterEvents, &mask, nullptr) != nullptr) { LOG((CLOG_WARN "cannot get IC filter events")); XDestroyIC(ic); XCloseIM(im); @@ -1140,7 +1140,7 @@ Bool XWindowsScreen::findKeyEvent(Display *, XEvent *xevent, XPointer arg) void XWindowsScreen::handleSystemEvent(const Event &event, void *) { XEvent *xevent = static_cast(event.getData()); - assert(xevent != NULL); + assert(xevent != nullptr); // update key state bool isRepeat = false; @@ -1178,7 +1178,7 @@ void XWindowsScreen::handleSystemEvent(const Event &event, void *) } // let input methods try to handle event first - if (m_ic != NULL) { + if (m_ic != nullptr) { // XFilterEvent() may eat the event and generate a new KeyPress // event with a keycode of 0 because there isn't an actual key // associated with the keysym. but the KeyRelease may pass @@ -1623,7 +1623,7 @@ Cursor XWindowsScreen::createBlankCursor() const ClipboardID XWindowsScreen::getClipboardID(Atom selection) const { for (ClipboardID id = 0; id < kClipboardEnd; ++id) { - if (m_clipboard[id] != NULL && m_clipboard[id]->getSelection() == selection) { + if (m_clipboard[id] != nullptr && m_clipboard[id]->getSelection() == selection) { return id; } } @@ -1634,7 +1634,7 @@ void XWindowsScreen::processClipboardRequest(Window requestor, Time time, Atom p { // check every clipboard until one returns success for (ClipboardID id = 0; id < kClipboardEnd; ++id) { - if (m_clipboard[id] != NULL && m_clipboard[id]->processRequest(requestor, time, property)) { + if (m_clipboard[id] != nullptr && m_clipboard[id]->processRequest(requestor, time, property)) { break; } } @@ -1644,7 +1644,7 @@ void XWindowsScreen::destroyClipboardRequest(Window requestor) { // check every clipboard until one returns success for (ClipboardID id = 0; id < kClipboardEnd; ++id) { - if (m_clipboard[id] != NULL && m_clipboard[id]->destroyRequest(requestor)) { + if (m_clipboard[id] != nullptr && m_clipboard[id]->destroyRequest(requestor)) { break; } } @@ -1653,13 +1653,13 @@ void XWindowsScreen::destroyClipboardRequest(Window requestor) void XWindowsScreen::onError() { // prevent further access to the X display - m_events->adoptBuffer(NULL); + m_events->adoptBuffer(nullptr); m_screensaver->destroy(); - m_screensaver = NULL; - m_display = NULL; + m_screensaver = nullptr; + m_display = nullptr; // notify of failure - sendEvent(m_events->forIScreen().error(), NULL); + sendEvent(m_events->forIScreen().error(), nullptr); // FIXME -- should ensure that we ignore operations that involve // m_display from now on. however, Xlib will simply exit the @@ -1741,7 +1741,7 @@ KeyID XWindowsScreen::mapKeyFromX(XKeyEvent *event) const { // convert to a keysym KeySym keysym; - if (event->type == KeyPress && m_ic != NULL) { + if (event->type == KeyPress && m_ic != nullptr) { // do multibyte lookup. can only call XmbLookupString with a // key press event and a valid XIC so we checked those above. char scratch[32]; @@ -1772,7 +1772,7 @@ KeyID XWindowsScreen::mapKeyFromX(XKeyEvent *event) const } else { // plain old lookup char dummy[1]; - XLookupString(event, dummy, 0, &keysym, NULL); + XLookupString(event, dummy, 0, &keysym, nullptr); } LOG((CLOG_DEBUG2 "mapped code=%d to keysym=0x%04x", event->keycode, keysym)); @@ -1867,7 +1867,7 @@ void XWindowsScreen::warpCursorNoFlush(int32_t x, int32_t y) void XWindowsScreen::updateButtons() { // query the button mapping - uint32_t numButtons = XGetPointerMapping(m_display, NULL, 0); + uint32_t numButtons = XGetPointerMapping(m_display, nullptr, 0); unsigned char *tmpButtons = new unsigned char[numButtons]; XGetPointerMapping(m_display, tmpButtons, numButtons); diff --git a/src/lib/platform/XWindowsScreen.h b/src/lib/platform/XWindowsScreen.h index e07e48632..5ee3b18a0 100644 --- a/src/lib/platform/XWindowsScreen.h +++ b/src/lib/platform/XWindowsScreen.h @@ -89,7 +89,7 @@ protected: private: // event sending - void sendEvent(Event::Type, void * = NULL); + void sendEvent(Event::Type, void * = nullptr); void sendClipboardEvent(Event::Type, ClipboardID); // create the transparent cursor diff --git a/src/lib/platform/XWindowsScreenSaver.cpp b/src/lib/platform/XWindowsScreenSaver.cpp index 98471e37e..8e6fe2b93 100644 --- a/src/lib/platform/XWindowsScreenSaver.cpp +++ b/src/lib/platform/XWindowsScreenSaver.cpp @@ -57,7 +57,7 @@ XWindowsScreenSaver::XWindowsScreenSaver(Display *display, Window window, void * m_dpms(false), m_disabled(false), m_suppressDisable(false), - m_disableTimer(NULL), + m_disableTimer(nullptr), m_disablePos(0), m_events(events) { @@ -114,12 +114,12 @@ XWindowsScreenSaver::XWindowsScreenSaver(Display *display, Window window, void * XWindowsScreenSaver::~XWindowsScreenSaver() { // done with disable job - if (m_disableTimer != NULL) { + if (m_disableTimer != nullptr) { m_events->deleteTimer(m_disableTimer); } m_events->removeHandler(Event::kTimer, this); - if (m_display != NULL) { + if (m_display != nullptr) { enableDPMS(m_dpmsEnabled); XSetScreenSaver(m_display, m_timeout, m_interval, m_preferBlanking, m_allowExposures); clearWatchForXScreenSaver(); @@ -130,7 +130,7 @@ XWindowsScreenSaver::~XWindowsScreenSaver() void XWindowsScreenSaver::destroy() { - m_display = NULL; + m_display = nullptr; delete this; } @@ -347,7 +347,7 @@ bool XWindowsScreenSaver::isXScreenSaver(Window w) const // check for m_atomScreenSaverVersion string property Atom type; return ( - XWindowsUtil::getWindowProperty(m_display, w, m_atomScreenSaverVersion, NULL, &type, NULL, False) && + XWindowsUtil::getWindowProperty(m_display, w, m_atomScreenSaverVersion, nullptr, &type, nullptr, False) && type == XA_STRING ); } @@ -459,12 +459,12 @@ void XWindowsScreenSaver::addWatchXScreenSaver(Window window) void XWindowsScreenSaver::updateDisableTimer() { - if (m_disabled && !m_suppressDisable && m_disableTimer == NULL) { + if (m_disabled && !m_suppressDisable && m_disableTimer == nullptr) { // 5 seconds should be plenty often to suppress the screen saver m_disableTimer = m_events->newTimer(5.0, this); - } else if ((!m_disabled || m_suppressDisable) && m_disableTimer != NULL) { + } else if ((!m_disabled || m_suppressDisable) && m_disableTimer != nullptr) { m_events->deleteTimer(m_disableTimer); - m_disableTimer = NULL; + m_disableTimer = nullptr; } } diff --git a/src/lib/platform/XWindowsScreenSaver.h b/src/lib/platform/XWindowsScreenSaver.h index c070a3580..713779a3a 100644 --- a/src/lib/platform/XWindowsScreenSaver.h +++ b/src/lib/platform/XWindowsScreenSaver.h @@ -153,7 +153,7 @@ private: // to activate the screen saver even if disabled. bool m_suppressDisable; - // the disable timer (NULL if not installed) + // the disable timer (nullptr if not installed) EventQueueTimer *m_disableTimer; // fake mouse motion position for suppressing the screen saver. diff --git a/src/lib/platform/XWindowsUtil.cpp b/src/lib/platform/XWindowsUtil.cpp index 734002f6f..3c592f71f 100644 --- a/src/lib/platform/XWindowsUtil.cpp +++ b/src/lib/platform/XWindowsUtil.cpp @@ -1507,7 +1507,7 @@ bool XWindowsUtil::getWindowProperty( Display *display, Window window, Atom property, std::string *data, Atom *type, int32_t *format, bool deleteProperty ) { - assert(display != NULL); + assert(display != nullptr); Atom actualType; int actualDatumSize; @@ -1555,7 +1555,7 @@ bool XWindowsUtil::getWindowProperty( } // append data - if (data != NULL) { + if (data != nullptr) { data->append((char *)rawData, numBytes); } else { // data is not required so don't try to get any more @@ -1572,15 +1572,17 @@ bool XWindowsUtil::getWindowProperty( } // save property info - if (type != NULL) { + if (type != nullptr) { *type = actualType; } - if (format != NULL) { + if (format != nullptr) { *format = static_cast(actualDatumSize); } if (okay) { - LOG((CLOG_DEBUG2 "read property %d on window 0x%08x: bytes=%d", property, window, (data == NULL) ? 0 : data->size()) + LOG( + (CLOG_DEBUG2 "read property %d on window 0x%08x: bytes=%d", property, window, + (data == nullptr) ? 0 : data->size()) ); return true; } else { @@ -1898,11 +1900,11 @@ void XWindowsUtil::initKeyMaps() // XWindowsUtil::ErrorLock // -XWindowsUtil::ErrorLock *XWindowsUtil::ErrorLock::s_top = NULL; +XWindowsUtil::ErrorLock *XWindowsUtil::ErrorLock::s_top = nullptr; XWindowsUtil::ErrorLock::ErrorLock(Display *display) : m_display(display) { - install(&XWindowsUtil::ErrorLock::ignoreHandler, NULL); + install(&XWindowsUtil::ErrorLock::ignoreHandler, nullptr); } XWindowsUtil::ErrorLock::ErrorLock(Display *display, bool *flag) : m_display(display) @@ -1918,7 +1920,7 @@ XWindowsUtil::ErrorLock::ErrorLock(Display *display, ErrorHandler handler, void XWindowsUtil::ErrorLock::~ErrorLock() { // make sure everything finishes before uninstalling handler - if (m_display != NULL) { + if (m_display != nullptr) { XSync(m_display, False); } @@ -1930,7 +1932,7 @@ XWindowsUtil::ErrorLock::~ErrorLock() void XWindowsUtil::ErrorLock::install(ErrorHandler handler, void *data) { // make sure everything finishes before installing handler - if (m_display != NULL) { + if (m_display != nullptr) { XSync(m_display, False); } @@ -1944,7 +1946,7 @@ void XWindowsUtil::ErrorLock::install(ErrorHandler handler, void *data) int XWindowsUtil::ErrorLock::internalHandler(Display *display, XErrorEvent *event) { - if (s_top != NULL && s_top->m_handler != NULL) { + if (s_top != nullptr && s_top->m_handler != nullptr) { s_top->m_handler(display, event, s_top->m_userData); } return 0; diff --git a/src/lib/platform/XWindowsUtil.h b/src/lib/platform/XWindowsUtil.h index d30b854c8..9e14eb1a8 100644 --- a/src/lib/platform/XWindowsUtil.h +++ b/src/lib/platform/XWindowsUtil.h @@ -28,9 +28,9 @@ public: //! Get property /*! Gets property \c property on \c window. \b Appends the data to - \c *data if \c data is not NULL, saves the property type in \c *type - if \c type is not NULL, and saves the property format in \c *format - if \c format is not NULL. If \c deleteProperty is true then the + \c *data if \c data is not nullptr, saves the property type in \c *type + if \c type is not nullptr, and saves the property format in \c *format + if \c format is not nullptr. If \c deleteProperty is true then the property is deleted after being read. */ static bool getWindowProperty( diff --git a/src/lib/server/ClientListener.cpp b/src/lib/server/ClientListener.cpp index 120474d6d..9d3da0f44 100644 --- a/src/lib/server/ClientListener.cpp +++ b/src/lib/server/ClientListener.cpp @@ -28,12 +28,12 @@ ClientListener::ClientListener( const NetworkAddress &address, ISocketFactory *socketFactory, IEventQueue *events, SecurityLevel securityLevel ) : m_socketFactory(socketFactory), - m_server(NULL), + m_server(nullptr), m_events(events), m_securityLevel(securityLevel), m_address(address) { - assert(m_socketFactory != NULL); + assert(m_socketFactory != nullptr); try { start(); @@ -57,13 +57,13 @@ ClientListener::~ClientListener() void ClientListener::setServer(Server *server) { - assert(server != NULL); + assert(server != nullptr); m_server = server; } ClientProxy *ClientListener::getNextClient() { - ClientProxy *client = NULL; + ClientProxy *client = nullptr; if (!m_waitingClients.empty()) { client = m_waitingClients.front(); m_waitingClients.pop_front(); @@ -127,7 +127,7 @@ void ClientListener::handleClientConnecting(const Event &, void *) // accept client connection IDataSocket *socket = m_listen->accept(); - if (socket == NULL) { + if (socket == nullptr) { return; } @@ -153,7 +153,7 @@ void ClientListener::handleClientAccepted(const Event &, void *vsocket) // filter socket messages, including a packetizing filter deskflow::IStream *stream = new PacketStreamFilter(m_events, socket, false); - assert(m_server != NULL); + assert(m_server != nullptr); // create proxy for unknown client ClientProxyUnknown *client = new ClientProxyUnknown(stream, 30.0, m_server, m_events); diff --git a/src/lib/server/ClientListener.h b/src/lib/server/ClientListener.h index c2e0071db..197b56219 100644 --- a/src/lib/server/ClientListener.h +++ b/src/lib/server/ClientListener.h @@ -51,7 +51,7 @@ public: /*! Returns the next connected client and removes it from the internal list. The client is responsible for deleting the returned client. - Returns NULL if no clients are available. + Returns nullptr if no clients are available. */ ClientProxy *getNextClient(); diff --git a/src/lib/server/ClientProxy1_0.cpp b/src/lib/server/ClientProxy1_0.cpp index 4493adfec..00c2e98ca 100644 --- a/src/lib/server/ClientProxy1_0.cpp +++ b/src/lib/server/ClientProxy1_0.cpp @@ -22,33 +22,33 @@ ClientProxy1_0::ClientProxy1_0(const std::string &name, deskflow::IStream *stream, IEventQueue *events) : ClientProxy(name, stream), - m_heartbeatTimer(NULL), + m_heartbeatTimer(nullptr), m_parser(&ClientProxy1_0::parseHandshakeMessage), m_events(events) { // install event handlers m_events->adoptHandler( m_events->forIStream().inputReady(), stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleData, NULL) + new TMethodEventJob(this, &ClientProxy1_0::handleData, nullptr) ); m_events->adoptHandler( m_events->forIStream().outputError(), stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleWriteError, NULL) + new TMethodEventJob(this, &ClientProxy1_0::handleWriteError, nullptr) ); m_events->adoptHandler( m_events->forIStream().inputShutdown(), stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleDisconnect, NULL) + new TMethodEventJob(this, &ClientProxy1_0::handleDisconnect, nullptr) ); m_events->adoptHandler( m_events->forIStream().inputFormatError(), stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleDisconnect, NULL) + new TMethodEventJob(this, &ClientProxy1_0::handleDisconnect, nullptr) ); m_events->adoptHandler( m_events->forIStream().outputShutdown(), stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleWriteError, NULL) + new TMethodEventJob(this, &ClientProxy1_0::handleWriteError, nullptr) ); m_events->adoptHandler( - Event::kTimer, this, new TMethodEventJob(this, &ClientProxy1_0::handleFlatline, NULL) + Event::kTimer, this, new TMethodEventJob(this, &ClientProxy1_0::handleFlatline, nullptr) ); setHeartbeatRate(kHeartRate, kHeartRate * kHeartBeatsUntilDeath); @@ -92,9 +92,9 @@ void ClientProxy1_0::addHeartbeatTimer() void ClientProxy1_0::removeHeartbeatTimer() { - if (m_heartbeatTimer != NULL) { + if (m_heartbeatTimer != nullptr) { m_events->deleteTimer(m_heartbeatTimer); - m_heartbeatTimer = NULL; + m_heartbeatTimer = nullptr; } } diff --git a/src/lib/server/ClientProxy1_3.cpp b/src/lib/server/ClientProxy1_3.cpp index fb5ffce8f..c3ad3fcdf 100644 --- a/src/lib/server/ClientProxy1_3.cpp +++ b/src/lib/server/ClientProxy1_3.cpp @@ -22,7 +22,7 @@ ClientProxy1_3::ClientProxy1_3(const std::string &name, deskflow::IStream *stream, IEventQueue *events) : ClientProxy1_2(name, stream, events), m_keepAliveRate(kKeepAliveRate), - m_keepAliveTimer(NULL), + m_keepAliveTimer(nullptr), m_events(events) { setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath); @@ -74,10 +74,10 @@ void ClientProxy1_3::addHeartbeatTimer() { // create and install a timer to periodically send keep alives if (m_keepAliveRate > 0.0) { - m_keepAliveTimer = m_events->newTimer(m_keepAliveRate, NULL); + m_keepAliveTimer = m_events->newTimer(m_keepAliveRate, nullptr); m_events->adoptHandler( Event::kTimer, m_keepAliveTimer, - new TMethodEventJob(this, &ClientProxy1_3::handleKeepAlive, NULL) + new TMethodEventJob(this, &ClientProxy1_3::handleKeepAlive, nullptr) ); } @@ -88,10 +88,10 @@ void ClientProxy1_3::addHeartbeatTimer() void ClientProxy1_3::removeHeartbeatTimer() { // remove the timer that sends keep alives periodically - if (m_keepAliveTimer != NULL) { + if (m_keepAliveTimer != nullptr) { m_events->removeHandler(Event::kTimer, m_keepAliveTimer); m_events->deleteTimer(m_keepAliveTimer); - m_keepAliveTimer = NULL; + m_keepAliveTimer = nullptr; } // superclass does the alarm diff --git a/src/lib/server/ClientProxy1_4.cpp b/src/lib/server/ClientProxy1_4.cpp index d7fe6a17d..aa5df5b7c 100644 --- a/src/lib/server/ClientProxy1_4.cpp +++ b/src/lib/server/ClientProxy1_4.cpp @@ -24,7 +24,7 @@ ClientProxy1_4::ClientProxy1_4(const std::string &name, deskflow::IStream *strea : ClientProxy1_3(name, stream, events), m_server(server) { - assert(m_server != NULL); + assert(m_server != nullptr); } ClientProxy1_4::~ClientProxy1_4() diff --git a/src/lib/server/ClientProxy1_5.cpp b/src/lib/server/ClientProxy1_5.cpp index 295181fa4..29ae32825 100644 --- a/src/lib/server/ClientProxy1_5.cpp +++ b/src/lib/server/ClientProxy1_5.cpp @@ -27,7 +27,7 @@ ClientProxy1_5::ClientProxy1_5(const std::string &name, deskflow::IStream *strea m_events->adoptHandler( m_events->forFile().keepAlive(), this, - new TMethodEventJob(this, &ClientProxy1_3::handleKeepAlive, NULL) + new TMethodEventJob(this, &ClientProxy1_3::handleKeepAlive, nullptr) ); } diff --git a/src/lib/server/ClientProxyUnknown.cpp b/src/lib/server/ClientProxyUnknown.cpp index 8c66b5405..8198bd3dc 100644 --- a/src/lib/server/ClientProxyUnknown.cpp +++ b/src/lib/server/ClientProxyUnknown.cpp @@ -36,15 +36,15 @@ ClientProxyUnknown::ClientProxyUnknown(deskflow::IStream *stream, double timeout, Server *server, IEventQueue *events) : m_stream(stream), - m_proxy(NULL), + m_proxy(nullptr), m_ready(false), m_server(server), m_events(events) { - assert(m_server != NULL); + assert(m_server != nullptr); m_events->adoptHandler( - Event::kTimer, this, new TMethodEventJob(this, &ClientProxyUnknown::handleTimeout, NULL) + Event::kTimer, this, new TMethodEventJob(this, &ClientProxyUnknown::handleTimeout, nullptr) ); m_timer = m_events->newOneShotTimer(timeout, this); addStreamHandlers(); @@ -69,10 +69,10 @@ ClientProxy *ClientProxyUnknown::orphanClientProxy() if (m_ready) { removeHandlers(); ClientProxy *proxy = m_proxy; - m_proxy = NULL; + m_proxy = nullptr; return proxy; } else { - return NULL; + return nullptr; } } @@ -86,7 +86,7 @@ void ClientProxyUnknown::sendSuccess() void ClientProxyUnknown::sendFailure() { delete m_proxy; - m_proxy = NULL; + m_proxy = nullptr; m_ready = false; removeHandlers(); removeTimer(); @@ -95,7 +95,7 @@ void ClientProxyUnknown::sendFailure() void ClientProxyUnknown::addStreamHandlers() { - assert(m_stream != NULL); + assert(m_stream != nullptr); m_events->adoptHandler( m_events->forIStream().inputReady(), m_stream->getEventTarget(), @@ -121,7 +121,7 @@ void ClientProxyUnknown::addStreamHandlers() void ClientProxyUnknown::addProxyHandlers() { - assert(m_proxy != NULL); + assert(m_proxy != nullptr); m_events->adoptHandler( m_events->forClientProxy().ready(), m_proxy, @@ -135,14 +135,14 @@ void ClientProxyUnknown::addProxyHandlers() void ClientProxyUnknown::removeHandlers() { - if (m_stream != NULL) { + if (m_stream != nullptr) { m_events->removeHandler(m_events->forIStream().inputReady(), m_stream->getEventTarget()); m_events->removeHandler(m_events->forIStream().outputError(), m_stream->getEventTarget()); m_events->removeHandler(m_events->forIStream().inputShutdown(), m_stream->getEventTarget()); m_events->removeHandler(m_events->forIStream().inputFormatError(), m_stream->getEventTarget()); m_events->removeHandler(m_events->forIStream().outputShutdown(), m_stream->getEventTarget()); } - if (m_proxy != NULL) { + if (m_proxy != nullptr) { m_events->removeHandler(m_events->forClientProxy().ready(), m_proxy); m_events->removeHandler(m_events->forClientProxy().disconnected(), m_proxy); } @@ -150,10 +150,10 @@ void ClientProxyUnknown::removeHandlers() void ClientProxyUnknown::removeTimer() { - if (m_timer != NULL) { + if (m_timer != nullptr) { m_events->deleteTimer(m_timer); m_events->removeHandler(Event::kTimer, this); - m_timer = NULL; + m_timer = nullptr; } } @@ -200,7 +200,7 @@ void ClientProxyUnknown::initProxy(const std::string &name, int major, int minor } // hangup (with error) if version isn't supported - if (m_proxy == NULL) { + if (m_proxy == nullptr) { throw XIncompatibleClient(major, minor); } } @@ -241,7 +241,7 @@ void ClientProxyUnknown::handleData(const Event &, void *) // the proxy is created and now proxy now owns the stream LOG((CLOG_DEBUG1 "created proxy for client \"%s\" version %d.%d", name.c_str(), major, minor)); - m_stream = NULL; + m_stream = nullptr; // wait until the proxy signals that it's ready or has disconnected addProxyHandlers(); diff --git a/src/lib/server/ClientProxyUnknown.h b/src/lib/server/ClientProxyUnknown.h index bd675f5e5..a3370ae85 100644 --- a/src/lib/server/ClientProxyUnknown.h +++ b/src/lib/server/ClientProxyUnknown.h @@ -38,7 +38,7 @@ public: //! Get the client proxy /*! Returns the client proxy created after a successful handshake - (i.e. when this object sends a success event). Returns NULL + (i.e. when this object sends a success event). Returns nullptr if the handshake is unsuccessful or incomplete. */ ClientProxy *orphanClientProxy(); diff --git a/src/lib/server/Config.cpp b/src/lib/server/Config.cpp index b653e11a0..0b35bb4cc 100644 --- a/src/lib/server/Config.cpp +++ b/src/lib/server/Config.cpp @@ -258,7 +258,7 @@ void Config::setDeskflowAddress(const NetworkAddress &addr) bool Config::addOption(const std::string &name, OptionID option, OptionValue value) { // find options - ScreenOptions *options = NULL; + ScreenOptions *options = nullptr; if (name.empty()) { options = &m_globalOptions; } else { @@ -267,7 +267,7 @@ bool Config::addOption(const std::string &name, OptionID option, OptionValue val options = &index->second.m_options; } } - if (options == NULL) { + if (options == nullptr) { return false; } @@ -279,7 +279,7 @@ bool Config::addOption(const std::string &name, OptionID option, OptionValue val bool Config::removeOption(const std::string &name, OptionID option) { // find options - ScreenOptions *options = NULL; + ScreenOptions *options = nullptr; if (name.empty()) { options = &m_globalOptions; } else { @@ -288,7 +288,7 @@ bool Config::removeOption(const std::string &name, OptionID option) options = &index->second.m_options; } } - if (options == NULL) { + if (options == nullptr) { return false; } @@ -300,7 +300,7 @@ bool Config::removeOption(const std::string &name, OptionID option) bool Config::removeOptions(const std::string &name) { // find options - ScreenOptions *options = NULL; + ScreenOptions *options = nullptr; if (name.empty()) { options = &m_globalOptions; } else { @@ -309,7 +309,7 @@ bool Config::removeOptions(const std::string &name) options = &index->second.m_options; } } - if (options == NULL) { + if (options == nullptr) { return false; } @@ -432,7 +432,7 @@ Config::getNeighbor(const std::string &srcName, EDirection srcSide, float positi return ""; } else { // compute position on neighbor - if (positionOut != NULL) { + if (positionOut != nullptr) { *positionOut = dstEdge->inverseTransform(srcEdge->transform(position)); } @@ -481,7 +481,7 @@ const NetworkAddress &Config::getDeskflowAddress() const const Config::ScreenOptions *Config::getOptions(const std::string &name) const { // find options - const ScreenOptions *options = NULL; + const ScreenOptions *options = nullptr; if (name.empty()) { options = &m_globalOptions; } else { @@ -1254,7 +1254,7 @@ const char *Config::getOptionName(OptionID id) if (id == kOptionClipboardSharingSize) { return "clipboardSharingSize"; } - return NULL; + return nullptr; } std::string Config::getOptionValue(OptionID id, OptionValue value) @@ -1605,11 +1605,11 @@ std::ostream &operator<<(std::ostream &s, const Config &config) for (Config::const_iterator screen = config.begin(); screen != config.end(); ++screen) { s << "\t" << screen->c_str() << ":" << std::endl; const Config::ScreenOptions *options = config.getOptions(*screen); - if (options != NULL && options->size() > 0) { + if (options != nullptr && options->size() > 0) { for (Config::ScreenOptions::const_iterator option = options->begin(); option != options->end(); ++option) { const char *name = Config::getOptionName(option->first); std::string value = Config::getOptionValue(option->first, option->second); - if (name != NULL && !value.empty()) { + if (name != nullptr && !value.empty()) { s << "\t\t" << name << " = " << value << std::endl; } } @@ -1659,11 +1659,11 @@ std::ostream &operator<<(std::ostream &s, const Config &config) // options section s << "section: options" << std::endl; const Config::ScreenOptions *options = config.getOptions(""); - if (options != NULL && options->size() > 0) { + if (options != nullptr && options->size() > 0) { for (Config::ScreenOptions::const_iterator option = options->begin(); option != options->end(); ++option) { const char *name = Config::getOptionName(option->first); std::string value = Config::getOptionValue(option->first, option->second); - if (name != NULL && !value.empty()) { + if (name != nullptr && !value.empty()) { s << "\t" << name << " = " << value << std::endl; } } diff --git a/src/lib/server/Config.h b/src/lib/server/Config.h index 24a30fead..3ade23826 100644 --- a/src/lib/server/Config.h +++ b/src/lib/server/Config.h @@ -203,7 +203,7 @@ public: virtual ~Config(); #ifdef TEST_ENV - Config() : m_inputFilter(NULL) + Config() : m_inputFilter(nullptr) { } #endif @@ -386,7 +386,7 @@ public: direction (set through connect()) at position \c position. Returns the empty string if there is no neighbor in that direction, otherwise saves the position on the neighbor in \c positionOut if it's not - \c NULL. + \c nullptr. */ std::string getNeighbor(const std::string &, EDirection, float position, float *positionOut) const; @@ -414,7 +414,7 @@ public: //! Get the screen options /*! - Returns all the added options for the named screen. Returns NULL + Returns all the added options for the named screen. Returns nullptr if the screen is unknown and an empty collection if there are no options. */ diff --git a/src/lib/server/InputFilter.cpp b/src/lib/server/InputFilter.cpp index 49138e37a..f7adaade6 100644 --- a/src/lib/server/InputFilter.cpp +++ b/src/lib/server/InputFilter.cpp @@ -492,11 +492,11 @@ void InputFilter::KeystrokeAction::perform(const Event &event) Event::Type type = m_press ? m_events->forIKeyState().keyDown() : m_events->forIKeyState().keyUp(); m_events->addEvent( - Event(m_events->forIPrimaryScreen().fakeInputBegin(), event.getTarget(), NULL, Event::kDeliverImmediately) + Event(m_events->forIPrimaryScreen().fakeInputBegin(), event.getTarget(), nullptr, Event::kDeliverImmediately) ); m_events->addEvent(Event(type, event.getTarget(), m_keyInfo, Event::kDeliverImmediately | Event::kDontFreeData)); m_events->addEvent( - Event(m_events->forIPrimaryScreen().fakeInputEnd(), event.getTarget(), NULL, Event::kDeliverImmediately) + Event(m_events->forIPrimaryScreen().fakeInputEnd(), event.getTarget(), nullptr, Event::kDeliverImmediately) ); } @@ -546,7 +546,7 @@ void InputFilter::MouseButtonAction::perform(const Event &event) { // send modifiers - IPlatformScreen::KeyInfo *modifierInfo = NULL; + IPlatformScreen::KeyInfo *modifierInfo = nullptr; if (m_buttonInfo->m_mask != 0) { KeyID key = m_press ? kKeySetModifiers : kKeyClearModifiers; modifierInfo = IKeyState::KeyInfo::alloc(key, m_buttonInfo->m_mask, 0, 1); @@ -569,7 +569,7 @@ const char *InputFilter::MouseButtonAction::formatName() const // InputFilter::Rule // -InputFilter::Rule::Rule() : m_condition(NULL) +InputFilter::Rule::Rule() : m_condition(nullptr) { // do nothing } @@ -579,7 +579,7 @@ InputFilter::Rule::Rule(Condition *adoptedCondition) : m_condition(adoptedCondit // do nothing } -InputFilter::Rule::Rule(const Rule &rule) : m_condition(NULL) +InputFilter::Rule::Rule(const Rule &rule) : m_condition(nullptr) { copy(rule); } @@ -607,7 +607,7 @@ void InputFilter::Rule::clear() delete *i; } - m_condition = NULL; + m_condition = nullptr; m_activateActions.clear(); m_deactivateActions.clear(); } @@ -615,7 +615,7 @@ void InputFilter::Rule::clear() void InputFilter::Rule::copy(const Rule &rule) { clear(); - if (rule.m_condition != NULL) { + if (rule.m_condition != nullptr) { m_condition = rule.m_condition->clone(); } for (ActionList::const_iterator i = rule.m_activateActions.begin(); i != rule.m_activateActions.end(); ++i) { @@ -634,7 +634,7 @@ void InputFilter::Rule::setCondition(Condition *adopted) void InputFilter::Rule::adoptAction(Action *action, bool onActivation) { - if (action != NULL) { + if (action != nullptr) { if (onActivation) { m_activateActions.push_back(action); } else { @@ -656,7 +656,7 @@ void InputFilter::Rule::removeAction(bool onActivation, uint32_t index) void InputFilter::Rule::replaceAction(Action *adopted, bool onActivation, uint32_t index) { - if (adopted == NULL) { + if (adopted == nullptr) { removeAction(onActivation, index); } else if (onActivation) { delete m_activateActions[index]; @@ -669,22 +669,22 @@ void InputFilter::Rule::replaceAction(Action *adopted, bool onActivation, uint32 void InputFilter::Rule::enable(PrimaryClient *primaryClient) { - if (m_condition != NULL) { + if (m_condition != nullptr) { m_condition->enablePrimary(primaryClient); } } void InputFilter::Rule::disable(PrimaryClient *primaryClient) { - if (m_condition != NULL) { + if (m_condition != nullptr) { m_condition->disablePrimary(primaryClient); } } bool InputFilter::Rule::handleEvent(const Event &event) { - // NULL condition never matches - if (m_condition == NULL) { + // nullptr condition never matches + if (m_condition == nullptr) { return false; } @@ -718,7 +718,7 @@ bool InputFilter::Rule::handleEvent(const Event &event) std::string InputFilter::Rule::format() const { std::string s; - if (m_condition != NULL) { + if (m_condition != nullptr) { // condition s += m_condition->format(); s += " = "; @@ -775,26 +775,29 @@ const InputFilter::Action &InputFilter::Rule::getAction(bool onActivation, uint3 // ----------------------------------------------------------------------------- // Input Filter Class // ----------------------------------------------------------------------------- -InputFilter::InputFilter(IEventQueue *events) : m_primaryClient(NULL), m_events(events) +InputFilter::InputFilter(IEventQueue *events) : m_primaryClient(nullptr), m_events(events) { // do nothing } -InputFilter::InputFilter(const InputFilter &x) : m_ruleList(x.m_ruleList), m_primaryClient(NULL), m_events(x.m_events) +InputFilter::InputFilter(const InputFilter &x) + : m_ruleList(x.m_ruleList), + m_primaryClient(nullptr), + m_events(x.m_events) { setPrimaryClient(x.m_primaryClient); } InputFilter::~InputFilter() { - setPrimaryClient(NULL); + setPrimaryClient(nullptr); } InputFilter &InputFilter::operator=(const InputFilter &x) { if (&x != this) { PrimaryClient *oldClient = m_primaryClient; - setPrimaryClient(NULL); + setPrimaryClient(nullptr); m_ruleList = x.m_ruleList; @@ -806,14 +809,14 @@ InputFilter &InputFilter::operator=(const InputFilter &x) void InputFilter::addFilterRule(const Rule &rule) { m_ruleList.push_back(rule); - if (m_primaryClient != NULL) { + if (m_primaryClient != nullptr) { m_ruleList.back().enable(m_primaryClient); } } void InputFilter::removeFilterRule(uint32_t index) { - if (m_primaryClient != NULL) { + if (m_primaryClient != nullptr) { m_ruleList[index].disable(m_primaryClient); } m_ruleList.erase(m_ruleList.begin() + index); @@ -830,7 +833,7 @@ void InputFilter::setPrimaryClient(PrimaryClient *client) return; } - if (m_primaryClient != NULL) { + if (m_primaryClient != nullptr) { for (RuleList::iterator rule = m_ruleList.begin(); rule != m_ruleList.end(); ++rule) { rule->disable(m_primaryClient); } @@ -847,7 +850,7 @@ void InputFilter::setPrimaryClient(PrimaryClient *client) m_primaryClient = client; - if (m_primaryClient != NULL) { + if (m_primaryClient != nullptr) { m_events->adoptHandler( m_events->forIKeyState().keyDown(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &InputFilter::handleEvent) diff --git a/src/lib/server/InputFilter.h b/src/lib/server/InputFilter.h index 068d66c8b..633f635af 100644 --- a/src/lib/server/InputFilter.h +++ b/src/lib/server/InputFilter.h @@ -360,7 +360,7 @@ public: virtual ~InputFilter(); #ifdef TEST_ENV - InputFilter() : m_primaryClient(NULL) + InputFilter() : m_primaryClient(nullptr) { } #endif @@ -377,7 +377,7 @@ public: Rule &getRule(uint32_t index); // enable event filtering using the given primary client. disable - // if client is NULL. + // if client is nullptr. virtual void setPrimaryClient(PrimaryClient *client); // convert rules to a string diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index 9a566ace8..e60fbf023 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -56,11 +56,11 @@ Server::Server( m_yDelta2(0), m_config(&config), m_inputFilter(config.getInputFilter()), - m_activeSaver(NULL), + m_activeSaver(nullptr), m_switchDir(kNoDirection), - m_switchScreen(NULL), + m_switchScreen(nullptr), m_switchWaitDelay(0.0), - m_switchWaitTimer(NULL), + m_switchWaitTimer(nullptr), m_switchTwoTapDelay(0.0), m_switchTwoTapEngaged(false), m_switchTwoTapArmed(false), @@ -84,9 +84,9 @@ Server::Server( m_args(args) { // must have a primary client and it must have a canonical name - assert(m_primaryClient != NULL); + assert(m_primaryClient != nullptr); assert(config.isScreen(primaryClient->getName())); - assert(m_screen != NULL); + assert(m_screen != nullptr); std::string primaryName = getName(primaryClient); @@ -234,7 +234,7 @@ Server::~Server() } // remove input filter - m_inputFilter->setPrimaryClient(NULL); + m_inputFilter->setPrimaryClient(nullptr); // disable and disconnect primary client m_primaryClient->disable(); @@ -283,7 +283,7 @@ bool Server::setConfig(const ServerConfig &config) void Server::adoptClient(BaseClientProxy *client) { - assert(client != NULL); + assert(client != nullptr); // watch for client disconnection m_events->adoptHandler( @@ -311,7 +311,7 @@ void Server::adoptClient(BaseClientProxy *client) sendOptions(client); // activate screen saver on new client if active on the primary screen - if (m_activeSaver != NULL) { + if (m_activeSaver != nullptr) { client->screensaver(true); } @@ -422,7 +422,7 @@ int32_t Server::getJumpZoneSize(BaseClientProxy *client) const void Server::switchScreen(BaseClientProxy *dst, int32_t x, int32_t y, bool forScreensaver) { - assert(dst != NULL); + assert(dst != nullptr); int32_t dx, dy, dw, dh; dst->getShape(dx, dy, dw, dh); @@ -456,7 +456,7 @@ void Server::switchScreen(BaseClientProxy *dst, int32_t x, int32_t y, bool forSc ); } - assert(m_active != NULL); + assert(m_active != nullptr); LOG((CLOG_INFO "switch from \"%s\" to \"%s\" at %d,%d", getName(m_active).c_str(), getName(dst).c_str(), x, y)); @@ -534,7 +534,7 @@ void Server::switchScreen(BaseClientProxy *dst, int32_t x, int32_t y, bool forSc void Server::jumpToScreen(BaseClientProxy *newScreen) { - assert(newScreen != NULL); + assert(newScreen != nullptr); // record the current cursor position on the active screen m_active->setJumpCursorPos(m_x, m_y); @@ -589,7 +589,7 @@ void Server::mapToPixel(BaseClientProxy *client, EDirection dir, float f, int32_ bool Server::hasAnyNeighbor(BaseClientProxy *client, EDirection dir) const { - assert(client != NULL); + assert(client != nullptr); return m_config->hasNeighbor(getName(client), dir); } @@ -598,7 +598,7 @@ BaseClientProxy *Server::getNeighbor(BaseClientProxy *src, EDirection dir, int32 { // note -- must be locked on entry - assert(src != NULL); + assert(src != nullptr); // get source screen name std::string srcName = getName(src); @@ -613,13 +613,13 @@ BaseClientProxy *Server::getNeighbor(BaseClientProxy *src, EDirection dir, int32 for (;;) { std::string dstName(m_config->getNeighbor(srcName, dir, t, &tTmp)); - // if nothing in that direction then return NULL. if the + // if nothing in that direction then return nullptr. if the // destination is the source then we can make no more // progress in this direction. since we haven't found a - // connected neighbor we return NULL. + // connected neighbor we return nullptr. if (dstName.empty()) { LOG((CLOG_DEBUG2 "no neighbor on %s of \"%s\"", Config::dirName(dir), srcName.c_str())); - return NULL; + return nullptr; } // look up neighbor cell. if the screen is connected and @@ -644,12 +644,12 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide, { // note -- must be locked on entry - assert(src != NULL); + assert(src != nullptr); // get the first neighbor BaseClientProxy *dst = getNeighbor(src, srcSide, x, y); - if (dst == NULL) { - return NULL; + if (dst == nullptr) { + return nullptr; } // get the source screen's size @@ -665,7 +665,7 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide, switch (srcSide) { case kLeft: x -= dx; - while (dst != NULL) { + while (dst != nullptr) { lastGoodScreen = dst; lastGoodScreen->getShape(dx, dy, dw, dh); x += dw; @@ -675,13 +675,13 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide, LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str())); dst = getNeighbor(lastGoodScreen, srcSide, x, y); } - assert(lastGoodScreen != NULL); + assert(lastGoodScreen != nullptr); x += dx; break; case kRight: x -= dx; - while (dst != NULL) { + while (dst != nullptr) { x -= dw; lastGoodScreen = dst; lastGoodScreen->getShape(dx, dy, dw, dh); @@ -691,13 +691,13 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide, LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str())); dst = getNeighbor(lastGoodScreen, srcSide, x, y); } - assert(lastGoodScreen != NULL); + assert(lastGoodScreen != nullptr); x += dx; break; case kTop: y -= dy; - while (dst != NULL) { + while (dst != nullptr) { lastGoodScreen = dst; lastGoodScreen->getShape(dx, dy, dw, dh); y += dh; @@ -707,13 +707,13 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide, LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str())); dst = getNeighbor(lastGoodScreen, srcSide, x, y); } - assert(lastGoodScreen != NULL); + assert(lastGoodScreen != nullptr); y += dy; break; case kBottom: y -= dy; - while (dst != NULL) { + while (dst != nullptr) { y -= dh; lastGoodScreen = dst; lastGoodScreen->getShape(dx, dy, dw, dh); @@ -723,17 +723,17 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide, LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str())); dst = getNeighbor(lastGoodScreen, srcSide, x, y); } - assert(lastGoodScreen != NULL); + assert(lastGoodScreen != nullptr); y += dy; break; case kNoDirection: assert(0 && "bad direction"); - return NULL; + return nullptr; } // save destination screen - assert(lastGoodScreen != NULL); + assert(lastGoodScreen != nullptr); dst = lastGoodScreen; // if entering primary screen then be sure to move in far enough @@ -763,22 +763,22 @@ void Server::avoidJumpZone(BaseClientProxy *dst, EDirection dir, int32_t &x, int // don't need to move inwards because that side can't provoke a jump. switch (dir) { case kLeft: - if (!m_config->getNeighbor(dstName, kRight, t, NULL).empty() && x > dx + dw - 1 - z) + if (!m_config->getNeighbor(dstName, kRight, t, nullptr).empty() && x > dx + dw - 1 - z) x = dx + dw - 1 - z; break; case kRight: - if (!m_config->getNeighbor(dstName, kLeft, t, NULL).empty() && x < dx + z) + if (!m_config->getNeighbor(dstName, kLeft, t, nullptr).empty() && x < dx + z) x = dx + z; break; case kTop: - if (!m_config->getNeighbor(dstName, kBottom, t, NULL).empty() && y > dy + dh - 1 - z) + if (!m_config->getNeighbor(dstName, kBottom, t, nullptr).empty() && y > dy + dh - 1 - z) y = dy + dh - 1 - z; break; case kBottom: - if (!m_config->getNeighbor(dstName, kTop, t, NULL).empty() && y < dy + z) + if (!m_config->getNeighbor(dstName, kTop, t, nullptr).empty() && y < dy + z) y = dy + z; break; @@ -794,7 +794,7 @@ bool Server::isSwitchOkay( LOG((CLOG_DEBUG1 "try to leave \"%s\" on %s", getName(m_active).c_str(), Config::dirName(dir))); // is there a neighbor? - if (newScreen == NULL) { + if (newScreen == nullptr) { // there's no neighbor. we don't want to switch and we don't // want to try to switch later. LOG((CLOG_DEBUG1 "no neighbor %s", Config::dirName(dir))); @@ -809,7 +809,7 @@ bool Server::isSwitchOkay( // note if the switch direction has changed. save the new // direction and screen if so. bool isNewDirection = (dir != m_switchDir); - if (isNewDirection || m_switchScreen == NULL) { + if (isNewDirection || m_switchScreen == nullptr) { m_switchDir = dir; m_switchScreen = newScreen; } @@ -838,10 +838,10 @@ bool Server::isSwitchOkay( // are we in a locked corner? first check if screen has the option set // and, if not, check the global options. const Config::ScreenOptions *options = m_config->getOptions(getName(m_active)); - if (options == NULL || options->count(kOptionScreenSwitchCorners) == 0) { + if (options == nullptr || options->count(kOptionScreenSwitchCorners) == 0) { options = m_config->getOptions(""); } - if (options != NULL && options->count(kOptionScreenSwitchCorners) > 0) { + if (options != nullptr && options->count(kOptionScreenSwitchCorners) > 0) { // get corner mask and size Config::ScreenOptions::const_iterator i = options->find(kOptionScreenSwitchCorners); uint32_t corners = static_cast(i->second); @@ -889,8 +889,8 @@ void Server::noSwitch(int32_t x, int32_t y) void Server::stopSwitch() { - if (m_switchScreen != NULL) { - m_switchScreen = NULL; + if (m_switchScreen != nullptr) { + m_switchScreen = nullptr; m_switchDir = kNoDirection; stopSwitchTwoTap(); stopSwitchWait(); @@ -978,20 +978,20 @@ void Server::startSwitchWait(int32_t x, int32_t y) void Server::stopSwitchWait() { - if (m_switchWaitTimer != NULL) { + if (m_switchWaitTimer != nullptr) { m_events->deleteTimer(m_switchWaitTimer); - m_switchWaitTimer = NULL; + m_switchWaitTimer = nullptr; } } bool Server::isSwitchWaitStarted() const { - return (m_switchWaitTimer != NULL); + return (m_switchWaitTimer != nullptr); } uint32_t Server::getCorner(BaseClientProxy *client, int32_t x, int32_t y, int32_t size) const { - assert(client != NULL); + assert(client != nullptr); // get client screen shape int32_t ax, ay, aw, ah; @@ -1061,7 +1061,7 @@ void Server::sendOptions(BaseClientProxy *client) const // look up options for client const Config::ScreenOptions *options = m_config->getOptions(getName(client)); - if (options != NULL) { + if (options != nullptr) { // convert options to a more convenient form for sending optionsList.reserve(2 * options->size()); for (Config::ScreenOptions::const_iterator index = options->begin(); index != options->end(); ++index) { @@ -1072,7 +1072,7 @@ void Server::sendOptions(BaseClientProxy *client) const // look up global options options = m_config->getOptions(""); - if (options != NULL) { + if (options != nullptr) { // convert options to a more convenient form for sending optionsList.reserve(optionsList.size() + 2 * options->size()); for (Config::ScreenOptions::const_iterator index = options->begin(); index != options->end(); ++index) { @@ -1089,7 +1089,7 @@ void Server::sendOptions(BaseClientProxy *client) const void Server::processOptions() { const Config::ScreenOptions *options = m_config->getOptions(""); - if (options == NULL) { + if (options == nullptr) { return; } @@ -1365,7 +1365,7 @@ void Server::handleSwitchInDirectionEvent(const Event &event, void *) // jump to screen in chosen direction from center of this screen int32_t x = m_x, y = m_y; BaseClientProxy *newScreen = getNeighbor(m_active, info->m_direction, x, y); - if (newScreen == NULL) { + if (newScreen == nullptr) { LOG((CLOG_DEBUG1 "no neighbor %s", Config::dirName(info->m_direction))); } else { jumpToScreen(newScreen); @@ -1522,7 +1522,7 @@ void Server::onScreensaver(bool activated) // jump back to previous screen and position. we must check // that the position is still valid since the screen may have // changed resolutions while the screen saver was running. - if (m_activeSaver != NULL && m_activeSaver != m_primaryClient) { + if (m_activeSaver != nullptr && m_activeSaver != m_primaryClient) { // check position BaseClientProxy *screen = m_activeSaver; int32_t x, y, w, h; @@ -1544,7 +1544,7 @@ void Server::onScreensaver(bool activated) } // reset state - m_activeSaver = NULL; + m_activeSaver = nullptr; } // send message to all clients @@ -1557,7 +1557,7 @@ void Server::onScreensaver(bool activated) void Server::onKeyDown(KeyID id, KeyModifierMask mask, KeyButton button, const std::string &lang, const char *screens) { LOG((CLOG_DEBUG1 "onKeyDown id=%d mask=0x%04x button=0x%04x lang=%s", id, mask, button, lang.c_str())); - assert(m_active != NULL); + assert(m_active != nullptr); // relay if (!m_keyboardBroadcasting && IKeyState::KeyInfo::isDefault(screens)) { @@ -1580,7 +1580,7 @@ void Server::onKeyDown(KeyID id, KeyModifierMask mask, KeyButton button, const s void Server::onKeyUp(KeyID id, KeyModifierMask mask, KeyButton button, const char *screens) { LOG((CLOG_DEBUG1 "onKeyUp id=%d mask=0x%04x button=0x%04x", id, mask, button)); - assert(m_active != NULL); + assert(m_active != nullptr); // relay if (!m_keyboardBroadcasting && IKeyState::KeyInfo::isDefault(screens)) { @@ -1606,7 +1606,7 @@ void Server::onKeyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyButto (CLOG_DEBUG1 "onKeyRepeat id=%d mask=0x%04x count=%d button=0x%04x lang=\"%s\"", id, mask, count, button, lang.c_str()) ); - assert(m_active != NULL); + assert(m_active != nullptr); // relay m_active->keyRepeat(id, mask, count, button, lang); @@ -1615,7 +1615,7 @@ void Server::onKeyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyButto void Server::onMouseDown(ButtonID id) { LOG((CLOG_DEBUG1 "onMouseDown id=%d", id)); - assert(m_active != NULL); + assert(m_active != nullptr); // relay m_active->mouseDown(id); @@ -1627,7 +1627,7 @@ void Server::onMouseDown(ButtonID id) void Server::onMouseUp(ButtonID id) { LOG((CLOG_DEBUG1 "onMouseUp id=%d", id)); - assert(m_active != NULL); + assert(m_active != nullptr); // relay m_active->mouseUp(id); @@ -1811,7 +1811,7 @@ void Server::onMouseMoveSecondary(int32_t dx, int32_t dy) } // mouse move on secondary (client's) screen - assert(m_active != NULL); + assert(m_active != nullptr); if (m_active == m_primaryClient) { // stale event -- we're actually on the primary screen return; @@ -1883,7 +1883,7 @@ void Server::onMouseMoveSecondary(int32_t dx, int32_t dy) // if waiting and mouse is not on the border we're waiting // on then stop waiting. also if it's not on the border // then arm the double tap. - if (m_switchScreen != NULL) { + if (m_switchScreen != nullptr) { bool clearWait; int32_t zoneSize = m_primaryClient->getJumpZoneSize(); switch (m_switchDir) { @@ -1968,7 +1968,7 @@ void Server::onMouseMoveSecondary(int32_t dx, int32_t dy) void Server::onMouseWheel(int32_t xDelta, int32_t yDelta) { LOG((CLOG_DEBUG1 "onMouseWheel %+d,%+d", xDelta, yDelta)); - assert(m_active != NULL); + assert(m_active != nullptr); // relay m_active->mouseWheel(xDelta, yDelta); @@ -1979,7 +1979,7 @@ void Server::onFileChunkSending(const void *data) FileChunk *chunk = static_cast(const_cast(data)); LOG((CLOG_DEBUG1 "sending file chunk")); - assert(m_active != NULL); + assert(m_active != nullptr); // relay m_active->fileChunkSending(chunk->m_chunk[0], &chunk->m_chunk[1], chunk->m_dataSize); @@ -2063,7 +2063,7 @@ bool Server::removeClient(BaseClientProxy *client) void Server::closeClient(BaseClientProxy *client, const char *msg) { assert(client != m_primaryClient); - assert(msg != NULL); + assert(msg != nullptr); // send message to client. this message should cause the client // to disconnect. we add this client to the closed client list @@ -2081,7 +2081,7 @@ void Server::closeClient(BaseClientProxy *client, const char *msg) // install timer. wait timeout seconds for client to close. double timeout = 5.0; - EventQueueTimer *timer = m_events->newOneShotTimer(timeout, NULL); + EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr); m_events->adoptHandler( Event::kTimer, timer, new TMethodEventJob(this, &Server::handleClientCloseTimeout, client) ); @@ -2145,7 +2145,7 @@ void Server::removeOldClient(BaseClientProxy *client) void Server::forceLeaveClient(BaseClientProxy *client) { - BaseClientProxy *active = (m_activeSaver != NULL) ? m_activeSaver : m_active; + BaseClientProxy *active = (m_activeSaver != nullptr) ? m_activeSaver : m_active; if (active == client) { // record new position (center of primary screen) m_primaryClient->getCursorCenter(m_x, m_y); @@ -2167,7 +2167,7 @@ void Server::forceLeaveClient(BaseClientProxy *client) // enter new screen (unless we already have because of the // screen saver) - if (m_activeSaver == NULL) { + if (m_activeSaver == nullptr) { m_primaryClient->enter(m_x, m_y, m_seqNum, m_primaryClient->getToggleMask(), false); } } @@ -2176,7 +2176,7 @@ void Server::forceLeaveClient(BaseClientProxy *client) // then we can't switch back to it when the screen saver // deactivates. if (m_activeSaver == client) { - m_activeSaver = NULL; + m_activeSaver = nullptr; } // tell primary client about the active sides @@ -2252,7 +2252,7 @@ bool Server::isReceivedFileSizeValid() void Server::sendFileToClient(const char *filename) { - if (m_sendFileThread != NULL) { + if (m_sendFileThread != nullptr) { StreamChunker::interruptFile(); } diff --git a/src/lib/server/Server.h b/src/lib/server/Server.h index 4533bfdbe..41c2514be 100644 --- a/src/lib/server/Server.h +++ b/src/lib/server/Server.h @@ -131,7 +131,7 @@ public: Server &operator=(Server &&) = delete; #ifdef TEST_ENV - Server() : m_mock(true), m_config(NULL) + Server() : m_mock(true), m_config(nullptr) { } void setActive(BaseClientProxy *active) @@ -269,7 +269,7 @@ private: // source screen, find the screen we should move onto and where. // if the position is sufficiently far from the source then we // cross multiple screens. if there is no suitable screen then - // return NULL and x,y are not modified. + // return nullptr and x,y are not modified. BaseClientProxy *mapToNeighbor(BaseClientProxy *, EDirection, int32_t &x, int32_t &y) const; // adjusts x and y or neither to avoid ending up in a jump zone diff --git a/src/test/integtests/main.cpp b/src/test/integtests/main.cpp index c200da343..7e911ec5a 100644 --- a/src/test/integtests/main.cpp +++ b/src/test/integtests/main.cpp @@ -29,7 +29,7 @@ int main(int argc, char **argv) #if SYSAPI_WIN32 // record window instance for tray icon, etc - ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); + ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); #endif Arch arch; diff --git a/src/test/mock/deskflow/MockApp.h b/src/test/mock/deskflow/MockApp.h index 84f155716..5bae847a5 100644 --- a/src/test/mock/deskflow/MockApp.h +++ b/src/test/mock/deskflow/MockApp.h @@ -15,7 +15,7 @@ class MockApp : public App { public: - MockApp() : App(NULL, NULL) + MockApp() : App(nullptr, nullptr) { } diff --git a/src/test/mock/deskflow/MockArgParser.h b/src/test/mock/deskflow/MockArgParser.h index 2b1706eeb..c223bb369 100644 --- a/src/test/mock/deskflow/MockArgParser.h +++ b/src/test/mock/deskflow/MockArgParser.h @@ -15,7 +15,7 @@ class MockArgParser : public ArgParser { public: - MockArgParser() : ArgParser(NULL) + MockArgParser() : ArgParser(nullptr) { } diff --git a/src/test/shared/TestEventQueue.cpp b/src/test/shared/TestEventQueue.cpp index f4a24a6b3..a20a9a044 100644 --- a/src/test/shared/TestEventQueue.cpp +++ b/src/test/shared/TestEventQueue.cpp @@ -18,7 +18,7 @@ void TestEventQueue::raiseQuitEvent() void TestEventQueue::initQuitTimeout(double timeout) { assert(m_pQuitTimeoutTimer == nullptr); - m_pQuitTimeoutTimer = newOneShotTimer(timeout, NULL); + m_pQuitTimeoutTimer = newOneShotTimer(timeout, nullptr); adoptHandler( Event::kTimer, m_pQuitTimeoutTimer, new TMethodEventJob(this, &TestEventQueue::handleQuitTimeout) ); diff --git a/src/test/unittests/deskflow/ArgParserTests.cpp b/src/test/unittests/deskflow/ArgParserTests.cpp index 66d8696cb..39db02ccc 100644 --- a/src/test/unittests/deskflow/ArgParserTests.cpp +++ b/src/test/unittests/deskflow/ArgParserTests.cpp @@ -20,7 +20,7 @@ TEST(ArgParserTests, isArg_abbreviationsArg_returnTrue) int i = 1; const int argc = 2; const char *argv[argc] = {"stub", "-t"}; - bool result = ArgParser::isArg(i, argc, argv, "-t", NULL); + bool result = ArgParser::isArg(i, argc, argv, "-t", nullptr); EXPECT_EQ(true, result); } @@ -30,7 +30,7 @@ TEST(ArgParserTests, isArg_fullArg_returnTrue) int i = 1; const int argc = 2; const char *argv[argc] = {"stub", "--test"}; - bool result = ArgParser::isArg(i, argc, argv, NULL, "--test"); + bool result = ArgParser::isArg(i, argc, argv, nullptr, "--test"); EXPECT_EQ(true, result); } @@ -41,10 +41,10 @@ TEST(ArgParserTests, isArg_missingArgs_returnFalse) const int argc = 2; const char *argv[argc] = {"stub", "-t"}; static deskflow::ArgsBase argsBase; - ArgParser argParser(NULL); + ArgParser argParser(nullptr); argParser.setArgsBase(argsBase); - bool result = ArgParser::isArg(i, argc, argv, "-t", NULL, 1); + bool result = ArgParser::isArg(i, argc, argv, "-t", nullptr, 1); EXPECT_FALSE(result); EXPECT_EQ(true, argsBase.m_shouldExitFail); diff --git a/src/test/unittests/deskflow/DeprecatedArgsParsingTests.cpp b/src/test/unittests/deskflow/DeprecatedArgsParsingTests.cpp index ce64cf52a..b86dc7dec 100644 --- a/src/test/unittests/deskflow/DeprecatedArgsParsingTests.cpp +++ b/src/test/unittests/deskflow/DeprecatedArgsParsingTests.cpp @@ -16,7 +16,7 @@ TEST(DeprecatedArgsParsingTests, parseDeprecatedArgs_cryptoPass_returnTrue) const int argc = 3; const char *kCryptoPassCmd[argc] = {"stub", "--crypto-pass", "mock_pass"}; - ArgParser argParser(NULL); + ArgParser argParser(nullptr); bool result = argParser.parseDeprecatedArgs(argc, kCryptoPassCmd, i); @@ -30,7 +30,7 @@ TEST(DeprecatedArgsParsingTests, parseDeprecatedArgs_cryptoPass_returnFalse) const int argc = 3; const char *kCryptoPassCmd[argc] = {"stub", "--mock-arg", "mock_value"}; - ArgParser argParser(NULL); + ArgParser argParser(nullptr); bool result = argParser.parseDeprecatedArgs(argc, kCryptoPassCmd, i); diff --git a/src/test/unittests/deskflow/KeyStateTests.cpp b/src/test/unittests/deskflow/KeyStateTests.cpp index 78c009d4b..8d7beec93 100644 --- a/src/test/unittests/deskflow/KeyStateTests.cpp +++ b/src/test/unittests/deskflow/KeyStateTests.cpp @@ -74,7 +74,7 @@ TEST(KeyStateTests, sendKeyEvent_halfDuplexAndRepeat_addEventNotCalled) EXPECT_CALL(eventQueue, addEvent(_)).Times(0); - keyState.sendKeyEvent(NULL, false, true, kKeyCapsLock, 0, 0, 0); + keyState.sendKeyEvent(nullptr, false, true, kKeyCapsLock, 0, 0, 0); } TEST(KeyStateTests, sendKeyEvent_halfDuplex_addEventCalledTwice) @@ -90,7 +90,7 @@ TEST(KeyStateTests, sendKeyEvent_halfDuplex_addEventCalledTwice) EXPECT_CALL(eventQueue, addEvent(_)).Times(2); - keyState.sendKeyEvent(NULL, false, false, kKeyCapsLock, 0, 0, 0); + keyState.sendKeyEvent(nullptr, false, false, kKeyCapsLock, 0, 0, 0); } TEST(KeyStateTests, sendKeyEvent_keyRepeat_addEventCalledOnce) @@ -105,7 +105,7 @@ TEST(KeyStateTests, sendKeyEvent_keyRepeat_addEventCalledOnce) EXPECT_CALL(eventQueue, addEvent(_)).Times(1); - keyState.sendKeyEvent(NULL, false, true, 1, 0, 0, 0); + keyState.sendKeyEvent(nullptr, false, true, 1, 0, 0, 0); } TEST(KeyStateTests, sendKeyEvent_keyDown_addEventCalledOnce) @@ -120,7 +120,7 @@ TEST(KeyStateTests, sendKeyEvent_keyDown_addEventCalledOnce) EXPECT_CALL(eventQueue, addEvent(_)).Times(1); - keyState.sendKeyEvent(NULL, true, false, 1, 0, 0, 0); + keyState.sendKeyEvent(nullptr, true, false, 1, 0, 0, 0); } TEST(KeyStateTests, sendKeyEvent_keyUp_addEventCalledOnce) @@ -135,7 +135,7 @@ TEST(KeyStateTests, sendKeyEvent_keyUp_addEventCalledOnce) EXPECT_CALL(eventQueue, addEvent(_)).Times(1); - keyState.sendKeyEvent(NULL, false, false, 1, 0, 0, 0); + keyState.sendKeyEvent(nullptr, false, false, 1, 0, 0, 0); } TEST(KeyStateTests, updateKeyMap_mockKeyMap_keyMapGotMock) @@ -314,8 +314,8 @@ TEST(KeyStateTests, fakeKeyRepeat_nullKey_returnsFalse) ON_CALL(keyMap, mapKey(_, _, _, _, _, _, _, _)).WillByDefault(Return(&keyItem)); keyState.fakeKeyDown(1, 0, 0, "en"); - // change mapKey to return NULL so that fakeKeyRepeat exits early. - deskflow::KeyMap::KeyItem *nullKeyItem = NULL; + // change mapKey to return nullptr so that fakeKeyRepeat exits early. + deskflow::KeyMap::KeyItem *nullKeyItem = nullptr; ON_CALL(keyMap, mapKey(_, _, _, _, _, _, _, _)).WillByDefault(Return(nullKeyItem)); bool actual = keyState.fakeKeyRepeat(1, 0, 0, 0, "en"); diff --git a/src/test/unittests/deskflow/ProtocolUtilTests.cpp b/src/test/unittests/deskflow/ProtocolUtilTests.cpp index c10ee0fe1..0fbd482db 100644 --- a/src/test/unittests/deskflow/ProtocolUtilTests.cpp +++ b/src/test/unittests/deskflow/ProtocolUtilTests.cpp @@ -171,8 +171,8 @@ TEST_F(ProtocolUtilTests, readf_asserts) { } TEST_F(ProtocolUtilTests, readf_params_validation) { - EXPECT_FALSE(ProtocolUtil::readf(NULL, "%x", NULL)); - EXPECT_FALSE(ProtocolUtil::readf(&stream, NULL, NULL)); + EXPECT_FALSE(ProtocolUtil::readf(nullptr, "%x", nullptr)); + EXPECT_FALSE(ProtocolUtil::readf(&stream, nullptr, nullptr)); } TEST_F(ProtocolUtilTests, readf_string) { diff --git a/src/test/unittests/main.cpp b/src/test/unittests/main.cpp index bf513e903..fdf9bf21a 100644 --- a/src/test/unittests/main.cpp +++ b/src/test/unittests/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char **argv) #if SYSAPI_WIN32 // HACK: shouldn't be needed, but logging fails without this. - ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); + ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); #endif Arch arch; diff --git a/src/test/unittests/net/NetworkTests.cpp b/src/test/unittests/net/NetworkTests.cpp index 7fc5093d8..37ed36aee 100644 --- a/src/test/unittests/net/NetworkTests.cpp +++ b/src/test/unittests/net/NetworkTests.cpp @@ -56,7 +56,7 @@ void createFile(fstream &file, const char *filename, size_t size); class NetworkTests : public ::testing::Test { public: - NetworkTests() : m_mockData(NULL), m_mockDataSize(0), m_mockFileSize(0) { + NetworkTests() : m_mockData(nullptr), m_mockDataSize(0), m_mockFileSize(0) { m_mockData = newMockData(kMockDataSize); createFile(m_mockFile, kMockFilename, kMockFileSize); } @@ -353,7 +353,7 @@ void NetworkTests::sendToClient_mockData_handleClientConnected( Server *server = listener->getServer(); ClientProxy *client = listener->getNextClient(); - if (client == NULL) { + if (client == nullptr) { throw runtime_error("client is null"); } @@ -378,7 +378,7 @@ void NetworkTests::sendToClient_mockFile_handleClientConnected( Server *server = listener->getServer(); ClientProxy *client = listener->getNextClient(); - if (client == NULL) { + if (client == nullptr) { throw runtime_error("client is null"); } diff --git a/src/test/unittests/platform/MSWindowsClipboardTests.cpp b/src/test/unittests/platform/MSWindowsClipboardTests.cpp index 7d32e70fc..612b0d853 100644 --- a/src/test/unittests/platform/MSWindowsClipboardTests.cpp +++ b/src/test/unittests/platform/MSWindowsClipboardTests.cpp @@ -27,7 +27,7 @@ protected: private: void emptyClipboard() { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.empty(); } @@ -41,7 +41,7 @@ public: TEST_F(MSWindowsClipboardTests, emptyUnowned_openCalled_returnsTrue) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); bool actual = clipboard.emptyUnowned(); @@ -51,7 +51,7 @@ TEST_F(MSWindowsClipboardTests, emptyUnowned_openCalled_returnsTrue) TEST_F(MSWindowsClipboardTests, empty_openCalled_returnsTrue) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); bool actual = clipboard.empty(); @@ -61,7 +61,7 @@ TEST_F(MSWindowsClipboardTests, empty_openCalled_returnsTrue) TEST_F(MSWindowsClipboardTests, empty_singleFormat_hasReturnsFalse) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.add(MSWindowsClipboard::kText, "synergy rocks!"); @@ -73,7 +73,7 @@ TEST_F(MSWindowsClipboardTests, empty_singleFormat_hasReturnsFalse) TEST_F(MSWindowsClipboardTests, add_newValue_valueWasStored) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.add(IClipboard::kText, "synergy rocks!"); @@ -87,7 +87,7 @@ TEST_F(MSWindowsClipboardTests, add_newValue_writeWasCalled) MockFacade facade; EXPECT_CALL(facade, write(testing::_, testing::_)); - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.setFacade(facade); clipboard.open(0); @@ -96,7 +96,7 @@ TEST_F(MSWindowsClipboardTests, add_newValue_writeWasCalled) TEST_F(MSWindowsClipboardTests, add_replaceValue_valueWasReplaced) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.add(IClipboard::kText, "synergy rocks!"); @@ -108,7 +108,7 @@ TEST_F(MSWindowsClipboardTests, add_replaceValue_valueWasReplaced) TEST_F(MSWindowsClipboardTests, open_timeIsZero_returnsTrue) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); bool actual = clipboard.open(0); @@ -117,7 +117,7 @@ TEST_F(MSWindowsClipboardTests, open_timeIsZero_returnsTrue) TEST_F(MSWindowsClipboardTests, open_timeIsOne_returnsTrue) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); bool actual = clipboard.open(1); @@ -126,7 +126,7 @@ TEST_F(MSWindowsClipboardTests, open_timeIsOne_returnsTrue) TEST_F(MSWindowsClipboardTests, close_isOpen_noErrors) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.close(); @@ -138,7 +138,7 @@ TEST_F(MSWindowsClipboardTests, close_isOpen_noErrors) #if 0 TEST_F(MSWindowsClipboardTests, getTime_openWithNoEmpty_returnsOne) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(1); MSWindowsClipboard::Time actual = clipboard.getTime(); @@ -150,7 +150,7 @@ TEST_F(MSWindowsClipboardTests, getTime_openWithNoEmpty_returnsOne) TEST_F(MSWindowsClipboardTests, getTime_openAndEmpty_returnsOne) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(1); clipboard.empty(); @@ -162,7 +162,7 @@ TEST_F(MSWindowsClipboardTests, getTime_openAndEmpty_returnsOne) TEST_F(MSWindowsClipboardTests, has_withFormatAdded_returnsTrue) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.empty(); clipboard.add(IClipboard::kText, "synergy rocks!"); @@ -174,7 +174,7 @@ TEST_F(MSWindowsClipboardTests, has_withFormatAdded_returnsTrue) TEST_F(MSWindowsClipboardTests, has_withNoFormats_returnsFalse) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.empty(); @@ -185,7 +185,7 @@ TEST_F(MSWindowsClipboardTests, has_withNoFormats_returnsFalse) TEST_F(MSWindowsClipboardTests, get_withNoFormats_returnsEmpty) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.empty(); @@ -196,7 +196,7 @@ TEST_F(MSWindowsClipboardTests, get_withNoFormats_returnsEmpty) TEST_F(MSWindowsClipboardTests, get_withFormatAdded_returnsExpected) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); clipboard.empty(); clipboard.add(IClipboard::kText, "synergy rocks!"); @@ -208,7 +208,7 @@ TEST_F(MSWindowsClipboardTests, get_withFormatAdded_returnsExpected) TEST_F(MSWindowsClipboardTests, isOwnedByDeskflow_defaultState_noError) { - MSWindowsClipboard clipboard(NULL); + MSWindowsClipboard clipboard(nullptr); clipboard.open(0); bool actual = clipboard.isOwnedByDeskflow(); diff --git a/src/test/unittests/platform/XWindowsKeyStateTests.cpp b/src/test/unittests/platform/XWindowsKeyStateTests.cpp index 7c0fb6e89..6e66058b8 100644 --- a/src/test/unittests/platform/XWindowsKeyStateTests.cpp +++ b/src/test/unittests/platform/XWindowsKeyStateTests.cpp @@ -30,10 +30,10 @@ class XWindowsKeyStateTests : public ::testing::Test { protected: - XWindowsKeyStateTests() : m_display(NULL) {} + XWindowsKeyStateTests() : m_display(nullptr) {} ~XWindowsKeyStateTests() { - if (m_display != NULL) { + if (m_display != nullptr) { LOG((CLOG_DEBUG "closing display")); XCloseDisplay(m_display); } @@ -41,11 +41,11 @@ protected: virtual void SetUp() { // open the display only once for the entire test suite - if (this->m_display == NULL) { + if (this->m_display == nullptr) { LOG((CLOG_DEBUG "opening display")); - this->m_display = XOpenDisplay(NULL); + this->m_display = XOpenDisplay(nullptr); - ASSERT_TRUE(this->m_display != NULL) + ASSERT_TRUE(this->m_display != nullptr) << "unable to open display: " << errno; } } diff --git a/src/test/unittests/platform/XWindowsScreenSaverTests.cpp b/src/test/unittests/platform/XWindowsScreenSaverTests.cpp index 3a3fb4861..2ed3b1738 100644 --- a/src/test/unittests/platform/XWindowsScreenSaverTests.cpp +++ b/src/test/unittests/platform/XWindowsScreenSaverTests.cpp @@ -24,7 +24,7 @@ TEST(CXWindowsScreenSaverTests, activate_defaultScreen_todo) MockEventQueue eventQueue; EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1); CXWindowsScreenSaver screenSaver( - display, window, NULL, &eventQueue); + display, window, nullptr, &eventQueue); screenSaver.activate();