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  Fw::Serializable::SizeType getCapacity() 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 
73  FwSizeType queueDepth,
74  FwEnumStoreType instance
75  )
76  {
77  // Initialize base class
79 
80 #if !FW_DIRECT_PORT_CALLS
81  // Connect input port TextLogger
82  for (
83  FwIndexType port = 0;
84  port < static_cast<FwIndexType>(this->getNum_TextLogger_InputPorts());
85  port++
86  ) {
87  this->m_TextLogger_InputPort[port].init();
88  this->m_TextLogger_InputPort[port].addCallComp(
89  this,
90  m_p_TextLogger_in
91  );
92  this->m_TextLogger_InputPort[port].setPortNum(port);
93 
94 #if FW_OBJECT_NAMES == 1
95  Fw::ObjectName portName;
96  portName.format(
97  "%s_TextLogger_InputPort[%" PRI_FwIndexType "]",
98  this->m_objName.toChar(),
99  port
100  );
101  this->m_TextLogger_InputPort[port].setObjName(portName.toChar());
102 #endif
103  }
104 #endif
105 
106  // Create the queue
107  Os::Queue::Status qStat = this->createQueue(
108  queueDepth,
109  static_cast<FwSizeType>(ComponentIpcSerializableBuffer::SERIALIZATION_SIZE)
110  );
111  FW_ASSERT(
112  Os::Queue::Status::OP_OK == qStat,
113  static_cast<FwAssertArgType>(qStat)
114  );
115  }
116 
117 #if !FW_DIRECT_PORT_CALLS
118 
119  // ----------------------------------------------------------------------
120  // Getters for typed input ports
121  // ----------------------------------------------------------------------
122 
125  {
126  FW_ASSERT(
127  (0 <= portNum) && (portNum < this->getNum_TextLogger_InputPorts()),
128  static_cast<FwAssertArgType>(portNum)
129  );
130 
131  return &this->m_TextLogger_InputPort[portNum];
132  }
133 
134 #endif
135 
136  // ----------------------------------------------------------------------
137  // Component construction and destruction
138  // ----------------------------------------------------------------------
139 
141  ActiveTextLoggerComponentBase(const char* compName) :
142  Fw::ActiveComponentBase(compName)
143  {
144 
145  }
146 
149  {
150 
151  }
152 
153  // ----------------------------------------------------------------------
154  // Port handler base-class functions for typed input ports
155  //
156  // Call these functions directly to bypass the corresponding ports
157  // ----------------------------------------------------------------------
158 
161  FwIndexType portNum,
162  FwEventIdType id,
163  Fw::Time& timeTag,
164  const Fw::LogSeverity& severity,
165  Fw::TextLogString& text
166  )
167  {
168  // Make sure port number is valid
169  FW_ASSERT(
170  (0 <= portNum) && (portNum < this->getNum_TextLogger_InputPorts()),
171  static_cast<FwAssertArgType>(portNum)
172  );
173 
174  // Call handler function
175  this->TextLogger_handler(
176  portNum,
177  id,
178  timeTag,
179  severity,
180  text
181  );
182  }
183 
184  // ----------------------------------------------------------------------
185  // Internal interface base-class functions
186  // ----------------------------------------------------------------------
187 
190  {
191  ComponentIpcSerializableBuffer msg;
193 
194  // Serialize the message ID
195  _status = msg.serializeFrom(static_cast<FwEnumStoreType>(INT_IF_TEXTQUEUE));
196  FW_ASSERT (
197  _status == Fw::FW_SERIALIZE_OK,
198  static_cast<FwAssertArgType>(_status)
199  );
200 
201  // Fake port number to make message dequeue work
202  _status = msg.serializeFrom(static_cast<FwIndexType>(0));
203  FW_ASSERT (
204  _status == Fw::FW_SERIALIZE_OK,
205  static_cast<FwAssertArgType>(_status)
206  );
207 
208  _status = msg.serializeFrom(text);
209  FW_ASSERT(
210  _status == Fw::FW_SERIALIZE_OK,
211  static_cast<FwAssertArgType>(_status)
212  );
213 
214  // Send message
216  Os::Queue::Status qStatus = this->m_queue.send(msg, 0, _block);
217 
218  if (qStatus == Os::Queue::Status::FULL) {
219  this->incNumMsgDropped();
220  return;
221  }
222 
223  FW_ASSERT(
224  qStatus == Os::Queue::OP_OK,
225  static_cast<FwAssertArgType>(qStatus)
226  );
227  }
228 
229  // ----------------------------------------------------------------------
230  // Message dispatch functions
231  // ----------------------------------------------------------------------
232 
233  Fw::QueuedComponentBase::MsgDispatchStatus ActiveTextLoggerComponentBase ::
234  doDispatch()
235  {
236  ComponentIpcSerializableBuffer _msg;
237  FwQueuePriorityType _priority = 0;
238 
239  Os::Queue::Status _msgStatus = this->m_queue.receive(
240  _msg,
242  _priority
243  );
244  FW_ASSERT(
245  _msgStatus == Os::Queue::OP_OK,
246  static_cast<FwAssertArgType>(_msgStatus)
247  );
248 
249  // Reset to beginning of buffer
250  _msg.resetDeser();
251 
252  FwEnumStoreType _desMsg = 0;
253  Fw::SerializeStatus _deserStatus = _msg.deserializeTo(_desMsg);
254  FW_ASSERT(
255  _deserStatus == Fw::FW_SERIALIZE_OK,
256  static_cast<FwAssertArgType>(_deserStatus)
257  );
258 
259  MsgTypeEnum _msgType = static_cast<MsgTypeEnum>(_desMsg);
260 
261  if (_msgType == ACTIVETEXTLOGGER_COMPONENT_EXIT) {
262  return MSG_DISPATCH_EXIT;
263  }
264 
265  FwIndexType portNum = 0;
266  _deserStatus = _msg.deserializeTo(portNum);
267  FW_ASSERT(
268  _deserStatus == Fw::FW_SERIALIZE_OK,
269  static_cast<FwAssertArgType>(_deserStatus)
270  );
271 
272  switch (_msgType) {
273  // Handle internal interface TextQueue
274  case INT_IF_TEXTQUEUE: {
276  _deserStatus = _msg.deserializeTo(text);
277 
278  // Internal interface should always deserialize
279  FW_ASSERT(
280  Fw::FW_SERIALIZE_OK == _deserStatus,
281  static_cast<FwAssertArgType>(_deserStatus)
282  );
283 
284  // Make sure there was no data left over.
285  // That means the buffer size was incorrect.
286  FW_ASSERT(
287  _msg.getDeserializeSizeLeft() == 0,
288  static_cast<FwAssertArgType>(_msg.getDeserializeSizeLeft())
289  );
290 
291  // Call handler function
293  text
294  );
295 
296  break;
297  }
298 
299  default:
300  return MSG_DISPATCH_ERROR;
301  }
302 
303  return MSG_DISPATCH_OK;
304  }
305 
306  // ----------------------------------------------------------------------
307  // Calls for messages received on typed input ports
308  // ----------------------------------------------------------------------
309 
310  void ActiveTextLoggerComponentBase ::
311  m_p_TextLogger_in(
312  Fw::PassiveComponentBase* callComp,
313  FwIndexType portNum,
314  FwEventIdType id,
315  Fw::Time& timeTag,
316  const Fw::LogSeverity& severity,
317  Fw::TextLogString& text
318  )
319  {
320  FW_ASSERT(callComp);
321  ActiveTextLoggerComponentBase* compPtr = static_cast<ActiveTextLoggerComponentBase*>(callComp);
322  compPtr->TextLogger_handlerBase(
323  portNum,
324  id,
325  timeTag,
326  severity,
327  text
328  );
329  }
330 
331 }
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:26
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
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)
const char * toChar() const
Convert to a C-style char*.
Definition: ObjectName.hpp:50
FwSizeType SizeType
Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override
send a message into the queue through delegate
Definition: Queue.cpp:54
Enum representing event severity.
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
void setPortNum(FwIndexType portNum)
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
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:56
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.
message to exit active component task
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.