deskflow/src/lib/ipc/IpcLogOutputter.h

107 lines
2.6 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Synergy Si Ltd.
2012-06-10 16:50:54 +00:00
* Copyright (C) 2012 Nick Bolton
*
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
* found in the file LICENSE that should have accompanied this file.
*
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
#include "arch/Arch.h"
#include "arch/IArchMultithread.h"
#include "base/ILogOutputter.h"
#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
//! 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:
2014-11-11 13:51:47 +00:00
IpcLogOutputter(IpcServer& ipcServer);
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);
2015-05-15 13:44:25 +00:00
//! @name manipulators
//@{
//! Same as write, but allows message to sidestep anti-recursion mechanism.
bool write(ELevel level, const char* text, bool force);
//! Notify that the buffer should be sent.
void notifyBuffer();
2012-06-10 16:50:54 +00:00
2015-05-15 13:44:25 +00:00
//! Set the buffer size.
/*!
Set the maximum size of the buffer to protect memory
from runaway logging.
*/
void bufferMaxSize(UInt16 bufferMaxSize);
//! Close the outputter
/*!
Close the outputter. If \p waitForEmpty is true, it will wait until
the buffer has been sent to the IPC server before closing.
*/
void close(bool waitForEmpty);
//@}
//! @name accessors
//@{
//! Get the buffer size
/*!
Returns the maximum size of the buffer.
*/
UInt16 bufferMaxSize() const;
//@}
private:
2015-05-15 13:44:25 +00:00
void init();
void bufferThread(void*);
2014-11-11 13:51:47 +00:00
String getChunk(size_t count);
void sendBuffer();
2014-11-11 13:51:47 +00:00
void appendBuffer(const String& text);
private:
typedef std::deque<String> Buffer;
2014-11-11 13:51:47 +00:00
IpcServer& m_ipcServer;
Buffer m_buffer;
ArchMutex m_bufferMutex;
bool m_sending;
2015-05-15 13:44:25 +00:00
Thread* m_bufferThread;
bool m_running;
2014-11-11 13:51:47 +00:00
ArchCond m_notifyCond;
ArchMutex m_notifyMutex;
bool m_bufferWaiting;
IArchMultithread::ThreadID
m_bufferThreadId;
2015-05-15 13:44:25 +00:00
UInt16 m_bufferMaxSize;
ArchCond m_bufferEmptyCond;
ArchMutex m_bufferEmptyMutex;
2012-06-10 16:50:54 +00:00
};