1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
8 | *
|
---|
9 | * ä¸è¨è使¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
11 | * ã«ãã£ã¦å
|
---|
12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
15 | å¸ï¼ä»¥ä¸ï¼
|
---|
16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
21 | * ç¨ã§ããå½¢ã§åé
|
---|
22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
24 | * è
|
---|
25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
30 | * ã¨ï¼
|
---|
31 | * (a) åé
|
---|
32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
34 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
35 | * (b) åé
|
---|
36 | å¸ã®å½¢æ
|
---|
37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
38 | * å ±åãããã¨ï¼
|
---|
39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
40 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
42 | 責ãããã¨ï¼
|
---|
43 | *
|
---|
44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
45 | ã
|
---|
46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
49 | *
|
---|
50 | * @(#) $Id: component.h,v 1.8 2003/12/20 06:51:58 takayuki Exp $
|
---|
51 | */
|
---|
52 |
|
---|
53 | // $Header: /home/CVS/configurator/base/component.h,v 1.8 2003/12/20 06:51:58 takayuki Exp $
|
---|
54 |
|
---|
55 | #include "base/testsuite.h"
|
---|
56 | #include "base/singleton.h"
|
---|
57 | #include "base/except.h"
|
---|
58 | #include "base/message.h"
|
---|
59 | #include "base/option.h"
|
---|
60 | #include "base/collection.h"
|
---|
61 | #include "base/directorymap.h"
|
---|
62 |
|
---|
63 | #include <list>
|
---|
64 | #include <map>
|
---|
65 |
|
---|
66 | #ifndef COMPONENT_H
|
---|
67 | #define COMPONENT_H
|
---|
68 |
|
---|
69 | class Component : public RuntimeObject
|
---|
70 | {
|
---|
71 | public:
|
---|
72 | //ã³ã³ãã¼ãã³ãã®èµ·ååªå
|
---|
73 | 度
|
---|
74 | enum tagProcessStage {
|
---|
75 | INITIALIZE, //ã¨ã«ããçã£å
|
---|
76 | ã«åãããå¦ç
|
---|
77 |
|
---|
78 | BEFORE_PARSE, //ãã¼ã¹å
|
---|
79 | PARSER, //ãã¼ãµ
|
---|
80 | AFTER_PARSE, //ãã¼ã¹å¾
|
---|
81 |
|
---|
82 | PREDECESSOR, //æ±ç¨ã®å
|
---|
83 | GENERAL_PURPOSE, //æ±ç¨
|
---|
84 | SUCCESSOR, //æ±ç¨ã®å¾
|
---|
85 |
|
---|
86 | BEFORE_CODEGENERATION, //ã³ã¼ãçæå
|
---|
87 | CODEGENERATOR, //ã³ã¼ãçæ
|
---|
88 | AFTER_CODEGENERATION, //ã³ã¼ãçæå¾
|
---|
89 |
|
---|
90 | FINALIZE
|
---|
91 | };
|
---|
92 |
|
---|
93 | //ã³ã³ãã¼ãã³ãã«å
|
---|
94 | ±éã®ãã¼ã¿ãæã¤/æä½ããã¯ã©ã¹
|
---|
95 | class ComponentInfo
|
---|
96 | {
|
---|
97 | protected:
|
---|
98 | std::string banner;
|
---|
99 | std::multimap<int, Component *> componentList;
|
---|
100 | std::list<Component *> activatedComponentList;
|
---|
101 |
|
---|
102 | //ã³ã³ã¹ãã©ã¯ã¿ (ãã¹ãç¨)
|
---|
103 | ComponentInfo(void) throw() {}
|
---|
104 | public:
|
---|
105 | //ã³ã³ã¹ãã©ã¯ã¿
|
---|
106 | SINGLETON_CONSTRUCTOR(ComponentInfo) {}
|
---|
107 |
|
---|
108 | //ã³ã³ãã¼ãã³ãã®è¿½å
|
---|
109 | bool addComponent(Component * component, int order) throw();
|
---|
110 |
|
---|
111 | //ã³ã³ãã¼ãã³ãã®ç»é²è§£é¤
|
---|
112 | void removeComponent(Component * component, int order) throw(); //ç¹å®ã®åªå
|
---|
113 | 度ã ããè§£é¤
|
---|
114 | void removeComponent(Component * component) throw(); //å
|
---|
115 | ¨ã¦è§£é¤
|
---|
116 |
|
---|
117 | //ã³ã³ãã¼ãã³ãã®èµ·åè¦æ±
|
---|
118 | bool activateComponent(Component * component) throw();
|
---|
119 |
|
---|
120 | //ãªãã·ã§ã³ã®ãã¼ã¹
|
---|
121 | void parseOption(OptionParameter & option);
|
---|
122 |
|
---|
123 | //ã³ã³ãã¼ãã³ãã®èµ·å
|
---|
124 | void activateComponent(void);
|
---|
125 |
|
---|
126 | //ç°å¸¸å¦çãã³ãã©ã®èµ·å
|
---|
127 | void onFatalExit(void);
|
---|
128 |
|
---|
129 | //ã³ã³ãã¼ãã³ãTãèµ·åãã¦ããããå¤å®
|
---|
130 | template<class T>
|
---|
131 | bool isActive(void) const throw()
|
---|
132 | {
|
---|
133 | std::list<Component *>::const_iterator scope;
|
---|
134 |
|
---|
135 | scope = activatedComponentList.begin();
|
---|
136 | while(scope != activatedComponentList.end()) {
|
---|
137 | if(dynamic_cast<T *>(*scope) != 0)
|
---|
138 | return true;
|
---|
139 | ++ scope;
|
---|
140 | }
|
---|
141 | return false;
|
---|
142 | }
|
---|
143 |
|
---|
144 | //ããã¼å¤æ°ã¸ã®ã¢ã¯ã»ãµ
|
---|
145 | inline void setBanner(std::string src)
|
---|
146 | { banner = src; }
|
---|
147 | inline std::string getBanner(void) const
|
---|
148 | { return banner; }
|
---|
149 |
|
---|
150 |
|
---|
151 | TESTSUITE_PROTOTYPE(main)
|
---|
152 | };
|
---|
153 |
|
---|
154 |
|
---|
155 | protected:
|
---|
156 | static bool is_valid; //ã³ã³ãã¼ãã³ãã®åæåã«æåãããã©ãããæã¤ãã©ã°
|
---|
157 |
|
---|
158 | /*
|
---|
159 | * 使¥é¢æ°
|
---|
160 | */
|
---|
161 |
|
---|
162 | //ã³ã³ãã¼ãã³ãã®èµ·å
|
---|
163 | inline bool activateComponent(void) throw()
|
---|
164 | { return Singleton<ComponentInfo>::getInstance()->activateComponent(this); }
|
---|
165 |
|
---|
166 | //ä¸è¬çãªãªãã·ã§ã³ã®å¦ç
|
---|
167 | static void _parseCommonOption(OptionParameter & option) throw();
|
---|
168 |
|
---|
169 |
|
---|
170 | //èªåã«å
|
---|
171 | è¡ããã³ã³ãã¼ãã³ãã®èµ·åå¤å®
|
---|
172 | template<class T>
|
---|
173 | static bool isActive(void) throw()
|
---|
174 | {
|
---|
175 | bool result = false;
|
---|
176 | ComponentInfo * info = Singleton<ComponentInfo>::getInstance(std::nothrow);
|
---|
177 | if(info != 0)
|
---|
178 | result = info->isActive<T>();
|
---|
179 | return result;
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | /*
|
---|
184 | * éå»ã¨ã®äºææ§ã®ããã®ãã©ã¡ã¼ã¿æä½API
|
---|
185 | */
|
---|
186 |
|
---|
187 | static bool findOption (const char * key1, const char * key2 = 0, std::string * = 0) throw();
|
---|
188 | static bool checkOption(const char * key1, const char * key2 = 0) throw();
|
---|
189 | static OptionParameter::OptionItem getOption (const char * key1, const char * key2 = 0, bool dirty = true) throw();
|
---|
190 | static OptionParameter::OptionItem mergeOption(const char * key1, const char * key2 = 0) throw();
|
---|
191 |
|
---|
192 | public:
|
---|
193 | //ã³ã³ã¹ãã©ã¯ã¿
|
---|
194 | Component(int order = GENERAL_PURPOSE) throw();
|
---|
195 |
|
---|
196 | //ãã¹ãã©ã¯ã¿
|
---|
197 | virtual ~Component(void) throw();
|
---|
198 |
|
---|
199 | //æå¹å¤å®
|
---|
200 | static bool isValid(void) throw()
|
---|
201 | { return is_valid && SingletonBase::isValid(); }
|
---|
202 |
|
---|
203 | //ã³ã³ãã¼ãã³ãã®å®è¡
|
---|
204 | static void executeComponents(OptionParameter & option);
|
---|
205 | static void executeComponents(int argc, char * argv []);
|
---|
206 |
|
---|
207 | //ããã¼ã¢ã¯ã»ãµ
|
---|
208 | static void setBanner(std::string) throw(std::bad_alloc);
|
---|
209 | static std::string getBanner(void) throw(std::bad_alloc);
|
---|
210 |
|
---|
211 | /*
|
---|
212 | * ã¤ãã³ããã³ãã©
|
---|
213 | */
|
---|
214 |
|
---|
215 | //ãªãã·ã§ã³ã®ãã¼ã¹
|
---|
216 | virtual void parseOption(OptionParameter &)
|
---|
217 | { parseOption(*Singleton<Directory>::getInstance()); }
|
---|
218 |
|
---|
219 | virtual void parseOption(Directory &) {}
|
---|
220 |
|
---|
221 | //ã³ã³ãã¼ãã³ãã®æ¬ä½
|
---|
222 | virtual void body(void) { body(*Singleton<Directory>::getInstance()); }
|
---|
223 | virtual void body(Directory &) {}
|
---|
224 |
|
---|
225 | //ç°å¸¸çµäºãã³ãã©
|
---|
226 | virtual void onFatalExit(void) {}
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 | TESTSUITE_PROTOTYPE(main)
|
---|
231 | };
|
---|
232 |
|
---|
233 |
|
---|
234 | #endif
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|