F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
A framework for building embedded system applications to NASA flight quality standards.
LogPortAc.cpp
Go to the documentation of this file.
1 #include <FpConfig.hpp>
2 #include <Fw/Types/Assert.hpp>
4 
5 #include <Fw/Log/LogPortAc.hpp>
6 namespace Fw {
7 
8 
9  namespace {
10 
11  class LogPortBuffer : public Fw::SerializeBufferBase {
12 
13  public:
14  NATIVE_UINT_TYPE getBuffCapacity(void) const {
15  return sizeof(m_buff);
16  }
17 
18  U8* getBuffAddr(void) {
19  return m_buff;
20  }
21 
22  const U8* getBuffAddr(void) const {
23  return m_buff;
24  }
25 
26  private:
27 
29 
30  };
31 
32  }
34  Fw::InputPortBase(),
35  m_func(0) {
36  }
37 
38  void InputLogPort::init(void) {
40  }
41 
42  void InputLogPort::addCallComp(Fw::PassiveComponentBase* callComp, CompFuncPtr funcPtr) {
43  FW_ASSERT(callComp);
44  FW_ASSERT(funcPtr);
45 
46  this->m_comp = callComp;
47  this->m_func = funcPtr;
48  this->m_connObj = callComp;
49  }
50 
51  // call virtual logging function for component
52  void InputLogPort::invoke(FwEventIdType id, Fw::Time &timeTag, LogSeverity severity, LogBuffer &args) {
53 
54 #if FW_PORT_TRACING == 1
55  this->trace();
56 #endif
57  FW_ASSERT(this->m_comp);
58  FW_ASSERT(this->m_func);
59  this->m_func(this->m_comp, this->m_portNum, id, timeTag, severity, args);
60  }
61 
62 #if FW_PORT_SERIALIZATION == 1
63  Fw::SerializeStatus InputLogPort::invokeSerial(Fw::SerializeBufferBase &buffer) {
64  Fw::SerializeStatus _status;
65 #if FW_PORT_TRACING == 1
66  this->trace();
67 #endif
68  FW_ASSERT(this->m_comp);
69  FW_ASSERT(this->m_func);
70 
71 
72  FwEventIdType id;
73  _status = buffer.deserialize(id);
74  if (Fw::FW_SERIALIZE_OK != _status) {
75  return _status;
76  }
77 
78  Fw::Time timeTag;
79  _status = buffer.deserialize(timeTag);
80  if (Fw::FW_SERIALIZE_OK != _status) {
81  return _status;
82  }
83  FwEnumStoreType severity_val;
84  _status = buffer.deserialize(severity_val);
85  if (Fw::FW_SERIALIZE_OK != _status) {
86  return _status;
87  }
88  LogSeverity severity = static_cast<LogSeverity>(severity_val);
89 
90  LogBuffer args;
91  _status = buffer.deserialize(args);
92  if (Fw::FW_SERIALIZE_OK != _status) {
93  return _status;
94  }
95 
96  this->m_func(this->m_comp, this->m_portNum, id, timeTag, severity, args);
97 
98  return Fw::FW_SERIALIZE_OK;
99  }
100 #endif
101 
103  Fw::OutputPortBase(),
104  m_port(0) {
105 }
106 
109 }
110 
112  FW_ASSERT(callPort);
113 
114  this->m_port = callPort;
115  this->m_connObj = callPort;
116 #if FW_PORT_SERIALIZATION == 1
117  this->m_serPort = 0;
118 #endif
119 }
120 
121 void OutputLogPort::invoke(FwEventIdType id, Fw::Time &timeTag, LogSeverity severity, LogBuffer &args) {
122 #if FW_PORT_TRACING == 1
123  this->trace();
124 #endif
125 
126 #if FW_PORT_SERIALIZATION
127  FW_ASSERT(this->m_port||this->m_serPort);
128 #else
129  FW_ASSERT(this->m_port);
130 #endif
131 
132  if (this->m_port) {
133  this->m_port->invoke(id, timeTag, severity, args);
134 #if FW_PORT_SERIALIZATION
135  } else if (this->m_serPort) {
136 
137  Fw::SerializeStatus status;
138 
139  LogPortBuffer _buffer;
140  status = _buffer.serialize(id);
141  FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<AssertArg>(status));
142 
143  status = _buffer.serialize(timeTag);
144  FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<AssertArg>(status));
145 
146  status = _buffer.serialize(static_cast<NATIVE_INT_TYPE>(severity));
147  FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<AssertArg>(status));
148 
149  status = _buffer.serialize(args);
150  FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<AssertArg>(status));
151 
152  status = this->m_serPort->invokeSerial(_buffer);
153  FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<AssertArg>(status));
154  }
155 #else
156  }
157 #endif
158 
159 } // end OutputLogPort::invoke(...)
160 
161 } // end namespace Fw
Fw::Time
Definition: Time.hpp:10
Fw::InputPortBase::m_portNum
NATIVE_INT_TYPE m_portNum
Definition: InputPortBase.hpp:29
Fw::SerializeBufferBase
Definition: Serializable.hpp:43
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Serializable.hpp
Fw::OutputLogPort::invoke
void invoke(FwEventIdType id, Fw::Time &timeTag, LogSeverity severity, LogBuffer &args)
Definition: LogPortAc.cpp:121
Fw::OutputPortBase::init
virtual void init(void)
Definition: OutputPortBase.cpp:23
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
FwEnumStoreType
#define FwEnumStoreType
Type representation for an enumeration value.
Definition: FpConfig.hpp:84
Fw::LogBuffer
Definition: LogBuffer.hpp:22
Fw::LogSeverity
LogSeverity
Definition: LogPortAc.hpp:26
Assert.hpp
Fw::FW_SERIALIZE_OK
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
Definition: Serializable.hpp:15
Fw::PassiveComponentBase
Definition: PassiveComponentBase.hpp:10
Fw::OutputLogPort::init
void init(void)
Definition: LogPortAc.cpp:107
Fw::InputPortBase
Definition: InputPortBase.hpp:14
Fw::InputLogPort::addCallComp
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
call to register a component
Definition: LogPortAc.cpp:42
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Fw::InputLogPort::InputLogPort
InputLogPort(void)
constructor
Definition: LogPortAc.cpp:33
Fw::OutputLogPort::OutputLogPort
OutputLogPort(void)
Definition: LogPortAc.cpp:102
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::InputLogPort::invoke
void invoke(FwEventIdType id, Fw::Time &timeTag, LogSeverity severity, LogBuffer &args)
invoke port interface
Definition: LogPortAc.cpp:52
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:292
FpConfig.hpp
ISF configuration file.
Fw::OutputLogPort::addCallPort
void addCallPort(InputLogPort *callPort)
Definition: LogPortAc.cpp:111
Fw::OutputPortBase
Definition: OutputPortBase.hpp:13
Fw::InputPortBase::m_comp
PassiveComponentBase * m_comp
Definition: InputPortBase.hpp:28
Fw::InputPortBase::init
virtual void init(void)
Definition: InputPortBase.cpp:20
Fw::InputLogPort
Definition: LogPortAc.hpp:40
Fw::PortBase::m_connObj
Fw::ObjBase * m_connObj
Definition: PortBase.hpp:33
FwEventIdType
#define FwEventIdType
Type representation for a event id.
Definition: FpConfig.hpp:70
Fw::InputLogPort::init
void init(void)
initialization function
Definition: LogPortAc.cpp:38
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
AssertArg
#define AssertArg
Definition: FpConfig.hpp:51
LogPortAc.hpp
Fw
Definition: BufferGetPortAc.cpp:6
Fw::InputLogPort::SERIALIZED_SIZE
@ SERIALIZED_SIZE
serialized size of port arguments
Definition: LogPortAc.hpp:43