F´ Flight Software - C/C++ Documentation
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 "Fw/Types/Assert.hpp"
9 #if FW_ENABLE_TEXT_LOGGING
10 #include "Fw/Types/String.hpp"
11 #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  // Offset into data in buffer: Size of message ID and port number
41  DATA_OFFSET = sizeof(FwEnumStoreType) + sizeof(FwIndexType),
42  // Max data size
43  MAX_DATA_SIZE = sizeof(BuffUnion),
44  // Max message size: Size of message id + size of port + max data size
45  SERIALIZATION_SIZE = DATA_OFFSET + MAX_DATA_SIZE
46  };
47 
48  ComponentIpcSerializableBuffer() : Fw::LinearBufferBase(m_buff, sizeof(m_buff)) {
49 
50  }
51 
52  private:
53  // Should be the max of all the input ports serialized sizes...
54  U8 m_buff[SERIALIZATION_SIZE];
55 
56  };
57  }
58 
59  // ----------------------------------------------------------------------
60  // Component initialization
61  // ----------------------------------------------------------------------
62 
65  FwSizeType queueDepth,
66  FwEnumStoreType instance
67  )
68  {
69  // Initialize base class
71 
72 #if !FW_DIRECT_PORT_CALLS
73  // Connect input port TextLogger
74  for (
75  FwIndexType port = 0;
76  port < static_cast<FwIndexType>(this->getNum_TextLogger_InputPorts());
77  port++
78  ) {
79  this->m_TextLogger_InputPort[port].init();
80  this->m_TextLogger_InputPort[port].addCallComp(
81  this,
82  m_p_TextLogger_in
83  );
84  this->m_TextLogger_InputPort[port].setPortNum(port);
85 
86 #if FW_OBJECT_NAMES == 1
87  Fw::ObjectName portName;
88  portName.format(
89  "%s_TextLogger_InputPort[%" PRI_FwIndexType "]",
90  this->m_objName.toChar(),
91  port
92  );
93  this->m_TextLogger_InputPort[port].setObjName(portName.toChar());
94 #endif
95  }
96 #endif
97 
98  // Create the queue
99  Os::Queue::Status qStat = this->createQueue(
100  queueDepth,
101  static_cast<FwSizeType>(ComponentIpcSerializableBuffer::SERIALIZATION_SIZE)
102  );
103  FW_ASSERT(
104  Os::Queue::Status::OP_OK == qStat,
105  static_cast<FwAssertArgType>(qStat)
106  );
107  }
108 
109 #if !FW_DIRECT_PORT_CALLS
110 
111  // ----------------------------------------------------------------------
112  // Getters for typed input ports
113  // ----------------------------------------------------------------------
114 
117  {
118  FW_ASSERT(
119  (0 <= portNum) && (portNum < this->getNum_TextLogger_InputPorts()),
120  static_cast<FwAssertArgType>(portNum)
121  );
122 
123  return &this->m_TextLogger_InputPort[portNum];
124  }
125 
126 #endif
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  // Port handler base-class functions for typed input ports
147  //
148  // Call these functions directly to bypass the corresponding ports
149  // ----------------------------------------------------------------------
150 
153  FwIndexType portNum,
154  FwEventIdType id,
155  Fw::Time& timeTag,
156  const Fw::LogSeverity& severity,
157  Fw::TextLogString& text
158  )
159  {
160  // Make sure port number is valid
161  FW_ASSERT(
162  (0 <= portNum) && (portNum < this->getNum_TextLogger_InputPorts()),
163  static_cast<FwAssertArgType>(portNum)
164  );
165 
166  // Call handler function
167  this->TextLogger_handler(
168  portNum,
169  id,
170  timeTag,
171  severity,
172  text
173  );
174  }
175 
176  // ----------------------------------------------------------------------
177  // Internal interface base-class functions
178  // ----------------------------------------------------------------------
179 
182  {
183  ComponentIpcSerializableBuffer msg;
185 
186  // Serialize the message ID
187  _status = msg.serializeFrom(static_cast<FwEnumStoreType>(INT_IF_TEXTQUEUE));
188  FW_ASSERT (
189  _status == Fw::FW_SERIALIZE_OK,
190  static_cast<FwAssertArgType>(_status)
191  );
192 
193  // Fake port number to make message dequeue work
194  _status = msg.serializeFrom(static_cast<FwIndexType>(0));
195  FW_ASSERT (
196  _status == Fw::FW_SERIALIZE_OK,
197  static_cast<FwAssertArgType>(_status)
198  );
199 
200  _status = msg.serializeFrom(text);
201  FW_ASSERT(
202  _status == Fw::FW_SERIALIZE_OK,
203  static_cast<FwAssertArgType>(_status)
204  );
205 
206  // Send message
208  Os::Queue::Status qStatus = this->m_queue.send(msg, 0, _block);
209 
210  if (qStatus == Os::Queue::Status::FULL) {
211  this->incNumMsgDropped();
212  return;
213  }
214 
215  FW_ASSERT(
216  qStatus == Os::Queue::OP_OK,
217  static_cast<FwAssertArgType>(qStatus)
218  );
219  }
220 
221  // ----------------------------------------------------------------------
222  // Message dispatch functions
223  // ----------------------------------------------------------------------
224 
225  Fw::QueuedComponentBase::MsgDispatchStatus ActiveTextLoggerComponentBase ::
226  doDispatch()
227  {
228  ComponentIpcSerializableBuffer _msg;
229  FwQueuePriorityType _priority = 0;
230 
231  Os::Queue::Status _msgStatus = this->m_queue.receive(
232  _msg,
234  _priority
235  );
236  FW_ASSERT(
237  _msgStatus == Os::Queue::OP_OK,
238  static_cast<FwAssertArgType>(_msgStatus)
239  );
240 
241  // Reset to beginning of buffer
242  _msg.resetDeser();
243 
244  FwEnumStoreType _desMsg = 0;
245  Fw::SerializeStatus _deserStatus = _msg.deserializeTo(_desMsg);
246  FW_ASSERT(
247  _deserStatus == Fw::FW_SERIALIZE_OK,
248  static_cast<FwAssertArgType>(_deserStatus)
249  );
250 
251  MsgTypeEnum _msgType = static_cast<MsgTypeEnum>(_desMsg);
252 
253  if (_msgType == ACTIVETEXTLOGGER_COMPONENT_EXIT) {
254  return MSG_DISPATCH_EXIT;
255  }
256 
257  FwIndexType portNum = 0;
258  _deserStatus = _msg.deserializeTo(portNum);
259  FW_ASSERT(
260  _deserStatus == Fw::FW_SERIALIZE_OK,
261  static_cast<FwAssertArgType>(_deserStatus)
262  );
263 
264  switch (_msgType) {
265  // Handle internal interface TextQueue
266  case INT_IF_TEXTQUEUE: {
268  _deserStatus = _msg.deserializeTo(text);
269 
270  // Internal interface should always deserialize
271  FW_ASSERT(
272  Fw::FW_SERIALIZE_OK == _deserStatus,
273  static_cast<FwAssertArgType>(_deserStatus)
274  );
275 
276  // Make sure there was no data left over.
277  // That means the buffer size was incorrect.
278  FW_ASSERT(
279  _msg.getDeserializeSizeLeft() == 0,
280  static_cast<FwAssertArgType>(_msg.getDeserializeSizeLeft())
281  );
282 
283  // Call handler function
285  text
286  );
287 
288  break;
289  }
290 
291  default:
292  return MSG_DISPATCH_ERROR;
293  }
294 
295  return MSG_DISPATCH_OK;
296  }
297 
298  // ----------------------------------------------------------------------
299  // Calls for messages received on typed input ports
300  // ----------------------------------------------------------------------
301 
302  void ActiveTextLoggerComponentBase ::
303  m_p_TextLogger_in(
304  Fw::PassiveComponentBase* callComp,
305  FwIndexType portNum,
306  FwEventIdType id,
307  Fw::Time& timeTag,
308  const Fw::LogSeverity& severity,
309  Fw::TextLogString& text
310  )
311  {
312  FW_ASSERT(callComp != nullptr);
313  ActiveTextLoggerComponentBase* compPtr = static_cast<ActiveTextLoggerComponentBase*>(callComp);
314  compPtr->TextLogger_handlerBase(
315  portNum,
316  id,
317  timeTag,
318  severity,
319  text
320  );
321  }
322 
323 }
Serialization/Deserialization operation was successful.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
virtual void TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString &text)=0
Internal interface handler for TextQueue.
Operation succeeded.
Definition: Os.hpp:27
void init()
Initialization function.
PlatformSizeType FwSizeType
Status receive(U8 *destination, FwSizeType capacity, BlockingType blockType, FwSizeType &actualSize, FwQueuePriorityType &priority) override
receive a message from the queue through delegate
Definition: Queue.cpp:71
I32 FwEnumStoreType
Status
status returned from the queue send function
Definition: Queue.hpp:30
message to exit active component task
virtual void TextLogger_handler(FwIndexType portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text)=0
Handler for input port TextLogger.
ActiveTextLoggerComponentBase(const char *compName="")
Construct ActiveTextLoggerComponentBase object.
Os::Queue m_queue
queue object for active component
void init()
Object initializer.
Definition: ObjBase.cpp:24
SerializeStatus
forward declaration for string
Message will block until space is available.
Definition: Queue.hpp:47
FwIdType FwEventIdType
The type of an event identifier.
Os::Queue::Status createQueue(FwSizeType depth, FwSizeType msgSize)
virtual ~ActiveTextLoggerComponentBase()
Destroy ActiveTextLoggerComponentBase object.
Fw::InputLogTextPort * get_TextLogger_InputPort(FwIndexType portNum)
Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override
send a message into the queue through delegate
Definition: Queue.cpp:54
const char * toChar() const
Convert to a C-style char*.
Enum representing event severity.
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:58
void setPortNum(FwIndexType portNum)
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
BlockingType
message type
Definition: Queue.hpp:46
PlatformQueuePriorityType FwQueuePriorityType
The type of queue priorities used.
A message was sent requesting an exit of the loop.
PlatformIndexType FwIndexType
void incNumMsgDropped()
increment the number of messages dropped
RateGroupDivider component implementation.
message sent/received okay
Definition: Queue.hpp:31
U8 BYTE
byte type
Definition: BasicTypes.h:57
Message will return with status when space is unavailable.
Definition: Queue.hpp:48
Implementation of malloc based allocator.
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.
static constexpr FwIndexType getNum_TextLogger_InputPorts()
void TextQueue_internalInterfaceInvoke(const Fw::InternalInterfaceString &text)
Internal interface base-class function for TextQueue.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.