CORDET Framework - C2 Implementation
CrFwOutManager.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include configuration files */
21 #include "CrFwOutManagerUserPar.h"
22 #include "CrFwCmpData.h"
23 /* Include framework files */
24 #include "CrFwConstants.h"
25 #include "CrFwRepErr.h"
26 #include "CrFwTime.h"
27 #include "CrFwOutManager.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 "OutCmp/CrFwOutCmp.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 OutManagerInitAction(FwPrDesc_t initPr);
69 
76 static void OutManagerConfigAction(FwPrDesc_t initPr);
77 
83 static void OutManagerShutdownAction(FwSmDesc_t smDesc);
84 
92 static void OutManagerExecAction(FwPrDesc_t execPr);
93 
94 /*-----------------------------------------------------------------------------------------*/
96  FwPrDesc_t resetPr, execPr, initPr;
97 
98  if (i >= CR_FW_NOF_OUTMANAGER) {
100  return NULL;
101  }
102 
103  if (outManagerDesc[i] != NULL) {
104  return outManagerDesc[i]; /* The requested SM has already been created */
105  }
106 
107  /* Create the requested SM as an extension of the base component SM */
108  outManagerDesc[i] = FwSmCreateDer(CrFwBaseCmpMake());
109 
110  /* Create the Reset Procedure for the OutManager Component */
111  resetPr = FwPrCreateDer(CrFwCmpGetResetProc());
112  FwPrOverrideAction(resetPr, &CrFwBaseCmpDefConfigAction, &OutManagerConfigAction);
113 
114  /* Create the Initialization Procedure for the OutManager Component */
115  initPr = FwPrCreateDer(CrFwCmpGetInitProc());
116  FwPrOverrideAction(initPr, &CrFwBaseCmpDefInitAction, &OutManagerInitAction);
117 
118  /* Create the Execution Procedure for the OutManager Component */
119  execPr = FwPrCreateDer(CrFwBaseCmpGetDummyExecProc());
120  FwPrOverrideAction(execPr, &CwFwBaseCmpDummyExecAction, &OutManagerExecAction);
121 
122  /* Override the Shutdown Action for the OutManager Component */
124 
125  /* Initialize the data for the requested SM */
126  outManagerData[i].outcome = 1;
127  outManagerData[i].initProc = initPr;
128  outManagerData[i].resetProc = resetPr;
129  outManagerData[i].execProc = execPr;
130  outManagerData[i].instanceId = i;
131  outManagerData[i].typeId = CR_FW_OUTMANAGER_TYPE;
132  outManagerData[i].cmpSpecificData = &outManagerCmpSpecificData[i];
133 
134  /* Attach the data to the OutManager state machine and to its procedures. */
135  FwSmSetData(outManagerDesc[i], &outManagerData[i]);
136  FwPrSetData(outManagerData[i].initProc, &outManagerData[i]);
137  FwPrSetData(outManagerData[i].resetProc, &outManagerData[i]);
138  FwPrSetData(outManagerData[i].execProc, &outManagerData[i]);
139 
140  /* Start the OutManager */
141  FwSmStart(outManagerDesc[i]);
142 
143  return outManagerDesc[i];
144 }
145 
146 /*-----------------------------------------------------------------------------------------*/
147 static void OutManagerExecAction(FwPrDesc_t prDesc) {
148  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwPrGetData(prDesc);
149  CrFwOutManagerData_t* outManagerCSData = (CrFwOutManagerData_t*)outManagerDataLocal->cmpSpecificData;
150  CrFwInstanceId_t id = outManagerDataLocal->instanceId;
151  FwSmDesc_t outCmp;
152  CrFwCounterU2_t i;
153  CrFwOutRegistryCmdRepState_t outCmpState;
154 
155  outManagerCSData->nextFreePoclPos = 0;
156  for (i=0; i<outManagerPoclSize[id]; i++) {
157  outCmp = outManagerCSData->pocl[i];
158  if (outCmp != NULL) {
159  FwSmExecute(outCmp);
162  outCmpState = crOutRegistryAborted;
163  else if (CrFwOutCmpIsInPending(outCmp))
164  outCmpState = crOutRegistryPending;
165  else
166  outCmpState = crOutRegistryTerminated;
167 
168  if (outCmpState != crOutRegistryPending) {
169  CrFwOutRegistryUpdateState(outCmp,outCmpState);
171  outManagerCSData->pocl[i] = NULL;
172  outManagerCSData->nOfOutCmpInPocl--;
173  }
174  }
175  }
176 }
177 
178 /*-----------------------------------------------------------------------------------------*/
179 CrFwBool_t CrFwOutManagerLoad(FwSmDesc_t smDesc, FwSmDesc_t outCmp) {
180  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
181  CrFwOutManagerData_t* outManagerCSData = (CrFwOutManagerData_t*)outManagerDataLocal->cmpSpecificData;
182  CrFwInstanceId_t id = outManagerDataLocal->instanceId;
183  CrFwCounterU2_t i, freePos, size;
184 
185  freePos = outManagerCSData->nextFreePoclPos;
186  size = outManagerPoclSize[id];
187 
188  /* Check if POCL is already full */
189  if (outManagerCSData->nOfOutCmpInPocl == size) {
190  CrFwRepErr(crOutManagerPoclFull, outManagerDataLocal->typeId, outManagerDataLocal->instanceId);
192  return 0;
193  }
194 
195  /* Check if this is the first load request after the OutManager was reset or after it was executed.
196  * If this is the case, find the first free position in the POCL.
197  * NB: Since the for-loop is only entered if the POCL is not full, it will always terminate
198  * through the break. This means that, when measuring branch coverage, the fall-through case
199  * at the for-loop will never occur. */
200  if (freePos == 0)
201  for (i=0; i<size; i++)
202  if (outManagerCSData->pocl[i] == NULL) {
203  freePos = i;
204  break;
205  }
206 
207  /* POCL is not full --> load outCmp */
208  outManagerCSData->pocl[freePos] = outCmp;
209  outManagerCSData->nOfOutCmpInPocl++;
210  outManagerCSData->nOfLoadedOutCmp++;
211 
212  /* Start tracking OutComponent */
214 
215  /* Identify next free position in POCL */
216  for (i=freePos+1; i<size; i++)
217  if (outManagerCSData->pocl[i] == NULL) {
218  outManagerCSData->nextFreePoclPos = (CrFwCounterU1_t)i;
219  return 1; /* a free position has been found */
220  }
221 
222  outManagerCSData->nextFreePoclPos = (CrFwCounterU1_t)size; /* no free position was found */
223  return 1;
224 }
225 
226 /*-----------------------------------------------------------------------------------------*/
227 static void OutManagerInitAction(FwPrDesc_t initPr) {
228  CrFwCounterU1_t i;
229  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwPrGetData(initPr);
230  CrFwOutManagerData_t* outManagerCSData = (CrFwOutManagerData_t*)outManagerDataLocal->cmpSpecificData;
231  CrFwInstanceId_t id = outManagerDataLocal->instanceId;
232  outManagerCSData->pocl = malloc(sizeof(FwSmDesc_t)*outManagerPoclSize[id]);
233  for (i=0; i<outManagerPoclSize[id]; i++)
234  outManagerCSData->pocl[i] = NULL;
235  outManagerCSData->nOfOutCmpInPocl = 0;
236  outManagerDataLocal->outcome = 1;
237 }
238 
239 /*-----------------------------------------------------------------------------------------*/
240 static void OutManagerConfigAction(FwPrDesc_t initPr) {
241  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwPrGetData(initPr);
242  CrFwOutManagerData_t* outManagerCSData = (CrFwOutManagerData_t*)outManagerDataLocal->cmpSpecificData;
243  CrFwInstanceId_t id = outManagerDataLocal->instanceId;
244  CrFwCounterU1_t i;
245 
246  for (i=0; i<outManagerPoclSize[id]; i++) {
247  if (outManagerCSData->pocl[i] != NULL) {
248  CrFwOutFactoryReleaseOutCmp(outManagerCSData->pocl[i]);
249  outManagerCSData->pocl[i] = NULL;
250  }
251  }
252  outManagerCSData->nOfOutCmpInPocl = 0;
253  outManagerCSData->nOfLoadedOutCmp = 0;
254  outManagerCSData->nextFreePoclPos = 0;
255  outManagerDataLocal->outcome = 1;
256 }
257 
258 /*-----------------------------------------------------------------------------------------*/
259 static void OutManagerShutdownAction(FwSmDesc_t smDesc) {
260  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
261  CrFwOutManagerData_t* outManagerCSData = (CrFwOutManagerData_t*)outManagerDataLocal->cmpSpecificData;
262  CrFwInstanceId_t id = outManagerDataLocal->instanceId;
263  CrFwCounterU1_t i;
264 
265  for (i=0; i<outManagerPoclSize[id]; i++) {
266  if (outManagerCSData->pocl[i] != NULL) {
267  CrFwOutFactoryReleaseOutCmp(outManagerCSData->pocl[i]);
268  outManagerCSData->pocl[i] = NULL;
269  }
270  }
271  free(outManagerCSData->pocl);
272  outManagerCSData->nOfOutCmpInPocl = 0;
273 }
274 
275 /*-----------------------------------------------------------------------------------------*/
277  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
278  CrFwOutManagerData_t* outManagerCSData = (CrFwOutManagerData_t*)outManagerDataLocal->cmpSpecificData;
279  return outManagerCSData->nOfOutCmpInPocl;
280 }
281 
282 /*-----------------------------------------------------------------------------------------*/
284  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
285  CrFwOutManagerData_t* outManagerCSData = (CrFwOutManagerData_t*)outManagerDataLocal->cmpSpecificData;
286  return outManagerCSData->nOfLoadedOutCmp;
287 }
288 
289 /*-----------------------------------------------------------------------------------------*/
291  CrFwCmpData_t* outManagerDataLocal = (CrFwCmpData_t*)FwSmGetData(smDesc);
292  CrFwInstanceId_t id = outManagerDataLocal->instanceId;
294 }
295 
unsigned char CrFwCounterU1_t
Type used for unsigned integers with a "short" range.
Type for the Framework Component Data (FCD).
Definition: CrFwCmpData.h:79
Interface through which framework components access the current time.
static void OutManagerExecAction(FwPrDesc_t execPr)
Implement the logic of the Execution Procedure (see figure below).
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
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
CrFwCounterU2_t nOfLoadedOutCmp
Number of successfully loaded OutComponents.
FwPrDesc_t CrFwCmpGetResetProc()
Retrieve the singleton instance of the CRP.
Definition: CrFwResetProc.c:45
Definition of the Framework Component Data (FCD) Type.
static FwSmDesc_t outCmp[CR_FW_OUTFACTORY_MAX_NOF_OUTCMP]
The pre-allocated OutComponent instances.
void CrFwOutCmpTerminate(FwSmDesc_t smDesc)
Send command Terminate to the argument OutComponent.
Definition: CrFwOutCmp.c:143
void CrFwSetAppErrCode(CrFwAppErrCode_t errCode)
Set the value of the application error code (see CrFwGetAppErrCode).
Definition of the OutFactory component.
static CrFwCmpData_t outManagerData[CR_FW_NOF_OUTMANAGER]
The data structures for the OutManager State Machines and their Procedures.
FwSmDesc_t CrFwOutManagerMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th OutManager State Machine instance.
Interface for creating and accessing a report or command packet.
void CrFwBaseCmpDefShutdownAction(FwSmDesc_t smDesc)
Function which performs the Shutdown Action for the Base State Machine.
Definition: CrFwBaseCmp.c:217
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
FwPrDesc_t resetProc
The Component Reset Procedure (CRP) (see CrFwResetProc.h).
Definition: CrFwCmpData.h:97
Dummy Component Execution Procedure (CEP) for the Base Component.
Definition of the OutRegistry Component.
void CrFwOutRegistryStartTracking(FwSmDesc_t outCmp)
Ask the OutRegistry to start tracking an out-going command or report.
Header file to define all invariant publicly available constants and types for the CORDET Framework...
CrFwCounterU1_t nOfOutCmpInPocl
Number of OutComponents currently in POCL.
The Pending OutComponent List (POCL) of an OutManager is full (see CrFwOutManager.h)
Out-going command or report is pending (waiting to be sent)
CrFwInstanceId_t instanceId
The instance identifier of the framework component.
Definition: CrFwCmpData.h:81
void CrFwBaseCmpDefInitAction(FwPrDesc_t prDesc)
Function which performs the default Initialization Action of the CIP.
Definition: CrFwInitProc.c:42
#define CR_FW_NOF_OUTMANAGER
The number of OutManager components in the application.
CrFwCounterU2_t CrFwOutManagerGetNOfLoadedOutCmp(FwSmDesc_t smDesc)
Return the number of OutComponents successfully loaded in the POCL of an OutManager since the OutMana...
CrFwBool_t CrFwOutCmpIsInAborted(FwSmDesc_t smDesc)
Return true if the argument OutComponent is in state ABORTED.
Definition: CrFwOutCmp.c:153
Interface for reporting an error detected by a framework component.
static void OutManagerConfigAction(FwPrDesc_t initPr)
Configuration action for OutManagers.
void CrFwOutRegistryUpdateState(FwSmDesc_t outCmp, CrFwOutRegistryCmdRepState_t newState)
Ask the OutRegistry to update the state of an out-going command or report.
User-modifiable parameters for the OutManager components (see CrFwOutManager.h).
#define CR_FW_OUTMANAGER_TYPE
Type identifier for the OutManager component.
static CrFwCounterU2_t outManagerPoclSize[CR_FW_NOF_OUTMANAGER]
The sizes of the POCL in the OutManager components.
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
Definition and management of packet queues.
void * cmpSpecificData
Derived data which are specific to each type of framework component.
Definition: CrFwCmpData.h:101
void CrFwBaseCmpDefConfigAction(FwPrDesc_t prDesc)
Function which performs the default Configuration Action of the CRP.
Definition: CrFwResetProc.c:39
Definition of the utility functions for the CORDET Framework.
static CrFwOutManagerData_t outManagerCmpSpecificData[CR_FW_NOF_OUTMANAGER]
The component-specific data for the OutManager instances.
FwPrDesc_t execProc
The Component Execution Procedure (CEP) (see CrFwBaseCmp.h).
Definition: CrFwCmpData.h:99
FwSmDesc_t CrFwBaseCmpMake()
Retrieve the singleton instance of the Base State Machine.
Definition: CrFwBaseCmp.c:77
static void OutManagerShutdownAction(FwSmDesc_t smDesc)
Shutdown action for OutManager.
FwPrDesc_t CrFwBaseCmpGetDummyExecProc()
Retrieve the singleton instance of the Dummy CEP.
FwSmDesc_t * pocl
Pending OutComponent List (POCL) for the OutManager.
static void OutManagerInitAction(FwPrDesc_t initPr)
Initialization action for OutManagers.
Definition of Base Component.
void CrFwOutFactoryReleaseOutCmp(FwSmDesc_t outCmpInstance)
Release function for an OutComponent.
Out-going command or report has been aborted.
void CrFwRepErr(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId)
Report an error which has no parameters attached to it.
Definition: CrFwRepErr.c:81
Component Initialization Procedure (CIP) for the Base Component.
Out-going command or report has been passed to the OutStream.
Definition of the OutComponent Component of the framework.
Definition of the OutManager component.
CrFwOutRegistryCmdRepState_t
Enumerated type for the state of an out-going command or report tracked by the OutRegistry.
CrFwCounterU1_t nextFreePoclPos
Next free position in the POCL.
CrFwTypeId_t typeId
The type identifier of the framework component.
Definition: CrFwCmpData.h:83
CrFwCounterU1_t CrFwOutManagerGetPOCLSize(FwSmDesc_t smDesc)
Return the size of the POCL of an OutManager.
CrFwCounterU1_t CrFwOutManagerGetNOfPendingOutCmp(FwSmDesc_t smDesc)
Return the number of OutComponents currently in the POCL of an OutManager.
static FwSmDesc_t outManagerDesc[CR_FW_NOF_OUTMANAGER]
The descriptors of the OutManager State Machines.
#define CR_FW_OUTMANAGER_POCLSIZE
The sizes of the Pending OutComponent List (POCL) of the OutManager components.
FwPrDesc_t CrFwCmpGetInitProc()
Retrieve the singleton instance of the CIP.
Definition: CrFwInitProc.c:48
A framework function has been called with an illegal OutManager identifier.
CrFwBool_t CrFwOutManagerLoad(FwSmDesc_t smDesc, FwSmDesc_t outCmp)
Load a new OutComponent into the OutManager.
Component Reset Procedure (CRP) for the Base Component.
FwPrDesc_t initProc
The Component Initialization Procedure (CIP) (see CrFwInitProc.h).
Definition: CrFwCmpData.h:95
CrFwBool_t CrFwOutCmpIsInPending(FwSmDesc_t smDesc)
Return true if the argument OutComponent is in state PENDING.
Definition: CrFwOutCmp.c:158
void CwFwBaseCmpDummyExecAction(FwPrDesc_t prDesc)
Dummy action executed in the single node of the Dummy Execution Procedure.
Type for the data describing an OutManager.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved