2009-03-28 08:57:34 +00:00
|
|
|
// Copyright (C) 2003-2009 Dolphin Project.
|
2009-03-18 17:17:58 +00: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 08:57:34 +00:00
|
|
|
#ifndef _LOGMANAGER_H_
|
|
|
|
#define _LOGMANAGER_H_
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
#include "Thread.h"
|
|
|
|
#include "StringUtil.h"
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
#include <vector>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define MAX_MESSAGES 8000
|
|
|
|
#define MAX_MSGLEN 512
|
|
|
|
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
// pure virtual interface (well, except the destructor which we just leave empty).
|
|
|
|
class LogListener {
|
2009-03-18 17:17:58 +00:00
|
|
|
public:
|
2009-03-20 19:12:04 +00:00
|
|
|
virtual ~LogListener() {}
|
2009-03-18 17:17:58 +00:00
|
|
|
virtual void Log(LogTypes::LOG_LEVELS, const char *msg) = 0;
|
2009-03-20 19:12:04 +00:00
|
|
|
virtual const char *getName() const = 0;
|
2009-03-18 17:17:58 +00:00
|
|
|
};
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
class FileLogListener : public LogListener {
|
2009-03-18 17:17:58 +00: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 19:12:04 +00:00
|
|
|
|
|
|
|
const char *getName() const { return "file"; }
|
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
private:
|
|
|
|
char *m_filename;
|
|
|
|
FILE *m_logfile;
|
|
|
|
bool m_enable;
|
|
|
|
};
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
class ConsoleListener : public LogListener
|
2009-03-18 17:17:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-03-20 22:21:04 +00:00
|
|
|
ConsoleListener();
|
2009-03-18 17:17:58 +00:00
|
|
|
~ConsoleListener();
|
|
|
|
|
2009-03-20 18:25:36 +00:00
|
|
|
void Open(int Width = 100, int Height = 100,
|
2009-06-28 20:07:38 +00:00
|
|
|
const char * Name = "Console");
|
2009-03-20 18:25:36 +00:00
|
|
|
void Close();
|
|
|
|
bool IsOpen();
|
2009-03-18 17:17:58 +00:00
|
|
|
void Log(LogTypes::LOG_LEVELS, const char *text);
|
|
|
|
void ClearScreen();
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
const char *getName() const { return "console"; }
|
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
private:
|
|
|
|
#ifdef _WIN32
|
|
|
|
HWND GetHwnd(void);
|
|
|
|
HANDLE m_hStdOut;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
class LogContainer {
|
|
|
|
public:
|
2009-03-20 20:52:37 +00:00
|
|
|
LogContainer(const char* shortName, const char* fullName, bool enable = false);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
const char *getShortName() const { return m_shortName; }
|
|
|
|
const char *getFullName() const { return m_fullName; }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
bool isListener(LogListener *listener) const;
|
|
|
|
void addListener(LogListener *listener);
|
|
|
|
void removeListener(LogListener *listener);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
void trigger(LogTypes::LOG_LEVELS, const char *msg);
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
bool isEnable() const { return m_enable; }
|
2009-03-18 17:17:58 +00:00
|
|
|
void setEnable(bool enable) {
|
|
|
|
m_enable = enable;
|
|
|
|
}
|
|
|
|
|
2009-03-20 20:52:37 +00:00
|
|
|
LogTypes::LOG_LEVELS getLevel() const {
|
2009-03-18 17:17:58 +00: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 19:12:04 +00:00
|
|
|
std::vector<LogListener *> listeners;
|
2009-03-18 17:17:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class LogManager
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
|
2009-03-20 21:23:36 +00:00
|
|
|
Common::CriticalSection logMutex;
|
2009-03-18 17:17:58 +00:00
|
|
|
FileLogListener *m_fileLog;
|
|
|
|
ConsoleListener *m_consoleLog;
|
2009-03-20 19:12:04 +00:00
|
|
|
static LogManager *m_logManager; // Singleton. Ugh.
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
public:
|
2009-03-20 20:52:37 +00:00
|
|
|
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
2009-07-12 21:58:32 +00:00
|
|
|
const char *fmt, va_list args);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
void setLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) {
|
2009-03-18 17:17:58 +00:00
|
|
|
m_Log[type]->setLevel(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnable(LogTypes::LOG_TYPE type, bool enable) {
|
|
|
|
m_Log[type]->setEnable(enable);
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
const char *getShortName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_Log[type]->getShortName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
const char *getFullName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_Log[type]->getFullName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
bool isListener(LogTypes::LOG_TYPE type, LogListener *listener) const {
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_Log[type]->isListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
void addListener(LogTypes::LOG_TYPE type, LogListener *listener) {
|
2009-03-18 17:17:58 +00:00
|
|
|
m_Log[type]->addListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
void removeListener(LogTypes::LOG_TYPE type, LogListener *listener);
|
2009-03-18 17:17:58 +00: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 08:57:34 +00:00
|
|
|
#endif // _LOGMANAGER_H_
|