67 lines
1.5 KiB
C++
Raw Normal View History

2014-09-16 22:42:47 +03:00
#include "interface/module.h"
2014-09-16 23:14:04 +03:00
#include "interface/server.h"
#include "interface/fs.h"
2014-09-17 01:04:51 +03:00
#include "interface/event.h"
2014-09-16 23:57:31 +03:00
#include <iostream>
2014-09-16 22:42:47 +03:00
2014-09-17 01:04:51 +03:00
using interface::Event;
2014-09-17 02:18:03 +03:00
namespace __loader {
2014-09-16 23:14:04 +03:00
struct Module: public interface::Module
2014-09-16 22:42:47 +03:00
{
interface::Server *m_server;
2014-09-17 02:18:03 +03:00
Event::Type m_EventType_core_load_modules;
Module(interface::Server *server):
2014-09-17 02:18:03 +03:00
m_server(server),
2014-09-17 14:53:06 +03:00
m_EventType_core_load_modules(interface::Event::t("core:load_modules"))
2014-09-16 23:14:04 +03:00
{
2014-09-16 23:57:31 +03:00
std::cout<<"__loader construct"<<std::endl;
2014-09-16 23:14:04 +03:00
}
2014-09-16 22:42:47 +03:00
2014-09-17 14:53:06 +03:00
void init()
{
std::cout<<"__loader init"<<std::endl;
m_server->sub_event(this, m_EventType_core_load_modules);
}
2014-09-16 23:14:04 +03:00
~Module()
{
2014-09-16 23:57:31 +03:00
std::cout<<"__loader destruct"<<std::endl;
2014-09-16 23:14:04 +03:00
}
2014-09-16 22:42:47 +03:00
2014-09-17 01:04:51 +03:00
void event(const interface::Event &event)
{
2014-09-17 02:18:03 +03:00
if(event.type == m_EventType_core_load_modules){
load_modules();
2014-09-17 01:04:51 +03:00
}
}
2014-09-17 02:18:03 +03:00
void load_modules()
{
2014-09-17 11:43:53 +03:00
m_server->load_module("network",
m_server->get_builtin_modules_path()+"/network");
2014-09-17 02:18:03 +03:00
sv_<ss_> load_list = {"test1", "test2"};
for(const ss_ &name : load_list){
m_server->load_module(name, m_server->get_modules_path()+"/"+name);
}
2014-09-17 02:18:03 +03:00
/*// TODO: Dependencies
auto list = interface::getGlobalFilesystem()->list_directory(m_server->get_modules_path());
for(const interface::Filesystem::Node &n : list){
if(n.name == "__loader")
continue;
m_server->load_module(n.name, m_server->get_modules_path()+"/"+n.name);
2014-09-17 02:18:03 +03:00
}*/
}
2014-09-16 23:14:04 +03:00
};
extern "C" {
2014-09-17 02:18:03 +03:00
EXPORT void* createModule___loader(interface::Server *server){
return (void*)(new Module(server));
}
2014-09-16 23:14:04 +03:00
}
2014-09-16 22:42:47 +03:00
}