2009-07-28 15:32:10 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
#ifndef _LOGMANAGER_H_
|
|
|
|
#define _LOGMANAGER_H_
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
#include "Thread.h"
|
|
|
|
#include "StringUtil.h"
|
2009-09-01 02:44:32 -06:00
|
|
|
#ifdef _WIN32
|
2009-03-18 11:17:58 -06:00
|
|
|
#include <windows.h>
|
2009-09-01 02:44:32 -06:00
|
|
|
#endif
|
2009-03-18 11:17:58 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define MAX_MESSAGES 8000
|
|
|
|
#define MAX_MSGLEN 512
|
|
|
|
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
// pure virtual interface (well, except the destructor which we just leave empty).
|
|
|
|
class LogListener {
|
2009-03-18 11:17:58 -06:00
|
|
|
public:
|
2009-03-20 13:12:04 -06:00
|
|
|
virtual ~LogListener() {}
|
2009-03-18 11:17:58 -06:00
|
|
|
virtual void Log(LogTypes::LOG_LEVELS, const char *msg) = 0;
|
2009-03-20 13:12:04 -06:00
|
|
|
virtual const char *getName() const = 0;
|
2009-03-18 11:17:58 -06:00
|
|
|
};
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
class FileLogListener : public LogListener {
|
2009-03-18 11:17:58 -06:00
|
|
|
public:
|
|
|
|
FileLogListener(const char *filename);
|
|
|
|
~FileLogListener();
|
|
|
|
|
|
|
|
void Log(LogTypes::LOG_LEVELS, const char *msg);
|
|
|
|
|
|
|
|
bool isValid() {
|
|
|
|
return (m_logfile != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEnable() {
|
|
|
|
return m_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnable(bool enable) {
|
|
|
|
m_enable = enable;
|
|
|
|
}
|
2009-03-20 13:12:04 -06:00
|
|
|
|
|
|
|
const char *getName() const { return "file"; }
|
|
|
|
|
2009-03-18 11:17:58 -06:00
|
|
|
private:
|
|
|
|
char *m_filename;
|
|
|
|
FILE *m_logfile;
|
|
|
|
bool m_enable;
|
|
|
|
};
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
class ConsoleListener : public LogListener
|
2009-03-18 11:17:58 -06:00
|
|
|
{
|
|
|
|
public:
|
2009-03-20 16:21:04 -06:00
|
|
|
ConsoleListener();
|
2009-03-18 11:17:58 -06:00
|
|
|
~ConsoleListener();
|
|
|
|
|
2009-09-01 08:33:16 -06:00
|
|
|
void Open(bool Hidden = false, int Width = 100, int Height = 100, const char * Name = "Console");
|
2009-09-01 06:44:02 -06:00
|
|
|
void UpdateHandle();
|
2009-03-20 12:25:36 -06:00
|
|
|
void Close();
|
|
|
|
bool IsOpen();
|
2009-08-29 00:08:14 -06:00
|
|
|
void LetterSpace(int Width, int Height);
|
2009-08-30 02:22:05 -06:00
|
|
|
void BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst);
|
2009-08-29 00:08:14 -06:00
|
|
|
void PixelSpace(int Left, int Top, int Width, int Height, bool);
|
2009-08-30 02:22:05 -06:00
|
|
|
#ifdef _WIN32
|
|
|
|
COORD GetCoordinates(int BytesRead, int BufferWidth);
|
|
|
|
#endif
|
2009-11-12 11:57:35 -07:00
|
|
|
void CustomLog(const char *Text);
|
2009-08-29 00:08:14 -06:00
|
|
|
void Log(LogTypes::LOG_LEVELS, const char *Text);
|
2009-08-30 02:22:05 -06:00
|
|
|
void ClearScreen(bool Cursor = true);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2009-08-29 00:08:14 -06:00
|
|
|
const char *getName() const { return "Console"; }
|
2009-03-20 13:12:04 -06:00
|
|
|
|
2009-03-18 11:17:58 -06:00
|
|
|
private:
|
|
|
|
#ifdef _WIN32
|
|
|
|
HWND GetHwnd(void);
|
2009-08-29 00:08:14 -06:00
|
|
|
HANDLE hConsole;
|
2009-03-18 11:17:58 -06:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
class LogContainer {
|
|
|
|
public:
|
2009-03-20 14:52:37 -06:00
|
|
|
LogContainer(const char* shortName, const char* fullName, bool enable = false);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
const char *getShortName() const { return m_shortName; }
|
|
|
|
const char *getFullName() const { return m_fullName; }
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
bool isListener(LogListener *listener) const;
|
|
|
|
void addListener(LogListener *listener);
|
|
|
|
void removeListener(LogListener *listener);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
void trigger(LogTypes::LOG_LEVELS, const char *msg);
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
bool isEnable() const { return m_enable; }
|
2009-03-18 11:17:58 -06:00
|
|
|
void setEnable(bool enable) {
|
|
|
|
m_enable = enable;
|
|
|
|
}
|
|
|
|
|
2009-03-20 14:52:37 -06:00
|
|
|
LogTypes::LOG_LEVELS getLevel() const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLevel(LogTypes::LOG_LEVELS level) {
|
|
|
|
m_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
char m_fullName[128];
|
|
|
|
char m_shortName[32];
|
|
|
|
bool m_enable;
|
|
|
|
LogTypes::LOG_LEVELS m_level;
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
std::vector<LogListener *> listeners;
|
2009-03-18 11:17:58 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class LogManager
|
|
|
|
{
|
|
|
|
private:
|
2009-09-04 05:34:21 -06:00
|
|
|
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
|
2009-03-20 15:23:36 -06:00
|
|
|
Common::CriticalSection logMutex;
|
2009-03-18 11:17:58 -06:00
|
|
|
FileLogListener *m_fileLog;
|
|
|
|
ConsoleListener *m_consoleLog;
|
2009-03-20 13:12:04 -06:00
|
|
|
static LogManager *m_logManager; // Singleton. Ugh.
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
public:
|
2009-03-20 14:52:37 -06:00
|
|
|
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
2009-07-12 15:58:32 -06:00
|
|
|
const char *fmt, va_list args);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
void setLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) {
|
2009-03-18 11:17:58 -06:00
|
|
|
m_Log[type]->setLevel(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnable(LogTypes::LOG_TYPE type, bool enable) {
|
|
|
|
m_Log[type]->setEnable(enable);
|
|
|
|
}
|
|
|
|
|
2009-09-04 05:34:21 -06:00
|
|
|
bool isEnable(LogTypes::LOG_TYPE type) {
|
|
|
|
return m_Log[type]->isEnable();
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
const char *getShortName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_Log[type]->getShortName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
const char *getFullName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_Log[type]->getFullName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
bool isListener(LogTypes::LOG_TYPE type, LogListener *listener) const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_Log[type]->isListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
void addListener(LogTypes::LOG_TYPE type, LogListener *listener) {
|
2009-03-18 11:17:58 -06:00
|
|
|
m_Log[type]->addListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
void removeListener(LogTypes::LOG_TYPE type, LogListener *listener);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
FileLogListener *getFileListener() {
|
|
|
|
return m_fileLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleListener *getConsoleListener() {
|
|
|
|
return m_consoleLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LogManager* GetInstance() {
|
|
|
|
if (! m_logManager)
|
|
|
|
m_logManager = new LogManager();
|
|
|
|
return m_logManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetInstance(LogManager *logManager) {
|
|
|
|
m_logManager = logManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogManager();
|
|
|
|
~LogManager();
|
|
|
|
};
|
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
#endif // _LOGMANAGER_H_
|