F´ Flight Software - C/C++ Documentation
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 
7 #include "Fw/Types/Assert.hpp"
9 #if FW_ENABLE_TEXT_LOGGING
10 #include "Fw/Types/String.hpp"
11 #endif
13 
14 namespace Svc {
15 
16  // ----------------------------------------------------------------------
17  // Component initialization
18  // ----------------------------------------------------------------------
19 
22  {
23  // Initialize base class
25 
26 #if !FW_DIRECT_PORT_CALLS
27  // Connect input port bufferAllocate
28  for (
29  FwIndexType port = 0;
30  port < static_cast<FwIndexType>(this->getNum_bufferAllocate_InputPorts());
31  port++
32  ) {
33  this->m_bufferAllocate_InputPort[port].init();
34  this->m_bufferAllocate_InputPort[port].addCallComp(
35  this,
36  m_p_bufferAllocate_in
37  );
38  this->m_bufferAllocate_InputPort[port].setPortNum(port);
39 
40 #if FW_OBJECT_NAMES == 1
41  Fw::ObjectName portName;
42  portName.format(
43  "%s_bufferAllocate_InputPort[%" PRI_FwIndexType "]",
44  this->m_objName.toChar(),
45  port
46  );
47  this->m_bufferAllocate_InputPort[port].setObjName(portName.toChar());
48 #endif
49  }
50 #endif
51 
52 #if !FW_DIRECT_PORT_CALLS
53  // Connect input port bufferDeallocate
54  for (
55  FwIndexType port = 0;
56  port < static_cast<FwIndexType>(this->getNum_bufferDeallocate_InputPorts());
57  port++
58  ) {
59  this->m_bufferDeallocate_InputPort[port].init();
60  this->m_bufferDeallocate_InputPort[port].addCallComp(
61  this,
62  m_p_bufferDeallocate_in
63  );
64  this->m_bufferDeallocate_InputPort[port].setPortNum(port);
65 
66 #if FW_OBJECT_NAMES == 1
67  Fw::ObjectName portName;
68  portName.format(
69  "%s_bufferDeallocate_InputPort[%" PRI_FwIndexType "]",
70  this->m_objName.toChar(),
71  port
72  );
73  this->m_bufferDeallocate_InputPort[port].setObjName(portName.toChar());
74 #endif
75  }
76 #endif
77  }
78 
79 #if !FW_DIRECT_PORT_CALLS
80 
81  // ----------------------------------------------------------------------
82  // Getters for typed input ports
83  // ----------------------------------------------------------------------
84 
87  {
88  FW_ASSERT(
89  (0 <= portNum) && (portNum < this->getNum_bufferAllocate_InputPorts()),
90  static_cast<FwAssertArgType>(portNum)
91  );
92 
93  return &this->m_bufferAllocate_InputPort[portNum];
94  }
95 
98  {
99  FW_ASSERT(
100  (0 <= portNum) && (portNum < this->getNum_bufferDeallocate_InputPorts()),
101  static_cast<FwAssertArgType>(portNum)
102  );
103 
104  return &this->m_bufferDeallocate_InputPort[portNum];
105  }
106 
107 #endif
108 
109  // ----------------------------------------------------------------------
110  // Component construction and destruction
111  // ----------------------------------------------------------------------
112 
114  StaticMemoryComponentBase(const char* compName) :
115  Fw::PassiveComponentBase(compName)
116  {
117 
118  }
119 
122  {
123 
124  }
125 
126  // ----------------------------------------------------------------------
127  // Port handler base-class functions for typed input ports
128  //
129  // Call these functions directly to bypass the corresponding ports
130  // ----------------------------------------------------------------------
131 
134  FwIndexType portNum,
135  FwSizeType size
136  )
137  {
138  // Make sure port number is valid
139  FW_ASSERT(
140  (0 <= portNum) && (portNum < this->getNum_bufferAllocate_InputPorts()),
141  static_cast<FwAssertArgType>(portNum)
142  );
143 
144  Fw::Buffer retVal;
145 
146  // Lock guard mutex before calling
147  this->lock();
148 
149  // Call handler function
150  retVal = this->bufferAllocate_handler(
151  portNum,
152  size
153  );
154 
155  // Unlock guard mutex
156  this->unLock();
157 
158  return retVal;
159  }
160 
163  FwIndexType portNum,
164  Fw::Buffer& fwBuffer
165  )
166  {
167  // Make sure port number is valid
168  FW_ASSERT(
169  (0 <= portNum) && (portNum < this->getNum_bufferDeallocate_InputPorts()),
170  static_cast<FwAssertArgType>(portNum)
171  );
172 
173  // Lock guard mutex before calling
174  this->lock();
175 
176  // Call handler function
178  portNum,
179  fwBuffer
180  );
181 
182  // Unlock guard mutex
183  this->unLock();
184  }
185 
186  // ----------------------------------------------------------------------
187  // Mutex operations for guarded ports
188  //
189  // You can override these operations to provide more sophisticated
190  // synchronization
191  // ----------------------------------------------------------------------
192 
195  {
196  this->m_guardedPortMutex.lock();
197  }
198 
201  {
202  this->m_guardedPortMutex.unLock();
203  }
204 
205  // ----------------------------------------------------------------------
206  // Calls for messages received on typed input ports
207  // ----------------------------------------------------------------------
208 
209  Fw::Buffer StaticMemoryComponentBase ::
210  m_p_bufferAllocate_in(
211  Fw::PassiveComponentBase* callComp,
212  FwIndexType portNum,
213  FwSizeType size
214  )
215  {
216  FW_ASSERT(callComp);
217  StaticMemoryComponentBase* compPtr = static_cast<StaticMemoryComponentBase*>(callComp);
218  return compPtr->bufferAllocate_handlerBase(
219  portNum,
220  size
221  );
222  }
223 
224  void StaticMemoryComponentBase ::
225  m_p_bufferDeallocate_in(
226  Fw::PassiveComponentBase* callComp,
227  FwIndexType portNum,
228  Fw::Buffer& fwBuffer
229  )
230  {
231  FW_ASSERT(callComp);
232  StaticMemoryComponentBase* compPtr = static_cast<StaticMemoryComponentBase*>(callComp);
233  compPtr->bufferDeallocate_handlerBase(
234  portNum,
235  fwBuffer
236  );
237  }
238 
239 }
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
PlatformSizeType FwSizeType
Fw::InputBufferGetPort * get_bufferAllocate_InputPort(FwIndexType portNum)
I32 FwEnumStoreType
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:41
Fw::Buffer bufferAllocate_handlerBase(FwIndexType portNum, FwSizeType size)
Handler base-class function for input port bufferAllocate.
void init()
Object initializer.
Definition: ObjBase.cpp:24
static constexpr FwIndexType getNum_bufferAllocate_InputPorts()
virtual void bufferDeallocate_handler(FwIndexType portNum, Fw::Buffer &fwBuffer)=0
Handler for input port bufferDeallocate.
virtual void unLock()
Unlock the guarded mutex.
void init()
Initialization function.
virtual void lock()
Lock the guarded mutex.
Fw::InputBufferSendPort * get_bufferDeallocate_InputPort(FwIndexType portNum)
const char * toChar() const
Convert to a C-style char*.
Definition: ObjectName.hpp:50
static constexpr FwIndexType getNum_bufferDeallocate_InputPorts()
void bufferDeallocate_handlerBase(FwIndexType portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port bufferDeallocate.
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
virtual ~StaticMemoryComponentBase()
Destroy StaticMemoryComponentBase object.
void setPortNum(FwIndexType portNum)
void init()
Initialization function.
StaticMemoryComponentBase(const char *compName="")
Construct StaticMemoryComponentBase object.
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
Auto-generated base for StaticMemory component.
Implementation of malloc based allocator.
virtual Fw::Buffer bufferAllocate_handler(FwIndexType portNum, FwSizeType size)=0
Handler for input port bufferAllocate.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34