CompileDES  3.12
Executable-Code Generation from Synchronised libFAUDES Automata
cgp_eventconfig.cpp
Go to the documentation of this file.
1 
3 /*
4  FAU Discrete Event Systems Library (libFAUDES)
5 
6  Copyright (C) 2010, Thomas Moor
7 
8 */
9 
10 // my includes
11 #include "cgp_eventconfig.h"
12 
13 
14 /*
15 ******************************************************************
16 ******************************************************************
17 ******************************************************************
18 
19 AttributeCodeGeneratorEvent implementation
20 
21 ******************************************************************
22 ******************************************************************
23 ******************************************************************
24 */
25 
26 // faudes type std
27 FAUDES_TYPE_IMPLEMENTATION(AttributeCodeGeneratorEvent,AttributeCodeGeneratorEvent,AttributeVoid)
28 
29 
30 // reset to default
31 void AttributeCodeGeneratorEvent::Clear(void) {
32  mType = ETInternal;
33  mPriority=0;
34  mTriggers.clear();
35  mActions.clear();
36  mTimeConstraint.mInitialValue="";
37  mTimeConstraint.mStartEvents.Clear();
38  mTimeConstraint.mStopEvents.Clear();
39  mTimeConstraint.mResetEvents.Clear();
40 };
41 
42 
43 //DoAssign(Src)
45  FD_DCG("AttributeCodeGeneratorEvent(" << this << "):DoAssign(): assignment from " << &rSrc);
46  mType=rSrc.mType;
47  mPriority=rSrc.mPriority;
48  mTriggers=rSrc.mTriggers;
49  mActions=rSrc.mActions;
51  return *this;
52 }
53 
54 //DoWrite(rTw);
55 void AttributeCodeGeneratorEvent::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
56  (void) rLabel; (void) pContext;
57  FD_DCG("AttributeCodeGeneratorEvent::DoWrite()");
58  std::vector<InputTrigger>::const_iterator tit;
59  std::vector<OutputAction>::const_iterator ait;
60  Token token;
61  switch(mType) {
62  // its an input event
63  case ETInput:
64  rTw.WriteBegin("Input");
65  token.SetEmpty("Priority");
66  token.InsAttributeFloat("val",mPriority);
67  rTw.Write(token);
68  rTw.WriteBegin("Triggers");
69  for(tit=mTriggers.begin(); tit!=mTriggers.end(); tit++) {
70  rTw.WriteString(tit->mAddress);
71  if(tit->mPos && (!tit->mNeg))
72  rTw.WriteOption("PosEdge");
73  if((!tit->mPos) && tit->mNeg)
74  rTw.WriteOption("NegEdge");
75  if((tit->mPos) && tit->mNeg)
76  rTw.WriteOption("AnyEdge");
77  if(tit->mStatic)
78  rTw.WriteOption("Static");
79  if((tit->mExe))
80  rTw.WriteOption("Value");
81  }
82  rTw.WriteEnd("Triggers");
83  rTw.WriteEnd("Input");
84  break;
85  // its an output event
86  case ETOutput:
87  rTw.WriteBegin("Output");
88  token.SetEmpty("Priority");
89  token.InsAttributeFloat("val",mPriority);
90  rTw.Write(token);
91  rTw.WriteBegin("Actions");
92  for(ait=mActions.begin(); ait!=mActions.end(); ait++) {
93  rTw.WriteString(ait->mAddress);
94  if(ait->mSet) rTw.WriteOption("Set");
95  if(ait->mClr) rTw.WriteOption("Clr");
96  if(ait->mExe) rTw.WriteOption("Exe");
97  }
98  rTw.WriteEnd("Actions");
99  rTw.WriteEnd("Output");
100  break;
101  // its an internal event
102  case ETInternal:
103  rTw.WriteBegin("Internal");
104  token.SetEmpty("Priority");
105  token.InsAttributeFloat("val",mPriority);
106  rTw.Write(token);
108  token.SetBegin("Timer");
109  token.InsAttributeString("val",mTimeConstraint.mInitialValue);
110  rTw.Write(token);
111  mTimeConstraint.mStartEvents.Write(rTw,"StartEvents");
112  mTimeConstraint.mStopEvents.Write(rTw,"StopEvents");
113  mTimeConstraint.mResetEvents.Write(rTw,"ResetEvents");
114  rTw.WriteEnd("Timer");
115  }
116  rTw.WriteEnd("Internal");
117  break;
118  // unimplemented others
119  default:
120  break;
121  }
122 }
123 
124 
125 //DoRead(rTr)
126 void AttributeCodeGeneratorEvent::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
127  (void) rLabel; (void) pContext;
128  std::string label;
129  bool err=false;
130  FD_DCG("AttributeCodeGeneratorEvent::DoRead()");
131  // clear
132  Clear();
133  // test for type
134  Token token;
135  rTr.Peek(token);
136  // output section
137  if(token.Type()==Token::Begin)
138  if(token.StringValue()=="Output") {
139  mType=ETOutput;
140  label="Output";
141  }
142  // input section
143  if(token.Type()==Token::Begin)
144  if(token.StringValue()=="Input") {
145  mType=ETInput;
146  label="Input";
147  }
148  // internal section
149  if(token.Type()==Token::Begin)
150  if(token.StringValue()=="Internal") {
151  mType=ETInternal;
152  label="Internal";
153  }
154  // none of the above
155  if(label=="") return;
156  // read my section
157  while(!rTr.Eos(label)) {
158  rTr.Peek(token);
159  // priority
160  if(token.Type()==Token::Begin)
161  if(token.StringValue()=="Priority") {
162  rTr.ReadBegin("Priority");
163  mPriority=(int) token.AttributeFloatValue("val");
164  rTr.ReadEnd("Priority");
165  continue;
166  }
167  // output
168  if(mType==ETOutput)
169  if(token.Type()==Token::Begin)
170  if(token.StringValue()=="Actions") {
171  rTr.ReadBegin("Actions");
172  while(!rTr.Eos("Actions")) {
173  // action
174  OutputAction action;
175  action.mClr=false;
176  action.mSet=false;
177  action.mExe=false;
178  // 1: address
179  action.mAddress=rTr.ReadString();
180  // 2: value
181  std::string value=rTr.ReadOption();
182  if(value== "Set") {
183  action.mSet=true;
184  } else if(value == "Clr") {
185  action.mClr=true;
186  } else if(value == "Execute") {
187  action.mExe=true;
188  } else {
189  err=true;
190  break;
191  }
192  // 3. record
193  mActions.push_back(action);
194  }
195  // done
196  rTr.ReadEnd("Actions");
197  continue;
198  }
199  // input
200  if(mType==ETInput)
201  if(token.Type()==Token::Begin)
202  if(token.StringValue()=="Triggers") {
203  rTr.ReadBegin("Triggers");
204  while(!rTr.Eos("Triggers")) {
205  // action
206  InputTrigger trigger;
207  trigger.mPos=false;
208  trigger.mNeg=false;
209  trigger.mExe=false;
210  trigger.mStatic=false;
211  // 1: address
212  trigger.mAddress=rTr.ReadString();
213  // 2: value
214  std::string value=rTr.ReadOption();
215  if (value == "PosEdge") {
216  trigger.mPos=true;
217  } else if (value == "NegEdge") {
218  trigger.mNeg=true;
219  } else if (value == "AnyEdge") {
220  trigger.mPos=true;
221  trigger.mNeg=true;
222  } else if (value == "Value") {
223  trigger.mExe=true;
224  } else {
225  err=true;
226  break;
227  }
228  // 3. static option
229  if(trigger.mPos || trigger.mNeg) {
230  rTr.Peek(token);
231  if(token.IsOption())
232  if(token.StringValue()=="Static") {
233  rTr.Get(token);
234  trigger.mStatic=true;
235  }
236  }
237  // 4. record
238  mTriggers.push_back(trigger);
239  }
240  // done
241  rTr.ReadEnd("Triggers");
242  continue;
243  }
244  // internal
245  if(mType==ETInternal)
246  if(token.Type()==Token::Begin)
247  if(token.StringValue()=="Timer") {
248  rTr.ReadBegin("Timer");
249  // 1: initial value
250  mTimeConstraint.mInitialValue = token.AttributeStringValue("val");
251  // 2,3,4: loop for event sets
252  while(!rTr.Eos("Timer")) {
253  rTr.Peek(token);
254  if(token.Type()==Token::Begin)
255  if(token.StringValue()=="StartEvents") {
256  mTimeConstraint.mStartEvents.Read(rTr,"StartEvents");
257  continue;
258  }
259  if(token.Type()==Token::Begin)
260  if(token.StringValue()=="StopEvents") {
261  mTimeConstraint.mStopEvents.Read(rTr,"StopEvents");
262  continue;
263  }
264  if(token.Type()==Token::Begin)
265  if(token.StringValue()=="ResetEvents") {
266  mTimeConstraint.mResetEvents.Read(rTr,"ResetEvents");
267  continue;
268  }
269  // ignore unknown tokens (should throw)
270  rTr.Get(token);
271  }
272  // done
273  rTr.ReadEnd("Timer");
274  continue;
275  }
276  // ignore unknown sections
277  rTr.Get(token);
278  }
279  rTr.ReadEnd(label);
280  // report error
281  if(err) {
282  std::stringstream errstr;
283  errstr << "invalid code generator event property" << rTr.FileLine();
284  throw Exception("AttributeCodeGeneratorEvent::Read", errstr.str(), 52); //52 oder 352
285  }
286 }//DoRead
287 
288 // register type for XML token-io
289 AutoRegisterType<cgEventSet> gRtiRegisterCodeGeneratorAlphabet("CodeGeneratorAlphabet");
290 AutoRegisterXElementTag<cgEventSet> gRtiRegisterCodeGeneratorAlphabetElementTagAlphabet("CodeGeneratorAlphabet", "Event");
291 
292 
EventSet mStartEvents
Events that start this timer.
std::string mAddress
Abstract address.
Event attributes for the purpose of code generation.
TimeConstraint mTimeConstraint
Timer definition (indicate timer event iff mInitialValue non-empty)
EventSet mResetEvents
Events that reset this timer.
std::string mAddress
Abstract address.
bool mNeg
Negative edge triggers event.
std::vector< InputTrigger > mTriggers
List of triggers (input events only)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
bool mStatic
Fake an initial edge on initialisation to sense static levels.
virtual AttributeCodeGeneratorEvent & DoAssign(const AttributeCodeGeneratorEvent &rSrcAttr)
bool mExe
Evaluate literal expression to trigger event.
virtual void Clear(void)
Clear to default.
bool mPos
Positive edge triggers event.
std::vector< OutputAction > mActions
List of actions to perform (output events only)
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Event attributes (execution semantics)
EventSet mStopEvents
Events that stop this timer.
Typedef for an individual trigger condition.
Typedef for an individual output action.
std::string mInitialValue
Initial value (literal to allow for advanced units, empty string for "not a timer") ...