2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-06-10 16:50:54 +00:00
|
|
|
* Copyright (C) 2012 Nick Bolton
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* 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
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "arch/Arch.h"
|
|
|
|
|
#include "arch/IArchMultithread.h"
|
|
|
|
|
#include "base/ILogOutputter.h"
|
2024-08-09 13:03:48 +00:00
|
|
|
#include "common/ipc.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
|
2015-05-15 14:04:16 +00:00
|
|
|
#include <deque>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
class IpcServer;
|
|
|
|
|
class Event;
|
|
|
|
|
class IpcClientProxy;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2012-07-03 14:15:05 +00:00
|
|
|
//! Write log to GUI over IPC
|
|
|
|
|
/*!
|
|
|
|
|
This outputter writes output to the GUI via IPC.
|
|
|
|
|
*/
|
2014-11-11 13:51:47 +00:00
|
|
|
class IpcLogOutputter : public ILogOutputter {
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2024-07-02 19:07:06 +00:00
|
|
|
/*!
|
|
|
|
|
If \p useThread is \c true, the buffer will be sent using a thread.
|
|
|
|
|
If \p useThread is \c false, then the buffer needs to be sent manually
|
|
|
|
|
using the \c sendBuffer() function.
|
|
|
|
|
*/
|
2024-07-16 13:36:44 +00:00
|
|
|
IpcLogOutputter(
|
2024-07-18 07:04:39 +00:00
|
|
|
IpcServer &ipcServer, IpcClientType clientType, bool useThread);
|
2024-07-02 19:07:06 +00:00
|
|
|
IpcLogOutputter(IpcLogOutputter const &) = delete;
|
|
|
|
|
virtual ~IpcLogOutputter();
|
|
|
|
|
|
|
|
|
|
// ILogOutputter overrides
|
|
|
|
|
virtual void open(const char *title);
|
|
|
|
|
virtual void close();
|
|
|
|
|
virtual void show(bool showIfEmpty);
|
|
|
|
|
virtual bool write(ELevel level, const char *message);
|
|
|
|
|
|
|
|
|
|
//! @name manipulators
|
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
//! Notify that the buffer should be sent.
|
|
|
|
|
void notifyBuffer();
|
|
|
|
|
|
|
|
|
|
//! Set the buffer size
|
|
|
|
|
/*!
|
|
|
|
|
Set the maximum size of the buffer to protect memory
|
|
|
|
|
from runaway logging.
|
|
|
|
|
*/
|
|
|
|
|
void bufferMaxSize(UInt16 bufferMaxSize);
|
|
|
|
|
|
|
|
|
|
//! Set the rate limit
|
|
|
|
|
/*!
|
|
|
|
|
Set the maximum number of \p writeRate for every \p timeRate in seconds.
|
|
|
|
|
*/
|
|
|
|
|
void bufferRateLimit(UInt16 writeLimit, double timeLimit);
|
|
|
|
|
|
|
|
|
|
//! Send the buffer
|
|
|
|
|
/*!
|
|
|
|
|
Sends a chunk of the buffer to the IPC server, normally called
|
|
|
|
|
when threaded mode is on.
|
|
|
|
|
*/
|
|
|
|
|
void sendBuffer();
|
|
|
|
|
|
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
//! @name accessors
|
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
//! Get the buffer size
|
|
|
|
|
/*!
|
|
|
|
|
Returns the maximum size of the buffer.
|
|
|
|
|
*/
|
|
|
|
|
UInt16 bufferMaxSize() const;
|
|
|
|
|
|
|
|
|
|
//@}
|
2015-05-15 13:44:25 +00:00
|
|
|
|
2012-07-08 16:01:27 +00:00
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
void init();
|
|
|
|
|
void bufferThread(void *);
|
|
|
|
|
String getChunk(size_t count);
|
|
|
|
|
void appendBuffer(const String &text);
|
|
|
|
|
bool isRunning();
|
2012-07-06 12:27:22 +00:00
|
|
|
|
2012-07-03 14:15:05 +00:00
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
typedef std::deque<String> Buffer;
|
|
|
|
|
|
|
|
|
|
IpcServer &m_ipcServer;
|
|
|
|
|
Buffer m_buffer;
|
|
|
|
|
ArchMutex m_bufferMutex;
|
|
|
|
|
bool m_sending;
|
|
|
|
|
Thread *m_bufferThread;
|
|
|
|
|
bool m_running;
|
|
|
|
|
ArchCond m_notifyCond;
|
|
|
|
|
ArchMutex m_notifyMutex;
|
|
|
|
|
bool m_bufferWaiting;
|
|
|
|
|
IArchMultithread::ThreadID m_bufferThreadId;
|
|
|
|
|
UInt16 m_bufferMaxSize;
|
|
|
|
|
UInt16 m_bufferRateWriteLimit;
|
|
|
|
|
double m_bufferRateTimeLimit;
|
|
|
|
|
UInt16 m_bufferWriteCount;
|
|
|
|
|
double m_bufferRateStart;
|
2024-07-18 07:04:39 +00:00
|
|
|
IpcClientType m_clientType;
|
2024-07-02 19:07:06 +00:00
|
|
|
ArchMutex m_runningMutex;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|