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 
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  namespace {
17  enum MsgTypeEnum {
18  ACTIVETEXTLOGGER_COMPONENT_EXIT = Fw::ActiveComponentBase::ACTIVE_COMPONENT_EXIT,
19  INT_IF_TEXTQUEUE,
20  };
21 
22  // Get the max size by constructing a union of the async input, command, and
23  // internal port serialization sizes
24  union BuffUnion {
25  // Size of TextQueue argument list
26  BYTE TextQueueIntIfSize[
28  ];
29  };
30 
31  // Define a message buffer class large enough to handle all the
32  // asynchronous inputs to the component
33  class ComponentIpcSerializableBuffer :
35  {
36 
37  public:
38 
39  enum {
40  // Max. message size = size of data + message id + port
41  SERIALIZATION_SIZE =
42  sizeof(BuffUnion) +
43  sizeof(FwEnumStoreType) +
44  sizeof(FwIndexType)
45  };
46 
47  Fw::Serializable::SizeType getBuffCapacity() const {
48  return sizeof(m_buff);
49  }
50 
51  U8* getBuffAddr() {
52  return m_buff;
53  }
54 
55  const U8* getBuffAddr() const {
56  return m_buff;
57  }
58 
59  private:
60  // Should be the max of all the input ports serialized sizes...
61  U8 m_buff[SERIALIZATION_SIZE];
62 
63  };
64  }
65 
66  // ----------------------------------------------------------------------
67  // Component initialization
68  // ----------------------------------------------------------------------
69 
71  init(
72  FwQueueSizeType queueDepth,
73  FwEnumStoreType instance
74  )
75  {
76  // Initialize base class
78 
79  // Connect input port TextLogger
80  for (
81  FwIndexType port = 0;
82  port < static_cast<FwIndexType>(this->getNum_TextLogger_InputPorts());
83  port++
84  ) {
85  this->m_TextLogger_InputPort[port].init();
86  this->m_TextLogger_InputPort[port].addCallComp(
87  this,
88  m_p_TextLogger_in
89  );
90  this->m_TextLogger_InputPort[port].setPortNum(port);
91 
92 #if FW_OBJECT_NAMES == 1
93  Fw::ObjectName portName;
94  portName.format(
95  "%s_TextLogger_InputPort[%" PRI_PlatformIntType "]",
96  this->m_objName.toChar(),
97  port
98  );
99  this->m_TextLogger_InputPort[port].setObjName(portName.toChar());
100 #endif
101  }
102 
103  Os::Queue::QueueStatus qStat = this->createQueue(
104  queueDepth,
105  ComponentIpcSerializableBuffer::SERIALIZATION_SIZE
106  );
107  FW_ASSERT(
108  Os::Queue::QUEUE_OK == qStat,
109  static_cast<FwAssertArgType>(qStat)
110  );
111  }
112 
113  // ----------------------------------------------------------------------
114  // Getters for typed input ports
115  // ----------------------------------------------------------------------
116 
119  {
120  FW_ASSERT(
121  portNum < this->getNum_TextLogger_InputPorts(),
122  static_cast<FwAssertArgType>(portNum)
123  );
124 
125  return &this->m_TextLogger_InputPort[portNum];
126  }
127 
128  // ----------------------------------------------------------------------
129  // Component construction and destruction
130  // ----------------------------------------------------------------------
131 
133  ActiveTextLoggerComponentBase(const char* compName) :
134  Fw::ActiveComponentBase(compName)
135  {
136 
137  }
138 
141  {
142 
143  }
144 
145  // ----------------------------------------------------------------------
146  // Getters for numbers of typed input ports
147  // ----------------------------------------------------------------------
148 
151  {
152  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_TextLogger_InputPort));
153  }
154 
155  // ----------------------------------------------------------------------
156  // Port handler base-class functions for typed input ports
157  //
158  // Call these functions directly to bypass the corresponding ports
159  // ----------------------------------------------------------------------
160 
163  FwIndexType portNum,
164  FwEventIdType id,
165  Fw::Time& timeTag,
166  const Fw::LogSeverity& severity,
167  Fw::TextLogString& text
168  )
169  {
170  // Make sure port number is valid
171  FW_ASSERT(
172  portNum < this->getNum_TextLogger_InputPorts(),
173  static_cast<FwAssertArgType>(portNum)
174  );
175 
176  // Call handler function
177  this->TextLogger_handler(
178  portNum,
179  id,
180  timeTag,
181  severity,
182  text
183  );
184  }
185 
186  // ----------------------------------------------------------------------
187  // Internal interface base-class functions
188  // ----------------------------------------------------------------------
189 
192  {
193  ComponentIpcSerializableBuffer msg;
195 
196  // Serialize the message ID
197  _status = msg.serialize(static_cast<FwEnumStoreType>(INT_IF_TEXTQUEUE));
198  FW_ASSERT (
199  _status == Fw::FW_SERIALIZE_OK,
200  static_cast<FwAssertArgType>(_status)
201  );
202 
203  // Fake port number to make message dequeue work
204  _status = msg.serialize(static_cast<FwIndexType>(0));
205  FW_ASSERT (
206  _status == Fw::FW_SERIALIZE_OK,
207  static_cast<FwAssertArgType>(_status)
208  );
209 
210  _status = msg.serialize(text);
211  FW_ASSERT(
212  _status == Fw::FW_SERIALIZE_OK,
213  static_cast<FwAssertArgType>(_status)
214  );
215 
216  // Send message
218  Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 1, _block);
219 
220  if (qStatus == Os::Queue::QUEUE_FULL) {
221  this->incNumMsgDropped();
222  return;
223  }
224 
225  FW_ASSERT(
226  qStatus == Os::Queue::QUEUE_OK,
227  static_cast<FwAssertArgType>(qStatus)
228  );
229  }
230 
231  // ----------------------------------------------------------------------
232  // Message dispatch functions
233  // ----------------------------------------------------------------------
234 
235  Fw::QueuedComponentBase::MsgDispatchStatus ActiveTextLoggerComponentBase ::
236  doDispatch()
237  {
238  ComponentIpcSerializableBuffer msg;
239  FwQueuePriorityType priority = 0;
240 
241  Os::Queue::QueueStatus msgStatus = this->m_queue.receive(
242  msg,
243  priority,
245  );
246  FW_ASSERT(
247  msgStatus == Os::Queue::QUEUE_OK,
248  static_cast<FwAssertArgType>(msgStatus)
249  );
250 
251  // Reset to beginning of buffer
252  msg.resetDeser();
253 
254  FwEnumStoreType desMsg = 0;
255  Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
256  FW_ASSERT(
257  deserStatus == Fw::FW_SERIALIZE_OK,
258  static_cast<FwAssertArgType>(deserStatus)
259  );
260 
261  MsgTypeEnum msgType = static_cast<MsgTypeEnum>(desMsg);
262 
263  if (msgType == ACTIVETEXTLOGGER_COMPONENT_EXIT) {
264  return MSG_DISPATCH_EXIT;
265  }
266 
267  FwIndexType portNum = 0;
268  deserStatus = msg.deserialize(portNum);
269  FW_ASSERT(
270  deserStatus == Fw::FW_SERIALIZE_OK,
271  static_cast<FwAssertArgType>(deserStatus)
272  );
273 
274  switch (msgType) {
275  // Handle internal interface TextQueue
276  case INT_IF_TEXTQUEUE: {
278  deserStatus = msg.deserialize(text);
279 
280  // Internal interface should always deserialize
281  FW_ASSERT(
282  Fw::FW_SERIALIZE_OK == deserStatus,
283  static_cast<FwAssertArgType>(deserStatus)
284  );
285 
286  // Make sure there was no data left over.
287  // That means the buffer size was incorrect.
288  FW_ASSERT(
289  msg.getBuffLeft() == 0,
290  static_cast<FwAssertArgType>(msg.getBuffLeft())
291  );
292 
293  // Call handler function
295  text
296  );
297 
298  break;
299  }
300 
301  default:
302  return MSG_DISPATCH_ERROR;
303  }
304 
305  return MSG_DISPATCH_OK;
306  }
307 
308  // ----------------------------------------------------------------------
309  // Calls for messages received on typed input ports
310  // ----------------------------------------------------------------------
311 
312  void ActiveTextLoggerComponentBase ::
313  m_p_TextLogger_in(
314  Fw::PassiveComponentBase* callComp,
315  FwIndexType portNum,
316  FwEventIdType id,
317  Fw::Time& timeTag,
318  const Fw::LogSeverity& severity,
319  Fw::TextLogString& text
320  )
321  {
322  FW_ASSERT(callComp);
323  ActiveTextLoggerComponentBase* compPtr = static_cast<ActiveTextLoggerComponentBase*>(callComp);
324  compPtr->TextLogger_handlerBase(
325  portNum,
326  id,
327  timeTag,
328  severity,
329  text
330  );
331  }
332 
333 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
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
#define PRI_PlatformIntType
I32 FwEnumStoreType
Definition: FpConfig.h:51
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:34
U32 FwEventIdType
Definition: FpConfig.h:86
FwIndexType FwQueueSizeType
Definition: FpConfig.h:117
I32 FwQueuePriorityType
Definition: FpConfig.h:98
PlatformIndexType FwIndexType
Definition: FpConfig.h:20
@ 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)
Enum representing event severity.
void init()
Object initializer.
Definition: ObjBase.cpp:27
const char * toChar() const
Definition: ObjectName.hpp:50
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.
NATIVE_UINT_TYPE SizeType
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
Definition: StringBase.cpp:147
void format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:56
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.
Fw::InputLogTextPort * get_TextLogger_InputPort(FwIndexType portNum)
void TextQueue_internalInterfaceInvoke(const Fw::InternalInterfaceString &text)
Internal interface base-class function for TextQueue.
virtual void TextLogger_handler(FwIndexType portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text)=0
Handler for input port TextLogger.
virtual ~ActiveTextLoggerComponentBase()
Destroy ActiveTextLoggerComponentBase object.
void TextLogger_handlerBase(FwIndexType portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text)
Handler base-class function 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.