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 
7 #include <cstdio>
8 
10 #include "Fw/Types/Assert.hpp"
11 #if FW_ENABLE_TEXT_LOGGING
12 #include "Fw/Types/String.hpp"
13 #endif
14 
15 namespace Svc {
16 
17  // ----------------------------------------------------------------------
18  // Component initialization
19  // ----------------------------------------------------------------------
20 
22  init(NATIVE_INT_TYPE instance)
23  {
24  // Initialize base class
26 
27  // Connect input port bufferAllocate
28  for (
29  PlatformIntType port = 0;
30  port < static_cast<PlatformIntType>(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  // The port name consists of this->m_objName and some extra info.
42  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
43  // However, the compiler may assume that this->m_objName fills
44  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
45  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
46  // bytes to cover the extra info.
47  char portName[2*FW_OBJ_NAME_MAX_SIZE];
48  (void) snprintf(
49  portName,
50  sizeof(portName),
51  "%s_bufferAllocate_InputPort[%" PRI_PlatformIntType "]",
52  this->m_objName,
53  port
54  );
55  this->m_bufferAllocate_InputPort[port].setObjName(portName);
56 #endif
57  }
58 
59  // Connect input port bufferDeallocate
60  for (
61  PlatformIntType port = 0;
62  port < static_cast<PlatformIntType>(this->getNum_bufferDeallocate_InputPorts());
63  port++
64  ) {
65  this->m_bufferDeallocate_InputPort[port].init();
66  this->m_bufferDeallocate_InputPort[port].addCallComp(
67  this,
68  m_p_bufferDeallocate_in
69  );
70  this->m_bufferDeallocate_InputPort[port].setPortNum(port);
71 
72 #if FW_OBJECT_NAMES == 1
73  // The port name consists of this->m_objName and some extra info.
74  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
75  // However, the compiler may assume that this->m_objName fills
76  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
77  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
78  // bytes to cover the extra info.
79  char portName[2*FW_OBJ_NAME_MAX_SIZE];
80  (void) snprintf(
81  portName,
82  sizeof(portName),
83  "%s_bufferDeallocate_InputPort[%" PRI_PlatformIntType "]",
84  this->m_objName,
85  port
86  );
87  this->m_bufferDeallocate_InputPort[port].setObjName(portName);
88 #endif
89  }
90  }
91 
92  // ----------------------------------------------------------------------
93  // Getters for typed input ports
94  // ----------------------------------------------------------------------
95 
98  {
99  FW_ASSERT(
100  portNum < this->getNum_bufferAllocate_InputPorts(),
101  static_cast<FwAssertArgType>(portNum)
102  );
103 
104  return &this->m_bufferAllocate_InputPort[portNum];
105  }
106 
109  {
110  FW_ASSERT(
111  portNum < this->getNum_bufferDeallocate_InputPorts(),
112  static_cast<FwAssertArgType>(portNum)
113  );
114 
115  return &this->m_bufferDeallocate_InputPort[portNum];
116  }
117 
118  // ----------------------------------------------------------------------
119  // Component construction and destruction
120  // ----------------------------------------------------------------------
121 
123  StaticMemoryComponentBase(const char* compName) :
124  Fw::PassiveComponentBase(compName)
125  {
126 
127  }
128 
131  {
132 
133  }
134 
135  // ----------------------------------------------------------------------
136  // Getters for numbers of typed input ports
137  // ----------------------------------------------------------------------
138 
141  {
142  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_bufferAllocate_InputPort));
143  }
144 
147  {
148  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_bufferDeallocate_InputPort));
149  }
150 
151  // ----------------------------------------------------------------------
152  // Port handler base-class functions for typed input ports
153  //
154  // Call these functions directly to bypass the corresponding ports
155  // ----------------------------------------------------------------------
156 
159  NATIVE_INT_TYPE portNum,
160  U32 size
161  )
162  {
163  // Make sure port number is valid
164  FW_ASSERT(
165  portNum < this->getNum_bufferAllocate_InputPorts(),
166  static_cast<FwAssertArgType>(portNum)
167  );
168 
169  Fw::Buffer retVal;
170 
171  // Lock guard mutex before calling
172  this->lock();
173 
174  // Call handler function
175  retVal = this->bufferAllocate_handler(
176  portNum,
177  size
178  );
179 
180  // Unlock guard mutex
181  this->unLock();
182 
183  return retVal;
184  }
185 
188  NATIVE_INT_TYPE portNum,
189  Fw::Buffer& fwBuffer
190  )
191  {
192  // Make sure port number is valid
193  FW_ASSERT(
194  portNum < this->getNum_bufferDeallocate_InputPorts(),
195  static_cast<FwAssertArgType>(portNum)
196  );
197 
198  // Lock guard mutex before calling
199  this->lock();
200 
201  // Call handler function
203  portNum,
204  fwBuffer
205  );
206 
207  // Unlock guard mutex
208  this->unLock();
209  }
210 
211  // ----------------------------------------------------------------------
212  // Mutex operations for guarded ports
213  //
214  // You can override these operations to provide more sophisticated
215  // synchronization
216  // ----------------------------------------------------------------------
217 
219  lock()
220  {
221  this->m_guardedPortMutex.lock();
222  }
223 
225  unLock()
226  {
227  this->m_guardedPortMutex.unLock();
228  }
229 
230  // ----------------------------------------------------------------------
231  // Calls for messages received on typed input ports
232  // ----------------------------------------------------------------------
233 
234  Fw::Buffer StaticMemoryComponentBase ::
235  m_p_bufferAllocate_in(
236  Fw::PassiveComponentBase* callComp,
237  NATIVE_INT_TYPE portNum,
238  U32 size
239  )
240  {
241  FW_ASSERT(callComp);
242  StaticMemoryComponentBase* compPtr = static_cast<StaticMemoryComponentBase*>(callComp);
243  return compPtr->bufferAllocate_handlerBase(
244  portNum,
245  size
246  );
247  }
248 
249  void StaticMemoryComponentBase ::
250  m_p_bufferDeallocate_in(
251  Fw::PassiveComponentBase* callComp,
252  NATIVE_INT_TYPE portNum,
253  Fw::Buffer& fwBuffer
254  )
255  {
256  FW_ASSERT(callComp);
257  StaticMemoryComponentBase* compPtr = static_cast<StaticMemoryComponentBase*>(callComp);
258  compPtr->bufferDeallocate_handlerBase(
259  portNum,
260  fwBuffer
261  );
262  }
263 
264 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
#define PRI_PlatformIntType
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:21
#define FW_OBJ_NAME_MAX_SIZE
Size of object name (if object names enabled). AC Limits to 80, truncation occurs above 80.
Definition: FpConfig.h:184
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
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(NATIVE_INT_TYPE portNum)
StaticMemoryComponentBase(const char *compName="")
Construct StaticMemoryComponentBase object.
NATIVE_INT_TYPE getNum_bufferAllocate_InputPorts() const
void bufferDeallocate_handlerBase(NATIVE_INT_TYPE portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port bufferDeallocate.
NATIVE_INT_TYPE getNum_bufferDeallocate_InputPorts() const
virtual ~StaticMemoryComponentBase()
Destroy StaticMemoryComponentBase object.
Fw::Buffer bufferAllocate_handlerBase(NATIVE_INT_TYPE portNum, U32 size)
Handler base-class function for input port bufferAllocate.
virtual void bufferDeallocate_handler(NATIVE_INT_TYPE portNum, Fw::Buffer &fwBuffer)=0
Handler for input port bufferDeallocate.
Fw::InputBufferSendPort * get_bufferDeallocate_InputPort(NATIVE_INT_TYPE portNum)
virtual void lock()
Lock the guarded mutex.
virtual Fw::Buffer bufferAllocate_handler(NATIVE_INT_TYPE portNum, U32 size)=0
Handler for input port bufferAllocate.
virtual void unLock()
Unlock the guarded mutex.