CORDET Framework - C2 Implementation
CrFwInRegistry.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include configuration files */
21 #include "CrFwInRegistryUserPar.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 "CrFwInRegistry.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 
43 typedef struct {
49 
52 
55 
57 static FwSmDesc_t inRegistry = NULL;
58 
61 
68 static void InRegistryConfigAction(FwPrDesc_t resetPr);
69 
75 static void InRegistryShutdownAction(FwSmDesc_t smDesc);
76 
77 /*------------------------------------------------------------------------------------*/
78 FwSmDesc_t CrFwInRegistryMake() {
79  FwPrDesc_t resetPr, execPr, initPr;
80 
81  if (inRegistry != NULL) {
82  return inRegistry;
83  }
84 
85  /* Extend the Base Component */
86  inRegistry = FwSmCreateDer(CrFwBaseCmpMake());
87 
88  /* Create the Reset Procedure for the InRegistry Component */
89  resetPr = FwPrCreateDer(CrFwCmpGetResetProc());
90  FwPrOverrideAction(resetPr, &CrFwBaseCmpDefConfigAction, &InRegistryConfigAction);
91 
92  /* Create the Initialization Procedure for the InRegistry Component */
93  initPr = FwPrCreateDer(CrFwCmpGetInitProc());
94 
95  /* Override the Shutdown Action for the InRegistry Component */
97 
98  /* Get the Dummy Execution Procedure for the InRegistry Component */
99  execPr = CrFwBaseCmpGetDummyExecProc();
100 
101  /* Initialize the data for the requested SM */
103  inRegistryData.initProc = initPr;
104  inRegistryData.resetProc = resetPr;
105  inRegistryData.execProc = execPr;
108 
109  /* Attach the data to the InRegistry state machine and to its procedures. */
110  FwSmSetData(inRegistry, &inRegistryData);
111  FwPrSetData(inRegistryData.initProc, &inRegistryData);
112  FwPrSetData(inRegistryData.resetProc, &inRegistryData);
113 
114  /* Start the InRegistry */
115  FwSmStart(inRegistry);
116 
117  return inRegistry;
118 }
119 
120 /*------------------------------------------------------------------------------------*/
121 void CrFwInRegistryStartTracking(FwSmDesc_t inCmp) {
122  CrFwCmpData_t* inCmpData = (CrFwCmpData_t*)FwSmGetData(inCmp);
125 
128  if (inCmpData->typeId == CR_FW_INREPORT_TYPE) {
131  } else {
134  }
135 
137  cmdRepStateIndex = 0;
138  else
140 }
141 
142 /*------------------------------------------------------------------------------------*/
143 void CrFwInRegistryUpdateState(FwSmDesc_t inCmp, CrFwInRegistryCmdRepState_t newState) {
144  CrFwCmpData_t* inCmpData = (CrFwCmpData_t*)FwSmGetData(inCmp);
148 
149  if (inCmpData->typeId == CR_FW_INREPORT_TYPE) {
152  } else {
155  }
156  if (cmdRepState[i].instanceId == inCmpData->instanceId) {
157  cmdRepState[i].state = newState;
158  }
159 }
160 
161 /*------------------------------------------------------------------------------------*/
165 
166  if (cmdRepStateIndex > 0)
168  else
169  i = (CR_FW_OUTREGISTRY_N-1);
170 
171  for (j=0; j<CR_FW_OUTREGISTRY_N; j++) {
172  if (cmdRepState[i].state == crInRegistryNoEntry)
173  break;
174  if (cmdRepState[i].instanceId == cmdRepId) {
175  return cmdRepState[i].state;
176  } else if (i == 0)
177  i = (CR_FW_OUTREGISTRY_N-1);
178  else
179  i--;
180  }
181 
182  return crInRegistryNotTracked;
183 }
184 
185 /*------------------------------------------------------------------------------------*/
186 static void InRegistryConfigAction(FwPrDesc_t initPr) {
187  CrFwCmpData_t* cmpData = (CrFwCmpData_t*)FwPrGetData(initPr);
188  CrFwCounterU2_t k;
189 
190  for (k=0; k<CR_FW_OUTREGISTRY_N; k++)
191  cmdRepState[k].state = crInRegistryNoEntry;
192 
193  cmdRepStateIndex = 0;
194 
195  cmpData->outcome = 1;
196 }
197 
198 /*------------------------------------------------------------------------------------*/
199 static void InRegistryShutdownAction(FwSmDesc_t smDesc) {
200  CrFwCounterU2_t k;
201  CRFW_UNUSED(smDesc);
202 
203  for (k=0; k<CR_FW_OUTREGISTRY_N; k++)
204  cmdRepState[k].state = crInRegistryNoEntry;
205 
206  cmdRepStateIndex = 0;
207 }
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
#define CR_FW_INREPORT_TYPE
Type identifier for the InReport component.
#define CR_FW_INREGISTRY_TYPE
Type identifier for the OutRegistry component.
FwPrDesc_t CrFwBaseCmpGetDummyExecProc()
Retrieve the singleton instance of the Dummy CEP.
Dummy Component Execution Procedure (CEP) for the Base Component.
static CrFwInCmdData_t inCmdCmpSpecificData[CR_FW_INFACTORY_MAX_NOF_INCMD]
The component-specific data for the pre-allocated InCommand instances.
Definition: CrFwInFactory.c:67
static CrFwInRepData_t inRepCmpSpecificData[CR_FW_INFACTORY_MAX_NOF_INREP]
The component-specific data for the pre-allocated InReport instances.
Definition: CrFwInFactory.c:73
static CrFwCmpData_t inRegistryData
The data for the InRegistry singleton.
void CrFwInRegistryUpdateState(FwSmDesc_t inCmp, CrFwInRegistryCmdRepState_t newState)
Ask the InRegistry to update the state of an incoming command or report.
static void InRegistryShutdownAction(FwSmDesc_t smDesc)
Shutdown action for InRegistry.
static void InRegistryConfigAction(FwPrDesc_t resetPr)
Configuration action for InRegistry.
FwSmDesc_t CrFwInRegistryMake()
Factory function for the singleton instance of the InRegistry.
static FwSmDesc_t inRegistry
The InRegistry singleton.
void CrFwInRegistryStartTracking(FwSmDesc_t inCmp)
Ask the InRegistry to start tracking an incoming command or report.
static CrFwTrackedState_t cmdRepState[CR_FW_INREGISTRY_N]
Array to track the state of incoming commands or reports.
CrFwInRegistryCmdRepState_t CrFwInRegistryGetState(CrFwInstanceId_t cmdRepId)
Query the InRegistry for the state of an incoming command or report.
static CrFwTrackingIndex_t cmdRepStateIndex
The index of the most recent entry in cmdRepState.
Definition of the InRegistry Component.
CrFwInRegistryCmdRepState_t
Enumerated type for the state of a command or report tracked by the InRegistry.
@ crInRegistryNotTracked
Incoming command or report is not tracked.
@ crInRegistryNoEntry
No entry yet in InRegistry.
@ crInRegistryPending
Incoming command or report is pending (waiting to be sent)
User-modifiable parameters for the InRegistry component (see CrFwInRegistry.h).
#define CR_FW_INREGISTRY_N
The maximum number of commands or reports which can be tracked by the InRegistry.
static CrFwInstanceId_t cmdRepId
Command or Report Identifier.
FwPrDesc_t CrFwCmpGetInitProc()
Retrieve the singleton instance of the CIP.
Definition: CrFwInitProc.c:48
Component Initialization Procedure (CIP) for the Base Component.
Definition of the OutComponent Component of the framework.
#define CR_FW_OUTREGISTRY_N
The maximum number of out-going commands or reports which can be tracked by the OutRegistry.
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 short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
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.
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
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.
Type for the data describing an InCommand.
CrFwTrackingIndex_t trackingIndex
Index through which an InCommand is tracked by the InRegistry (see CrFwInRegistry....
Type for the data describing an InReport.
CrFwTrackingIndex_t trackingIndex
Index through which an InReport is tracked by the InRegistry (see CrFwInRegistry.h)
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved