00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include "XMLParser.h"
00052
00053 namespace DREAM
00054 {
00055
00056 void XMLParser::parse (char* xmlFile, DREAM::System* system)
00057 throw (DREAM::Exception)
00058 {
00059 const char* path = getenv ("DREAM_ROOT");
00060 if (path == "NULL")
00061 throw DREAM::XMLException ("Environment variable DREAM_ROOT is not set.");
00062
00063 std::cout << std::endl << "Parsing XML system description file \"" << xmlFile << "\"" << std::endl << std::endl;
00064 system_ptr_ = system;
00065
00066 xmlTextReaderPtr reader = xmlReaderForFile (xmlFile, NULL, 0);
00067
00068 if (reader != NULL)
00069 {
00070 std::string schema = path;
00071 schema += "/xsd/dream.xsd";
00072
00073 int schema_init = xmlTextReaderSchemaValidate (reader, schema.c_str ());
00074
00075 if (schema_init < 0)
00076 {
00077
00078 xmlFreeTextReader (reader);
00079 xmlCleanupParser ();
00080 std::string message;
00081 message << "XSD schema \"" << schema << "\" cannot be accessed.";
00082 throw DREAM::XMLException (message);
00083 }
00084
00085 if (xmlTextReaderIsValid (reader) != 1)
00086 {
00087
00088 xmlFreeTextReader (reader);
00089 xmlCleanupParser ();
00090 std::string message;
00091 message << "DREAM input XML \"" << xmlFile << "\" does not validate with XSD schema \"" << schema << "\".";
00092 throw DREAM::XMLException (message);
00093 }
00094
00095 int retval = xmlTextReaderRead (reader);
00096
00097 try
00098 {
00099 while (retval == 1)
00100 {
00101
00102 if (xmlTextReaderNodeType (reader) == 1)
00103 process_node (reader);
00104 retval = xmlTextReaderRead (reader);
00105 }
00106 }
00107 catch (DREAM::XMLException* &ex)
00108 {
00109
00110 xmlFreeTextReader (reader);
00111 xmlCleanupParser ();
00112 std::for_each (node_map_.begin (), node_map_.end (), delete_pair ());
00113 std::for_each (thread_map_.begin (), thread_map_.end (), delete_pair ());
00114 throw ex;
00115 }
00116
00117 xmlFreeTextReader (reader);
00118 xmlCleanupParser ();
00119
00120 if (retval != 0)
00121 {
00122 std::string message;
00123 message << "Error while parsing " << xmlFile << "...";
00124 throw DREAM::XMLException (message);
00125 }
00126 }
00127 else
00128 {
00129 std::string message;
00130 message << "Unable to open " << xmlFile << " for reading...";
00131 throw DREAM::XMLException (message);
00132 }
00133 }
00134
00135 void XMLParser::check_mapping ()
00136 throw (DREAM::Exception)
00137 {
00138 DREAM::NODE_MAP::const_iterator node_iter;
00139 std::string message;
00140 bool correct=true;
00141
00142 for (node_iter = node_map_.begin (); node_iter != node_map_.end (); node_iter++)
00143 {
00144 if (!node_iter->second->scheduler ())
00145 {
00146 correct=false;
00147 message << "DREAM Node " << node_iter->first << " is not assigned to any threads.\n";
00148 delete node_iter->second;
00149 }
00150 }
00151
00152 DREAM::THREAD_STR_MAP::const_iterator thread_iter;
00153
00154 for (thread_iter = thread_map_.begin (); thread_iter != thread_map_.end (); thread_iter++)
00155 {
00156 if (!thread_iter->second->scheduler ())
00157 {
00158 correct=false;
00159 message << "DREAM Thread " << thread_iter->first << " is not assigned to any CPUs.\n";
00160 delete thread_iter->second;
00161 }
00162 }
00163
00164 if (!correct)
00165 {
00166 message << "Incorrect model.";
00167 throw DREAM::XMLException (message);
00168 }
00169 }
00170
00171 DREAM::Node* XMLParser::find_node (const std::string& name)
00172 throw (DREAM::Exception)
00173 {
00174 DREAM::NODE_MAP::iterator node_iter;
00175
00176 for (node_iter = node_map_.begin (); node_iter != node_map_.end (); node_iter++)
00177 {
00178 if (node_iter->first == name)
00179 return node_iter->second;
00180 }
00181
00182 std::string message;
00183 message << "Node \"" << name << "\" is not declared but used.";
00184 throw DREAM::XMLException (message);
00185 }
00186
00187 DREAM::Thread* XMLParser::find_thread (const std::string& name)
00188 throw (DREAM::Exception)
00189 {
00190 DREAM::THREAD_STR_MAP::iterator thread_iter;
00191
00192 for (thread_iter = thread_map_.begin (); thread_iter != thread_map_.end (); thread_iter++)
00193 {
00194 if (thread_iter->first == name)
00195 return thread_iter->second;
00196 }
00197
00198 std::string message;
00199 message << "Thread \"" << name << "\" is not declared but used.";
00200 throw DREAM::XMLException (message);
00201 }
00202
00203 void XMLParser::set_system (DREAM::System* system_ptr)
00204 {
00205 system_ptr_ = system_ptr;
00206 }
00207
00208 void XMLParser::process_node (xmlTextReaderPtr reader)
00209 throw (DREAM::Exception)
00210 {
00211 const xmlChar *name_ptr = xmlTextReaderConstName (reader);
00212 if (name_ptr == NULL)
00213 throw DREAM::XMLException ("Empty XML node encountered while parsing...");
00214
00215 std::string type = (const char*) name_ptr;
00216
00217 if (type == "Node")
00218 std::cout << "Parsing nodes...\n";
00219 else if (type == "Task")
00220 process_task (reader);
00221 else if (type == "Channel")
00222 process_channel (reader);
00223 else if (type == "Timer")
00224 process_timer (reader);
00225
00226 else if (type == "Dependency")
00227 std::cout << "Parsing dependencies...\n";
00228 else if (type == "TimerToTask")
00229 process_timer_to_task (reader);
00230 else if (type == "TaskToTask")
00231 process_task_to_task (reader);
00232 else if (type == "TaskToChannel")
00233 process_task_to_channel (reader);
00234 else if (type == "ChannelToTask")
00235 process_channel_to_task (reader);
00236
00237 else if (type == "Thread")
00238 process_thread (reader);
00239 else if (type == "TaskMapping")
00240 process_task_mapping (reader);
00241 else if (type == "ChannelMapping")
00242 process_channel_mapping (reader);
00243 else if (type == "TimerMapping")
00244 process_timer_mapping (reader);
00245
00246 else if (type == "CPU")
00247 process_CPU (reader);
00248 else if (type == "ThreadMapping")
00249 process_thread_mapping (reader);
00250
00251
00252 }
00253
00254 void XMLParser::process_task (xmlTextReaderPtr reader)
00255 throw (DREAM::Exception)
00256 {
00257 DREAM::Task* task_ptr = NULL;
00258
00259 xmlChar* name_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "name");
00260 if (name_ptr == NULL)
00261 {
00262 xmlFree (name_ptr);
00263 throw DREAM::XMLException ("<Task ... name=\"\" .../> is an empty attribute");
00264 }
00265 std::string name = (const char*) name_ptr;
00266
00267 xmlChar* deadline_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "deadline");
00268 if (deadline_ptr == NULL)
00269 {
00270 xmlFree (name_ptr);
00271 xmlFree (deadline_ptr);
00272 throw DREAM::XMLException ("<Task ... deadline=\"\" .../> is an empty attribute");
00273 }
00274 std::string deadline = (const char*) deadline_ptr;
00275
00276 xmlChar* wcet_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "wcet");
00277 if (wcet_ptr == NULL)
00278 {
00279 xmlFree (name_ptr);
00280 xmlFree (deadline_ptr);
00281 xmlFree (wcet_ptr);
00282 throw DREAM::XMLException ("<Task ... wcet=\"\" .../> is an empty attribute");
00283 }
00284 std::string wcet = (const char*) wcet_ptr;
00285
00286 xmlChar* subpriority_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "subpriority");
00287 xmlChar* bcet_ptr;
00288
00289 if (subpriority_ptr == NULL)
00290 task_ptr = new DREAM::Task (name.c_str (), NULL, chartouint (wcet.c_str ()), chartouint (deadline.c_str ()));
00291 else
00292 {
00293 std::string subpriority = (const char*) subpriority_ptr;
00294 bcet_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "bcet");
00295
00296 if (bcet_ptr == NULL)
00297 task_ptr = new DREAM::Task (name.c_str (), NULL, chartouint (wcet.c_str ()), chartouint (deadline.c_str ()), chartouint (subpriority.c_str ()));
00298 else
00299 {
00300 std::string bcet = (const char*) bcet_ptr;
00301 task_ptr = new DREAM::Task (name.c_str (), NULL, chartouint (wcet.c_str ()), chartouint (bcet.c_str ()), chartouint (deadline.c_str ()), chartouint (subpriority.c_str ()));
00302 }
00303 xmlFree (bcet_ptr);
00304 }
00305
00306 node_map_.insert (DREAM::NODE_PAIR (name.c_str (), task_ptr));
00307
00308 xmlFree (name_ptr);
00309 xmlFree (deadline_ptr);
00310 xmlFree (wcet_ptr);
00311 xmlFree (subpriority_ptr);
00312 }
00313
00314 void XMLParser::process_channel (xmlTextReaderPtr reader)
00315 throw (DREAM::Exception)
00316 {
00317 DREAM::Channel* channel_ptr = NULL;
00318
00319 xmlChar* name_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "name");
00320 if (name_ptr == NULL)
00321 {
00322 xmlFree (name_ptr);
00323 throw DREAM::XMLException ("<Channel ... name=\"\" .../> is an empty attribute");
00324 }
00325 std::string name = (const char*) name_ptr;
00326
00327 xmlChar* buffersize_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "buffersize");
00328 if (buffersize_ptr == NULL)
00329 {
00330 xmlFree (name_ptr);
00331 xmlFree (buffersize_ptr);
00332 throw DREAM::XMLException ("<Channel ... buffersize=\"\" .../> is an empty attribute");
00333 }
00334 std::string buffersize = (const char*) buffersize_ptr;
00335
00336 xmlChar* delay_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "delay");
00337 std::string delay;
00338 if (delay_ptr == NULL)
00339 delay = "0";
00340
00341 else
00342 delay = (const char*) delay_ptr;
00343
00344 xmlChar* bcdelay_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "bcdelay");
00345
00346 if (bcdelay_ptr == NULL)
00347 channel_ptr = new DREAM::Channel (name.c_str (), NULL, chartouint (delay.c_str ()), chartouint (buffersize.c_str ()));
00348 else
00349 {
00350 std::string bcdelay = (const char*) bcdelay_ptr;
00351 channel_ptr = new DREAM::Channel (name.c_str (), NULL, chartouint (delay.c_str ()), chartouint (bcdelay.c_str ()), chartouint (buffersize.c_str ()));
00352 }
00353
00354 node_map_.insert (DREAM::NODE_PAIR (name.c_str (), channel_ptr));
00355
00356 xmlFree (name_ptr);
00357 xmlFree (buffersize_ptr);
00358 xmlFree (delay_ptr);
00359 xmlFree (bcdelay_ptr);
00360 }
00361
00362 void XMLParser::process_timer (xmlTextReaderPtr reader)
00363 throw (DREAM::Exception)
00364 {
00365 DREAM::Timer* timer_ptr = NULL;
00366
00367 xmlChar* name_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "name");
00368 if (name_ptr == NULL)
00369 {
00370 xmlFree (name_ptr);
00371 throw DREAM::XMLException ("<Timer ... name=\"\" .../> is an empty attribute");
00372 }
00373 std::string name = (const char*) name_ptr;
00374
00375 xmlChar* period_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "period");
00376 if (period_ptr == NULL)
00377 {
00378 xmlFree (name_ptr);
00379 xmlFree (period_ptr);
00380 throw DREAM::XMLException ("<Timer ... period=\"\" .../> is an empty attribute");
00381 }
00382 std::string period = (const char*) period_ptr;
00383
00384 xmlChar* bcperiod_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "bcperiod");
00385
00386 if (bcperiod_ptr == NULL)
00387 timer_ptr = new DREAM::Timer (name.c_str (), NULL, chartouint (period.c_str ()));
00388 else
00389 {
00390 std::string bcperiod = (const char*) bcperiod_ptr;
00391 timer_ptr = new DREAM::Timer (name.c_str (), NULL, chartouint (period.c_str ()), chartouint (bcperiod.c_str ()));
00392 }
00393
00394 node_map_.insert (DREAM::NODE_PAIR (name.c_str (), timer_ptr));
00395
00396 xmlFree (name_ptr);
00397 xmlFree (period_ptr);
00398 xmlFree (bcperiod_ptr);
00399 }
00400
00401 void XMLParser::process_thread (xmlTextReaderPtr reader)
00402 throw (DREAM::Exception)
00403 {
00404 DREAM::Thread* thread_ptr = NULL;
00405
00406 xmlChar* name_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "name");
00407 if (name_ptr == NULL)
00408 {
00409 xmlFree (name_ptr);
00410 throw DREAM::XMLException ("<Thread ... name=\"\" .../> is an empty attribute");
00411 }
00412 std::string name = (const char*) name_ptr;
00413
00414 std::cout << "Parsing thread \"" << name << "\"...\n";
00415
00416 xmlChar* numberofthreads_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "numberofthreads");
00417 std::string numberofthreads;
00418 if (numberofthreads_ptr == NULL)
00419 numberofthreads = "1";
00420
00421 else
00422 numberofthreads = (const char*) numberofthreads_ptr;
00423
00424 xmlChar* priority_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "priority");
00425 std::string priority;
00426 if (priority_ptr == NULL)
00427 priority = "1";
00428
00429 else
00430 priority = (const char*) priority_ptr;
00431
00432 xmlChar* queueingpolicy_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "queueingpolicy");
00433 if (queueingpolicy_ptr == NULL)
00434 {
00435 xmlFree (name_ptr);
00436 xmlFree (numberofthreads_ptr);
00437 xmlFree (priority_ptr);
00438 xmlFree (queueingpolicy_ptr);
00439 throw DREAM::XMLException ("<Thread ... queueingpolicy=\"\" .../> is an empty attribute");
00440 }
00441 std::string policy = (const char*) queueingpolicy_ptr;
00442
00443 if (policy == "FixedPriority")
00444 thread_ptr = new DREAM::Thread (NULL, chartouint (priority.c_str ()), chartouint (numberofthreads.c_str ()));
00445 else
00446 {
00447 std::string message;
00448 throw DREAM::XMLException
00449 (message << "Unknown scheduling policy specified for thread \"" << name << "\"...");
00450 }
00451
00452 current_thread_ = thread_ptr;
00453
00454 thread_map_.insert (THREAD_STR_PAIR (name.c_str (), thread_ptr));
00455
00456 xmlFree (name_ptr);
00457 xmlFree (numberofthreads_ptr);
00458 xmlFree (priority_ptr);
00459 xmlFree (queueingpolicy_ptr);
00460 }
00461
00462 void XMLParser::process_timer_to_task (xmlTextReaderPtr reader)
00463 throw (DREAM::Exception)
00464 {
00465 xmlChar* timer_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "timer");
00466 if (timer_ptr == NULL)
00467 {
00468 xmlFree (timer_ptr);
00469 throw DREAM::XMLException ("<TimerToTask ... timer=\"\" .../> is an empty attribute");
00470 }
00471 std::string timer = (const char*) timer_ptr;
00472
00473 xmlChar* task_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "task");
00474 if (task_ptr == NULL)
00475 {
00476 xmlFree (timer_ptr);
00477 xmlFree (task_ptr);
00478 throw DREAM::XMLException ("<TimerToTask ... task=\"\" .../> is an empty attribute");
00479 }
00480 std::string task = (const char*) task_ptr;
00481
00482 try
00483 {
00484 find_node (timer.c_str ())->add_dependent (find_node (task.c_str ()));
00485 }
00486 catch (DREAM::XMLException* &ex)
00487 {
00488
00489 xmlFree (timer_ptr);
00490 xmlFree (task_ptr);
00491 throw ex;
00492 }
00493
00494 xmlFree (timer_ptr);
00495 xmlFree (task_ptr);
00496 }
00497
00498 void XMLParser::process_task_to_task (xmlTextReaderPtr reader)
00499 throw (DREAM::Exception)
00500 {
00501 xmlChar* sourcetask_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "sourcetask");
00502 if (sourcetask_ptr == NULL)
00503 {
00504 xmlFree (sourcetask_ptr);
00505 throw DREAM::XMLException ("<TaskToTask ... sourcetask=\"\" .../> is an empty attribute");
00506 }
00507 std::string sourcetask = (const char*) sourcetask_ptr;
00508
00509 xmlChar* destinationtask_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "destinationtask");
00510 if (destinationtask_ptr == NULL)
00511 {
00512 xmlFree (sourcetask_ptr);
00513 xmlFree (destinationtask_ptr);
00514 throw DREAM::XMLException ("<TaskToTask ... destinationtask=\"\" .../> is an empty attribute");
00515 }
00516 std::string destinationtask = (const char*) destinationtask_ptr;
00517
00518 try
00519 {
00520 find_node (sourcetask.c_str ())->add_dependent (find_node (destinationtask.c_str ()));
00521 }
00522 catch (DREAM::XMLException* &ex)
00523 {
00524
00525 xmlFree (sourcetask_ptr);
00526 xmlFree (destinationtask_ptr);
00527 throw ex;
00528 }
00529
00530 xmlFree (sourcetask_ptr);
00531 xmlFree (destinationtask_ptr);
00532 }
00533
00534 void XMLParser::process_task_to_channel (xmlTextReaderPtr reader)
00535 throw (DREAM::Exception)
00536 {
00537 xmlChar* task_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "task");
00538 if (task_ptr == NULL)
00539 {
00540 xmlFree (task_ptr);
00541 throw DREAM::XMLException ("<TaskToChannel ... task=\"\" .../> is an empty attribute");
00542 }
00543 std::string task = (const char*) task_ptr;
00544
00545 xmlChar* channel_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "channel");
00546 if (channel_ptr == NULL)
00547 {
00548 xmlFree (task_ptr);
00549 xmlFree (channel_ptr);
00550 throw DREAM::XMLException ("<TaskToChannel ... channel=\"\" .../> is an empty attribute");
00551 }
00552 std::string channel = (const char*) channel_ptr;
00553
00554 try
00555 {
00556 find_node (task.c_str ())->add_dependent (find_node (channel.c_str ()));
00557 }
00558 catch (DREAM::XMLException* &ex)
00559 {
00560
00561 xmlFree (task_ptr);
00562 xmlFree (channel_ptr);
00563 throw ex;
00564 }
00565
00566 xmlFree (task_ptr);
00567 xmlFree (channel_ptr);
00568 }
00569
00570 void XMLParser::process_channel_to_task (xmlTextReaderPtr reader)
00571 throw (DREAM::Exception)
00572 {
00573 xmlChar* channel_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "channel");
00574 if (channel_ptr == NULL)
00575 {
00576 xmlFree (channel_ptr);
00577 throw DREAM::XMLException ("<ChannelToTask ... channel=\"\" .../> is an empty attribute");
00578 }
00579 std::string channel = (const char*) channel_ptr;
00580
00581 xmlChar* task_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "task");
00582 if (task_ptr == NULL)
00583 {
00584 xmlFree (channel_ptr);
00585 xmlFree (task_ptr);
00586 throw DREAM::XMLException ("<ChannelToTask ... task=\"\" .../> is an empty attribute");
00587 }
00588 std::string task = (const char*) task_ptr;
00589
00590 try
00591 {
00592 find_node (channel.c_str ())->add_dependent (find_node (task.c_str ()));
00593 }
00594 catch (DREAM::XMLException* &ex)
00595 {
00596
00597 xmlFree (task_ptr);
00598 xmlFree (channel_ptr);
00599 throw ex;
00600 }
00601
00602 xmlFree (channel_ptr);
00603 xmlFree (task_ptr);
00604 }
00605
00606 void XMLParser::process_task_mapping (xmlTextReaderPtr reader)
00607 throw (DREAM::Exception)
00608 {
00609 xmlChar* task_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "task");
00610 if (task_ptr == NULL)
00611 {
00612 xmlFree (task_ptr);
00613 throw DREAM::XMLException ("<TaskMapping ... task=\"\" .../> is an empty attribute");
00614 }
00615 std::string task = (const char*) task_ptr;
00616
00617 try
00618 {
00619 find_node (task.c_str ())->deploy (current_thread_);
00620 }
00621 catch (DREAM::XMLException* &ex)
00622 {
00623
00624 xmlFree (task_ptr);
00625 throw ex;
00626 }
00627
00628 xmlFree (task_ptr);
00629 }
00630
00631 void XMLParser::process_channel_mapping (xmlTextReaderPtr reader)
00632 throw (DREAM::Exception)
00633 {
00634 xmlChar* channel_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "channel");
00635 if (channel_ptr == NULL)
00636 {
00637 xmlFree (channel_ptr);
00638 throw DREAM::XMLException ("<ChannelMapping ... channel=\"\" .../> is an empty attribute");
00639 }
00640 std::string channel = (const char*) channel_ptr;
00641
00642 try
00643 {
00644 find_node (channel.c_str ())->deploy (current_thread_);
00645 }
00646 catch (DREAM::XMLException* &ex)
00647 {
00648
00649 xmlFree (channel_ptr);
00650 throw ex;
00651 }
00652
00653 xmlFree (channel_ptr);
00654 }
00655
00656 void XMLParser::process_timer_mapping (xmlTextReaderPtr reader)
00657 throw (DREAM::Exception)
00658 {
00659 xmlChar* timer_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "timer");
00660 if (timer_ptr == NULL)
00661 {
00662 xmlFree (timer_ptr);
00663 throw DREAM::XMLException ("<TimerMapping ... timer=\"\" .../> is an empty attribute");
00664 }
00665 std::string timer = (const char*) timer_ptr;
00666
00667 try
00668 {
00669 find_node (timer.c_str ())->deploy (current_thread_);
00670 }
00671 catch (DREAM::XMLException* &ex)
00672 {
00673
00674 xmlFree (timer_ptr);
00675 throw ex;
00676 }
00677
00678 xmlFree (timer_ptr);
00679 }
00680
00681 void XMLParser::process_CPU (xmlTextReaderPtr reader)
00682 throw (DREAM::Exception)
00683 {
00684 DREAM::Scheduler* scheduler_ptr = NULL;
00685
00686 xmlChar* name_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "name");
00687 if (name_ptr == NULL)
00688 {
00689 xmlFree (name_ptr);
00690 throw DREAM::XMLException ("<CPU ... name=\"\" .../> is an empty attribute");
00691 }
00692 std::string name = (const char*) name_ptr;
00693
00694 xmlChar* numberofCPUs_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "numberofCPUs");
00695 std::string numberofCPUs;
00696 if (numberofCPUs_ptr == NULL)
00697 numberofCPUs = "1";
00698
00699 else
00700 numberofCPUs = (const char*) numberofCPUs_ptr;
00701
00702 xmlChar* schedulingpolicy_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "schedulingpolicy");
00703 if (schedulingpolicy_ptr == NULL)
00704 {
00705 xmlFree (name_ptr);
00706 xmlFree (numberofCPUs_ptr);
00707 xmlFree (schedulingpolicy_ptr);
00708 throw DREAM::XMLException ("<CPU ... schedulingpolicy=\"\" .../> is an empty attribute");
00709 }
00710
00711 std::cout << "Parsing CPU \"" << name << "\"...\n";
00712
00713 std::string policy = (const char*) schedulingpolicy_ptr;
00714
00715 if (policy == "FixedPriority")
00716 scheduler_ptr = new DREAM::FixedPriorityScheduler (name.c_str (), system_ptr_, chartouint (numberofCPUs.c_str ()));
00717 else if (policy == "NonConcurrent")
00718 scheduler_ptr = new DREAM::NonConcurrentScheduler (name.c_str (), system_ptr_);
00719 else
00720 {
00721 xmlFree (name_ptr);
00722 xmlFree (numberofCPUs_ptr);
00723 xmlFree (schedulingpolicy_ptr);
00724 std::string message;
00725 throw DREAM::XMLException
00726 (message << "Unknown scheduling policy specified for CPU \"" << name << "\"...");
00727 }
00728
00729 current_scheduler_ = scheduler_ptr;
00730
00731 if (system_ptr_)
00732 system_ptr_->add_scheduler (scheduler_ptr);
00733 else
00734 {
00735 xmlFree (name_ptr);
00736 xmlFree (numberofCPUs_ptr);
00737 xmlFree (schedulingpolicy_ptr);
00738 throw DREAM::XMLException ("XMLParseHandler::processCPU (): System pointer was not set before parsing.");
00739 }
00740
00741 xmlFree (name_ptr);
00742 xmlFree (numberofCPUs_ptr);
00743 xmlFree (schedulingpolicy_ptr);
00744 }
00745
00746 void XMLParser::process_thread_mapping (xmlTextReaderPtr reader)
00747 throw (DREAM::Exception)
00748 {
00749 xmlChar* thread_ptr = xmlTextReaderGetAttribute (reader, (const xmlChar*) "thread");
00750 if (thread_ptr == NULL)
00751 {
00752 xmlFree (thread_ptr);
00753 throw DREAM::XMLException ("<ThreadMapping ... thread=\"\" .../> is an empty attribute");
00754 }
00755 std::string thread = (const char*) thread_ptr;
00756
00757 try
00758 {
00759 find_thread (thread.c_str ())->deploy (current_scheduler_);
00760 }
00761 catch (DREAM::XMLException* &ex)
00762 {
00763
00764 xmlFree (thread_ptr);
00765 throw ex;
00766 }
00767
00768 xmlFree (thread_ptr);
00769 }
00770
00771 };
00772