source: cfg_oil/trunk/toppers/oil/configuration_manager.cpp@ 8

Last change on this file since 8 was 8, checked in by msugi, 14 years ago

ディレクトリ構造の作成,ソース一式とReleaseビルドのコミット.

File size: 6.3 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2010 by Meika Sugimoto
6 *
7 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
8 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
9 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
10 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
11 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
12 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
13 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
14 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
15ƒƒ“ƒgi—˜—p
16 * ŽÒƒ}ƒjƒ…
17ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
18 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
19 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
20 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
21 * ‚ƁD
22 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
23ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
24ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
25 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
26 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
27 * •ñ‚·‚邱‚ƁD
28 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
29 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
30 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
31 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
32 * –Ɛӂ·‚邱‚ƁD
33 *
34 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
35 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
36 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
37 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
38 * ‚̐ӔC‚𕉂í‚È‚¢D
39 *
40 */
41
42#include <vector>
43#include <map>
44#include <algorithm>
45#include <functional>
46
47#include "toppers/global.hpp"
48#include "toppers/oil/configuration_manager.hpp"
49
50using namespace std;
51using namespace toppers::oil;
52using namespace toppers::oil::oil_implementation;
53using namespace toppers::oil::oil_definition;
54
55namespace toppers
56{
57 namespace configuration_manager
58 {
59 // APPMODE‚ð’T‚·ƒtƒ@ƒ“ƒNƒ^
60 bool find_appmode_object(object_definition *p)
61 {
62 if(p->get_object_type() == "APPMODE")
63 {
64 return true;
65 }
66 return false;
67 }
68
69 bool config_manage::read_configuration
70 (toppers::text *txt , std::vector<std::string> const& objlist)
71 {
72 description = txt;
73
74 // ƒXƒgƒŠƒ“ƒO‚ðì‚é
75 description_str = new string();
76 typedef text::container::const_iterator const_row_iterator;
77 typedef std::string::size_type size_type;
78 const_row_iterator first( txt->begin().get_row() ), last( txt->end().get_row() );
79
80 for ( const_row_iterator iter( first ); iter != last; ++iter )
81 {
82 *description_str += iter->buf;
83 }
84
85 // ƒp[ƒT‚̐¶¬
86 try
87 {
88 parser = new ::oil_parser(description_str , objlist);
89 }
90 catch( ... )
91 {
92 toppers::fatal("Memory allocation error.");
93 }
94
95 if(parser->do_parse(&oil_impl , &oil_def) == 0)
96 {
97 std::string kernel_type;
98 // APPMODE‚ª’è‹`‚³‚ê‚Ä‚¢‚È‚¢Žž‚ÍOSDEFAULTAPPMODE‚ð‘}“ü
99 toppers::get_global("kernel" , kernel_type);
100 if((kernel_type == "atk1")
101 && (oil_def->end() ==
102 (find_if(oil_def->begin() , oil_def->end() , find_appmode_object))))
103 {
104 oil_def->push_back(new object_definition("APPMODE OSDEFAULTAPPMODE"));
105 }
106
107 return true;
108 }
109 else
110 {
111 std::string message;
112 int position;
113 text::const_iterator iter;
114
115 // ƒGƒ‰[ˆÊ’u‚̎擾
116 parser->get_error(&position , &message);
117 // ŠY“–s‚̎擾
118 iter = description->line_at(position);
119 text::line_type error_occur = iter.line();
120
121 // •¶–@ƒGƒ‰[‚Í‚·‚®‚ɏI—¹
122 toppers::fatal(iter.line() , "%1%" , message);
123
124 return false;
125 }
126 }
127
128 bool object_matching(object_definition* obj , oil_object_impl* impl)
129 {
130 return impl->validate_object_configuration(obj , NULL);
131 }
132
133 bool config_manage::validate_and_assign_default_configuration(void)
134 {
135 bool result = true;
136 std::vector<oil_definition::object_definition*>::iterator p;
137 std::vector<oil_implementation::oil_object_impl*>::iterator q , found;
138
139 // ‘S‚ẴIƒuƒWƒFƒNƒg’è‹`‚ðŽÀ‘•‚Ɛ®‡‚µ‚Ä‚¢‚é‚©ƒ`ƒFƒbƒN‚µA
140 // ƒfƒtƒHƒ‹ƒgƒpƒ‰ƒ[ƒ^‚̕⊮‚ðs‚¤
141 for(p = oil_def->begin() ; p != oil_def->end() ; p++)
142 {
143 std::vector<toppers::oil::object_ref> object_refs;
144 for(q = oil_impl->begin() ; q != oil_impl->end() ; q++)
145 {
146 if((*q)->validate_object_configuration(*p , &object_refs) == true)
147 {
148 break;
149 }
150 }
151
152 if(q >= oil_impl->end())
153 {
154 // ƒpƒ‰ƒ[ƒ^‚̐®‡«ƒ`ƒFƒbƒN
155 result = false;
156 break;
157 }
158
159 // ƒŠƒtƒ@ƒŒƒ“ƒXæ‚ª³‚µ‚¢‚©‚̃`ƒFƒbƒN
160 result = validate_object_reference((*p)->get_name() , &object_refs);
161 }
162
163 return result;
164 }
165 bool config_manage::validate_object_reference
166 (std::string obj_name , std::vector<object_ref> *obj_refs)
167 {
168 std::vector<oil_definition::object_definition*>::iterator q;
169 std::vector<object_ref>::iterator p;
170 bool result = true;
171
172 for(p = obj_refs->begin() ; p != obj_refs->end() ; p++)
173 {
174 std::vector<oil_definition::object_definition*> name_match;
175 // –¼‘O‚ª“¯‚¶‚à‚Ì‚ð’Tõ
176 for(q = oil_def->begin() ; q != oil_def->end() ; q++)
177 {
178 if((*p).obj_name == (*q)->get_name())
179 {
180 name_match.push_back(*q);
181 }
182 }
183 // –¼‘O‚ªˆê’v‚µ‚È‚¯‚ê‚΂»‚ÌŽž“_‚ŃGƒ‰[
184 if(name_match.empty() == true)
185 {
186 toppers::error("Object %1%'s parameter %2% reference %3% , but not found." ,
187 obj_name , (*p).obj_type , (*p).obj_name);
188 result = false;
189 continue;
190 }
191
192 // ŽQÆæ‚̃^ƒCƒv‚ª“¯‚¶‚©’Tõ
193 for(q = name_match.begin() ; q != name_match.end() ; q++)
194 {
195 if((*p).obj_type == (*q)->get_object_type())
196 {
197 break;
198 }
199 }
200 // ƒ^ƒCƒv‚ª“¯‚¶‚à‚Ì‚ª‚È‚¯‚ê‚΃Gƒ‰[
201 if(q == name_match.end())
202 {
203 toppers::error("Object %1%'s parameter %2% reference %3% , but referenced object is not %4%_TYPE" ,
204 obj_name , (*p).obj_type , (*p).obj_name , (*p).obj_type);
205 result = false;
206 }
207 }
208
209 return result;
210 }
211
212 } /* namespace oil */
213
214} /* namespace toppers */
215
Note: See TracBrowser for help on using the repository browser.