1 | /*
|
---|
2 | * TOPPERS Software
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
4 | *
|
---|
5 | * Copyright (C) 2010 by Meika Sugimoto
|
---|
6 | *
|
---|
7 | * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
8 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
9 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
10 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
11 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
12 | * スコード中に含まれていること.
|
---|
13 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
14 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
15 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
16 | * の無保証規定を掲載すること.
|
---|
17 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
18 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
19 | * と.
|
---|
20 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
21 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
22 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
23 | * 報告すること.
|
---|
24 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
25 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
26 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
27 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
28 | * 免責すること.
|
---|
29 | *
|
---|
30 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
31 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
32 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
33 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
34 | * の責任を負わない.
|
---|
35 | *
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <vector>
|
---|
39 | #include <map>
|
---|
40 | #include <algorithm>
|
---|
41 | #include <functional>
|
---|
42 |
|
---|
43 | #include "toppers/global.hpp"
|
---|
44 | #include "toppers/oil/configuration_manager.hpp"
|
---|
45 |
|
---|
46 | using namespace std;
|
---|
47 | using namespace toppers::oil;
|
---|
48 | using namespace toppers::oil::oil_implementation;
|
---|
49 | using namespace toppers::oil::oil_definition;
|
---|
50 |
|
---|
51 | namespace toppers
|
---|
52 | {
|
---|
53 | namespace configuration_manager
|
---|
54 | {
|
---|
55 | // APPMODEを探すファンクタ
|
---|
56 | bool find_appmode_object(object_definition *p)
|
---|
57 | {
|
---|
58 | if(p->get_object_type() == "APPMODE")
|
---|
59 | {
|
---|
60 | return true;
|
---|
61 | }
|
---|
62 | return false;
|
---|
63 | }
|
---|
64 |
|
---|
65 | bool config_manage::read_configuration
|
---|
66 | (toppers::text *txt , std::vector<std::string> const& objlist)
|
---|
67 | {
|
---|
68 | description = txt;
|
---|
69 |
|
---|
70 | // ストリングを作る
|
---|
71 | description_str = new string();
|
---|
72 | typedef text::container::const_iterator const_row_iterator;
|
---|
73 | typedef std::string::size_type size_type;
|
---|
74 | const_row_iterator first( txt->begin().get_row() ), last( txt->end().get_row() );
|
---|
75 |
|
---|
76 | for ( const_row_iterator iter( first ); iter != last; ++iter )
|
---|
77 | {
|
---|
78 | *description_str += iter->buf;
|
---|
79 | }
|
---|
80 |
|
---|
81 | // パーサの生成
|
---|
82 | try
|
---|
83 | {
|
---|
84 | parser = new ::oil_parser(description_str , objlist);
|
---|
85 | }
|
---|
86 | catch( ... )
|
---|
87 | {
|
---|
88 | toppers::fatal("Memory allocation error.");
|
---|
89 | }
|
---|
90 |
|
---|
91 | if(parser->do_parse(&oil_impl , &oil_def) == 0)
|
---|
92 | {
|
---|
93 | std::string kernel_type;
|
---|
94 | // APPMODEが定義されていない時はOSDEFAULTAPPMODEを挿入
|
---|
95 | toppers::get_global("kernel" , kernel_type);
|
---|
96 | if((kernel_type == "atk1")
|
---|
97 | && (oil_def->end() ==
|
---|
98 | (find_if(oil_def->begin() , oil_def->end() , find_appmode_object))))
|
---|
99 | {
|
---|
100 | oil_def->push_back(new object_definition("APPMODE OSDEFAULTAPPMODE"));
|
---|
101 | }
|
---|
102 |
|
---|
103 | return true;
|
---|
104 | }
|
---|
105 | else
|
---|
106 | {
|
---|
107 | std::string message;
|
---|
108 | int position;
|
---|
109 | text::const_iterator iter;
|
---|
110 |
|
---|
111 | // エラー位置の取得
|
---|
112 | parser->get_error(&position , &message);
|
---|
113 | // 該当行の取得
|
---|
114 | iter = description->line_at(position);
|
---|
115 | text::line_type error_occur = iter.line();
|
---|
116 |
|
---|
117 | // 文法エラーはすぐに終了
|
---|
118 | toppers::fatal(iter.line() , "%1%" , message);
|
---|
119 |
|
---|
120 | return false;
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | bool object_matching(object_definition* obj , oil_object_impl* impl)
|
---|
125 | {
|
---|
126 | return impl->validate_object_configuration(obj , NULL);
|
---|
127 | }
|
---|
128 |
|
---|
129 | bool config_manage::validate_and_assign_default_configuration(void)
|
---|
130 | {
|
---|
131 | bool result = true;
|
---|
132 | std::vector<oil_definition::object_definition*>::iterator p;
|
---|
133 | std::vector<oil_implementation::oil_object_impl*>::iterator q , found;
|
---|
134 |
|
---|
135 | // 全てのオブジェクト定義を実装と整合しているかチェックし、
|
---|
136 | // デフォルトパラメータの補完を行う
|
---|
137 | for(p = oil_def->begin() ; p != oil_def->end() ; p++)
|
---|
138 | {
|
---|
139 | std::vector<toppers::oil::object_ref> object_refs;
|
---|
140 | for(q = oil_impl->begin() ; q != oil_impl->end() ; q++)
|
---|
141 | {
|
---|
142 | if((*q)->validate_object_configuration(*p , &object_refs) == true)
|
---|
143 | {
|
---|
144 | break;
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | if(q >= oil_impl->end())
|
---|
149 | {
|
---|
150 | // パラメータの整合性チェック
|
---|
151 | result = false;
|
---|
152 | break;
|
---|
153 | }
|
---|
154 |
|
---|
155 | // リファレンス先が正しいかのチェック
|
---|
156 | result = validate_object_reference((*p)->get_name() , &object_refs);
|
---|
157 | }
|
---|
158 |
|
---|
159 | return result;
|
---|
160 | }
|
---|
161 | bool config_manage::validate_object_reference
|
---|
162 | (std::string obj_name , std::vector<object_ref> *obj_refs)
|
---|
163 | {
|
---|
164 | std::vector<oil_definition::object_definition*>::iterator q;
|
---|
165 | std::vector<object_ref>::iterator p;
|
---|
166 | bool result = true;
|
---|
167 |
|
---|
168 | for(p = obj_refs->begin() ; p != obj_refs->end() ; p++)
|
---|
169 | {
|
---|
170 | std::vector<oil_definition::object_definition*> name_match;
|
---|
171 | // 名前が同じものを探索
|
---|
172 | for(q = oil_def->begin() ; q != oil_def->end() ; q++)
|
---|
173 | {
|
---|
174 | if((*p).obj_name == (*q)->get_name())
|
---|
175 | {
|
---|
176 | name_match.push_back(*q);
|
---|
177 | }
|
---|
178 | }
|
---|
179 | // 名前が一致しなければその時点でエラー
|
---|
180 | if(name_match.empty() == true)
|
---|
181 | {
|
---|
182 | toppers::error("Object %1%'s parameter %2% reference %3% , but not found." ,
|
---|
183 | obj_name , (*p).obj_type , (*p).obj_name);
|
---|
184 | result = false;
|
---|
185 | continue;
|
---|
186 | }
|
---|
187 |
|
---|
188 | // 参照先のタイプが同じか探索
|
---|
189 | for(q = name_match.begin() ; q != name_match.end() ; q++)
|
---|
190 | {
|
---|
191 | if((*p).obj_type == (*q)->get_object_type())
|
---|
192 | {
|
---|
193 | break;
|
---|
194 | }
|
---|
195 | }
|
---|
196 | // タイプが同じものがなければエラー
|
---|
197 | if(q == name_match.end())
|
---|
198 | {
|
---|
199 | toppers::error("Object %1%'s parameter %2% reference %3% , but referenced object is not %4%_TYPE" ,
|
---|
200 | obj_name , (*p).obj_type , (*p).obj_name , (*p).obj_type);
|
---|
201 | result = false;
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | return result;
|
---|
206 | }
|
---|
207 |
|
---|
208 | } /* namespace oil */
|
---|
209 |
|
---|
210 | } /* namespace toppers */
|
---|
211 |
|
---|