diff options
| author | 2021-11-10 00:54:13 -0500 | |
|---|---|---|
| committer | 2021-11-10 00:54:13 -0500 | |
| commit | beb08eb751fa8e1f72042f263316ab5e5ddb596d (patch) | |
| tree | 3b00df983527648bdae610ac7b88cb639b1f1828 /src/lib/base | |
| parent | fbc30002ab3438356c0476e70c4577a0310d52c0 (diff) | |
New upstream version 2.4.0+dfsg.upstream/2.4.0+dfsgupstream
Diffstat (limited to 'src/lib/base')
35 files changed, 243 insertions, 261 deletions
diff --git a/src/lib/base/CMakeLists.txt b/src/lib/base/CMakeLists.txt index 66ba5a6..9bd4472 100644 --- a/src/lib/base/CMakeLists.txt +++ b/src/lib/base/CMakeLists.txt @@ -1,11 +1,11 @@ # barrier -- mouse and keyboard sharing utility # Copyright (C) 2012-2016 Symless Ltd. # Copyright (C) 2009 Nick Bolton -# +# # This package is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # found in the file LICENSE that should have accompanied this file. -# +# # This package is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/ELevel.h b/src/lib/base/ELevel.h index ec0f94f..45b51d7 100644 --- a/src/lib/base/ELevel.h +++ b/src/lib/base/ELevel.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2011 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/Event.cpp b/src/lib/base/Event.cpp index f2c1a12..cc548fc 100644 --- a/src/lib/base/Event.cpp +++ b/src/lib/base/Event.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/Event.h b/src/lib/base/Event.h index 2741813..38a2cf1 100644 --- a/src/lib/base/Event.h +++ b/src/lib/base/Event.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -71,7 +71,7 @@ public: Deletes event data for the given event (using free()). */ static void deleteData(const Event&); - + //! Set data (non-POD) /*! Set non-POD (non plain old data), where delete is called when the event @@ -114,7 +114,7 @@ public: Returns the event flags. */ Flags getFlags() const; - + //@} private: diff --git a/src/lib/base/EventQueue.cpp b/src/lib/base/EventQueue.cpp index 2429522..7764ed8 100644 --- a/src/lib/base/EventQueue.cpp +++ b/src/lib/base/EventQueue.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -100,7 +100,7 @@ EventQueue::~EventQueue() delete m_buffer; delete m_readyCondVar; delete m_readyMutex; - + ARCH->setSignalHandler(Arch::kINTERRUPT, NULL, NULL); ARCH->setSignalHandler(Arch::kTERMINATE, NULL, NULL); } @@ -121,7 +121,7 @@ EventQueue::loop() addEventToBuffer(event); m_pending.pop(); } - + Event event; getEvent(event); while (event.getType() != Event::kQuit) { @@ -298,7 +298,7 @@ EventQueue::addEvent(const Event& event) default: break; } - + if ((event.getFlags() & Event::kDeliverImmediately) != 0) { dispatchEvent(event); Event::deleteData(event); @@ -315,10 +315,10 @@ void EventQueue::addEventToBuffer(const Event& event) { std::lock_guard<std::mutex> lock(m_mutex); - + // store the event's data locally UInt32 eventID = saveEvent(event); - + // add it if (!m_buffer->addEvent(eventID)) { // failed to send event @@ -568,7 +568,7 @@ EventQueue::waitForReady() const { double timeout = ARCH->time() + 10; Lock lock(m_readyMutex); - + while (!m_readyCondVar->wait()) { if (ARCH->time() > timeout) { throw std::runtime_error("event queue is not ready within 5 sec"); diff --git a/src/lib/base/EventQueue.h b/src/lib/base/EventQueue.h index 842c5ca..55b6fce 100644 --- a/src/lib/base/EventQueue.h +++ b/src/lib/base/EventQueue.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -71,7 +71,7 @@ private: double getNextTimerTimeout() const; void addEventToBuffer(const Event& event); bool parent_requests_shutdown() const; - + private: class Timer { public: diff --git a/src/lib/base/EventTypes.cpp b/src/lib/base/EventTypes.cpp index 2ba2077..173a0a9 100644 --- a/src/lib/base/EventTypes.cpp +++ b/src/lib/base/EventTypes.cpp @@ -1,11 +1,11 @@ /* * barrier -- mouse and keyboard sharing utility * Copyright (C) 2013-2016 Symless Ltd. - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -56,6 +56,7 @@ REGISTER_EVENT(IStream, outputFlushed) REGISTER_EVENT(IStream, outputError) REGISTER_EVENT(IStream, inputShutdown) REGISTER_EVENT(IStream, outputShutdown) +REGISTER_EVENT(IStream, inputFormatError) // // IpcClient diff --git a/src/lib/base/EventTypes.h b/src/lib/base/EventTypes.h index f81617e..995490e 100644 --- a/src/lib/base/EventTypes.h +++ b/src/lib/base/EventTypes.h @@ -1,11 +1,11 @@ /* * barrier -- mouse and keyboard sharing utility * Copyright (C) 2013-2016 Symless Ltd. - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -133,14 +133,20 @@ public: */ Event::Type outputShutdown(); + /** Get input format error event type + + This is sent when a stream receives an irrecoverable input format error. + */ + Event::Type inputFormatError(); //@} - + private: Event::Type m_inputReady; Event::Type m_outputFlushed; Event::Type m_outputError; Event::Type m_inputShutdown; Event::Type m_outputShutdown; + Event::Type m_inputFormatError; }; class IpcClientEvents : public EventTypes { @@ -159,7 +165,7 @@ public: Event::Type messageReceived(); //@} - + private: Event::Type m_connected; Event::Type m_messageReceived; @@ -179,7 +185,7 @@ public: //! Raised when the client disconnects from the server. Event::Type disconnected(); - + //@} private: @@ -198,7 +204,7 @@ public: //! Raised when we have created the client proxy. Event::Type clientConnected(); - + //! Raised when a message is received through a client proxy. Event::Type messageReceived(); @@ -242,7 +248,7 @@ public: event when a remote connection has been established. */ Event::Type connected(); - + //! Get secure connected event type /*! Returns the secure socket connected event type. A secure socket sends @@ -342,14 +348,14 @@ public: //! @name accessors //@{ - + //! Get accepted event type /*! Returns the accepted event type. This is sent whenever a server accepts a client. */ Event::Type accepted(); - + //! Get connected event type /*! Returns the connected event type. This is sent whenever a @@ -419,7 +425,7 @@ public: Event::Type failure(); //@} - + private: Event::Type m_success; Event::Type m_failure; @@ -510,7 +516,7 @@ public: Event::Type screenSwitched(); //@} - + private: Event::Type m_error; Event::Type m_connected; @@ -529,16 +535,16 @@ public: m_reloadConfig(Event::kUnknown), m_forceReconnect(Event::kUnknown), m_resetServer(Event::kUnknown) { } - + //! @name accessors //@{ - + Event::Type reloadConfig(); Event::Type forceReconnect(); Event::Type resetServer(); //@} - + private: Event::Type m_reloadConfig; Event::Type m_forceReconnect; @@ -565,7 +571,7 @@ public: Event::Type keyRepeat(); //@} - + private: Event::Type m_keyDown; Event::Type m_keyUp; @@ -589,7 +595,7 @@ public: //! @name accessors //@{ - + //! button down event type. Event data is ButtonInfo*. Event::Type buttonDown(); @@ -677,7 +683,7 @@ public: to sleep or a user session is deactivated (fast user switching). */ Event::Type suspend(); - + //! Get resume event type /*! Returns the resume event type. This is sent whenever the system wakes @@ -686,7 +692,7 @@ public: Event::Type resume(); //@} - + private: Event::Type m_error; Event::Type m_shapeChanged; @@ -722,7 +728,7 @@ public: //! Clipboard sending event type /*! - Returns the clipboard sending event type. This is used to send + Returns the clipboard sending event type. This is used to send clipboard chunks. */ Event::Type clipboardSending(); diff --git a/src/lib/base/FunctionEventJob.cpp b/src/lib/base/FunctionEventJob.cpp index 705e058..751b50d 100644 --- a/src/lib/base/FunctionEventJob.cpp +++ b/src/lib/base/FunctionEventJob.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/FunctionEventJob.h b/src/lib/base/FunctionEventJob.h index 4b2c2fc..3d9acaa 100644 --- a/src/lib/base/FunctionEventJob.h +++ b/src/lib/base/FunctionEventJob.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/FunctionJob.cpp b/src/lib/base/FunctionJob.cpp deleted file mode 100644 index 859010e..0000000 --- a/src/lib/base/FunctionJob.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * barrier -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. - * Copyright (C) 2002 Chris Schoeneman - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "base/FunctionJob.h" - -// -// FunctionJob -// - -FunctionJob::FunctionJob(void (*func)(void*), void* arg) : - m_func(func), - m_arg(arg) -{ - // do nothing -} - -FunctionJob::~FunctionJob() -{ - // do nothing -} - -void -FunctionJob::run() -{ - if (m_func != NULL) { - m_func(m_arg); - } -} diff --git a/src/lib/base/FunctionJob.h b/src/lib/base/FunctionJob.h deleted file mode 100644 index 9cdfa9d..0000000 --- a/src/lib/base/FunctionJob.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * barrier -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. - * Copyright (C) 2002 Chris Schoeneman - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include "base/IJob.h" - -//! Use a function as a job -/*! -A job class that invokes a function. -*/ -class FunctionJob : public IJob { -public: - //! run() invokes \c func(arg) - FunctionJob(void (*func)(void*), void* arg = NULL); - virtual ~FunctionJob(); - - // IJob overrides - virtual void run(); - -private: - void (*m_func)(void*); - void* m_arg; -}; diff --git a/src/lib/base/IEventJob.h b/src/lib/base/IEventJob.h index 3e4a420..844cc4a 100644 --- a/src/lib/base/IEventJob.h +++ b/src/lib/base/IEventJob.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/IEventQueue.h b/src/lib/base/IEventQueue.h index 150595c..833081c 100644 --- a/src/lib/base/IEventQueue.h +++ b/src/lib/base/IEventQueue.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -184,7 +184,7 @@ public: be added. */ virtual void waitForReady() const = 0; - + //@} //! @name accessors //@{ @@ -216,7 +216,7 @@ public: virtual void* getSystemTarget() = 0; //@} - + // // Event type providers. // diff --git a/src/lib/base/IEventQueueBuffer.h b/src/lib/base/IEventQueueBuffer.h index b594436..f25cc66 100644 --- a/src/lib/base/IEventQueueBuffer.h +++ b/src/lib/base/IEventQueueBuffer.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -38,7 +38,7 @@ public: //! @name manipulators //@{ - + //! Initialize /*! Useful for platform-specific initialisation from a specific thread. diff --git a/src/lib/base/IJob.h b/src/lib/base/IJob.h index f966ec0..29aa941 100644 --- a/src/lib/base/IJob.h +++ b/src/lib/base/IJob.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/ILogOutputter.h b/src/lib/base/ILogOutputter.h index ab218fc..e11f9e2 100644 --- a/src/lib/base/ILogOutputter.h +++ b/src/lib/base/ILogOutputter.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/Log.cpp b/src/lib/base/Log.cpp index a3b328d..8f52a80 100644 --- a/src/lib/base/Log.cpp +++ b/src/lib/base/Log.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -25,7 +25,7 @@ #include <cstdio> #include <cstring> #include <iostream> -#include <ctime> +#include <ctime> // names of priorities static const char* g_priority[] = { @@ -62,7 +62,7 @@ Log::Log() { assert(s_log == NULL); - // other initalization + // other initialization m_maxPriority = g_defaultMaxPriority; m_maxNewlineLength = 0; insert(new ConsoleLogOutputter); @@ -145,7 +145,7 @@ Log::print(const char* file, int line, const char* fmt, ...) // try printing into the buffer va_list args; va_start(args, fmt); - int n = ARCH->vsnprintf(buffer, len - sPad, fmt, args); + int n = std::vsnprintf(buffer, len - sPad, fmt, args); va_end(args); // if the buffer wasn't big enough then make it bigger and try again diff --git a/src/lib/base/Log.h b/src/lib/base/Log.h index 0ed458f..22224b9 100644 --- a/src/lib/base/Log.h +++ b/src/lib/base/Log.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -91,7 +91,7 @@ public: then it simply returns true. */ bool setFilter(const char* name); - + //! Set the minimum priority filter (by ordinal). void setFilter(int); @@ -193,9 +193,9 @@ otherwise it expands to a call that doesn't. #define CLOG_TRACE __FILE__, __LINE__, #endif -// the CLOG_* defines are line and file plus %z and an octal number (060=0, -// 071=9), but the limitation is that once we run out of numbers at either -// end, then we resort to using non-numerical chars. this still works (since +// the CLOG_* defines are line and file plus %z and an octal number (060=0, +// 071=9), but the limitation is that once we run out of numbers at either +// end, then we resort to using non-numerical chars. this still works (since // to deduce the number we subtract octal \060, so '/' is -1, and ':' is 10 #define CLOG_PRINT CLOG_TRACE "%z\057" // char is '/' diff --git a/src/lib/base/PriorityQueue.h b/src/lib/base/PriorityQueue.h index d2ca70e..8aac88c 100644 --- a/src/lib/base/PriorityQueue.h +++ b/src/lib/base/PriorityQueue.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2003 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/SimpleEventQueueBuffer.cpp b/src/lib/base/SimpleEventQueueBuffer.cpp index b55fe55..a26f255 100644 --- a/src/lib/base/SimpleEventQueueBuffer.cpp +++ b/src/lib/base/SimpleEventQueueBuffer.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/SimpleEventQueueBuffer.h b/src/lib/base/SimpleEventQueueBuffer.h index 4aa76d3..db6a502 100644 --- a/src/lib/base/SimpleEventQueueBuffer.h +++ b/src/lib/base/SimpleEventQueueBuffer.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -28,7 +28,7 @@ An event queue buffer provides a queue of events for an IEventQueue. */ class SimpleEventQueueBuffer : public IEventQueueBuffer { public: - SimpleEventQueueBuffer(); + SimpleEventQueueBuffer(); ~SimpleEventQueueBuffer(); // IEventQueueBuffer overrides diff --git a/src/lib/base/Stopwatch.cpp b/src/lib/base/Stopwatch.cpp index b9ceb85..a174ea6 100644 --- a/src/lib/base/Stopwatch.cpp +++ b/src/lib/base/Stopwatch.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/Stopwatch.h b/src/lib/base/Stopwatch.h index dda74ea..81098fd 100644 --- a/src/lib/base/Stopwatch.h +++ b/src/lib/base/Stopwatch.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -88,7 +88,7 @@ public: */ bool isStopped() const; - // return the time since the last reset(). + // return the time since the last reset(). //! Get elapsed time /*! Returns the time since the last reset(). This cannot trigger the diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index 1ab3623..adbb11d 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -1,11 +1,11 @@ /* * barrier -- mouse and keyboard sharing utility * Copyright (C) 2014-2016 Symless Ltd. - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -35,6 +35,42 @@ namespace barrier { namespace string { +namespace { + +// returns negative in case of non-matching character +int hex_to_number(char ch) +{ + switch (ch) { + case '0': return 0; + case '1': return 1; + case '2': return 2; + case '3': return 3; + case '4': return 4; + case '5': return 5; + case '6': return 6; + case '7': return 7; + case '8': return 8; + case '9': return 9; + + case 'a': return 10; + case 'b': return 11; + case 'c': return 12; + case 'd': return 13; + case 'e': return 14; + case 'f': return 15; + + case 'A': return 10; + case 'B': return 11; + case 'C': return 12; + case 'D': return 13; + case 'E': return 14; + case 'F': return 15; + } + return -1; +} + +} // namespace + std::string format(const char* fmt, ...) { @@ -135,7 +171,7 @@ sprintf(const char* fmt, ...) // try printing into the buffer va_list args; va_start(args, fmt); - int n = ARCH->vsnprintf(buffer, len, fmt, args); + int n = std::vsnprintf(buffer, len, fmt, args); va_end(args); // if the buffer wasn't big enough then make it bigger and try again @@ -185,16 +221,42 @@ removeFileExt(std::string filename) return filename.substr(0, dot); } -void -toHex(std::string& subject, int width, const char fill) +std::string to_hex(const std::vector<std::uint8_t>& subject, int width, const char fill) { std::stringstream ss; ss << std::hex; - for (unsigned int i = 0; i < subject.length(); i++) { - ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i]; + for (unsigned int i = 0; i < subject.size(); i++) { + ss << std::setw(width) << std::setfill(fill) << static_cast<int>(subject[i]); } - subject = ss.str(); + return ss.str(); +} + +std::vector<std::uint8_t> from_hex(const std::string& data) +{ + std::vector<std::uint8_t> result; + result.reserve(data.size() / 2); + + std::size_t i = 0; + while (i < data.size()) { + if (data[i] == ':') { + i++; + continue; + } + + if (i + 2 > data.size()) { + return {}; // uneven character count follows, it's unclear how to interpret it + } + + auto high = hex_to_number(data[i]); + auto low = hex_to_number(data[i + 1]); + if (high < 0 || low < 0) { + return {}; + } + result.push_back(high * 16 + low); + i += 2; + } + return result; } void diff --git a/src/lib/base/String.h b/src/lib/base/String.h index 73526b4..9c5a53b 100644 --- a/src/lib/base/String.h +++ b/src/lib/base/String.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -75,7 +75,10 @@ std::string removeFileExt(std::string filename); /*! Convert each character in \c subject into hexdecimal form with \c width */ -void toHex(std::string& subject, int width, const char fill = '0'); +std::string to_hex(const std::vector<std::uint8_t>& subject, int width, const char fill = '0'); + +/// Convert binary data from hexadecimal +std::vector<std::uint8_t> from_hex(const std::string& data); //! Convert to all uppercase /*! diff --git a/src/lib/base/TMethodEventJob.h b/src/lib/base/TMethodEventJob.h index a65f8c9..04a36fd 100644 --- a/src/lib/base/TMethodEventJob.h +++ b/src/lib/base/TMethodEventJob.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/TMethodJob.h b/src/lib/base/TMethodJob.h deleted file mode 100644 index ec88f05..0000000 --- a/src/lib/base/TMethodJob.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * barrier -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. - * Copyright (C) 2002 Chris Schoeneman - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include "IJob.h" - -//! Use a function as a job -/*! -A job class that invokes a member function. -*/ -template <class T> -class TMethodJob : public IJob { -public: - //! run() invokes \c object->method(arg) - TMethodJob(T* object, void (T::*method)(void*), void* arg = NULL); - virtual ~TMethodJob(); - - // IJob overrides - virtual void run(); - -private: - T* m_object; - void (T::*m_method)(void*); - void* m_arg; -}; - -template <class T> -inline -TMethodJob<T>::TMethodJob(T* object, void (T::*method)(void*), void* arg) : - m_object(object), - m_method(method), - m_arg(arg) -{ - // do nothing -} - -template <class T> -inline -TMethodJob<T>::~TMethodJob() -{ - // do nothing -} - -template <class T> -inline -void -TMethodJob<T>::run() -{ - if (m_object != NULL) { - (m_object->*m_method)(m_arg); - } -} diff --git a/src/lib/base/Unicode.cpp b/src/lib/base/Unicode.cpp index 05b0212..2bd0360 100644 --- a/src/lib/base/Unicode.cpp +++ b/src/lib/base/Unicode.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/Unicode.h b/src/lib/base/Unicode.h index 9bf83ae..430bb1b 100644 --- a/src/lib/base/Unicode.h +++ b/src/lib/base/Unicode.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/XBase.cpp b/src/lib/base/XBase.cpp index cb0db2e..b7a7baf 100644 --- a/src/lib/base/XBase.cpp +++ b/src/lib/base/XBase.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/XBase.h b/src/lib/base/XBase.h index 59b700e..0b46750 100644 --- a/src/lib/base/XBase.h +++ b/src/lib/base/XBase.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/base/finally.h b/src/lib/base/finally.h new file mode 100644 index 0000000..f3be617 --- /dev/null +++ b/src/lib/base/finally.h @@ -0,0 +1,61 @@ +/* + barrier -- mouse and keyboard sharing utility + Copyright (C) Barrier contributors + + This package is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + found in the file LICENSE that should have accompanied this file. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef BARRIER_LIB_BASE_FINALLY_H +#define BARRIER_LIB_BASE_FINALLY_H + +#include <utility> + +namespace barrier { + +// this implements a common pattern of executing an action at the end of function + +template<class Callable> +class final_action { +public: + final_action() noexcept {} + final_action(Callable callable) noexcept : callable_{callable} {} + + ~final_action() noexcept + { + if (!invoked_) { + callable_(); + } + } + + final_action(final_action&& other) noexcept : + callable_{std::move(other.callable_)} + { + std::swap(invoked_, other.invoked_); + } + + final_action(const final_action&) = delete; + final_action& operator=(const final_action&) = delete; +private: + bool invoked_ = false; + Callable callable_; +}; + +template<class Callable> +inline final_action<Callable> finally(Callable&& callable) noexcept +{ + return final_action<Callable>(std::forward<Callable>(callable)); +} + +} // namespace barrier + +#endif // BARRIER_LIB_BASE_FINALLY_H diff --git a/src/lib/base/log_outputters.cpp b/src/lib/base/log_outputters.cpp index af53192..176af2d 100644 --- a/src/lib/base/log_outputters.cpp +++ b/src/lib/base/log_outputters.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -17,10 +17,9 @@ */ #include "base/log_outputters.h" -#include "base/TMethodJob.h" #include "arch/Arch.h" #include "base/String.h" - +#include "io/filesystem.h" #include <fstream> enum EFileLogOutputter { @@ -260,7 +259,7 @@ FileLogOutputter::write(ELevel level, const char *message) bool moveFile = false; std::ofstream m_handle; - m_handle.open(m_fileName.c_str(), std::fstream::app); + barrier::open_utf8_path(m_handle, m_fileName, std::fstream::app); if (m_handle.is_open() && m_handle.fail() != true) { m_handle << message << std::endl; @@ -305,7 +304,7 @@ MesssageBoxLogOutputter::~MesssageBoxLogOutputter() } void -MesssageBoxLogOutputter::open(const char* title) +MesssageBoxLogOutputter::open(const char* title) { // do nothing } diff --git a/src/lib/base/log_outputters.h b/src/lib/base/log_outputters.h index 15f1e7a..2a84170 100644 --- a/src/lib/base/log_outputters.h +++ b/src/lib/base/log_outputters.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
