interface/module_info.h
This commit is contained in:
parent
bd7d185dbf
commit
851cc805a7
@ -7,33 +7,17 @@
|
|||||||
#include "interface/module.h"
|
#include "interface/module.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
namespace interface
|
||||||
|
{
|
||||||
|
struct ModuleInfo;
|
||||||
|
};
|
||||||
|
|
||||||
namespace loader
|
namespace loader
|
||||||
{
|
{
|
||||||
struct ModuleDependency
|
|
||||||
{
|
|
||||||
ss_ module;
|
|
||||||
bool optional = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ModuleMeta
|
|
||||||
{
|
|
||||||
ss_ cxxflags;
|
|
||||||
ss_ ldflags;
|
|
||||||
sv_<ModuleDependency> dependencies;
|
|
||||||
sv_<ModuleDependency> reverse_dependencies;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ModuleInfo
|
|
||||||
{
|
|
||||||
ss_ name;
|
|
||||||
ss_ path;
|
|
||||||
ModuleMeta meta;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Interface
|
struct Interface
|
||||||
{
|
{
|
||||||
virtual void activate() = 0;
|
virtual void activate() = 0;
|
||||||
virtual ModuleInfo* get_module_info(const ss_ &name) = 0;
|
virtual interface::ModuleInfo* get_module_info(const ss_ &name) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool access(interface::Server *server,
|
inline bool access(interface::Server *server,
|
||||||
|
@ -7,34 +7,35 @@
|
|||||||
#include "interface/server.h"
|
#include "interface/server.h"
|
||||||
#include "interface/fs.h"
|
#include "interface/fs.h"
|
||||||
#include "interface/event.h"
|
#include "interface/event.h"
|
||||||
|
#include "interface/module_info.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using interface::Event;
|
using interface::Event;
|
||||||
|
|
||||||
namespace loader {
|
namespace loader {
|
||||||
|
|
||||||
static ModuleDependency load_module_dependency(const json::Value &v)
|
static interface::ModuleDependency load_module_dependency(const json::Value &v)
|
||||||
{
|
{
|
||||||
ModuleDependency r;
|
interface::ModuleDependency r;
|
||||||
r.module = v.get("module").as_string();
|
r.module = v.get("module").as_string();
|
||||||
r.optional = v.get("optional").as_boolean();
|
r.optional = v.get("optional").as_boolean();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ModuleMeta load_module_meta(const json::Value &v)
|
static interface::ModuleMeta load_module_meta(const json::Value &v)
|
||||||
{
|
{
|
||||||
ModuleMeta r;
|
interface::ModuleMeta r;
|
||||||
r.cxxflags = v.get("cxxflags").as_string();
|
r.cxxflags = v.get("cxxflags").as_string();
|
||||||
r.ldflags = v.get("ldflags").as_string();
|
r.ldflags = v.get("ldflags").as_string();
|
||||||
const json::Value &deps_v = v.get("dependencies");
|
const json::Value &deps_v = v.get("dependencies");
|
||||||
for(unsigned int i = 0; i < deps_v.size(); i++){
|
for(unsigned int i = 0; i < deps_v.size(); i++){
|
||||||
const json::Value &dep_v = deps_v.at(i);
|
const json::Value &dep_v = deps_v.at(i);
|
||||||
ModuleDependency dep = load_module_dependency(deps_v.at(i));
|
interface::ModuleDependency dep = load_module_dependency(deps_v.at(i));
|
||||||
r.dependencies.push_back(dep);
|
r.dependencies.push_back(dep);
|
||||||
}
|
}
|
||||||
const json::Value &rev_deps_v = v.get("reverse_dependencies");
|
const json::Value &rev_deps_v = v.get("reverse_dependencies");
|
||||||
for(unsigned int i = 0; i < rev_deps_v.size(); i++){
|
for(unsigned int i = 0; i < rev_deps_v.size(); i++){
|
||||||
ModuleDependency dep = load_module_dependency(rev_deps_v.at(i));
|
interface::ModuleDependency dep = load_module_dependency(rev_deps_v.at(i));
|
||||||
r.reverse_dependencies.push_back(dep);
|
r.reverse_dependencies.push_back(dep);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
@ -56,7 +57,7 @@ struct ResolveState
|
|||||||
// The previous vector as a set
|
// The previous vector as a set
|
||||||
set_<ss_> m_promised_modules;
|
set_<ss_> m_promised_modules;
|
||||||
// Reverse dependencies to each module (listed in a forward way)
|
// Reverse dependencies to each module (listed in a forward way)
|
||||||
sm_<ss_, sv_<ModuleDependency>> m_reverse_dependencies;
|
sm_<ss_, sv_<interface::ModuleDependency>> m_reverse_dependencies;
|
||||||
|
|
||||||
ResolveState(Interface *loader):
|
ResolveState(Interface *loader):
|
||||||
m_loader(loader)
|
m_loader(loader)
|
||||||
@ -90,7 +91,7 @@ struct ResolveState
|
|||||||
return true;
|
return true;
|
||||||
log_d(MODULE, "require_module(): New requirement: \"%s\"", cs(name));
|
log_d(MODULE, "require_module(): New requirement: \"%s\"", cs(name));
|
||||||
|
|
||||||
ModuleInfo *info = m_loader->get_module_info(name);
|
interface::ModuleInfo *info = m_loader->get_module_info(name);
|
||||||
if(info == nullptr){
|
if(info == nullptr){
|
||||||
if(optional){
|
if(optional){
|
||||||
log_d(MODULE, "require_module(): "
|
log_d(MODULE, "require_module(): "
|
||||||
@ -126,7 +127,7 @@ struct ResolveState
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store dependency information
|
// Store dependency information
|
||||||
ModuleDependency forward_dep;
|
interface::ModuleDependency forward_dep;
|
||||||
forward_dep = dep; // Base dependency on reverted one
|
forward_dep = dep; // Base dependency on reverted one
|
||||||
forward_dep.module = name; // The other module depends now on this
|
forward_dep.module = name; // The other module depends now on this
|
||||||
// dep.module is the other module which should depeend on this one
|
// dep.module is the other module which should depeend on this one
|
||||||
@ -158,14 +159,14 @@ struct ResolveState
|
|||||||
follow_optdepends ? "true" : "false");
|
follow_optdepends ? "true" : "false");
|
||||||
// Pick a required module that isn't already loaded and which has all
|
// Pick a required module that isn't already loaded and which has all
|
||||||
// dependencies promised
|
// dependencies promised
|
||||||
ModuleInfo *info_to_load = nullptr;
|
interface::ModuleInfo *info_to_load = nullptr;
|
||||||
bool all_promised = true;
|
bool all_promised = true;
|
||||||
for(const ss_ &name : m_required_modules){
|
for(const ss_ &name : m_required_modules){
|
||||||
if(m_promised_modules.count(name))
|
if(m_promised_modules.count(name))
|
||||||
continue;
|
continue;
|
||||||
log_d(MODULE, "step(): Checking \"%s\"", cs(name));
|
log_d(MODULE, "step(): Checking \"%s\"", cs(name));
|
||||||
all_promised = false;
|
all_promised = false;
|
||||||
ModuleInfo *info = m_loader->get_module_info(name);
|
interface::ModuleInfo *info = m_loader->get_module_info(name);
|
||||||
if(!info)
|
if(!info)
|
||||||
return set_error(ss_()+"Couldn't get module info for \""+name+"\"");
|
return set_error(ss_()+"Couldn't get module info for \""+name+"\"");
|
||||||
bool deps_promised = true;
|
bool deps_promised = true;
|
||||||
@ -227,7 +228,7 @@ struct ResolveState
|
|||||||
for(const ss_ &name : m_required_modules){
|
for(const ss_ &name : m_required_modules){
|
||||||
if(m_promised_modules.count(name))
|
if(m_promised_modules.count(name))
|
||||||
continue;
|
continue;
|
||||||
ModuleInfo *info = m_loader->get_module_info(name);
|
interface::ModuleInfo *info = m_loader->get_module_info(name);
|
||||||
if(!info)
|
if(!info)
|
||||||
return set_error(ss_()+"Couldn't get module info for \""+name+"\"");
|
return set_error(ss_()+"Couldn't get module info for \""+name+"\"");
|
||||||
set_<ss_> missing_deps;
|
set_<ss_> missing_deps;
|
||||||
@ -288,9 +289,9 @@ struct Module: public interface::Module, public loader::Interface
|
|||||||
interface::ModuleModifiedEvent)
|
interface::ModuleModifiedEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm_<ss_, ModuleInfo> m_module_info;
|
sm_<ss_, interface::ModuleInfo> m_module_info;
|
||||||
|
|
||||||
ModuleInfo* get_module_info(const ss_ &name)
|
interface::ModuleInfo* get_module_info(const ss_ &name)
|
||||||
{
|
{
|
||||||
auto it = m_module_info.find(name);
|
auto it = m_module_info.find(name);
|
||||||
if(it != m_module_info.end()){
|
if(it != m_module_info.end()){
|
||||||
@ -320,7 +321,7 @@ struct Module: public interface::Module, public loader::Interface
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
// meta.txt is valid; read information
|
// meta.txt is valid; read information
|
||||||
ModuleInfo &info = m_module_info[name];
|
interface::ModuleInfo &info = m_module_info[name];
|
||||||
info.name = name;
|
info.name = name;
|
||||||
info.path = module_path;
|
info.path = module_path;
|
||||||
info.meta = load_module_meta(meta_v);
|
info.meta = load_module_meta(meta_v);
|
||||||
@ -365,7 +366,7 @@ struct Module: public interface::Module, public loader::Interface
|
|||||||
log_i(MODULE, "Module load order: %s", cs(dump(resolve.m_module_load_order)));
|
log_i(MODULE, "Module load order: %s", cs(dump(resolve.m_module_load_order)));
|
||||||
|
|
||||||
for(const ss_ &name : resolve.m_module_load_order){
|
for(const ss_ &name : resolve.m_module_load_order){
|
||||||
ModuleInfo *info = get_module_info(name);
|
interface::ModuleInfo *info = get_module_info(name);
|
||||||
if(!info)
|
if(!info)
|
||||||
throw Exception(ss_()+"Couldn't get module info for \""+name+"\"");
|
throw Exception(ss_()+"Couldn't get module info for \""+name+"\"");
|
||||||
if(!m_server->load_module(name, info->path)){
|
if(!m_server->load_module(name, info->path)){
|
||||||
|
29
src/interface/module_info.h
Normal file
29
src/interface/module_info.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
// Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
||||||
|
#pragma once
|
||||||
|
#include "core/types.h"
|
||||||
|
|
||||||
|
namespace interface
|
||||||
|
{
|
||||||
|
struct ModuleDependency
|
||||||
|
{
|
||||||
|
ss_ module;
|
||||||
|
bool optional = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ModuleMeta
|
||||||
|
{
|
||||||
|
ss_ cxxflags;
|
||||||
|
ss_ ldflags;
|
||||||
|
sv_<ModuleDependency> dependencies;
|
||||||
|
sv_<ModuleDependency> reverse_dependencies;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ModuleInfo
|
||||||
|
{
|
||||||
|
ss_ name;
|
||||||
|
ss_ path;
|
||||||
|
ModuleMeta meta;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// vim: set noet ts=4 sw=4:
|
Loading…
x
Reference in New Issue
Block a user