FW Profile - C1 Implementation
FwPrCore.c
Go to the documentation of this file.
1 
18 #include "FwPrCore.h"
19 #include "FwPrPrivate.h"
20 #include <stdlib.h>
21 
22 /* ----------------------------------------------------------------------------------------------------------------- */
24  (void)(prDesc);
25  return 1;
26 }
27 
28 /* ----------------------------------------------------------------------------------------------------------------- */
29 void FwPrStart(FwPrDesc_t prDesc) {
30  if (prDesc->curNode == 0) {
31  prDesc->curNode = -1;
32  prDesc->prExecCnt = 0;
33  prDesc->nodeExecCnt = 0;
34  }
35 }
36 
37 /* ----------------------------------------------------------------------------------------------------------------- */
38 void FwPrStop(FwPrDesc_t prDesc) {
39  prDesc->curNode = 0;
40 }
41 
42 /* ----------------------------------------------------------------------------------------------------------------- */
43 void FwPrExecute(FwPrDesc_t prDesc) {
45  PrDNode_t* decNode;
46  PrFlow_t* flow;
48  PrBaseDesc_t* prBase = prDesc->prBase;
49  FwPrCounterS1_t trueGuardFound;
50 
51  /* check if procedure is started */
52  if (prDesc->curNode == 0) { /* procedure is stopped */
53  return;
54  }
55 
56  prDesc->prExecCnt++; /* Increment procedure execution counter */
57  prDesc->nodeExecCnt++; /* Increment node execution counter */
58 
59  /* Get the Control Flow issuing from the current node */
60  if (prDesc->curNode == -1) { /* procedure is at initial node */
61  flow = &(prBase->flows[0]);
62  }
63  else {
64  curNode = &(prBase->aNodes[prDesc->curNode - 1]); /* procedure is at an action node */
65  flow = &(prBase->flows[curNode->iFlow]);
66  }
67 
68  /* Evaluate guard of control flow issuing from current node */
69  trueGuardFound = (FwPrCounterS1_t)prDesc->prGuards[flow->iGuard](prDesc);
70 
71  /* Execute loop as long as guard of control flow issuing from current node is true */
72  while (trueGuardFound) {
73  /* Target of flow is a final node */
74  if (flow->dest == 0) {
75  prDesc->curNode = 0; /* Stop procedure */
76  return;
77  }
78 
79  if (flow->dest > 0) { /* Target of control flow is an action node */
80  prDesc->curNode = flow->dest;
81  prDesc->nodeExecCnt = 0;
82  curNode = &(prBase->aNodes[(prDesc->curNode) - 1]);
83  prDesc->prActions[curNode->iAction](prDesc);
84  flow = &(prBase->flows[curNode->iFlow]);
85  trueGuardFound = (FwPrCounterS1_t)prDesc->prGuards[flow->iGuard](prDesc);
86  }
87  else { /* Target of flow is a decision node */
88  trueGuardFound = 0;
89  decNode = &(prBase->dNodes[(-flow->dest) - 1]);
90  /* Evaluate guards of control flows issuing from decision node */
91  for (i = 0; i < decNode->nOfOutTrans; i++) {
92  flow = &(prBase->flows[decNode->outFlowIndex + i]);
93  if (prDesc->prGuards[flow->iGuard](prDesc) != 0) {
94  trueGuardFound = 1;
95  break; /* First control flow out of dec. node with true guard */
96  }
97  }
98  /* All control flows out of decision node have false guards */
99  if (trueGuardFound == 0) {
100  prDesc->errCode = prFlowErr;
101  return;
102  }
103  }
104  }
105  return;
106 }
107 
108 /* ----------------------------------------------------------------------------------------------------------------- */
109 void FwPrRun(FwPrDesc_t prDesc) {
110  FwPrStart(prDesc);
111  FwPrExecute(prDesc);
112  FwPrStop(prDesc);
113  return;
114 }
115 
116 /* ----------------------------------------------------------------------------------------------------------------- */
118  return prDesc->curNode;
119 }
120 
121 /* ----------------------------------------------------------------------------------------------------------------- */
123  if (prDesc->curNode == 0) {
124  return 0;
125  }
126 
127  return 1;
128 }
129 
130 /* ----------------------------------------------------------------------------------------------------------------- */
132  return prDesc->errCode;
133 }
134 
135 /* ----------------------------------------------------------------------------------------------------------------- */
137  return prDesc->prExecCnt;
138 }
139 
140 /* ----------------------------------------------------------------------------------------------------------------- */
142  return prDesc->nodeExecCnt;
143 }
Structure representing a decision node in a procedure.
Definition: FwPrPrivate.h:121
Structure representing an action node in a procedure.
Definition: FwPrPrivate.h:98
FwPrCounterU3_t FwPrGetNodeExecCnt(FwPrDesc_t prDesc)
Return the Node Execution Counter.
Definition: FwPrCore.c:141
FwPrCounterS1_t iAction
index of the action attached to the node
Definition: FwPrPrivate.h:102
Structure representing the base descriptor of a procedure.
Definition: FwPrPrivate.h:186
An error was encountered while executing a transition in a procedure (see FwPrExecute).
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
PrBaseDesc_t * prBase
pointer to the base descriptor
Definition: FwPrPrivate.h:256
PrANode_t * aNodes
array holding the action nodes in the procedure
Definition: FwPrPrivate.h:188
unsigned int FwPrCounterU3_t
Type used for unsigned counters with a "long" range.
Definition: FwPrConstants.h:72
void FwPrStop(FwPrDesc_t prDesc)
Stop a procedure.
Definition: FwPrCore.c:38
int FwPrBool_t
Type used for booleans (0 is "false" and 1 is "true").
Definition: FwPrConstants.h:48
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
FwPrBool_t PrDummyGuard(FwPrDesc_t prDesc)
Dummy guard which always returns true.
Definition: FwPrCore.c:23
FwPrCounterU3_t FwPrGetExecCnt(FwPrDesc_t prDesc)
Return the Procedure Execution Counter.
Definition: FwPrCore.c:136
Structure representing a control flow.
Definition: FwPrPrivate.h:152
FwPrCounterU3_t nodeExecCnt
the node execution counter
Definition: FwPrPrivate.h:274
FwPrErrCode_t errCode
either &#39;success&#39; or the code of the last error encountered by the procedure
Definition: FwPrPrivate.h:270
FwPrErrCode_t
Error codes and function return codes for the procedure functions.
Definition: FwPrConstants.h:81
FwPrCounterS1_t outFlowIndex
index of first out-going control flow in control flow array
Definition: FwPrPrivate.h:123
void FwPrExecute(FwPrDesc_t prDesc)
Execute a procedure.
Definition: FwPrCore.c:43
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
FwPrBool_t FwPrIsStarted(FwPrDesc_t prDesc)
Check whether the procedure is started.
Definition: FwPrCore.c:122
FwPrCounterS1_t FwPrGetCurNode(FwPrDesc_t prDesc)
Return the identifier of the current action node in a procedure.
Definition: FwPrCore.c:117
Declaration of the internal data structures of the FW Procedure Module.
FwPrCounterS1_t iFlow
index of out-going control flows
Definition: FwPrPrivate.h:100
FwPrCounterU3_t prExecCnt
the procedure execution counter
Definition: FwPrPrivate.h:272
FwPrGuard_t * prGuards
the control flow guards in the procedure
Definition: FwPrPrivate.h:260
Declaration of the execution interface for a FW Procedure.
FwPrCounterS1_t curNode
the current node of the procedure
Definition: FwPrPrivate.h:268
void FwPrStart(FwPrDesc_t prDesc)
Start a procedure.
Definition: FwPrCore.c:29
FwPrErrCode_t FwPrGetErrCode(FwPrDesc_t prDesc)
Return the error code of the argument procedure.
Definition: FwPrCore.c:131
void FwPrRun(FwPrDesc_t prDesc)
Run a procedure.
Definition: FwPrCore.c:109
P&P Software GmbH, Copyright 2011, All Rights Reserved