CORDET Framework - C2 Implementation
CrFwInManager.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include configuration files */
21 #include "CrFwInManagerUserPar.h"
22 #include "CrFwCmpData.h"
23 /* Include framework files */
24 #include "CrFwInManager.h"
25 #include "CrFwConstants.h"
26 #include "CrFwRepErr.h"
27 #include "CrFwTime.h"
28 #include "BaseCmp/CrFwBaseCmp.h"
29 #include "BaseCmp/CrFwInitProc.h"
30 #include "BaseCmp/CrFwResetProc.h"
32 #include "Pckt/CrFwPckt.h"
33 #include "Pckt/CrFwPcktQueue.h"
36 #include "InCmd/CrFwInCmd.h"
38 /* Include FW Profile files */
39 #include "FwSmConstants.h"
40 #include "FwSmDCreate.h"
41 #include "FwSmConfig.h"
42 #include "FwSmCore.h"
43 #include "FwPrConstants.h"
44 #include "FwPrDCreate.h"
45 #include "FwPrConfig.h"
46 #include "FwPrCore.h"
47 
50 
53 
56 
59 
68 static void InManagerInitAction(FwPrDesc_t initPr);
69 
77 static void InManagerConfigAction(FwPrDesc_t initPr);
78 
84 static void InManagerShutdownAction(FwSmDesc_t smDesc);
85 
93 static void InManagerExecAction(FwPrDesc_t execPr);
94 
95 /*-----------------------------------------------------------------------------------------*/
97  FwPrDesc_t resetPr, execPr, initPr;
98 
99  if (i >= CR_FW_NOF_INMANAGER) {
101  return NULL;
102  }
103 
104  if (inManagerDesc[i] != NULL) {
105  return inManagerDesc[i]; /* The requested SM has already been created */
106  }
107 
108  /* Create the requested SM as an extension of the base component SM */
109  inManagerDesc[i] = FwSmCreateDer(CrFwBaseCmpMake());
110 
111  /* Create the Reset Procedure for the InManager Component */
112  resetPr = FwPrCreateDer(CrFwCmpGetResetProc());
113  FwPrOverrideAction(resetPr, &CrFwBaseCmpDefConfigAction, &InManagerConfigAction);
114 
115  /* Create the Initialization Procedure for the InManager Component */
116  initPr = FwPrCreateDer(CrFwCmpGetInitProc());
117  FwPrOverrideAction(initPr, &CrFwBaseCmpDefInitAction, &InManagerInitAction);
118 
119  /* Create the Execution Procedure for the InManager Component */
120  execPr = FwPrCreateDer(CrFwBaseCmpGetDummyExecProc());
121  FwPrOverrideAction(execPr, &CwFwBaseCmpDummyExecAction, &InManagerExecAction);
122 
123  /* Override the Shutdown Action for the InManager Component */
125 
126  /* Initialize the data for the requested SM */
127  inManagerData[i].outcome = 1;
128  inManagerData[i].initProc = initPr;
129  inManagerData[i].resetProc = resetPr;
130  inManagerData[i].execProc = execPr;
131  inManagerData[i].instanceId = i;
134 
135  /* Attach the data to the InLoader state machine and to its procedures. */
136  FwSmSetData(inManagerDesc[i], &inManagerData[i]);
137  FwPrSetData(inManagerData[i].initProc, &inManagerData[i]);
138  FwPrSetData(inManagerData[i].resetProc, &inManagerData[i]);
139  FwPrSetData(inManagerData[i].execProc, &inManagerData[i]);
140 
141  /* Start the InManager */
142  FwSmStart(inManagerDesc[i]);
143 
144  return inManagerDesc[i];
145 }
146 
147 /*-----------------------------------------------------------------------------------------*/
148 static void InManagerExecAction(FwPrDesc_t prDesc) {
149  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwPrGetData(prDesc);
150  CrFwInManagerData_t* inManagerCSData = (CrFwInManagerData_t*)inManagerDataLocal->cmpSpecificData;
151  CrFwInstanceId_t id = inManagerDataLocal->instanceId;
152  FwSmDesc_t inCmp;
153  CrFwCmpData_t* inCmpData;
154  CrFwCounterU2_t i;
155  CrFwInRegistryCmdRepState_t inCmpState;
156 
157  inManagerCSData->nextFreePcrlPos = 0;
158  for (i=0; i<inManagerPcrlSize[id]; i++) {
159  inCmp = inManagerCSData->pcrl[i];
160  if (inCmp != NULL) {
161  FwSmExecute(inCmp);
162  inCmpData = (CrFwCmpData_t*)FwSmGetData(inCmp);
163  if (inCmpData->typeId == CR_FW_INREPORT_TYPE) {
164  inCmpState = crInRegistryTerminated;
165  } else {
166  CrFwInCmdTerminate(inCmp);
167  if (CrFwInCmdIsInAborted(inCmp))
168  inCmpState = crInRegistryAborted;
169  else if (CrFwInCmdIsInTerminated(inCmp))
170  inCmpState = crInRegistryTerminated;
171  else
172  inCmpState = crInRegistryPending;
173  }
174  if (inCmpState != crInRegistryPending) {
175  CrFwInRegistryUpdateState(inCmp, inCmpState);
176  /* Remove inCmp from PCRL */
177  inManagerCSData->pcrl[i] = NULL;
178  inManagerCSData->nOfInCmpInPcrl--;
179  if (inCmpData->typeId == CR_FW_INREPORT_TYPE)
181  else
183  }
184  }
185  }
186 }
187 
188 /*-----------------------------------------------------------------------------------------*/
189 CrFwBool_t CrFwInManagerLoad(FwSmDesc_t smDesc, FwSmDesc_t inCmp) {
190  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
191  CrFwInManagerData_t* inManagerCSData = (CrFwInManagerData_t*)inManagerDataLocal->cmpSpecificData;
192  CrFwInstanceId_t id = inManagerDataLocal->instanceId;
193  CrFwCounterU2_t i, freePos, size;
194 
195  freePos = inManagerCSData->nextFreePcrlPos;
196  size = inManagerPcrlSize[id];
197 
198  /* Check if PCRL is already full */
199  if (inManagerCSData->nOfInCmpInPcrl == size) {
200  CrFwRepErr(crInManagerPcrlFull, inManagerDataLocal->typeId, inManagerDataLocal->instanceId);
201  return 0;
202  }
203 
204  /* Check if this is the first load request after the OutManager was reset or after it was executed.
205  * If this is the case, find the first free position in the PCRL.
206  * NB: Since the for-loop is only entered if the PCRL is not full, it will always terminate
207  * through the break. This means that, when measuring branch coverage, the fall-through case
208  * at the for-loop will never occur. */
209  if (freePos == 0)
210  for (i=0; i<size; i++)
211  if (inManagerCSData->pcrl[i] == NULL) {
212  freePos = i;
213  break;
214  }
215 
216  /* PCRL is not full --> load inCmp */
217  inManagerCSData->pcrl[freePos] = inCmp;
218  inManagerCSData->nOfInCmpInPcrl++;
219  inManagerCSData->nOfLoadedInCmp++;
220 
221  /* Start tracking inCmp */
223 
224  /* Identify next free position in PCRL */
225  for (i=freePos+1; i<size; i++)
226  if (inManagerCSData->pcrl[i] == NULL) {
227  inManagerCSData->nextFreePcrlPos = (CrFwCounterU1_t)i;
228  return 1; /* a free position has been found */
229  }
230 
231  return 1;
232 }
233 
234 /*-----------------------------------------------------------------------------------------*/
235 static void InManagerInitAction(FwPrDesc_t initPr) {
236  CrFwCounterU1_t i;
237  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwPrGetData(initPr);
238  CrFwInManagerData_t* inManagerCSData = (CrFwInManagerData_t*)inManagerDataLocal->cmpSpecificData;
239  CrFwInstanceId_t id = inManagerDataLocal->instanceId;
240  inManagerCSData->pcrl = malloc(sizeof(FwSmDesc_t)*inManagerPcrlSize[id]);
241  for (i=0; i<inManagerPcrlSize[id]; i++)
242  inManagerCSData->pcrl[i] = NULL;
243  inManagerCSData->nOfInCmpInPcrl = 0;
244  inManagerDataLocal->outcome = 1;
245 }
246 
247 /*-----------------------------------------------------------------------------------------*/
248 static void InManagerConfigAction(FwPrDesc_t initPr) {
249  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwPrGetData(initPr);
250  CrFwInManagerData_t* inManagerCSData = (CrFwInManagerData_t*)inManagerDataLocal->cmpSpecificData;
251  CrFwInstanceId_t id = inManagerDataLocal->instanceId;
252  CrFwCmpData_t* inCmpData;
253  CrFwCounterU1_t i;
254 
255  for (i=0; i<inManagerPcrlSize[id]; i++) {
256  if (inManagerCSData->pcrl[i] != NULL) {
257  inCmpData = (CrFwCmpData_t*)FwSmGetData(inManagerCSData->pcrl[i]);
258  if (inCmpData->typeId == CR_FW_INREPORT_TYPE) /* pending component is an InReport */
259  CrFwInFactoryReleaseInRep(inManagerCSData->pcrl[i]);
260  else
261  CrFwInFactoryReleaseInCmd(inManagerCSData->pcrl[i]);
262  inManagerCSData->pcrl[i] = NULL;
263  }
264  }
265  inManagerCSData->nOfInCmpInPcrl = 0;
266  inManagerCSData->nOfLoadedInCmp = 0;
267  inManagerCSData->nextFreePcrlPos = 0;
268  inManagerDataLocal->outcome = 1;
269 }
270 
271 /*-----------------------------------------------------------------------------------------*/
272 static void InManagerShutdownAction(FwSmDesc_t smDesc) {
273  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
274  CrFwInManagerData_t* inManagerCSData = (CrFwInManagerData_t*)inManagerDataLocal->cmpSpecificData;
275  CrFwInstanceId_t id = inManagerDataLocal->instanceId;
276  CrFwCmpData_t* inCmpData;
277  CrFwCounterU1_t i;
278 
279  for (i=0; i<inManagerPcrlSize[id]; i++) {
280  if (inManagerCSData->pcrl[i] != NULL) {
281  inCmpData = (CrFwCmpData_t*)FwSmGetData(inManagerCSData->pcrl[i]);
282  if (inCmpData->typeId == CR_FW_INREPORT_TYPE) /* pending component is an InReport */
283  CrFwInFactoryReleaseInRep(inManagerCSData->pcrl[i]);
284  else
285  CrFwInFactoryReleaseInCmd(inManagerCSData->pcrl[i]);
286  inManagerCSData->pcrl[i] = NULL;
287  }
288  }
289  free(inManagerCSData->pcrl);
290  inManagerCSData->nOfInCmpInPcrl = 0;
291 }
292 
293 /*-----------------------------------------------------------------------------------------*/
295  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
296  CrFwInManagerData_t* inManagerCSData = (CrFwInManagerData_t*)inManagerDataLocal->cmpSpecificData;
297  return inManagerCSData->nOfInCmpInPcrl;
298 }
299 
300 /*-----------------------------------------------------------------------------------------*/
302  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
303  CrFwInManagerData_t* inManagerCSData = (CrFwInManagerData_t*)inManagerDataLocal->cmpSpecificData;
304  return inManagerCSData->nOfLoadedInCmp;
305 }
306 
307 /*-----------------------------------------------------------------------------------------*/
309  CrFwCmpData_t* inManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
310  CrFwInstanceId_t id = inManagerDataLocal->instanceId;
312 }
313 
void CrFwBaseCmpDefShutdownAction(FwSmDesc_t smDesc)
Function which performs the Shutdown Action for the Base State Machine.
Definition: CrFwBaseCmp.c:217
FwSmDesc_t CrFwBaseCmpMake()
Retrieve the singleton instance of the Base State Machine.
Definition: CrFwBaseCmp.c:77
Definition of Base Component.
Definition of the Framework Component Data (FCD) Type.
Header file to define all invariant publicly available constants and types for the CORDET Framework.
#define CR_FW_INREPORT_TYPE
Type identifier for the InReport component.
#define CR_FW_INMANAGER_TYPE
Type identifier for the InManager component.
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
FwPrDesc_t CrFwBaseCmpGetDummyExecProc()
Retrieve the singleton instance of the Dummy CEP.
void CwFwBaseCmpDummyExecAction(FwPrDesc_t prDesc)
Dummy action executed in the single node of the Dummy Execution Procedure.
Dummy Component Execution Procedure (CEP) for the Base Component.
void CrFwInCmdTerminate(FwSmDesc_t smDesc)
Send command Terminate to the argument InCommand.
Definition: CrFwInCmd.c:150
CrFwBool_t CrFwInCmdIsInAborted(FwSmDesc_t smDesc)
Return true if the argument InCommand is in state ABORTED.
Definition: CrFwInCmd.c:170
CrFwBool_t CrFwInCmdIsInTerminated(FwSmDesc_t smDesc)
Return true if the argument InCommand is in state TERMINATED.
Definition: CrFwInCmd.c:165
Definition of the InCommand Component of the framework.
void CrFwInFactoryReleaseInCmd(FwSmDesc_t inCmdInstance)
Release function for an InCommand.
void CrFwInFactoryReleaseInRep(FwSmDesc_t inRepInstance)
Release function for an InReport.
Definition of the InFactory component.
static void InManagerInitAction(FwPrDesc_t initPr)
Initialization action for InManagers.
CrFwBool_t CrFwInManagerLoad(FwSmDesc_t smDesc, FwSmDesc_t inCmp)
Load a new InReport or InCommand into the InManager.
static void InManagerShutdownAction(FwSmDesc_t smDesc)
Shutdown action for InManager.
static FwSmDesc_t inManagerDesc[CR_FW_NOF_INMANAGER]
The descriptors of the InManager State Machines.
Definition: CrFwInManager.c:52
static void InManagerConfigAction(FwPrDesc_t initPr)
Configuration action for InManagers.
static CrFwCounterU2_t inManagerPcrlSize[CR_FW_NOF_INMANAGER]
The sizes of the PCRL in the InManager components.
Definition: CrFwInManager.c:49
static void InManagerExecAction(FwPrDesc_t execPr)
Implement the logic of the Execution Procedure (see figure below).
CrFwCounterU2_t CrFwInManagerGetNOfLoadedInCmp(FwSmDesc_t smDesc)
Return the number of InReport or InCommands successfully loaded since the InManager was last reset.
CrFwCounterU1_t CrFwInManagerGetNOfPendingInCmp(FwSmDesc_t smDesc)
Return the number of InReport or InCommands currently in the PCRL of an InManager.
static CrFwCmpData_t inManagerData[CR_FW_NOF_INMANAGER]
The data structures for the InManager State Machines and their Procedures.
Definition: CrFwInManager.c:55
FwSmDesc_t CrFwInManagerMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th InManager State Machine instance.
Definition: CrFwInManager.c:96
static CrFwInManagerData_t inManagerCmpSpecificData[CR_FW_NOF_INMANAGER]
The component-specific data for the InManager instances.
Definition: CrFwInManager.c:58
CrFwCounterU1_t CrFwInManagerGetPCRLSize(FwSmDesc_t smDesc)
Return the size of the PCRL of an InManager.
Definition of the InManager component.
User-modifiable parameters for the InManager components (see CrFwInManager.h).
#define CR_FW_NOF_INMANAGER
The number of InManager components in the application.
#define CR_FW_INMANAGER_PCRLSIZE
The sizes of the Pending Command/Report List (PCRL) of the InManager components.
void CrFwInRegistryUpdateState(FwSmDesc_t inCmp, CrFwInRegistryCmdRepState_t newState)
Ask the InRegistry to update the state of an incoming command or report.
void CrFwInRegistryStartTracking(FwSmDesc_t inCmp)
Ask the InRegistry to start tracking an incoming command or report.
Definition of the InRegistry Component.
CrFwInRegistryCmdRepState_t
Enumerated type for the state of a command or report tracked by the InRegistry.
@ crInRegistryAborted
Incoming command has been aborted.
@ crInRegistryTerminated
Incoming command or report has completed execution.
@ crInRegistryPending
Incoming command or report is pending (waiting to be sent)
FwPrDesc_t CrFwCmpGetInitProc()
Retrieve the singleton instance of the CIP.
Definition: CrFwInitProc.c:48
void CrFwBaseCmpDefInitAction(FwPrDesc_t prDesc)
Function which performs the default Initialization Action of the CIP.
Definition: CrFwInitProc.c:42
Component Initialization Procedure (CIP) for the Base Component.
Interface for creating and accessing a report or command packet.
Definition and management of packet queues.
Interface for reporting an error detected by a framework component.
void CrFwRepErr(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId)
Report an error which has no parameters attached to it.
Definition: CrFwRepErr.c:89
FwPrDesc_t CrFwCmpGetResetProc()
Retrieve the singleton instance of the CRP.
Definition: CrFwResetProc.c:45
void CrFwBaseCmpDefConfigAction(FwPrDesc_t prDesc)
Function which performs the default Configuration Action of the CRP.
Definition: CrFwResetProc.c:39
Component Reset Procedure (CRP) for the Base Component.
Interface through which framework components access the current time.
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
unsigned char CrFwCounterU1_t
Type used for unsigned integers with a "short" range.
@ crInManagerPcrlFull
The Pending Command/Report List (PCRL) of an InManager is full (see CrFwInManager....
@ crInManagerIllId
A framework function has been called with an illegal InManager identifier.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
void CrFwSetAppErrCode(CrFwAppErrCode_t errCode)
Set the value of the application error code (see CrFwGetAppErrCode).
Definition of the utility functions for the CORDET Framework.
Type for the Framework Component Data (FCD).
Definition: CrFwCmpData.h:79
FwPrDesc_t initProc
The Component Initialization Procedure (CIP) (see CrFwInitProc.h).
Definition: CrFwCmpData.h:95
CrFwInstanceId_t instanceId
The instance identifier of the framework component.
Definition: CrFwCmpData.h:81
CrFwOutcome_t outcome
The outcome of an action or check executed by a state machine or by one of its procedures.
Definition: CrFwCmpData.h:93
FwPrDesc_t resetProc
The Component Reset Procedure (CRP) (see CrFwResetProc.h).
Definition: CrFwCmpData.h:97
FwPrDesc_t execProc
The Component Execution Procedure (CEP) (see CrFwBaseCmp.h).
Definition: CrFwCmpData.h:99
void * cmpSpecificData
Derived data which are specific to each type of framework component.
Definition: CrFwCmpData.h:101
CrFwTypeId_t typeId
The type identifier of the framework component.
Definition: CrFwCmpData.h:83
Type for the data describing an InManager.
CrFwCounterU1_t nextFreePcrlPos
Next free position in the PCRL.
CrFwCounterU2_t nOfLoadedInCmp
Number of successfully loaded InReports and InCommands
CrFwCounterU1_t nOfInCmpInPcrl
Number of InReports and InCommands currently in PCRL.
FwSmDesc_t * pcrl
Pending Command/Report List (PCRL) for the InManager.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved