CORDET Framework - C2 Implementation
CrFwOutRegistry.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include configuration files */
21 #include "CrFwOutRegistryUserPar.h"
22 #include "CrFwCmpData.h"
23 /* Include framework files */
24 #include "CrFwConstants.h"
26 #include "OutCmp/CrFwOutCmp.h"
27 #include "BaseCmp/CrFwBaseCmp.h"
28 #include "BaseCmp/CrFwInitProc.h"
29 #include "BaseCmp/CrFwResetProc.h"
31 #include "CrFwOutRegistry.h"
32 /* Include FW Profile files */
33 #include "FwPrConfig.h"
34 #include "FwPrDCreate.h"
35 #include "FwSmConfig.h"
36 #include "FwSmDCreate.h"
37 #include "FwPrCore.h"
38 
41 
46 typedef struct {
48  CrFwInstanceId_t instanceId;
52 
55 
58 
60 static FwSmDesc_t outRegistry = NULL;
61 
64 
76 static void OutRegistryInitAction(FwPrDesc_t initPr);
77 
85 static void OutRegistryConfigAction(FwPrDesc_t resetPr);
86 
94 static void OutRegistryShutdownAction(FwSmDesc_t smDesc);
95 
96 /*------------------------------------------------------------------------------------*/
97 FwSmDesc_t CrFwOutRegistryMake() {
98  FwPrDesc_t resetPr, execPr, initPr;
99 
100  if (outRegistry != NULL) {
101  return outRegistry;
102  }
103 
104  /* Extend the Base Component */
105  outRegistry = FwSmCreateDer(CrFwBaseCmpMake());
106 
107  /* Create the Reset Procedure for the OuRegistry Component */
108  resetPr = FwPrCreateDer(CrFwCmpGetResetProc());
109  FwPrOverrideAction(resetPr, &CrFwBaseCmpDefConfigAction, &OutRegistryConfigAction);
110 
111  /* Create the Initialization Procedure for the OuRegistry Component */
112  initPr = FwPrCreateDer(CrFwCmpGetInitProc());
113  FwPrOverrideAction(initPr, &CrFwBaseCmpDefInitAction, &OutRegistryInitAction);
114 
115  /* Override the Shutdown Action for the InStream Component */
117 
118  /* Get the Dummy Execution Procedure for the OutRegistry Component */
119  execPr = CrFwBaseCmpGetDummyExecProc();
120 
121  /* Initialize the data for the requested SM */
123  outRegistryData.initProc = initPr;
124  outRegistryData.resetProc = resetPr;
125  outRegistryData.execProc = execPr;
128 
129  /* Attach the data to the OutRegistry state machine and to its procedures. */
130  FwSmSetData(outRegistry, &outRegistryData);
133 
134  /* Start the OutRegistry */
135  FwSmStart(outRegistry);
136 
137  return outRegistry;
138 }
139 
140 /*------------------------------------------------------------------------------------*/
142  return servDesc[cmdRepIndex].servType;
143 }
144 
145 /*------------------------------------------------------------------------------------*/
147  return servDesc[cmdRepIndex].servSubType;
148 }
149 
150 /*------------------------------------------------------------------------------------*/
152  return servDesc[cmdRepIndex].upperBoundDisc;
153 }
154 
155 /*------------------------------------------------------------------------------------*/
157  return servDesc[cmdRepIndex].lowerBoundDisc;
158 }
159 
160 /*------------------------------------------------------------------------------------*/
162  CrFwDiscriminant_t lowerBound = servDesc[cmdRepIndex].lowerBoundDisc;
163  return servDesc[cmdRepIndex].isDiscriminantEnabled[disc - lowerBound];
164 }
165 
166 /*------------------------------------------------------------------------------------*/
168  CrFwCmdRepIndex_t i = 0;
169 
170  while (servDesc[i].nextServType != 0)
171  if (servDesc[i].servType < servType)
172  i = servDesc[i].nextServType;
173  else if (servDesc[i].servType > servType)
174  return CR_FW_OUTREGISTRY_NSERV; /* The specified type does not exist */
175  else
176  break;
177 
178  if (servDesc[i].servType != servType)
179  return CR_FW_OUTREGISTRY_NSERV; /* The specified type does not exist */
180 
181  while (servDesc[i].servSubType <= servSubType) {
182  if (servDesc[i].servSubType == servSubType)
183  return i; /* Cmd-Rep index found! */
184  i++;
185  if (servDesc[i].servType != servType)
186  return CR_FW_OUTREGISTRY_NSERV; /* The specified sub-type does not exist in the specified type */
187  }
188 
189  return CR_FW_OUTREGISTRY_NSERV; /* The specified sub-type does not exist in the specified type */
190 }
191 
192 /*------------------------------------------------------------------------------------*/
194  CrFwDiscriminant_t discriminant, CrFwBool_t isEnabled) {
195  CrFwCmdRepIndex_t i = 0;
196  CrFwDiscriminant_t discOffset;
197 
198  while (servDesc[i].nextServType != 0)
199  if (servDesc[i].servType < servType)
200  i = servDesc[i].nextServType;
201  else if (servDesc[i].servType > servType) {
203  return;
204  } else
205  break;
206 
207  if (servDesc[i].servType != servType) {
209  return;
210  }
211 
212  if (servSubType == 0) {
213  while (servDesc[i].servType == servType) {
214  servDesc[i].isServTypeEnabled = isEnabled;
215  i++;
216  if (i == CR_FW_OUTREGISTRY_NSERV)
217  return;
218  }
219  return;
220  }
221 
222  while (servDesc[i].servType == servType) {
224  i++;
225  else if (servDesc[i].servSubType > servSubType) {
227  return;
228  } else
229  break;
230  }
231 
232  if (servDesc[i].servSubType < servSubType) {
234  return;
235  }
236 
237  if (discriminant == 0) {
238  servDesc[i].isServSubTypeEnabled = isEnabled;
239  return;
240  }
241 
242  if (discriminant > servDesc[i].upperBoundDisc) {
244  return;
245  }
246 
247  if (discriminant < servDesc[i].lowerBoundDisc) {
249  return;
250  }
251 
252  discOffset = discriminant - servDesc[i].lowerBoundDisc;
253  servDesc[i].isDiscriminantEnabled[discOffset] = isEnabled;
254 }
255 
256 /*------------------------------------------------------------------------------------*/
258  CrFwCmpData_t* cmpData = (CrFwCmpData_t*)FwSmGetData(outCmp);
259  CrFwOutCmpData_t* cmpSpecificData = (CrFwOutCmpData_t*)cmpData->cmpSpecificData;
260  CrFwCmdRepIndex_t cmdRepIndex;
261  CrFwDiscriminant_t discriminant, discOffset;
262 
263  cmdRepIndex = cmpSpecificData->index;
264  if (servDesc[cmdRepIndex].isServTypeEnabled == 0)
265  return 0;
266 
267  if (servDesc[cmdRepIndex].isServSubTypeEnabled == 0)
268  return 0;
269 
270  discriminant = CrFwOutCmpGetDiscriminant(outCmp);
271  if (discriminant == 0)
272  return 1;
273  discOffset = (discriminant - servDesc[cmdRepIndex].lowerBoundDisc);
274  return servDesc[cmdRepIndex].isDiscriminantEnabled[discOffset];
275 }
276 
277 /*------------------------------------------------------------------------------------*/
279  CrFwCmpData_t* outCmpData = (CrFwCmpData_t*)FwSmGetData(outCmp);
281 
285  /*outCmpData->cmpSpecificData.outCmpData.trackingIndex = cmdRepStateIndex;*/
286 
288  cmdRepStateIndex = 0;
289  else
291 }
292 
293 /*------------------------------------------------------------------------------------*/
295  CrFwCmpData_t* outCmpData = (CrFwCmpData_t*)FwSmGetData(outCmp);
298 
300  /*i = outCmpData->cmpSpecificData.outCmpData.trackingIndex;*/
301  if (cmdRepState[i].instanceId == outCmpData->instanceId) {
302  cmdRepState[i].state = newState;
303  }
304 }
305 
306 /*------------------------------------------------------------------------------------*/
310 
311  if (cmdRepStateIndex > 0)
313  else
314  i = (CR_FW_OUTREGISTRY_N-1);
315 
316  for (j=0; j<CR_FW_OUTREGISTRY_N; j++) {
317  if (cmdRepState[i].state == crOutRegistryNoEntry)
318  break;
319  if (cmdRepState[i].instanceId == cmdRepId) {
320  return cmdRepState[i].state;
321  } else if (i == 0)
322  i = (CR_FW_OUTREGISTRY_N-1);
323  else
324  i--;
325  }
326 
328 }
329 
330 /*------------------------------------------------------------------------------------*/
331 static void OutRegistryInitAction(FwPrDesc_t initPr) {
332  CrFwCmdRepIndex_t i, nextServType;
333  CrFwCmpData_t* cmpData = (CrFwCmpData_t*)FwPrGetData(initPr);
334  CrFwDiscriminant_t nOfDiscValues;
335 
336  for (i=0; i<CR_FW_OUTREGISTRY_NSERV; i++) {
337  if (servDesc[i].upperBoundDisc == 0)
338  servDesc[i].isDiscriminantEnabled = malloc(1); /* To avoid dangling pointers */
339  else {
340  nOfDiscValues = servDesc[i].upperBoundDisc - servDesc[i].lowerBoundDisc + 1;
341  servDesc[i].isDiscriminantEnabled = malloc(nOfDiscValues);
342  }
343  }
344 
345  nextServType = 0;
346  for (i=CR_FW_OUTREGISTRY_NSERV-1; i>0; i--) {
347  servDesc[i].nextServType = nextServType;
348  if (servDesc[i-1].servType != servDesc[i].servType)
349  nextServType = i;
350  }
351  servDesc[0].nextServType = nextServType;
352 
353  cmpData->outcome = 1;
354 }
355 
356 /*------------------------------------------------------------------------------------*/
357 static void OutRegistryConfigAction(FwPrDesc_t initPr) {
360  CrFwCmpData_t* cmpData = (CrFwCmpData_t*)FwPrGetData(initPr);
361  CrFwCounterU2_t k;
362  CrFwDiscriminant_t nOfDiscValues;
363 
364  for (i=0; i<CR_FW_OUTREGISTRY_NSERV; i++) {
367  nOfDiscValues = servDesc[i].upperBoundDisc - servDesc[i].lowerBoundDisc + 1;
368  if (servDesc[i].upperBoundDisc != 0)
369  for (j=0; j<nOfDiscValues; j++)
370  servDesc[i].isDiscriminantEnabled[j] = 1;
371  }
372 
373  for (k=0; k<CR_FW_OUTREGISTRY_N; k++)
375 
376  cmdRepStateIndex = 0;
377 
378  cmpData->outcome = 1;
379 }
380 
381 /*------------------------------------------------------------------------------------*/
382 static void OutRegistryShutdownAction(FwSmDesc_t smDesc) {
384  CrFwCounterU2_t k;
385  CRFW_UNUSED(smDesc);
386 
387  for (i=0; i<CR_FW_OUTREGISTRY_NSERV; i++) {
390  free(servDesc[i].isDiscriminantEnabled);
392  }
393 
394  for (k=0; k<CR_FW_OUTREGISTRY_N; k++)
396 
397  cmdRepStateIndex = 0;
398 }
399 
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 CRFW_UNUSED(x)
A macro that can be used to specify that a function parameter is not used.
Definition: CrFwConstants.h:29
unsigned short CrFwCmdRepIndex_t
Type for the index of a command or report in the InRegistry or OutRegistry.
Definition: CrFwConstants.h:35
#define CR_FW_OUTREGISTRY_TYPE
Type identifier for the OutRegistry 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.
Dummy Component Execution Procedure (CEP) for the Base Component.
static CrFwServType_t servType
The InCommand type as computed in the Validity Check.
static CrFwDiscriminant_t disc
Discriminant.
static CrFwInstanceId_t cmdRepId
Command or Report Identifier.
static CrFwServSubType_t servSubType
Service sub-type.
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.
CrFwDiscriminant_t CrFwOutCmpGetDiscriminant(FwSmDesc_t smDesc)
Return the discriminant of the OutComponent.
Definition: CrFwOutCmp.c:251
Definition of the OutComponent Component of the framework.
static CrFwCmpData_t outCmpData[CR_FW_OUTFACTORY_MAX_NOF_OUTCMP]
The data for the pre-allocated OutComponent instances.
static CrFwOutCmpData_t outCmpSpecificData[CR_FW_OUTFACTORY_MAX_NOF_OUTCMP]
The component-specific data for the pre-allocated OutReport instances.
static FwSmDesc_t outCmp[CR_FW_OUTFACTORY_MAX_NOF_OUTCMP]
The pre-allocated OutComponent instances.
CrFwCmdRepIndex_t CrFwOutRegistryGetCmdRepIndex(CrFwServType_t servType, CrFwServSubType_t servSubType)
Get the index corresponding to the argument [service type, service sub-type] of an out-going command ...
CrFwServType_t CrFwOutRegistryGetServType(CrFwCmdRepIndex_t cmdRepIndex)
Get the service type of the argument command or report index.
static CrFwServDesc_t servDesc[CR_FW_OUTREGISTRY_NSERV]
Array of service descriptors (see CrFwServDesc_t).
CrFwServSubType_t CrFwOutRegistryGetServSubType(CrFwCmdRepIndex_t cmdRepIndex)
Get the service sub-type of the argument command or report index.
CrFwBool_t CrFwOutRegistryIsEnabled(FwSmDesc_t outCmp)
Query the enable status of an out-going command or report.
static CrFwTrackedState_t cmdRepState[CR_FW_OUTREGISTRY_N]
Array to track the state of out-going commands or reports.
void CrFwOutRegistryStartTracking(FwSmDesc_t outCmp)
Ask the OutRegistry to start tracking an out-going command or report.
static void OutRegistryConfigAction(FwPrDesc_t resetPr)
Configuration action for OutRegistry.
FwSmDesc_t CrFwOutRegistryMake()
Factory function for the singleton instance of the OutRegistry.
void CrFwOutRegistryUpdateState(FwSmDesc_t outCmp, CrFwOutRegistryCmdRepState_t newState)
Ask the OutRegistry to update the state of an out-going command or report.
CrFwDiscriminant_t CrFwOutRegistryGetLowerDiscriminant(CrFwCmdRepIndex_t cmdRepIndex)
Get the lower bound of the argument command or report index.
static CrFwCmpData_t outRegistryData
The data for the OutRegistry singleton.
CrFwDiscriminant_t CrFwOutRegistryGetUpperDiscriminant(CrFwCmdRepIndex_t cmdRepIndex)
Get the upper bound of the argument command or report index.
void CrFwOutRegistrySetEnable(CrFwServType_t servType, CrFwServSubType_t servSubType, CrFwDiscriminant_t discriminant, CrFwBool_t isEnabled)
Set the enable state of a set of out-going commands or reports.
static void OutRegistryShutdownAction(FwSmDesc_t smDesc)
Shutdown action for OutRegistry.
CrFwBool_t CrFwOutRegistryIsDiscriminantEnabled(CrFwCmdRepIndex_t cmdRepIndex, CrFwDiscriminant_t disc)
Get the enable status of a discriminant in the argument command or report index.
static FwSmDesc_t outRegistry
The OutRegistry singleton.
static void OutRegistryInitAction(FwPrDesc_t initPr)
Initialization action for OutRegistry.
CrFwOutRegistryCmdRepState_t CrFwOutRegistryGetState(CrFwInstanceId_t cmdRepId)
Query the OutRegistry for the state of an out-going command or report.
static CrFwTrackingIndex_t cmdRepStateIndex
The index of the most recent entry in cmdRepState.
Definition of the OutRegistry Component.
CrFwOutRegistryCmdRepState_t
Enumerated type for the state of an out-going command or report tracked by the OutRegistry.
@ crOutRegistryNoEntry
No entry yet in OutRegistry.
@ crOutRegistryPending
Out-going command or report is pending (waiting to be sent)
@ crOutRegistryNotTracked
Out-going command or report is not tracked.
User-modifiable parameters for the OutRegistry component (see CrFwOutRegistry.h).
#define CR_FW_OUTREGISTRY_INIT_SERV_DESC
Definition of the range of out-going services supported by an application.
#define CR_FW_OUTREGISTRY_N
The maximum number of out-going commands or reports which can be tracked by the OutRegistry.
#define CR_FW_OUTREGISTRY_NSERV
The total number of service types/sub-types provided by the application.
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.
unsigned char CrFwServType_t
Type used for the service type of a command or report.
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
unsigned short CrFwDiscriminant_t
Type used for the discriminant of a command or report.
@ crIllDiscriminant
A framework function was called with an illegal discriminant.
@ crIllServSubType
A framework function was called with an illegal service sub-type.
@ crIllServType
A framework function was called with an illegal service type.
unsigned short CrFwTrackingIndex_t
Type for the index used to track the state of a component.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
unsigned char CrFwServSubType_t
Type used for the command or report sub-type.
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
Service descriptor type.
CrFwDiscriminant_t upperBoundDisc
The upper bound of a range of discriminant values (or zero if no discriminant for this type/sub-type)
CrFwBool_t isServTypeEnabled
Number of discriminant values for this [type, sub-type] pair in the next row.
CrFwBool_t isServSubTypeEnabled
The enable state for the service sub-type (see CrFwOutRegistry.h)
CrFwDiscriminant_t lowerBoundDisc
The lower bound of a range of discriminant values (or zero if no discriminant for this type/sub-type)
unsigned char * isDiscriminantEnabled
The enable state for the discriminants in the range [lowerBoundDisc,lowerBoundDisc].
CrFwServType_t servType
The service type.
CrFwCmdRepIndex_t nextServType
Index of the next service type or zero when this is the last service type.
CrFwServSubType_t servSubType
The service sub-type.
An instance of this type holds the information about an incoming command or report which is being tra...
CrFwInstanceId_t instanceId
The identifier of the incoming command or report.
CrFwInRegistryCmdRepState_t state
The state of the incoming command or report.
CrFwOutRegistryCmdRepState_t state
The state of the out-going command or report.
Type for the data describing an OutComponent.
CrFwCmdRepIndex_t index
Index of out-going command or report (see CrFwOutRegistry.h)
CrFwTrackingIndex_t trackingIndex
Index through which an out-going command or report is tracked by the OutRegistry (see CrFwOutRegistry...
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved