F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
StaticMemoryComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title StaticMemoryComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for StaticMemory component base class
5 // ======================================================================
6 
8 #include "Fw/Types/Assert.hpp"
10 #if FW_ENABLE_TEXT_LOGGING
11 #include "Fw/Types/String.hpp"
12 #endif
13 
14 namespace Svc {
15 
16  // ----------------------------------------------------------------------
17  // Component initialization
18  // ----------------------------------------------------------------------
19 
21  init(FwEnumStoreType instance)
22  {
23  // Initialize base class
25 
26  // Connect input port bufferAllocate
27  for (
28  FwIndexType port = 0;
29  port < static_cast<FwIndexType>(this->getNum_bufferAllocate_InputPorts());
30  port++
31  ) {
32  this->m_bufferAllocate_InputPort[port].init();
33  this->m_bufferAllocate_InputPort[port].addCallComp(
34  this,
35  m_p_bufferAllocate_in
36  );
37  this->m_bufferAllocate_InputPort[port].setPortNum(port);
38 
39 #if FW_OBJECT_NAMES == 1
40  Fw::ObjectName portName;
41  portName.format(
42  "%s_bufferAllocate_InputPort[%" PRI_PlatformIntType "]",
43  this->m_objName.toChar(),
44  port
45  );
46  this->m_bufferAllocate_InputPort[port].setObjName(portName.toChar());
47 #endif
48  }
49 
50  // Connect input port bufferDeallocate
51  for (
52  FwIndexType port = 0;
53  port < static_cast<FwIndexType>(this->getNum_bufferDeallocate_InputPorts());
54  port++
55  ) {
56  this->m_bufferDeallocate_InputPort[port].init();
57  this->m_bufferDeallocate_InputPort[port].addCallComp(
58  this,
59  m_p_bufferDeallocate_in
60  );
61  this->m_bufferDeallocate_InputPort[port].setPortNum(port);
62 
63 #if FW_OBJECT_NAMES == 1
64  Fw::ObjectName portName;
65  portName.format(
66  "%s_bufferDeallocate_InputPort[%" PRI_PlatformIntType "]",
67  this->m_objName.toChar(),
68  port
69  );
70  this->m_bufferDeallocate_InputPort[port].setObjName(portName.toChar());
71 #endif
72  }
73  }
74 
75  // ----------------------------------------------------------------------
76  // Getters for typed input ports
77  // ----------------------------------------------------------------------
78 
81  {
82  FW_ASSERT(
83  portNum < this->getNum_bufferAllocate_InputPorts(),
84  static_cast<FwAssertArgType>(portNum)
85  );
86 
87  return &this->m_bufferAllocate_InputPort[portNum];
88  }
89 
92  {
93  FW_ASSERT(
94  portNum < this->getNum_bufferDeallocate_InputPorts(),
95  static_cast<FwAssertArgType>(portNum)
96  );
97 
98  return &this->m_bufferDeallocate_InputPort[portNum];
99  }
100 
101  // ----------------------------------------------------------------------
102  // Component construction and destruction
103  // ----------------------------------------------------------------------
104 
106  StaticMemoryComponentBase(const char* compName) :
107  Fw::PassiveComponentBase(compName)
108  {
109 
110  }
111 
114  {
115 
116  }
117 
118  // ----------------------------------------------------------------------
119  // Getters for numbers of typed input ports
120  // ----------------------------------------------------------------------
121 
124  {
125  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_bufferAllocate_InputPort));
126  }
127 
130  {
131  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_bufferDeallocate_InputPort));
132  }
133 
134  // ----------------------------------------------------------------------
135  // Port handler base-class functions for typed input ports
136  //
137  // Call these functions directly to bypass the corresponding ports
138  // ----------------------------------------------------------------------
139 
142  FwIndexType portNum,
143  U32 size
144  )
145  {
146  // Make sure port number is valid
147  FW_ASSERT(
148  portNum < this->getNum_bufferAllocate_InputPorts(),
149  static_cast<FwAssertArgType>(portNum)
150  );
151 
152  Fw::Buffer retVal;
153 
154  // Lock guard mutex before calling
155  this->lock();
156 
157  // Call handler function
158  retVal = this->bufferAllocate_handler(
159  portNum,
160  size
161  );
162 
163  // Unlock guard mutex
164  this->unLock();
165 
166  return retVal;
167  }
168 
171  FwIndexType portNum,
172  Fw::Buffer& fwBuffer
173  )
174  {
175  // Make sure port number is valid
176  FW_ASSERT(
177  portNum < this->getNum_bufferDeallocate_InputPorts(),
178  static_cast<FwAssertArgType>(portNum)
179  );
180 
181  // Lock guard mutex before calling
182  this->lock();
183 
184  // Call handler function
186  portNum,
187  fwBuffer
188  );
189 
190  // Unlock guard mutex
191  this->unLock();
192  }
193 
194  // ----------------------------------------------------------------------
195  // Mutex operations for guarded ports
196  //
197  // You can override these operations to provide more sophisticated
198  // synchronization
199  // ----------------------------------------------------------------------
200 
202  lock()
203  {
204  this->m_guardedPortMutex.lock();
205  }
206 
208  unLock()
209  {
210  this->m_guardedPortMutex.unLock();
211  }
212 
213  // ----------------------------------------------------------------------
214  // Calls for messages received on typed input ports
215  // ----------------------------------------------------------------------
216 
217  Fw::Buffer StaticMemoryComponentBase ::
218  m_p_bufferAllocate_in(
219  Fw::PassiveComponentBase* callComp,
220  FwIndexType portNum,
221  U32 size
222  )
223  {
224  FW_ASSERT(callComp);
225  StaticMemoryComponentBase* compPtr = static_cast<StaticMemoryComponentBase*>(callComp);
226  return compPtr->bufferAllocate_handlerBase(
227  portNum,
228  size
229  );
230  }
231 
232  void StaticMemoryComponentBase ::
233  m_p_bufferDeallocate_in(
234  Fw::PassiveComponentBase* callComp,
235  FwIndexType portNum,
236  Fw::Buffer& fwBuffer
237  )
238  {
239  FW_ASSERT(callComp);
240  StaticMemoryComponentBase* compPtr = static_cast<StaticMemoryComponentBase*>(callComp);
241  compPtr->bufferDeallocate_handlerBase(
242  portNum,
243  fwBuffer
244  );
245  }
246 
247 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
#define PRI_PlatformIntType
I32 FwEnumStoreType
Definition: FpConfig.h:51
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:34
PlatformIndexType FwIndexType
Definition: FpConfig.h:20
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void init()
Initialization function.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void init()
Initialization function.
void setPortNum(NATIVE_INT_TYPE portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:27
const char * toChar() const
Definition: ObjectName.hpp:50
void format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:56
void unLock()
unlock the mutex
Definition: Mutex.cpp:13
void lock()
lock the mutex
Definition: Mutex.cpp:12
Auto-generated base for StaticMemory component.
Fw::InputBufferGetPort * get_bufferAllocate_InputPort(FwIndexType portNum)
virtual void bufferDeallocate_handler(FwIndexType portNum, Fw::Buffer &fwBuffer)=0
Handler for input port bufferDeallocate.
FwIndexType getNum_bufferAllocate_InputPorts() const
StaticMemoryComponentBase(const char *compName="")
Construct StaticMemoryComponentBase object.
void bufferDeallocate_handlerBase(FwIndexType portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port bufferDeallocate.
Fw::Buffer bufferAllocate_handlerBase(FwIndexType portNum, U32 size)
Handler base-class function for input port bufferAllocate.
virtual ~StaticMemoryComponentBase()
Destroy StaticMemoryComponentBase object.
virtual Fw::Buffer bufferAllocate_handler(FwIndexType portNum, U32 size)=0
Handler for input port bufferAllocate.
Fw::InputBufferSendPort * get_bufferDeallocate_InputPort(FwIndexType portNum)
virtual void lock()
Lock the guarded mutex.
virtual void unLock()
Unlock the guarded mutex.
FwIndexType getNum_bufferDeallocate_InputPorts() const