Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/Log/ConsoleListener.h
3186 views
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.h"
30
#include "Common/CommonWindows.h"
31
32
struct LogMessage;
33
34
class ConsoleListener {
35
public:
36
ConsoleListener();
37
~ConsoleListener();
38
39
void Init(bool AutoOpen = true, int Width = 200, int Height = 100);
40
void Open();
41
void UpdateHandle();
42
void Close();
43
bool IsOpen();
44
void LetterSpace(int Width, int Height);
45
void BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst);
46
void PixelSpace(int Left, int Top, int Width, int Height, bool);
47
COORD GetCoordinates(int BytesRead, int BufferWidth);
48
void Log(const LogMessage &message);
49
void ClearScreen(bool Cursor = true);
50
51
void Show(bool bShow);
52
bool Hidden() const { return hidden_; }
53
54
private:
55
HWND hWnd = nullptr;
56
HANDLE hConsole = nullptr;
57
58
void LogWriterThread();
59
void SendToThread(LogLevel Level, const char *Text);
60
void WriteToConsole(LogLevel Level, const char *Text, size_t Len);
61
62
std::thread thread_;
63
64
HANDLE hTriggerEvent = nullptr;
65
CRITICAL_SECTION criticalSection{};
66
67
char *logPending_ = nullptr;
68
std::atomic<uint32_t> logPendingReadPos_;
69
std::atomic<uint32_t> logPendingWritePos_;
70
71
int openWidth_ = 0;
72
int openHeight_ = 0;
73
bool hidden_ = false;
74
bool useColor_ = true;
75
bool useThread_ = true;
76
};
77
78
#endif
79
80