📄 component.cpp
字号:
/*
* TOPPERS/JSP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Just Standard Profile Kernel
*
* Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
* Toyohashi Univ. of Technology, JAPAN
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
* @(#) $Id: component.cpp,v 1.10 2003/06/30 12:57:25 takayuki Exp $
*/
// $Header: /home/CVS/configurator/base/component.cpp,v 1.10 2003/06/30 12:57:25 takayuki Exp $
#include "base/component.h"
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
int Component::barrierFlag = 0; //婡擻僶儕傾
Directory Component::persistentContainer; //塱懕僨乕僞僐儞僥僫
Component::Component(int order)
{ componentList().insert(pair<int,Component *>(order,this)); }
//僨僗僩儔僋僞
Component::~Component(void)
{
multimap<int, Component *>::iterator scope;
//晹昳偺搊榐儕僗僩偐傜帺暘傪奜偡
scope = componentList().begin();
while(scope != componentList().end())
{
if(scope->second == this)
{
componentList().erase(scope);
break;
}
++ scope;
}
}
string & Component::bootBanner(void)
{
static string s_bootBanner;
return s_bootBanner;
}
multimap<int,Component *> & Component::componentList(void)
{
static multimap<int,Component *> s_componentList;
return s_componentList;
}
list<Component *> & Component::activatedComponentList(void)
{
static list<Component *> s_activatedComponentList;
return s_activatedComponentList;
}
//婲摦梫媮偺敪峴
// allow_multiinstance : 暋悢夞婲摦偡傞偙偲傪嫋壜偡傞
void Component::activateComponent(bool allow_multiinstance)
{
if(allow_multiinstance || (find(activatedComponentList().begin(),activatedComponentList().end(), this) == activatedComponentList().end()))
activatedComponentList().push_back(this);
}
bool Component::findOption(Directory & container, const char * id, const char * longId, std::string * value)
{
Directory * node = getOption(container, id, longId);
if(node != 0)
{
if(value != 0)
{
*value = node->getLastChild()->toString();
}
return true;
}
return false;
}
//巜掕偟偨僆僾僔儑儞傪奿擺偡傞僲乕僪偺庢摼
// container : 僆僾僔儑儞傪奿擺偡傞僐儞僥僫
// id : 僆僾僔儑儞傪幆暿偡傞ID (抁偄宍幃: -x)
// loongid : 僆僾僔儑儞傪幆暿偡傞ID (挿偄宍幃: --xx)
// dirty : 僟乕僥傿價僢僩傪棫偰傞偐偳偆偐
// 栠傝抣 : 憡摉偡傞僲乕僪 (NULL: 尒偮偐傜側偄)
Directory * Component::getOption(Directory & container, const char * id, const char * longId, bool dirty)
{
Directory * param;
Directory * scope;
param = container.findChild("Parameter");
if( ((id != 0) && ((scope = param->findChild(id)) != 0)) || /* 抁偄柤慜偑堦抳偡傞 */
((longId != 0) && ((scope = param->findChild(string("-") + longId)) != 0)) ) /* 挿偄柤慜偑堦抳偡傞 */
{
if(dirty)
(*scope) = 1;
return scope;
}
return NULL;
}
//僷儔儊乕僞偑偁傞偐偳偆偐偺妋擣傪偟偮偮丄
//乽僷儔儊乕僞傪妋擣嵪傒乿偺僠僃僢僋傪擖傟傞
bool Component::checkOption(Directory & container, const char * id, const char * longId)
{
bool result = false;
Directory * param;
Directory * scope;
param = container.findChild("Parameter");
if((scope = param->findChild(id)) != NULL)
(*scope) = 1, result = true;
if((scope = param->findChild(longId)) != NULL)
(*scope) = 1, result = true;
return result;
}
//2偮偺僆僾僔儑儞崁栚偺儅乕僕
Directory * Component::mergeOption(Directory & container, const char * to, const char * from)
{
Directory * src;
Directory * dest;
Directory * node;
src = container.findChild("Parameter",to,NULL);
dest = container.findChild(string("Parameter/") + from);
if(dest == 0)
return src;
if(src == 0)
src = container.openChild("Parameter",to,NULL);
node = dest->getFirstChild();
while(node != 0)
{
src->addChild(new Directory(node->toString()));
node = node->getNext();
}
dest->erase();
return src;
}
//僆僾僔儑儞崁栚偺捛壛
static void addOptionItem(Directory * parameter, const string & key, const string & item)
{
Directory * node;
node = parameter->findChild(key);
if(item.empty())
{
/* 拞恎偺柍偄僆僾僔儑儞傪暋悢巜掕偡傞偺偼嫋偝側偄 */
if(node != 0)
ExceptionMessage("The option [%] should not be specified twice or more times.","僆僾僔儑儞[%]偺懡廳巊梡偼偱偒傑偣傫") << key << throwException;
parameter->addChild(key, new Directory());
}else
{
if(node != 0)
{
//摨偠僆僾僔儑儞偱暋悢夞僷儔儊乕僞偑巜掕偝傟偰偄傞
node->addChild(item.empty() ? new Directory("") : new Directory(item));
*node = item;
}else
parameter->addChild(key, new Directory(item))->addChild("000", new Directory(item));
}
}
//僆僾僔儑儞夝愅
void Component::parseOption(int argc, char ** argv, Directory & container, const char * default_option)
{
multimap<int, Component *>::iterator scope;
Directory * parameter;
string work;
string prevparam;
string::size_type i,j;
if(default_option != 0)
{
work.assign(default_option);
work += string(" ");
}
//椺奜張棟梡
scope = componentList().begin();
try{
parameter = container.addChild("Parameter");
/* 幚峴宍幃偺応強 */
(*parameter)["#exec"] = *argv;
work.assign(*argv);
i = work.find_last_of("/\\");
if(i != string::npos)
{
work.erase(i+1);
if(!work.empty())
(*parameter)["#execdir"] = work;
}
/* 僷儔儊乕僞儕僗僩 */
for(i=1;*(argv+i)!=0;i++)
{
work += *(argv+i);
work += ' ';
}
(*parameter)["#cmdline"] = work.substr(0,work.size()-1);
//僷儔儊乕僞傪僷乕僗偡傞
prevparam = DEFAULT_PARAMETER;
while(*(++argv) != 0)
{
work.assign(*argv);
if(work[0] == '-')
{
i = work.find_first_of('=');
j = work.find_first_not_of('-');
if(i == j || j == string::npos)
ExceptionMessage(ExceptionMessage::FATAL,"Wrong option [%]","晄惓側僆僾僔儑儞 [%]") << work << throwException;
if(i != string::npos)
{
prevparam = DEFAULT_PARAMETER;
addOptionItem(parameter, work.substr(1, i-1), work.substr(i+1));
}
else
{
prevparam = work.substr(1);
addOptionItem(parameter, prevparam, string(""));
}
}else
addOptionItem(parameter, prevparam, work);
}
/* 僆僾僔儑儞柍巜掕偱僿儖僾昞帵 */
if(argc == 1)
parameter->addChild("h");
{ //僌儘乕僶儖側僆僾僔儑儞傪張棟偡傞
//僨僶僢僌張棟
if(findOption(container, "debug","debug"))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -