FW Profile - C1 Implementation
FwPrConfig.c
Go to the documentation of this file.
1 
18 #include "FwPrConfig.h"
19 #include "FwPrPrivate.h"
20 #include <stdlib.h>
21 
37 static void AddFlow(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, NodeType_t srcType, FwPrCounterS1_t destId,
38  FwPrGuard_t cfGuard);
39 
60 static FwPrCounterS1_t AddAction(FwPrDesc_t prDesc, FwPrAction_t action);
61 
79 static FwPrCounterS1_t AddGuard(FwPrDesc_t prDesc, FwPrGuard_t guard);
80 
81 /* ----------------------------------------------------------------------------------------------------------------- */
82 void FwPrSetData(FwPrDesc_t prDesc, void* prData) {
83  prDesc->prData = prData;
84 }
85 
86 /* ----------------------------------------------------------------------------------------------------------------- */
87 void* FwPrGetData(FwPrDesc_t prDesc) {
88  return prDesc->prData;
89 }
90 
91 /* ----------------------------------------------------------------------------------------------------------------- */
93 
94  PrANode_t* aNode;
95  PrBaseDesc_t* prBase = prDesc->prBase;
96 
97  if (action == NULL) {
98  prDesc->errCode = prNullAction;
99  return;
100  }
101 
102  if (nodeId > prBase->nOfANodes) {
103  prDesc->errCode = prIllActNodeId;
104  return;
105  }
106 
107  if (nodeId < 1) {
108  prDesc->errCode = prIllActNodeId;
109  return;
110  }
111 
112  if (prBase->aNodes[nodeId - 1].iFlow != -1) {
113  prDesc->errCode = prActNodeIdInUse;
114  return;
115  }
116 
117  if (prDesc->flowCnt + 1 > prBase->nOfFlows) {
118  prDesc->errCode = prTooManyOutFlows;
119  return;
120  }
121 
122  /* Initialize newly added state */
123  aNode = &(prBase->aNodes[nodeId - 1]);
124 
125  aNode->iFlow = prDesc->flowCnt;
126  prDesc->flowCnt = (FwPrCounterS1_t)(prDesc->flowCnt + 1);
127 
128  aNode->iAction = AddAction(prDesc, action);
129 
130  return;
131 }
132 
133 /* ----------------------------------------------------------------------------------------------------------------- */
135  PrDNode_t* dNode;
136  PrBaseDesc_t* prBase = prDesc->prBase;
137 
138  if (nodeId > prBase->nOfDNodes) {
139  prDesc->errCode = prIllDecNodeId;
140  return;
141  }
142 
143  if (nodeId < 1) {
144  prDesc->errCode = prIllDecNodeId;
145  return;
146  }
147 
148  if (prBase->dNodes[nodeId - 1].outFlowIndex != -1) {
149  prDesc->errCode = prDecNodeIdInUse;
150  return;
151  }
152 
153  if (nOfOutFlows < 2) {
154  prDesc->errCode = prIllNOfOutFlows;
155  return;
156  }
157 
158  if (prDesc->flowCnt + nOfOutFlows > prBase->nOfFlows) {
159  prDesc->errCode = prTooManyOutFlows;
160  return;
161  }
162 
163  /* Initialize newly added decision node */
164  dNode = &(prBase->dNodes[nodeId - 1]);
165 
166  dNode->outFlowIndex = prDesc->flowCnt;
167  prDesc->flowCnt = (FwPrCounterS1_t)(prDesc->flowCnt + nOfOutFlows);
168 
169  dNode->nOfOutTrans = nOfOutFlows;
170 
171  return;
172 }
173 
174 /* ----------------------------------------------------------------------------------------------------------------- */
176  AddFlow(prDesc, 0, stoppedNode, destId, cfGuard);
177 }
178 
179 /* ----------------------------------------------------------------------------------------------------------------- */
181  AddFlow(prDesc, 0, stoppedNode, (FwPrCounterS1_t)(-destId), cfGuard);
182 }
183 
184 /* ----------------------------------------------------------------------------------------------------------------- */
186  AddFlow(prDesc, srcId, actionNode, destId, cfGuard);
187 }
188 
189 /* ----------------------------------------------------------------------------------------------------------------- */
191  AddFlow(prDesc, srcId, actionNode, (FwPrCounterS1_t)(-destId), cfGuard);
192 }
193 
194 /* ----------------------------------------------------------------------------------------------------------------- */
196  AddFlow(prDesc, srcId, decisionNode, destId, cfGuard);
197 }
198 
199 /* ----------------------------------------------------------------------------------------------------------------- */
201  AddFlow(prDesc, srcId, decisionNode, (FwPrCounterS1_t)(-destId), cfGuard);
202 }
203 
204 /* ----------------------------------------------------------------------------------------------------------------- */
206  AddFlow(prDesc, srcId, actionNode, 0, cfGuard);
207 }
208 
209 /* ----------------------------------------------------------------------------------------------------------------- */
211  AddFlow(prDesc, srcId, decisionNode, 0, cfGuard);
212 }
213 
214 /* ----------------------------------------------------------------------------------------------------------------- */
215 static void AddFlow(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, NodeType_t srcType, FwPrCounterS1_t destId,
216  FwPrGuard_t cfGuard) {
217 
218  FwPrCounterS1_t i, baseLoc, nOfOutFlows;
219  FwPrCounterS1_t loc = -1;
220  PrFlow_t* flow;
221  PrBaseDesc_t* prBase = prDesc->prBase;
222 
223  /* check that the source state is legal and has been defined */
224  if (srcType == actionNode) {
225  if (srcId > prBase->nOfANodes) {
226  prDesc->errCode = prIllFlowSrc;
227  return;
228  }
229  if (srcId < 1) {
230  prDesc->errCode = prIllFlowSrc;
231  return;
232  }
233  if (prBase->aNodes[srcId - 1].iFlow == -1) {
234  prDesc->errCode = prUndefinedFlowSrc;
235  return;
236  }
237  baseLoc = prBase->aNodes[srcId - 1].iFlow;
238  nOfOutFlows = 1;
239  }
240  else if (srcType == decisionNode) {
241  if (srcId > prBase->nOfDNodes) {
242  prDesc->errCode = prIllFlowSrc;
243  return;
244  }
245  if (srcId < 1) {
246  prDesc->errCode = prIllFlowSrc;
247  return;
248  }
249  if (prBase->dNodes[srcId - 1].outFlowIndex == -1) {
250  prDesc->errCode = prUndefinedFlowSrc;
251  return;
252  }
253  baseLoc = prBase->dNodes[srcId - 1].outFlowIndex;
254  nOfOutFlows = prBase->dNodes[srcId - 1].nOfOutTrans;
255  }
256  else { /* Source state is the stopped state */
257  baseLoc = 0;
258  nOfOutFlows = 1;
259  }
260 
261  /* New control flow will be stored in the control flow array of the Procedure Descriptor at a location
262  * in the range [baseLoc, baseLoc+nOfOutFlows-1]. We check that this range of locations
263  * is not already full (note that the checks performed when a node is added to the procedure
264  * ensure that the location [baseLoc+nOfOutFlows-1] is within the range of flow array..
265  */
266  if (prBase->flows[baseLoc + nOfOutFlows - 1].iGuard != -1) {
267  prDesc->errCode = prTooManyFlows;
268  return;
269  }
270 
271  /* Identify location where newly added control flow will be stored in the control flow array.
272  * Note that the nOfOutFlows is guaranteed to be greater than zero by the way it is
273  * initialized in the previous statements in this function. Hence, the loop will be
274  * taken at least once. */
275  for (i = 0; i < nOfOutFlows; i++) {
276  if (prBase->flows[baseLoc + i].iGuard == -1) {
277  loc = (FwPrCounterS1_t)(baseLoc + i);
278  break;
279  }
280  }
281  flow = &(prBase->flows[loc]);
282 
283  /* Assign control flow destination */
284  flow->dest = destId;
285 
286  /* add guard to control flow descriptor */
287  flow->iGuard = AddGuard(prDesc, cfGuard);
288 
289  return;
290 }
291 
292 /* ----------------------------------------------------------------------------------------------------------------- */
293 static FwPrCounterS1_t AddAction(FwPrDesc_t prDesc, FwPrAction_t action) {
294  FwPrCounterS1_t i;
295 
296  for (i = 0; i < prDesc->nOfActions; i++) {
297  if (prDesc->prActions[i] == NULL) {
298  break;
299  }
300  if (action == prDesc->prActions[i]) {
301  return i;
302  }
303  }
304 
305  if (i < prDesc->nOfActions) {
306  prDesc->prActions[i] = action;
307  return i;
308  }
309 
310  prDesc->errCode = prTooManyActions;
311  return 0;
312 }
313 
314 /* ----------------------------------------------------------------------------------------------------------------- */
315 static FwPrCounterS1_t AddGuard(FwPrDesc_t prDesc, FwPrGuard_t guard) {
316  FwPrCounterS1_t i;
317 
318  if (guard == NULL) {
319  return 0;
320  }
321 
322  for (i = 1; i < prDesc->nOfGuards; i++) {
323  if (prDesc->prGuards[i] == NULL) {
324  break;
325  }
326  if (guard == prDesc->prGuards[i]) {
327  return i;
328  }
329  }
330 
331  if (i < prDesc->nOfGuards) {
332  prDesc->prGuards[i] = guard;
333  return i;
334  }
335 
336  prDesc->errCode = prTooManyGuards;
337  return 0;
338 }
339 
340 /* ----------------------------------------------------------------------------------------------------------------- */
342 
343  FwPrCounterS1_t i, j;
344  PrBaseDesc_t* prBase = prDesc->prBase;
345  FwPrBool_t found;
346 
347  /* Check that no error occurred during the configuration process */
348  if (prDesc->errCode != prSuccess) {
349  return prConfigErr;
350  }
351 
352  /* Check that all action nodes have been defined */
353  for (i = 0; i < prBase->nOfANodes; i++) {
354  if (prBase->aNodes[i].iFlow == -1) {
355  return prNullActNode;
356  }
357  }
358 
359  /* Check that all decision nodes have been defined */
360  for (i = 0; i < prBase->nOfDNodes; i++) {
361  if (prBase->dNodes[i].outFlowIndex == -1) {
362  return prNullDecNode;
363  }
364  }
365 
366  /* Check that all control flows have been defined */
367  for (i = 0; i < prBase->nOfFlows; i++) {
368  if (prBase->flows[i].iGuard == -1) {
369  return prNullFlow;
370  }
371  }
372 
373  /* Check that all control flow destinations are legal action nodes or decision nodes */
374  for (i = 0; i < prBase->nOfFlows; i++) {
375  if (prBase->flows[i].dest > prBase->nOfANodes) {
376  return prIllegalADest;
377  }
378  if (prBase->flows[i].dest < -prBase->nOfDNodes) {
379  return prIllegalDDest;
380  }
381  }
382 
383  /* Check that all actions have been defined */
384  for (i = 0; i < prDesc->nOfActions; i++) {
385  if (prDesc->prActions[i] == NULL) {
386  return prTooFewActions;
387  }
388  }
389 
390  /* Check that all guards have been defined */
391  for (i = 0; i < prDesc->nOfGuards; i++) {
392  if (prDesc->prGuards[i] == NULL) {
393  return prTooFewGuards;
394  }
395  }
396 
397  /* Check that all action nodes are reachable */
398  for (i = 1; i <= prBase->nOfANodes; i++) {
399  found = 0;
400  for (j = 0; j < prBase->nOfFlows; j++) {
401  if (prBase->flows[j].dest == i) {
402  found = 1;
403  break;
404  }
405  }
406  if (found == 0) {
407  return prUnreachableANode;
408  }
409  }
410 
411  /* Check that all decision nodes are reachable */
412  for (i = 1; i <= prBase->nOfDNodes; i++) {
413  found = 0;
414  for (j = 0; j < prBase->nOfFlows; j++) {
415  if (prBase->flows[j].dest == -i) {
416  found = 1;
417  break;
418  }
419  }
420  if (found == 0) {
421  return prUnreachableDNode;
422  }
423  }
424 
425  return prSuccess;
426 }
427 
428 /* ----------------------------------------------------------------------------------------------------------------- */
429 void FwPrOverrideAction(FwPrDesc_t prDesc, FwPrAction_t oldAction, FwPrAction_t newAction) {
430  FwPrCounterS1_t i;
431 
432  if (prDesc->flowCnt != 0) {
433  prDesc->errCode = prNotDerivedPr;
434  return;
435  }
436 
437  for (i = 0; i < prDesc->nOfActions; i++) {
438  if (prDesc->prActions[i] == oldAction) {
439  prDesc->prActions[i] = newAction;
440  return;
441  }
442  }
443 
444  prDesc->errCode = prUndefAction;
445 }
446 
447 /* ----------------------------------------------------------------------------------------------------------------- */
448 void FwPrOverrideGuard(FwPrDesc_t prDesc, FwPrGuard_t oldGuard, FwPrGuard_t newGuard) {
449  FwPrCounterS1_t i;
450 
451  if (prDesc->flowCnt != 0) {
452  prDesc->errCode = prNotDerivedPr;
453  return;
454  }
455 
456  for (i = 1; i < prDesc->nOfGuards; i++) {
457  if (prDesc->prGuards[i] == oldGuard) {
458  prDesc->prGuards[i] = newGuard;
459  return;
460  }
461  }
462 
463  prDesc->errCode = prUndefGuard;
464 }
Structure representing a decision node in a procedure.
Definition: FwPrPrivate.h:121
The number of actions added to the procedure is smaller than the number of actions declared when the ...
Structure representing an action node in a procedure.
Definition: FwPrPrivate.h:98
FwPrCounterS1_t nOfGuards
the number of guards in the procedure
Definition: FwPrPrivate.h:264
An action node is added to a procedure with an illegal (out-of-range) identifier. ...
The number of guards added to the procedure is smaller than the number of guards declared when the pr...
A decision node is added to a procedure with an illegal (out-of-range) identifier.
Declaration of the configuration interface for a FW Procedure.
The overridden guard in a derived procedure does not exist.
The number of guards added to the procedure exceeds the number of guards declared when the procedure ...
The overridden action in a derived procedure does not exist.
void FwPrOverrideGuard(FwPrDesc_t prDesc, FwPrGuard_t oldGuard, FwPrGuard_t newGuard)
Override a guard in a derived procedure.
Definition: FwPrConfig.c:448
FwPrCounterS1_t iAction
index of the action attached to the node
Definition: FwPrPrivate.h:102
An action node is defined with a null action.
Structure representing the base descriptor of a procedure.
Definition: FwPrPrivate.h:186
void * prData
the pointer to the data manipulated by the procedure actions and guards
Definition: FwPrPrivate.h:276
void FwPrAddFlowIniToDec(FwPrDesc_t prDesc, FwPrCounterS1_t destId, FwPrGuard_t cfGuard)
Create a control flow from the initial node to a decision node and add it to a procedure.
Definition: FwPrConfig.c:180
FwPrCounterS1_t nOfActions
the number of actions in the procedure
Definition: FwPrPrivate.h:262
A configuration error has been detected during the procedure configuration process.
An action node is added twice to the same procedure.
void FwPrAddFlowActToDec(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, FwPrCounterS1_t destId, FwPrGuard_t cfGuard)
Create a control flow from an action node to a decision node and add it to a procedure.
Definition: FwPrConfig.c:190
FwPrCounterS1_t nOfANodes
the number of action nodes in the procedure
Definition: FwPrPrivate.h:194
A choice pseudo-state is added to a procedure with less than 2 out-going control flows.
FwPrCounterS1_t dest
the index of the destination of the control flow
Definition: FwPrPrivate.h:154
PrFlow_t * flows
array holding the control flows in the procedure
Definition: FwPrPrivate.h:192
FwPrCounterS1_t nOfFlows
the number of control flows in the procedure (excluding control flow from initial node) ...
Definition: FwPrPrivate.h:198
PrBaseDesc_t * prBase
pointer to the base descriptor
Definition: FwPrPrivate.h:256
The procedure has an action node which is not a destination of any control flow.
A control flow is added to a procedure with an illegal (out-of-range) decision node destination...
PrANode_t * aNodes
array holding the action nodes in the procedure
Definition: FwPrPrivate.h:188
An action state in a procedure.
Definition: FwPrPrivate.h:57
void FwPrAddFlowDecToFin(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, FwPrGuard_t cfGuard)
Create a control flow from a decision node to the final node and add it to a procedure.
Definition: FwPrConfig.c:210
A node is added to a procedure which has more out-going transitions than fit into the control flow ar...
FwPrCounterS1_t flowCnt
the counter for the number of control flows added to the procedure
Definition: FwPrPrivate.h:266
int FwPrBool_t
Type used for booleans (0 is "false" and 1 is "true").
Definition: FwPrConstants.h:48
void FwPrOverrideAction(FwPrDesc_t prDesc, FwPrAction_t oldAction, FwPrAction_t newAction)
Override an action in a derived procedure.
Definition: FwPrConfig.c:429
PrDNode_t * dNodes
array holding the decision nodes in the procedure
Definition: FwPrPrivate.h:190
FwPrCounterS1_t iGuard
the index of the guard associated to the control flow
Definition: FwPrPrivate.h:156
A control flow is added to a SM with a source which has an illegal value.
There is an undefined control flow in a procedure.
void FwPrAddFlowActToFin(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, FwPrGuard_t cfGuard)
Create a control flow from an action node to the final node and add it to a procedure.
Definition: FwPrConfig.c:205
The procedure has a decision node which is not a destination of any control flow. ...
void FwPrAddFlowActToAct(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, FwPrCounterS1_t destId, FwPrGuard_t cfGuard)
Create a control flow from an action node to another action node and add it to a procedure.
Definition: FwPrConfig.c:185
A decision node in a procedure.
Definition: FwPrPrivate.h:61
void(* FwPrAction_t)(FwPrDesc_t)
Type for a pointer to a procedure action.
Definition: FwPrConstants.h:45
There is an undefined decision node in a procedure.
void * FwPrGetData(FwPrDesc_t prDesc)
Get the pointer to the procedure data in the procedure descriptor.
Definition: FwPrConfig.c:87
void FwPrSetData(FwPrDesc_t prDesc, void *prData)
Set the pointer to the procedure data in the procedure descriptor.
Definition: FwPrConfig.c:82
Structure representing a control flow.
Definition: FwPrPrivate.h:152
FwPrErrCode_t errCode
either &#39;success&#39; or the code of the last error encountered by the procedure
Definition: FwPrPrivate.h:270
The number of actions added to the procedure exceeds the number of actions declared when the procedur...
FwPrErrCode_t
Error codes and function return codes for the procedure functions.
Definition: FwPrConstants.h:81
void FwPrAddFlowDecToDec(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, FwPrCounterS1_t destId, FwPrGuard_t cfGuard)
Create a control flow from a decision node to another decision node and add it to a procedure...
Definition: FwPrConfig.c:200
FwPrCounterS1_t outFlowIndex
index of first out-going control flow in control flow array
Definition: FwPrPrivate.h:123
The procedure where an action or a guard is overridden or a procedure is embedded is not a derived pr...
Return codes of a function which has completed execution without errors.
Definition: FwPrConstants.h:85
void FwPrAddDecisionNode(FwPrDesc_t prDesc, FwPrCounterS1_t nodeId, FwPrCounterS1_t nOfOutFlows)
Create a decision node with the given characteristics and add it to a procedure.
Definition: FwPrConfig.c:134
A control flow is added to a procedure with a source (either a state or a source choice pseudo-state)...
signed char FwPrCounterS1_t
Type used for signed counters with a "short" range.
Definition: FwPrConstants.h:78
Structure representing a procedure descriptor.
Definition: FwPrPrivate.h:254
FwPrCounterS1_t nOfOutTrans
number of outgoing control flows from the decision node
Definition: FwPrPrivate.h:125
FwPrAction_t * prActions
the procedure actions
Definition: FwPrPrivate.h:258
A control flow from a certain source is added to a procedure but there isn&#39;t space for it in the cont...
A decision node is added twice to the same procedure.
Either the initial or the final node.
Definition: FwPrPrivate.h:65
There is an undefined action node in a procedure.
void FwPrAddFlowIniToAct(FwPrDesc_t prDesc, FwPrCounterS1_t destId, FwPrGuard_t cfGuard)
Create a control flow from the initial node to an action node and add it to a procedure.
Definition: FwPrConfig.c:175
Declaration of the internal data structures of the FW Procedure Module.
void FwPrAddActionNode(FwPrDesc_t prDesc, FwPrCounterS1_t nodeId, FwPrAction_t action)
Create an action node with the given characteristics and add it to a procedure.
Definition: FwPrConfig.c:92
FwPrErrCode_t FwPrCheck(FwPrDesc_t prDesc)
Check the correctness and completeness of the configuration of a procedure descriptor.
Definition: FwPrConfig.c:341
FwPrCounterS1_t iFlow
index of out-going control flows
Definition: FwPrPrivate.h:100
NodeType_t
Enumerated type for the type of a node in a procedure.
Definition: FwPrPrivate.h:53
FwPrGuard_t * prGuards
the control flow guards in the procedure
Definition: FwPrPrivate.h:260
A control flow is added to a procedure with an illegal (out-of-range) action node destination...
FwPrCounterS1_t nOfDNodes
the number of decision nodes in the procedure
Definition: FwPrPrivate.h:196
void FwPrAddFlowDecToAct(FwPrDesc_t prDesc, FwPrCounterS1_t srcId, FwPrCounterS1_t destId, FwPrGuard_t cfGuard)
Create a control flow from a decision node to an action node and add it to a procedure.
Definition: FwPrConfig.c:195
FwPrBool_t(* FwPrGuard_t)(FwPrDesc_t)
Type for a pointer to a procedure guard.
Definition: FwPrConstants.h:63
P&P Software GmbH, Copyright 2011, All Rights Reserved