2013-07-06 01:49:38 +02:00
|
|
|
#include "stdafx.h"
|
2014-06-02 19:27:24 +02:00
|
|
|
#include "Emu/ConLog.h"
|
|
|
|
|
#include "Emu/Memory/Memory.h"
|
|
|
|
|
#include "Emu/System.h"
|
|
|
|
|
#include "Emu/Cell/PPUThread.h"
|
|
|
|
|
#include "Emu/SysCalls/SC_FUNC.h"
|
|
|
|
|
#include "Emu/SysCalls/Modules.h"
|
2014-01-31 00:40:05 +01:00
|
|
|
#include <mutex>
|
2014-05-02 08:30:32 +02:00
|
|
|
#include "Emu/System.h"
|
|
|
|
|
#include "ModuleManager.h"
|
2013-07-06 01:49:38 +02:00
|
|
|
|
2014-04-10 00:54:32 +02:00
|
|
|
|
2013-07-12 14:42:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Module::Module(u16 id, const char* name)
|
|
|
|
|
: m_is_loaded(false)
|
|
|
|
|
, m_name(name)
|
|
|
|
|
, m_id(id)
|
2013-11-16 22:12:30 +01:00
|
|
|
, m_load_func(nullptr)
|
|
|
|
|
, m_unload_func(nullptr)
|
2013-07-12 14:42:17 +02:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
Emu.GetModuleManager().SetModule(m_id, this, false);
|
2013-07-12 14:42:17 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-16 22:12:30 +01:00
|
|
|
Module::Module(const char* name, void (*init)(), void (*load)(), void (*unload)())
|
2013-07-06 01:49:38 +02:00
|
|
|
: m_is_loaded(false)
|
|
|
|
|
, m_name(name)
|
2013-07-12 14:42:17 +02:00
|
|
|
, m_id(-1)
|
2013-11-16 22:12:30 +01:00
|
|
|
, m_load_func(load)
|
|
|
|
|
, m_unload_func(unload)
|
2013-07-12 14:42:17 +02:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
Emu.GetModuleManager().SetModule(m_id, this, init != nullptr);
|
2013-07-12 14:42:17 +02:00
|
|
|
if(init) init();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-16 22:12:30 +01:00
|
|
|
Module::Module(u16 id, void (*init)(), void (*load)(), void (*unload)())
|
2013-07-12 14:42:17 +02:00
|
|
|
: m_is_loaded(false)
|
2013-07-06 01:49:38 +02:00
|
|
|
, m_id(id)
|
2013-11-16 22:12:30 +01:00
|
|
|
, m_load_func(load)
|
|
|
|
|
, m_unload_func(unload)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
Emu.GetModuleManager().SetModule(m_id, this, init != nullptr);
|
2013-07-12 14:42:17 +02:00
|
|
|
if(init) init();
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
Module::Module(Module &&other)
|
|
|
|
|
: m_is_loaded(false)
|
|
|
|
|
, m_id(0)
|
|
|
|
|
, m_load_func(nullptr)
|
|
|
|
|
, m_unload_func(nullptr)
|
|
|
|
|
{
|
|
|
|
|
std::swap(this->m_name,other.m_name);
|
|
|
|
|
std::swap(this->m_id, other.m_id);
|
|
|
|
|
std::swap(this->m_is_loaded, other.m_is_loaded);
|
|
|
|
|
std::swap(this->m_load_func, other.m_load_func);
|
|
|
|
|
std::swap(this->m_unload_func, other.m_unload_func);
|
|
|
|
|
std::swap(this->m_funcs_list, other.m_funcs_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Module &Module::operator =(Module &&other)
|
|
|
|
|
{
|
|
|
|
|
std::swap(this->m_name, other.m_name);
|
|
|
|
|
std::swap(this->m_id, other.m_id);
|
|
|
|
|
std::swap(this->m_is_loaded, other.m_is_loaded);
|
|
|
|
|
std::swap(this->m_load_func, other.m_load_func);
|
|
|
|
|
std::swap(this->m_unload_func, other.m_unload_func);
|
|
|
|
|
std::swap(this->m_funcs_list, other.m_funcs_list);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-15 16:12:15 +02:00
|
|
|
Module::~Module()
|
|
|
|
|
{
|
|
|
|
|
UnLoad();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_funcs_list.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
delete m_funcs_list[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 01:49:38 +02:00
|
|
|
void Module::Load()
|
|
|
|
|
{
|
2013-11-16 22:12:30 +01:00
|
|
|
if(IsLoaded())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(m_load_func) m_load_func();
|
|
|
|
|
|
2014-04-10 00:54:32 +02:00
|
|
|
for(u32 i=0; i<m_funcs_list.size(); ++i)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
Emu.GetModuleManager().AddFunc(m_funcs_list[i]);
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
2013-11-16 22:12:30 +01:00
|
|
|
|
|
|
|
|
SetLoaded(true);
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Module::UnLoad()
|
|
|
|
|
{
|
2013-11-16 22:12:30 +01:00
|
|
|
if(!IsLoaded())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(m_unload_func) m_unload_func();
|
|
|
|
|
|
2014-04-10 00:54:32 +02:00
|
|
|
for(u32 i=0; i<m_funcs_list.size(); ++i)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
Emu.GetModuleManager().UnloadFunc(m_funcs_list[i]->id);
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
2013-11-16 22:12:30 +01:00
|
|
|
|
|
|
|
|
SetLoaded(false);
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Module::Load(u32 id)
|
|
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
if(Emu.GetModuleManager().IsLoadedFunc(id)) return false;
|
2013-07-06 01:49:38 +02:00
|
|
|
|
2014-04-10 00:54:32 +02:00
|
|
|
for(u32 i=0; i<m_funcs_list.size(); ++i)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-04-15 16:12:15 +02:00
|
|
|
if(m_funcs_list[i]->id == id)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
Emu.GetModuleManager().AddFunc(m_funcs_list[i]);
|
2013-07-06 01:49:38 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Module::UnLoad(u32 id)
|
|
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
return Emu.GetModuleManager().UnloadFunc(id);
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Module::SetLoaded(bool loaded)
|
|
|
|
|
{
|
|
|
|
|
m_is_loaded = loaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Module::IsLoaded() const
|
|
|
|
|
{
|
|
|
|
|
return m_is_loaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u16 Module::GetID() const
|
|
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 21:47:17 +01:00
|
|
|
std::string Module::GetName() const
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
|
|
|
|
return m_name;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 21:47:17 +01:00
|
|
|
void Module::SetName(const std::string& name)
|
2013-07-12 14:42:17 +02:00
|
|
|
{
|
|
|
|
|
m_name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Module::Log(const u32 id, std::string fmt, ...)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-02-13 20:05:23 +01:00
|
|
|
if(Ini.HLELogging.GetValue())
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
|
|
|
|
va_list list;
|
|
|
|
|
va_start(list, fmt);
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Write(GetName() + fmt::Format("[%d]: ", id) + fmt::FormatV(fmt, list));
|
2013-07-06 01:49:38 +02:00
|
|
|
va_end(list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Module::Log(std::string fmt, ...)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-02-13 20:05:23 +01:00
|
|
|
if(Ini.HLELogging.GetValue())
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
|
|
|
|
va_list list;
|
|
|
|
|
va_start(list, fmt);
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Write(GetName() + ": " + fmt::FormatV(fmt, list));
|
2013-07-06 01:49:38 +02:00
|
|
|
va_end(list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Module::Warning(const u32 id, std::string fmt, ...)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
|
|
|
|
va_list list;
|
|
|
|
|
va_start(list, fmt);
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Warning(GetName() + fmt::Format("[%d] warning: ", id) + fmt::FormatV(fmt, list));
|
2013-07-06 01:49:38 +02:00
|
|
|
va_end(list);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Module::Warning(std::string fmt, ...)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
|
|
|
|
va_list list;
|
|
|
|
|
va_start(list, fmt);
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Warning(GetName() + " warning: " + fmt::FormatV(fmt, list));
|
2013-07-06 01:49:38 +02:00
|
|
|
va_end(list);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Module::Error(const u32 id, std::string fmt, ...)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
|
|
|
|
va_list list;
|
|
|
|
|
va_start(list, fmt);
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Error(GetName() + fmt::Format("[%d] error: ", id) + fmt::FormatV(fmt, list));
|
2013-07-06 01:49:38 +02:00
|
|
|
va_end(list);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Module::Error(std::string fmt, ...)
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
|
|
|
|
va_list list;
|
|
|
|
|
va_start(list, fmt);
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Error(GetName() + " error: " + fmt::FormatV(fmt, list));
|
2013-07-06 01:49:38 +02:00
|
|
|
va_end(list);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-19 04:14:11 +01:00
|
|
|
bool Module::CheckID(u32 id) const
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-02-02 21:47:17 +01:00
|
|
|
return Emu.GetIdManager().CheckID(id) && Emu.GetIdManager().GetID(id).m_name == GetName();
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-19 04:14:11 +01:00
|
|
|
bool Module::CheckID(u32 id, ID*& _id) const
|
2013-07-06 01:49:38 +02:00
|
|
|
{
|
2014-02-02 21:47:17 +01:00
|
|
|
return Emu.GetIdManager().CheckID(id) && (_id = &Emu.GetIdManager().GetID(id))->m_name == GetName();
|
2013-07-06 01:49:38 +02:00
|
|
|
}
|
2014-04-10 00:54:32 +02:00
|
|
|
|