Scheduler
xmlTaskSet.cpp
Go to the documentation of this file.
1 
10 #include "xmlTaskSet.h"
11 
12 #include <iostream>
13 #include <stdexcept>
14 
15 #include <tinyxml2/tinyxml2.h>
16 
17 #include <utils/randomGenerator.h>
19 
20 #include "system.h"
21 #include "process.h"
22 
23 using namespace Scheduler;
24 
25 
26 
27 std::shared_ptr<std::vector<std::shared_ptr<Process>>>
29 {
31  tinyxml2::XMLError err = doc.LoadFile(filename.c_str());
32  if (err != tinyxml2::XML_SUCCESS)
33  throw std::runtime_error("could not load xml file"); //TODO: create a new exception
34 
35  tinyxml2::XMLElement *root = doc.RootElement();
36  if (root == nullptr)
37  throw std::runtime_error("no root node");
38 
39  tinyxml2::XMLElement *processElem = root->FirstChildElement("process");
40 
41  taskVector = std::make_shared<std::vector<std::shared_ptr<Process>>>();
42 
43  while (processElem != nullptr)
44  {
45  getTaskData(processElem);
46  processElem = processElem->NextSiblingElement("process");
47  }
48 
49 
50  return taskVector;
51 }
52 
53 
54 
55 
56 void XmlTaskSet::getTaskData(tinyxml2::XMLElement *elem)
57 {
58  double releaseTime = 0.0;
59  double wcet = 1.0;
60  double period = 10.0;
61  double deadline = 10.0;
62  int pid = Process::getNewPid();
63  int priority = 0;
64  double bcet = 0.0;
65  double powerCoeff = 1.0;
66  std::shared_ptr<Utils::BoundedRandomDistribution> randomDist = nullptr;
67 
68 
69  //FIXME release time not used
70  tinyxml2::XMLElement *releaseTimeElem = elem->FirstChildElement("releaseTime");
71  if (releaseTimeElem != nullptr)
72  {
73  releaseTimeElem->QueryDoubleText(&releaseTime);
74  }
75  tinyxml2::XMLElement *powerCoeffElem = elem->FirstChildElement("powerCoeff");
76  if (powerCoeffElem != nullptr)
77  {
78  powerCoeffElem->QueryDoubleText(&powerCoeff);
79  }
80  tinyxml2::XMLElement *priorityElem = elem->FirstChildElement("priority");
81  if (priorityElem != nullptr)
82  {
83  priorityElem->QueryIntText(&priority);
84  }
85  tinyxml2::XMLElement *periodElem = elem->FirstChildElement("period");
86  if (periodElem != nullptr)
87  {
88  periodElem->QueryDoubleText(&period);
89  }
90  tinyxml2::XMLElement *deadlineElem = elem->FirstChildElement("deadline");
91  if (deadlineElem != nullptr)
92  {
93  deadlineElem->QueryDoubleText(&deadline);
94  }
95  tinyxml2::XMLElement *wcetElem = elem->FirstChildElement("wcet");
96  if (wcetElem != nullptr)
97  {
98  wcetElem->QueryDoubleText(&wcet);
99  }
100  tinyxml2::XMLElement *durationDistribution
101  = elem->FirstChildElement("durationDistribution");
102  if (durationDistribution != nullptr)
103  {
104  if (durationDistribution->Attribute("xsi:type", "deterministic"))
105  {
106  //taken care of by having a nullptr randomDist
107  }
108  else if (durationDistribution->Attribute("xsi:type", "bernoulli"))
109  {
110  tinyxml2::XMLElement *bcetElem = durationDistribution->FirstChildElement("bcet");
111  tinyxml2::XMLElement *pElem = durationDistribution->FirstChildElement("p");
112  bcetElem->QueryDoubleText(&bcet);
113  double p;
114  pElem->QueryDoubleText(&p);
115  /*FIXME: where should this randomGen be created and destroyed?*/
117  randomDist = std::make_shared<Utils::Bernoulli>(randomGen, p);
118  }
119  else
120  {
121  //error
122  }
123  }
124 
125  std::shared_ptr<Process> task
126  = Process::createRealTimeTask(wcet, period, deadline, pid, priority, bcet);
127  task->setPowerCoeff(powerCoeff);
128  task->setDurationDistribution(randomDist);
129 
130  taskVector->push_back(task);
131 }
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:906
XMLError LoadFile(const char *filename)
Definition: tinyxml2.cpp:2075
const XMLElement * NextSiblingElement(const char *name=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
Definition: tinyxml2.cpp:930
std::shared_ptr< std::vector< std::shared_ptr< Process > > > getRealTimeTaskSetFromXml(std::string filename)
Definition: xmlTaskSet.cpp:28
static std::shared_ptr< Process > createRealTimeTask(double wcet, double T, double dl, int pid, int priority=0, double bcet=0.0)
creates a real time task
Definition: process.cpp:67
static int getNewPid()
returns new process identifier. The value returned gets incremented at each call
Definition: process.cpp:88
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
Definition: tinyxml2.cpp:1646
XMLElement * RootElement()
Definition: tinyxml2.h:1683
string filename
Definition: aging.py:5
const char * Attribute(const char *name, const char *value=0) const
Definition: tinyxml2.cpp:1472
XMLError QueryIntText(int *ival) const
Definition: tinyxml2.cpp:1594