F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
ActiveTextLoggerComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ActiveTextLoggerComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for ActiveTextLogger 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  namespace {
18  enum MsgTypeEnum {
19  ACTIVETEXTLOGGER_COMPONENT_EXIT = Fw::ActiveComponentBase::ACTIVE_COMPONENT_EXIT,
20  INT_IF_TEXTQUEUE,
21  };
22 
23  // Get the max size by constructing a union of the async input, command, and
24  // internal port serialization sizes
25  union BuffUnion {
26  // Size of TextQueue argument list
27  BYTE TextQueueIntIfSize[
29  ];
30  };
31 
32  // Define a message buffer class large enough to handle all the
33  // asynchronous inputs to the component
34  class ComponentIpcSerializableBuffer :
36  {
37 
38  public:
39 
40  enum {
41  // Max. message size = size of data + message id + port
42  SERIALIZATION_SIZE =
43  sizeof(BuffUnion) +
44  sizeof(NATIVE_INT_TYPE) +
45  sizeof(NATIVE_INT_TYPE)
46  };
47 
48  NATIVE_UINT_TYPE getBuffCapacity() const {
49  return sizeof(m_buff);
50  }
51 
52  U8* getBuffAddr() {
53  return m_buff;
54  }
55 
56  const U8* getBuffAddr() const {
57  return m_buff;
58  }
59 
60  private:
61  // Should be the max of all the input ports serialized sizes...
62  U8 m_buff[SERIALIZATION_SIZE];
63 
64  };
65  }
66 
67  // ----------------------------------------------------------------------
68  // Component initialization
69  // ----------------------------------------------------------------------
70 
72  init(
73  NATIVE_INT_TYPE queueDepth,
74  NATIVE_INT_TYPE instance
75  )
76  {
77  // Initialize base class
79 
80  // Connect input port TextLogger
81  for (
82  PlatformIntType port = 0;
83  port < static_cast<PlatformIntType>(this->getNum_TextLogger_InputPorts());
84  port++
85  ) {
86  this->m_TextLogger_InputPort[port].init();
87  this->m_TextLogger_InputPort[port].addCallComp(
88  this,
89  m_p_TextLogger_in
90  );
91  this->m_TextLogger_InputPort[port].setPortNum(port);
92 
93 #if FW_OBJECT_NAMES == 1
94  // The port name consists of this->m_objName and some extra info.
95  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
96  // However, the compiler may assume that this->m_objName fills
97  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
98  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
99  // bytes to cover the extra info.
100  char portName[2*FW_OBJ_NAME_MAX_SIZE];
101  (void) snprintf(
102  portName,
103  sizeof(portName),
104  "%s_TextLogger_InputPort[%" PRI_PlatformIntType "]",
105  this->m_objName,
106  port
107  );
108  this->m_TextLogger_InputPort[port].setObjName(portName);
109 #endif
110  }
111 
112  Os::Queue::QueueStatus qStat = this->createQueue(
113  queueDepth,
114  ComponentIpcSerializableBuffer::SERIALIZATION_SIZE
115  );
116  FW_ASSERT(
117  Os::Queue::QUEUE_OK == qStat,
118  static_cast<FwAssertArgType>(qStat)
119  );
120  }
121 
122  // ----------------------------------------------------------------------
123  // Getters for typed input ports
124  // ----------------------------------------------------------------------
125 
128  {
129  FW_ASSERT(
130  portNum < this->getNum_TextLogger_InputPorts(),
131  static_cast<FwAssertArgType>(portNum)
132  );
133 
134  return &this->m_TextLogger_InputPort[portNum];
135  }
136 
137  // ----------------------------------------------------------------------
138  // Component construction and destruction
139  // ----------------------------------------------------------------------
140 
142  ActiveTextLoggerComponentBase(const char* compName) :
143  Fw::ActiveComponentBase(compName)
144  {
145 
146  }
147 
150  {
151 
152  }
153 
154  // ----------------------------------------------------------------------
155  // Getters for numbers of typed input ports
156  // ----------------------------------------------------------------------
157 
160  {
161  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_TextLogger_InputPort));
162  }
163 
164  // ----------------------------------------------------------------------
165  // Port handler base-class functions for typed input ports
166  //
167  // Call these functions directly to bypass the corresponding ports
168  // ----------------------------------------------------------------------
169 
172  NATIVE_INT_TYPE portNum,
173  FwEventIdType id,
174  Fw::Time& timeTag,
175  const Fw::LogSeverity& severity,
176  Fw::TextLogString& text
177  )
178  {
179  // Make sure port number is valid
180  FW_ASSERT(
181  portNum < this->getNum_TextLogger_InputPorts(),
182  static_cast<FwAssertArgType>(portNum)
183  );
184 
185  // Call handler function
186  this->TextLogger_handler(
187  portNum,
188  id,
189  timeTag,
190  severity,
191  text
192  );
193  }
194 
195  // ----------------------------------------------------------------------
196  // Internal interface base-class functions
197  // ----------------------------------------------------------------------
198 
201  {
202  ComponentIpcSerializableBuffer msg;
204 
205  // Serialize the message ID
206  _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(INT_IF_TEXTQUEUE));
207  FW_ASSERT (
208  _status == Fw::FW_SERIALIZE_OK,
209  static_cast<FwAssertArgType>(_status)
210  );
211 
212  // Fake port number to make message dequeue work
213  _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(0));
214  FW_ASSERT (
215  _status == Fw::FW_SERIALIZE_OK,
216  static_cast<FwAssertArgType>(_status)
217  );
218 
219  _status = msg.serialize(text);
220  FW_ASSERT(
221  _status == Fw::FW_SERIALIZE_OK,
222  static_cast<FwAssertArgType>(_status)
223  );
224 
225  // Send message
227  Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 1, _block);
228 
229  if (qStatus == Os::Queue::QUEUE_FULL) {
230  this->incNumMsgDropped();
231  return;
232  }
233 
234  FW_ASSERT(
235  qStatus == Os::Queue::QUEUE_OK,
236  static_cast<FwAssertArgType>(qStatus)
237  );
238  }
239 
240  // ----------------------------------------------------------------------
241  // Message dispatch functions
242  // ----------------------------------------------------------------------
243 
244  Fw::QueuedComponentBase::MsgDispatchStatus ActiveTextLoggerComponentBase ::
245  doDispatch()
246  {
247  ComponentIpcSerializableBuffer msg;
248  NATIVE_INT_TYPE priority = 0;
249 
250  Os::Queue::QueueStatus msgStatus = this->m_queue.receive(
251  msg,
252  priority,
254  );
255  FW_ASSERT(
256  msgStatus == Os::Queue::QUEUE_OK,
257  static_cast<FwAssertArgType>(msgStatus)
258  );
259 
260  // Reset to beginning of buffer
261  msg.resetDeser();
262 
263  NATIVE_INT_TYPE desMsg = 0;
264  Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
265  FW_ASSERT(
266  deserStatus == Fw::FW_SERIALIZE_OK,
267  static_cast<FwAssertArgType>(deserStatus)
268  );
269 
270  MsgTypeEnum msgType = static_cast<MsgTypeEnum>(desMsg);
271 
272  if (msgType == ACTIVETEXTLOGGER_COMPONENT_EXIT) {
273  return MSG_DISPATCH_EXIT;
274  }
275 
276  NATIVE_INT_TYPE portNum = 0;
277  deserStatus = msg.deserialize(portNum);
278  FW_ASSERT(
279  deserStatus == Fw::FW_SERIALIZE_OK,
280  static_cast<FwAssertArgType>(deserStatus)
281  );
282 
283  switch (msgType) {
284  // Handle internal interface TextQueue
285  case INT_IF_TEXTQUEUE: {
287  deserStatus = msg.deserialize(text);
288 
289  // Internal interface should always deserialize
290  FW_ASSERT(
291  Fw::FW_SERIALIZE_OK == deserStatus,
292  static_cast<FwAssertArgType>(deserStatus)
293  );
294 
295  // Make sure there was no data left over.
296  // That means the buffer size was incorrect.
297  FW_ASSERT(
298  msg.getBuffLeft() == 0,
299  static_cast<FwAssertArgType>(msg.getBuffLeft())
300  );
301 
302  // Call handler function
304  text
305  );
306 
307  break;
308  }
309 
310  default:
311  return MSG_DISPATCH_ERROR;
312  }
313 
314  return MSG_DISPATCH_OK;
315  }
316 
317  // ----------------------------------------------------------------------
318  // Calls for messages received on typed input ports
319  // ----------------------------------------------------------------------
320 
321  void ActiveTextLoggerComponentBase ::
322  m_p_TextLogger_in(
323  Fw::PassiveComponentBase* callComp,
324  NATIVE_INT_TYPE portNum,
325  FwEventIdType id,
326  Fw::Time& timeTag,
327  const Fw::LogSeverity& severity,
328  Fw::TextLogString& text
329  )
330  {
331  FW_ASSERT(callComp);
332  ActiveTextLoggerComponentBase* compPtr = static_cast<ActiveTextLoggerComponentBase*>(callComp);
333  compPtr->TextLogger_handlerBase(
334  portNum,
335  id,
336  timeTag,
337  severity,
338  text
339  );
340  }
341 
342 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
U8 BYTE
byte type
Definition: BasicTypes.h:27
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
#define PRI_PlatformIntType
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:21
U32 FwEventIdType
Definition: FpConfig.h:62
#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
@ ACTIVE_COMPONENT_EXIT
message to exit active component task
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void init()
Initialization function.
void setPortNum(NATIVE_INT_TYPE portNum)
@ SERIALIZED_SIZE
Serialized size is size of buffer + size field.
Enum representing event severity.
void init()
Object initializer.
Definition: ObjBase.cpp:27
Os::Queue::QueueStatus createQueue(NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
Os::Queue m_queue
queue object for active component
void incNumMsgDropped()
increment the number of messages dropped
@ MSG_DISPATCH_OK
Dispatch was normal.
@ MSG_DISPATCH_EXIT
A message was sent requesting an exit of the loop.
@ MSG_DISPATCH_ERROR
Errors dispatching messages.
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
Definition: StringType.cpp:136
Definition: Time.hpp:9
QueueStatus
Definition: Queue.hpp:27
@ QUEUE_OK
message sent/received okay
Definition: Queue.hpp:28
@ QUEUE_FULL
queue was full when attempting to send a message
Definition: Queue.hpp:36
QueueStatus send(const Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE priority, QueueBlocking block)
send a message
Definition: QueueCommon.cpp:13
QueueStatus receive(Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE &priority, QueueBlocking block)
receive a message
Definition: QueueCommon.cpp:22
QueueBlocking
Definition: Queue.hpp:40
@ QUEUE_BLOCKING
Queue receive blocks until a message arrives.
Definition: Queue.hpp:41
@ QUEUE_NONBLOCKING
Queue receive always returns even if there is no message.
Definition: Queue.hpp:42
ActiveTextLoggerComponentBase(const char *compName="")
Construct ActiveTextLoggerComponentBase object.
void TextLogger_handlerBase(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text)
Handler base-class function for input port TextLogger.
Fw::InputLogTextPort * get_TextLogger_InputPort(NATIVE_INT_TYPE portNum)
void TextQueue_internalInterfaceInvoke(const Fw::InternalInterfaceString &text)
Internal interface base-class function for TextQueue.
virtual ~ActiveTextLoggerComponentBase()
Destroy ActiveTextLoggerComponentBase object.
virtual void TextLogger_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text)=0
Handler for input port TextLogger.
virtual void TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString &text)=0
Internal interface handler for TextQueue.
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.