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 OuRegistry Component */
89  resetPr = FwPrCreateDer(CrFwCmpGetResetProc());
90  FwPrOverrideAction(resetPr, &CrFwBaseCmpDefConfigAction, &InRegistryConfigAction);
91 
92  /* Create the Initialization Procedure for the OuRegistry Component */
93  initPr = FwPrCreateDer(CrFwCmpGetInitProc());
94 
95  /* Override the Shutdown Action for the InStream Component */
97 
98  /* Get the Dummy Execution Procedure for the InRegistry Component */
99  execPr = CrFwBaseCmpGetDummyExecProc();
100 
101  /* Initialize the data for the requested SM */
102  inRegistryData.outcome = 1;
103  inRegistryData.initProc = initPr;
104  inRegistryData.resetProc = resetPr;
105  inRegistryData.execProc = execPr;
106  inRegistryData.instanceId = 0;
107  inRegistryData.typeId = CR_FW_INREGISTRY_TYPE;
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 
126  cmdRepState[cmdRepStateIndex].instanceId = inCmpData->instanceId;
128  if (inCmpData->typeId == CR_FW_INREPORT_TYPE) {
129  inRepCmpSpecificData = (CrFwInRepData_t*)(inCmpData->cmpSpecificData);
130  inRepCmpSpecificData->trackingIndex = cmdRepStateIndex;
131  } else {
132  inCmdCmpSpecificData = (CrFwInCmdData_t*)(inCmpData->cmpSpecificData);
133  inCmdCmpSpecificData->trackingIndex = cmdRepStateIndex;
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) {
150  inRepCmpSpecificData = (CrFwInRepData_t*)(inCmpData->cmpSpecificData);
151  i = inRepCmpSpecificData->trackingIndex;
152  } else {
153  inCmdCmpSpecificData = (CrFwInCmdData_t*)(inCmpData->cmpSpecificData);
154  i = inCmdCmpSpecificData->trackingIndex;
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 }
static void InRegistryShutdownAction(FwSmDesc_t smDesc)
Shutdown action for InRegistry.
Type for the Framework Component Data (FCD).
Definition: CrFwCmpData.h:79
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
FwPrDesc_t CrFwCmpGetResetProc()
Retrieve the singleton instance of the CRP.
Definition: CrFwResetProc.c:45
Definition of the Framework Component Data (FCD) Type.
static CrFwCmpData_t inRegistryData
The data for the InRegistry singleton.
#define CRFW_UNUSED(x)
A macro that can be used to specify that a function parameter is not used.
Definition: CrFwConstants.h:29
CrFwTrackingIndex_t trackingIndex
Index through which an InReport is tracked by the InRegistry (see CrFwInRegistry.h) ...
#define CR_FW_INREPORT_TYPE
Type identifier for the InReport component.
Incoming command or report is not tracked.
#define CR_FW_INREGISTRY_TYPE
Type identifier for the OutRegistry component.
Type for the data describing an InReport.
void CrFwBaseCmpDefShutdownAction(FwSmDesc_t smDesc)
Function which performs the Shutdown Action for the Base State Machine.
Definition: CrFwBaseCmp.c:217
FwPrDesc_t resetProc
The Component Reset Procedure (CRP) (see CrFwResetProc.h).
Definition: CrFwCmpData.h:97
Dummy Component Execution Procedure (CEP) for the Base Component.
Header file to define all invariant publicly available constants and types for the CORDET Framework...
CrFwInRegistryCmdRepState_t
Enumerated type for the state of a command or report tracked by the InRegistry.
Definition of the InRegistry Component.
An instance of this type holds the information about an incoming command or report which is being tra...
No entry yet in InRegistry.
void CrFwInRegistryStartTracking(FwSmDesc_t inCmp)
Ask the InRegistry to start tracking an incoming command or report.
CrFwInstanceId_t instanceId
The instance identifier of the framework component.
Definition: CrFwCmpData.h:81
CrFwInstanceId_t instanceId
The identifier of the incoming command or report.
FwSmDesc_t CrFwInRegistryMake()
Factory function for the singleton instance of the InRegistry.
static CrFwTrackedState_t cmdRepState[CR_FW_OUTREGISTRY_N]
Array to track the state of incoming commands or reports.
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 void InRegistryConfigAction(FwPrDesc_t resetPr)
Configuration action for InRegistry.
User-modifiable parameters for the InRegistry component (see CrFwInRegistry.h).
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
static CrFwTrackingIndex_t cmdRepStateIndex
The index of the most recent entry in cmdRepState.
CrFwTrackingIndex_t trackingIndex
Index through which an InCommand is tracked by the InRegistry (see CrFwInRegistry.h)
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.
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 CrFwInstanceId_t cmdRepId
Command or Report Identifier.
void CrFwInRegistryUpdateState(FwSmDesc_t inCmp, CrFwInRegistryCmdRepState_t newState)
Ask the InRegistry to update the state of an incoming command or report.
FwPrDesc_t CrFwBaseCmpGetDummyExecProc()
Retrieve the singleton instance of the Dummy CEP.
CrFwInRegistryCmdRepState_t CrFwInRegistryGetState(CrFwInstanceId_t cmdRepId)
Query the InRegistry for the state of an incoming command or report.
Definition of Base Component.
#define CR_FW_OUTREGISTRY_N
The maximum number of out-going commands or reports which can be tracked by the OutRegistry.
static CrFwInRepData_t inRepCmpSpecificData[CR_FW_INFACTORY_MAX_NOF_INREP]
The component-specific data for the pre-allocated InReport instances.
Definition: CrFwInFactory.c:73
Component Initialization Procedure (CIP) for the Base Component.
Definition of the OutComponent Component of the framework.
CrFwTypeId_t typeId
The type identifier of the framework component.
Definition: CrFwCmpData.h:83
CrFwInRegistryCmdRepState_t state
The state of the incoming command or report.
Type for the data describing an InCommand.
unsigned short CrFwTrackingIndex_t
Type for the index used to track the state of a component.
static FwSmDesc_t inRegistry
The InRegistry singleton.
FwPrDesc_t CrFwCmpGetInitProc()
Retrieve the singleton instance of the CIP.
Definition: CrFwInitProc.c:48
Incoming command or report is pending (waiting to be sent)
Component Reset Procedure (CRP) for the Base Component.
FwPrDesc_t initProc
The Component Initialization Procedure (CIP) (see CrFwInitProc.h).
Definition: CrFwCmpData.h:95
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved