CORDET Framework - C2 Implementation
CrFwInLoader.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include configuration files */
21 #include "CrFwInLoaderUserPar.h"
22 #include "CrFwCmpData.h"
23 /* Include framework files */
24 #include "CrFwConstants.h"
25 #include "CrFwRepErr.h"
26 #include "CrFwTime.h"
27 #include "CrFwInLoader.h"
28 #include "CrFwRepInCmdOutcome.h"
29 #include "BaseCmp/CrFwBaseCmp.h"
30 #include "BaseCmp/CrFwInitProc.h"
31 #include "BaseCmp/CrFwResetProc.h"
33 #include "Pckt/CrFwPckt.h"
34 #include "Pckt/CrFwPcktQueue.h"
37 #include "InStream/CrFwInStream.h"
39 #include "InCmd/CrFwInCmd.h"
42 /* Include FW Profile files */
43 #include "FwSmConstants.h"
44 #include "FwSmDCreate.h"
45 #include "FwSmConfig.h"
46 #include "FwSmCore.h"
47 #include "FwPrConstants.h"
48 #include "FwPrDCreate.h"
49 #include "FwPrConfig.h"
50 #include "FwPrCore.h"
51 
53 static FwSmDesc_t inLoader = NULL;
54 
57 
60 
67 
70 
78 static void InLoaderExecAction(FwPrDesc_t execPr);
79 
87 static void InLoaderLoadCmdRep(CrFwPckt_t pckt);
88 
89 /*-----------------------------------------------------------------------------------------*/
90 FwSmDesc_t CrFwInLoaderMake() {
91  FwPrDesc_t resetPr, execPr, initPr;
92 
93  if (inLoader != NULL) {
94  return inLoader; /* The requested SM has already been created */
95  }
96 
97  /* Create the requested SM as an extension of the base component SM */
98  inLoader = FwSmCreateDer(CrFwBaseCmpMake());
99 
100  /* Create the Reset Procedure for the InLoader Component */
101  resetPr = FwPrCreateDer(CrFwCmpGetResetProc());
102 
103  /* Create the Initialization Procedure for the InLoader Component */
104  initPr = FwPrCreateDer(CrFwCmpGetInitProc());
105 
106  /* Create the Execution Procedure for the InLoader Component */
107  execPr = FwPrCreateDer(CrFwBaseCmpGetDummyExecProc());
108  FwPrOverrideAction(execPr, &CwFwBaseCmpDummyExecAction, &InLoaderExecAction);
109 
110  /* Initialize the data for the requested SM */
111  inLoaderData.outcome = 1;
112  inLoaderData.initProc = initPr;
113  inLoaderData.resetProc = resetPr;
114  inLoaderData.execProc = execPr;
118 
119  /* Attach the data to the InLoader state machine and to its procedures. */
120  FwSmSetData(inLoader, &inLoaderData);
121  FwPrSetData(inLoaderData.initProc, &inLoaderData);
122  FwPrSetData(inLoaderData.resetProc, &inLoaderData);
123  FwPrSetData(inLoaderData.execProc, &inLoaderData);
124 
125  /* Start the InLoader */
126  FwSmStart(inLoader);
127 
128  return inLoader;
129 }
130 
131 /*-----------------------------------------------------------------------------------------*/
132 void CrFwInLoaderSetInStream(FwSmDesc_t inStream) {
134 }
135 
136 /*-----------------------------------------------------------------------------------------*/
137 static void InLoaderExecAction(FwPrDesc_t prDesc) {
138  CrFwPckt_t pckt;
139  CrFwDestSrc_t pcktDest, reroutingDest;
140  FwSmDesc_t outStream;
141  CRFW_UNUSED(prDesc);
142 
143  /* Retrieve packet from InStream */
145  if (pckt == NULL)
146  return;
147 
148  /* Get packet destination and check whether it is the host application */
149  pcktDest = CrFwPcktGetDest(pckt);
150  if (pcktDest == CR_FW_HOST_APP_ID) {
151  InLoaderLoadCmdRep(pckt);
152  return;
153  }
154 
155  /* Check whether packet should be re-routed to another destination */
156  reroutingDest = getReroutingDest(pcktDest);
157  if (reroutingDest == 0) { /* destination is invalid */
159  CrFwPcktGetCmdRepId(pckt), pcktDest, pckt);
160  CrFwPcktRelease(pckt);
161  return;
162  }
163 
164  /* Re-route packet and then release it */
165  outStream = CrFwOutStreamGet(reroutingDest);
166  CrFwOutStreamSend(outStream, pckt);
167  CrFwPcktRelease(pckt);
168  return;
169 }
170 
171 /*-----------------------------------------------------------------------------------------*/
172 static void InLoaderLoadCmdRep(CrFwPckt_t pckt) {
173  FwSmDesc_t inCmp;
174  CrFwInstanceId_t instanceId = CrFwPcktGetCmdRepId(pckt);
178  CrFwCmdRepType_t cmdRepFlag = CrFwPcktGetCmdRepType(pckt);
179  CrFwCmpData_t* inCmpData;
180  CrFwInstanceId_t inManagerInstanceId;
181  CrFwBool_t inManagerLoadOutcome;
182 
183  if (CrFwPcktGetCmdRepType(pckt) == crCmdType) {
184  inCmp = CrFwInFactoryMakeInCmd(pckt);
185  if (inCmp == NULL) { /* InCmd had invalid type or no more resources are available */
187  CrFwPcktRelease(pckt);
188  return;
189  }
190  } else {
191  inCmp = CrFwInFactoryMakeInRep(pckt);
192  if (inCmp == NULL) { /* InRep had invalid type or no more resources are available */
194  CrFwPcktRelease(pckt);
195  return;
196  }
197  }
198 
199  if (FwSmGetCurState(inCmp) != CR_FW_BASE_STATE_CONFIGURED) { /* InRep/InCmd has failed its validity check */
200  inCmpData = FwSmGetData(inCmp);
201  if (cmdRepFlag == crRepType) {
204  return;
205  } else {
206  CrFwRepInCmdOutcome(crCmdAckAccFail, instanceId, servType, servSubType, disc, inCmpData->outcome, inCmp);
208  return;
209  }
210  }
211 
212  /* Select InManager */
213  inManagerInstanceId = getInManager(servType, servSubType, disc, cmdRepFlag);
214 
215  /* Load InReport/InCommand in selected InManager */
216  inManagerLoadOutcome = CrFwInManagerLoad(CrFwInManagerMake(inManagerInstanceId), inCmp);
217  if (inManagerLoadOutcome == 0) { /* Load operation has failed */
218  if (cmdRepFlag == crRepType) {
221  return;
222  } else {
223  CrFwRepInCmdOutcome(crCmdAckLdFail, instanceId, servType, servSubType, disc, 0, inCmp);
225  return;
226  }
227  } else /* Load operation was successful */
228  if (cmdRepFlag == crCmdType)
229  if (CrFwInCmdIsAcceptAck(inCmp) == 1)
230  CrFwRepInCmdOutcome(crCmdAckAccSucc, instanceId, servType, servSubType, disc, 0, inCmp);
231 }
232 
233 /*-----------------------------------------------------------------------------------------*/
235  return pcktDest;
236 }
237 
238 /*-----------------------------------------------------------------------------------------*/
240  CRFW_UNUSED(pcktDest);
241  return 0;
242 }
243 
244 /*-----------------------------------------------------------------------------------------*/
246  CrFwDiscriminant_t discriminant, CrFwCmdRepType_t cmdRepFlag) {
249  CRFW_UNUSED(discriminant);
250  if (cmdRepFlag == crCmdType)
251  return 0;
252  else
253  return 1;
254 }
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
CrFwCmdRepType_t
Enumerated type for command and reports.
Definition: CrFwConstants.h:41
@ crRepType
Report type.
Definition: CrFwConstants.h:45
@ crCmdType
Command type.
Definition: CrFwConstants.h:43
#define CR_FW_INLOADER_TYPE
Type identifier for the InLoader component.
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:38
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
#define CR_FW_BASE_STATE_CONFIGURED
State identifier for state CONFIGURED in the Base State Machine.
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.
CrFwBool_t CrFwInCmdIsAcceptAck(FwSmDesc_t smDesc)
Return the acknowledge level for command acceptance for the command encapsulated in the InCommand.
Definition: CrFwInCmd.c:359
Definition of the InCommand Component of the framework.
static CrFwServType_t servType
The InCommand type as computed in the Validity Check.
FwSmDesc_t CrFwInFactoryMakeInCmd(CrFwPckt_t pckt)
Make function for a component encapsulating an incoming command (InCommand).
void CrFwInFactoryReleaseInCmd(FwSmDesc_t inCmdInstance)
Release function for an InCommand.
void CrFwInFactoryReleaseInRep(FwSmDesc_t inRepInstance)
Release function for an InReport.
FwSmDesc_t CrFwInFactoryMakeInRep(CrFwPckt_t pckt)
Make function for a component encapsulating an incoming report (InReport).
Definition of the InFactory component.
void CrFwInLoaderSetInStream(FwSmDesc_t inStream)
Set the InStream from which the packets will be retrieved the next time the InLoader is executed.
Definition: CrFwInLoader.c:132
static void InLoaderLoadCmdRep(CrFwPckt_t pckt)
Load the command or report encapsulated in the argument packet into an InManager.
Definition: CrFwInLoader.c:172
static CrFwCmpData_t inLoaderData
The data structure for the InLoader.
Definition: CrFwInLoader.c:56
static FwSmDesc_t inLoader
The InLoader singleton.
Definition: CrFwInLoader.c:53
static CrFwInLoaderGetReroutingDest_t getReroutingDest
Pointer to function which takes a packet's destination as argument and returns the destination to whi...
Definition: CrFwInLoader.c:66
CrFwInstanceId_t CrFwInLoaderDefGetInManager(CrFwServType_t servType, CrFwServSubType_t servSubType, CrFwDiscriminant_t discriminant, CrFwCmdRepType_t cmdRepFlag)
Default implementation of the function which selects the InManager to which an incoming InReport or I...
Definition: CrFwInLoader.c:245
CrFwDestSrc_t CrFwInLoaderDefGetReroutingDestination(CrFwDestSrc_t pcktDest)
Default implementation of the function which checks the legality of a destination and returns the re-...
Definition: CrFwInLoader.c:234
static CrFwInLoaderGetInManager_t getInManager
Pointer to function which selects the InManager.
Definition: CrFwInLoader.c:69
static void InLoaderExecAction(FwPrDesc_t execPr)
Implement the logic of the InLoader Execution Procedure (see figure below).
Definition: CrFwInLoader.c:137
static CrFwInLoaderData_t inLoaderCmpSpecificData
The component-specific data for the InLoader.
Definition: CrFwInLoader.c:59
CrFwDestSrc_t CrFwInLoaderDefNoRerouting(CrFwDestSrc_t pcktDest)
Default implementation of the function which checks the legality of a destination and returns the re-...
Definition: CrFwInLoader.c:239
FwSmDesc_t CrFwInLoaderMake()
Factory function to retrieve the state machine implementing the InLoader singleton component.
Definition: CrFwInLoader.c:90
Definition of the InLoader component.
CrFwInstanceId_t(* CrFwInLoaderGetInManager_t)(CrFwServType_t, CrFwServSubType_t, CrFwDiscriminant_t, CrFwCmdRepType_t)
Type for a pointer to the function which selects the InManager where the InCommand or InReport must b...
Definition: CrFwInLoader.h:131
CrFwDestSrc_t(* CrFwInLoaderGetReroutingDest_t)(CrFwDestSrc_t)
Type for a pointer to the function which determines the re-routing destination of a packet.
Definition: CrFwInLoader.h:119
static CrFwDestSrc_t reroutingDest
Return value of function CrFwInLoaderDefGetReroutingDestination.
User-modifiable parameters for the InLoader components (see CrFwInLoader.h).
#define CR_FW_INLOADER_DET_REROUTING_DEST
The function which determines the re-routing destination of a packet.
#define CR_FW_INLOADER_SEL_INMANAGER
The function which determines the InManager into which an InReport or InCommand must be loaded.
CrFwBool_t CrFwInManagerLoad(FwSmDesc_t smDesc, FwSmDesc_t inCmp)
Load a new InReport or InCommand into the InManager.
FwSmDesc_t CrFwInManagerMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th InManager State Machine instance.
Definition: CrFwInManager.c:96
Definition of the InManager component.
Definition of the InRegistry Component.
CrFwPckt_t CrFwInStreamGetPckt(FwSmDesc_t smDesc)
Retrieve a packet from the InStream.
Definition: CrFwInStream.c:253
Definition of the InStream component.
static CrFwDiscriminant_t disc
Discriminant.
static CrFwServSubType_t servSubType
Service sub-type.
FwPrDesc_t CrFwCmpGetInitProc()
Retrieve the singleton instance of the CIP.
Definition: CrFwInitProc.c:48
Component Initialization Procedure (CIP) for the Base Component.
FwSmDesc_t CrFwOutStreamGet(CrFwDestSrc_t dest)
Getter function for the OutStream corresponding to the argument destination.
void CrFwOutStreamSend(FwSmDesc_t smDesc, CrFwPckt_t pckt)
Send a packet to the OutStream.
Definition of the OutStream component.
Interface for creating and accessing a report or command packet.
CrFwCmdRepType_t CrFwPcktGetCmdRepType(CrFwPckt_t pckt)
Return the type of a packet (either a command packet or a report packet).
Definition: CrFwPckt.c:229
CrFwServSubType_t CrFwPcktGetServSubType(CrFwPckt_t pckt)
Return the service sub-type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:333
CrFwDestSrc_t CrFwPcktGetDest(CrFwPckt_t pckt)
Return the destination of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:345
CrFwInstanceId_t CrFwPcktGetCmdRepId(CrFwPckt_t pckt)
Return the command or report identifier of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:369
void CrFwPcktRelease(CrFwPckt_t pckt)
Release function for command or report packets.
Definition: CrFwPckt.c:174
CrFwDiscriminant_t CrFwPcktGetDiscriminant(CrFwPckt_t pckt)
Return the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:303
CrFwServType_t CrFwPcktGetServType(CrFwPckt_t pckt)
Return the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:321
Definition and management of packet queues.
Interface for reporting an error detected by a framework component.
void CrFwRepErrRep(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId, FwSmDesc_t rep)
Report an error which has one parameter attached to it representing an report component.
Definition: CrFwRepErr.c:215
void CrFwRepErrInstanceIdAndDest(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId, CrFwInstanceId_t secondaryInstanceId, CrFwDestSrc_t dest, CrFwPckt_t pckt)
Report an error which has three parameters attached to it representing the instance identifier of a c...
Definition: CrFwRepErr.c:117
void CrFwRepErrPckt(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId, CrFwPckt_t pckt)
Report an error which has one parameter attached to it representing a command or report packet.
Definition: CrFwRepErr.c:201
Interface for reporting the outcome of the processing of an InCommand.
void CrFwRepInCmdOutcome(CrFwRepInCmdOutcome_t outcome, CrFwInstanceId_t instanceId, CrFwServType_t servType, CrFwServSubType_t servSubType, CrFwDiscriminant_t disc, CrFwOutcome_t failCode, FwSmDesc_t inCmd)
Report the outcome of the processing of an InCommand.
@ crCmdAckCreFail
Creation failure.
@ crCmdAckAccFail
Acceptance failure.
@ crCmdAckLdFail
Load failure.
@ crCmdAckAccSucc
Acceptance success.
void CrFwRepInCmdOutcomeCreFail(CrFwRepInCmdOutcome_t outcome, CrFwOutcome_t failCode, CrFwPckt_t pckt)
Report the a "creation failure" outcome for the processing of a packet carrying an InCommand.
FwPrDesc_t CrFwCmpGetResetProc()
Retrieve the singleton instance of the CRP.
Definition: CrFwResetProc.c:45
Component Reset Procedure (CRP) for the Base Component.
Interface through which framework components access the current time.
unsigned char CrFwServType_t
Type used for the service type of a command or report.
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
unsigned short CrFwDiscriminant_t
Type used for the discriminant of a command or report.
@ crInLoaderAccFail
An InReport has failed its validity check.
@ crInLoaderInvDest
The InLoader has retrieved a packet with an invalid destination (see CrFwInLoader....
@ crInLoaderLdFail
An InReport could not be loaded in its InManager.
@ crInLoaderCreFail
An InReport could not be created due to insufficient resources or illegal type/sub-type/discriminant.
#define CR_FW_HOST_APP_ID
The identifier of the host application (i.e.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
unsigned char CrFwServSubType_t
Type used for the command or report sub-type.
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 InLoader.
FwSmDesc_t inStream
InStream from which packets are to be retrieved in the next execution cycle.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved