F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
PolyDbComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title PolyDbComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for PolyDb 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 getValue
28  for (
29  PlatformIntType port = 0;
30  port < static_cast<PlatformIntType>(this->getNum_getValue_InputPorts());
31  port++
32  ) {
33  this->m_getValue_InputPort[port].init();
34  this->m_getValue_InputPort[port].addCallComp(
35  this,
36  m_p_getValue_in
37  );
38  this->m_getValue_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_getValue_InputPort[%" PRI_PlatformIntType "]",
52  this->m_objName,
53  port
54  );
55  this->m_getValue_InputPort[port].setObjName(portName);
56 #endif
57  }
58 
59  // Connect input port setValue
60  for (
61  PlatformIntType port = 0;
62  port < static_cast<PlatformIntType>(this->getNum_setValue_InputPorts());
63  port++
64  ) {
65  this->m_setValue_InputPort[port].init();
66  this->m_setValue_InputPort[port].addCallComp(
67  this,
68  m_p_setValue_in
69  );
70  this->m_setValue_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_setValue_InputPort[%" PRI_PlatformIntType "]",
84  this->m_objName,
85  port
86  );
87  this->m_setValue_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_getValue_InputPorts(),
101  static_cast<FwAssertArgType>(portNum)
102  );
103 
104  return &this->m_getValue_InputPort[portNum];
105  }
106 
109  {
110  FW_ASSERT(
111  portNum < this->getNum_setValue_InputPorts(),
112  static_cast<FwAssertArgType>(portNum)
113  );
114 
115  return &this->m_setValue_InputPort[portNum];
116  }
117 
118  // ----------------------------------------------------------------------
119  // Component construction and destruction
120  // ----------------------------------------------------------------------
121 
123  PolyDbComponentBase(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_getValue_InputPort));
143  }
144 
147  {
148  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_setValue_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 entry,
161  Svc::MeasurementStatus& status,
162  Fw::Time& time,
163  Fw::PolyType& val
164  )
165  {
166  // Make sure port number is valid
167  FW_ASSERT(
168  portNum < this->getNum_getValue_InputPorts(),
169  static_cast<FwAssertArgType>(portNum)
170  );
171 
172  // Lock guard mutex before calling
173  this->lock();
174 
175  // Call handler function
176  this->getValue_handler(
177  portNum,
178  entry,
179  status,
180  time,
181  val
182  );
183 
184  // Unlock guard mutex
185  this->unLock();
186  }
187 
190  NATIVE_INT_TYPE portNum,
191  U32 entry,
192  Svc::MeasurementStatus& status,
193  Fw::Time& time,
194  Fw::PolyType& val
195  )
196  {
197  // Make sure port number is valid
198  FW_ASSERT(
199  portNum < this->getNum_setValue_InputPorts(),
200  static_cast<FwAssertArgType>(portNum)
201  );
202 
203  // Lock guard mutex before calling
204  this->lock();
205 
206  // Call handler function
207  this->setValue_handler(
208  portNum,
209  entry,
210  status,
211  time,
212  val
213  );
214 
215  // Unlock guard mutex
216  this->unLock();
217  }
218 
219  // ----------------------------------------------------------------------
220  // Mutex operations for guarded ports
221  //
222  // You can override these operations to provide more sophisticated
223  // synchronization
224  // ----------------------------------------------------------------------
225 
227  lock()
228  {
229  this->m_guardedPortMutex.lock();
230  }
231 
233  unLock()
234  {
235  this->m_guardedPortMutex.unLock();
236  }
237 
238  // ----------------------------------------------------------------------
239  // Calls for messages received on typed input ports
240  // ----------------------------------------------------------------------
241 
242  void PolyDbComponentBase ::
243  m_p_getValue_in(
244  Fw::PassiveComponentBase* callComp,
245  NATIVE_INT_TYPE portNum,
246  U32 entry,
247  Svc::MeasurementStatus& status,
248  Fw::Time& time,
249  Fw::PolyType& val
250  )
251  {
252  FW_ASSERT(callComp);
253  PolyDbComponentBase* compPtr = static_cast<PolyDbComponentBase*>(callComp);
254  compPtr->getValue_handlerBase(
255  portNum,
256  entry,
257  status,
258  time,
259  val
260  );
261  }
262 
263  void PolyDbComponentBase ::
264  m_p_setValue_in(
265  Fw::PassiveComponentBase* callComp,
266  NATIVE_INT_TYPE portNum,
267  U32 entry,
268  Svc::MeasurementStatus& status,
269  Fw::Time& time,
270  Fw::PolyType& val
271  )
272  {
273  FW_ASSERT(callComp);
274  PolyDbComponentBase* compPtr = static_cast<PolyDbComponentBase*>(callComp);
275  compPtr->setValue_handlerBase(
276  portNum,
277  entry,
278  status,
279  time,
280  val
281  );
282  }
283 
284 }
#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 setPortNum(NATIVE_INT_TYPE portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:27
Definition: Time.hpp:9
void unLock()
unlock the mutex
Definition: Mutex.cpp:13
void lock()
lock the mutex
Definition: Mutex.cpp:12
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Definition: PolyPortAc.cpp:62
void init()
Initialization function.
Definition: PolyPortAc.cpp:56
An enumeration for measurement status.
Auto-generated base for PolyDb component.
virtual void unLock()
Unlock the guarded mutex.
NATIVE_INT_TYPE getNum_setValue_InputPorts() const
virtual void getValue_handler(NATIVE_INT_TYPE portNum, U32 entry, Svc::MeasurementStatus &status, Fw::Time &time, Fw::PolyType &val)=0
Handler for input port getValue.
PolyDbComponentBase(const char *compName="")
Construct PolyDbComponentBase object.
virtual void lock()
Lock the guarded mutex.
Svc::InputPolyPort * get_getValue_InputPort(NATIVE_INT_TYPE portNum)
void getValue_handlerBase(NATIVE_INT_TYPE portNum, U32 entry, Svc::MeasurementStatus &status, Fw::Time &time, Fw::PolyType &val)
Handler base-class function for input port getValue.
virtual void setValue_handler(NATIVE_INT_TYPE portNum, U32 entry, Svc::MeasurementStatus &status, Fw::Time &time, Fw::PolyType &val)=0
Handler for input port setValue.
NATIVE_INT_TYPE getNum_getValue_InputPorts() const
void setValue_handlerBase(NATIVE_INT_TYPE portNum, U32 entry, Svc::MeasurementStatus &status, Fw::Time &time, Fw::PolyType &val)
Handler base-class function for input port setValue.
virtual ~PolyDbComponentBase()
Destroy PolyDbComponentBase object.
Svc::InputPolyPort * get_setValue_InputPort(NATIVE_INT_TYPE portNum)