CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/Log/ConsoleListener.h
Views: 1401
1
// Copyright (C) 2003 Dolphin Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official SVN repository and contact information can be found at
16
// http://code.google.com/p/dolphin-emu/
17
18
#pragma once
19
20
// Windows-only.
21
22
#include "ppsspp_config.h"
23
24
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
25
26
#include <atomic>
27
#include <thread>
28
29
#include "Common/Log/LogManager.h"
30
#include "Common/CommonWindows.h"
31
32
class ConsoleListener : public LogListener {
33
public:
34
ConsoleListener();
35
~ConsoleListener();
36
37
void Init(bool AutoOpen = true, int Width = 200, int Height = 100);
38
void Open();
39
void UpdateHandle();
40
void Close();
41
bool IsOpen();
42
void LetterSpace(int Width, int Height);
43
void BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst);
44
void PixelSpace(int Left, int Top, int Width, int Height, bool);
45
COORD GetCoordinates(int BytesRead, int BufferWidth);
46
void Log(const LogMessage &message) override;
47
void ClearScreen(bool Cursor = true);
48
49
void Show(bool bShow);
50
bool Hidden() const { return hidden_; }
51
52
private:
53
HWND hWnd = nullptr;
54
HANDLE hConsole = nullptr;
55
56
void LogWriterThread();
57
void SendToThread(LogLevel Level, const char *Text);
58
void WriteToConsole(LogLevel Level, const char *Text, size_t Len);
59
60
std::thread thread_;
61
62
HANDLE hTriggerEvent = nullptr;
63
CRITICAL_SECTION criticalSection{};
64
65
char *logPending_ = nullptr;
66
std::atomic<uint32_t> logPendingReadPos_;
67
std::atomic<uint32_t> logPendingWritePos_;
68
69
int openWidth_ = 0;
70
int openHeight_ = 0;
71
bool hidden_ = false;
72
bool useColor_ = true;
73
bool useThread_ = true;
74
};
75
76
#endif
77
78