📄 component.h
字号:
/*
* 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.h,v 1.1 2006/04/14 02:46:02 9564907 Exp $
*/
// $Header: J:\\SapporoSoft\\usb20\\S1R72V05\\Debug\\Repository/S1R72V05_Toppers/Toppers/cfg/base/component.h,v 1.1 2006/04/14 02:46:02 9564907 Exp $
#include "base/testsuite.h"
#include "base/singleton.h"
#include "base/except.h"
#include "base/message.h"
#include "base/option.h"
#include "base/collection.h"
#include "base/directorymap.h"
#include <list>
#include <map>
#ifndef COMPONENT_H
#define COMPONENT_H
class Component : public RuntimeObject
{
public:
//僐儞億乕僱儞僩偺婲摦桪愭搙
enum tagProcessStage {
INITIALIZE, //偲偵偐偔恀偭愭偵摦偒偨偄張棟
BEFORE_PARSE, //僷乕僗慜
PARSER, //僷乕僒
AFTER_PARSE, //僷乕僗屻
PREDECESSOR, //斈梡偺慜
GENERAL_PURPOSE, //斈梡
SUCCESSOR, //斈梡偺屻
BEFORE_CODEGENERATION, //僐乕僪惗惉慜
CODEGENERATOR, //僐乕僪惗惉
AFTER_CODEGENERATION, //僐乕僪惗惉屻
FINALIZE
};
//僐儞億乕僱儞僩偵嫟捠偺僨乕僞傪帩偮/憖嶌偡傞僋儔僗
class ComponentInfo
{
protected:
std::string banner;
std::multimap<int, Component *> componentList;
std::list<Component *> activatedComponentList;
//僐儞僗僩儔僋僞 (僥僗僩梡)
ComponentInfo(void) throw() {}
public:
//僐儞僗僩儔僋僞
SINGLETON_CONSTRUCTOR(ComponentInfo) {}
//僐儞億乕僱儞僩偺捛壛
bool addComponent(Component * component, int order) throw();
//僐儞億乕僱儞僩偺搊榐夝彍
void removeComponent(Component * component, int order) throw(); //摿掕偺桪愭搙偩偗傪夝彍
void removeComponent(Component * component) throw(); //慡偰夝彍
//僐儞億乕僱儞僩偺婲摦梫媮
bool activateComponent(Component * component) throw();
//僆僾僔儑儞偺僷乕僗
void parseOption(OptionParameter & option);
//僐儞億乕僱儞僩偺婲摦
void activateComponent(void);
//堎忢張棟僴儞僪儔偺婲摦
void onFatalExit(void);
//僐儞億乕僱儞僩T偑婲摦偟偰偄傞偐傪敾掕
template<class T>
bool isActive(void) const throw()
{
std::list<Component *>::const_iterator scope;
scope = activatedComponentList.begin();
while(scope != activatedComponentList.end()) {
if(dynamic_cast<T *>(*scope) != 0)
return true;
++ scope;
}
return false;
}
//僶僫乕曄悢傊偺傾僋僙僒
inline void setBanner(std::string src)
{ banner = src; }
inline std::string getBanner(void) const
{ return banner; }
TESTSUITE_PROTOTYPE(main)
};
protected:
static bool is_valid; //僐儞億乕僱儞僩偺弶婜壔偵惉岟偟偨偐偳偆偐傪帩偮僼儔僌
/*
* 嶌嬈娭悢
*/
//僐儞億乕僱儞僩偺婲摦
inline bool activateComponent(void) throw()
{ return Singleton<ComponentInfo>::getInstance()->activateComponent(this); }
//堦斒揑側僆僾僔儑儞偺張棟
static void _parseCommonOption(OptionParameter & option) throw();
//帺暘偵愭峴偡傞僐儞億乕僱儞僩偺婲摦敾掕
template<class T>
static bool isActive(void) throw()
{
bool result = false;
ComponentInfo * info = Singleton<ComponentInfo>::getInstance(std::nothrow);
if(info != 0)
result = info->isActive<T>();
return result;
}
/*
* 夁嫀偲偺屳姺惈偺偨傔偺僷儔儊乕僞憖嶌API
*/
static bool findOption (const char * key1, const char * key2 = 0, std::string * = 0) throw();
static bool checkOption(const char * key1, const char * key2 = 0) throw();
static OptionParameter::OptionItem getOption (const char * key1, const char * key2 = 0, bool dirty = true) throw();
static OptionParameter::OptionItem mergeOption(const char * key1, const char * key2 = 0) throw();
public:
//僐儞僗僩儔僋僞
Component(int order = GENERAL_PURPOSE) throw();
//僨僗僩儔僋僞
virtual ~Component(void) throw();
//桳岠敾掕
static bool isValid(void) throw()
{ return is_valid && SingletonBase::isValid(); }
//僐儞億乕僱儞僩偺幚峴
static void executeComponents(OptionParameter & option);
static void executeComponents(int argc, char * argv []);
//僶僫乕傾僋僙僒
static void setBanner(std::string) throw(std::bad_alloc);
static std::string getBanner(void) throw(std::bad_alloc);
/*
* 僀儀儞僩僴儞僪儔
*/
//僆僾僔儑儞偺僷乕僗
virtual void parseOption(OptionParameter &)
{ parseOption(*Singleton<Directory>::getInstance()); }
virtual void parseOption(Directory &) {}
//僐儞億乕僱儞僩偺杮懱
virtual void body(void) { body(*Singleton<Directory>::getInstance()); }
virtual void body(Directory &) {}
//堎忢廔椆僴儞僪儔
virtual void onFatalExit(void) {}
TESTSUITE_PROTOTYPE(main)
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -