F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FileDispatcher.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FileDispatcher.cpp
3 // \author tcanham
4 // \brief cpp file for FileDispatcher component implementation class
5 // ======================================================================
6 
9 
10 namespace Svc {
11 
12 // ----------------------------------------------------------------------
13 // Component construction and destruction
14 // ----------------------------------------------------------------------
15 
16 FileDispatcher ::FileDispatcher(const char* const compName) : FileDispatcherComponentBase(compName) {
17  // disable entries
19  this->m_dispatchTable.entries[i].enabled = false;
20  }
21  this->m_dispatchTable.numEntries = 0;
22 }
23 
25 
27  // validate table
29  for (FwSizeType entry = 0; entry < table.numEntries; entry++) {
30  FW_ASSERT(table.entries[entry].port.isValid(),
31  table.entries[entry].port.e); // valid output port
32  FW_ASSERT(table.entries[entry].fileExt.length() > 0,
33  static_cast<FwAssertArgType>(table.entries[entry].fileExt.length())); // non-zero length
34  // Copy over table entry
35  this->m_dispatchTable.entries[entry].port = table.entries[entry].port;
36  this->m_dispatchTable.entries[entry].fileExt = table.entries[entry].fileExt;
37  this->m_dispatchTable.entries[entry].enabled = table.entries[entry].enabled;
38  }
39  // Set number of entries
40  this->m_dispatchTable.numEntries = table.numEntries;
41 }
42 
43 // ----------------------------------------------------------------------
44 // Handler implementations for typed input ports
45 // ----------------------------------------------------------------------
46 
47 void FileDispatcher ::fileAnnounceRecv_handler(FwIndexType portNum, Fw::StringBase& file_name) {
48  // determine file extension and dispatch accordingly
50  static_cast<FwAssertArgType>(this->m_dispatchTable.numEntries));
51 
52  // walk table to find match
53  for (FwSizeType i = 0; i < this->m_dispatchTable.numEntries; i++) {
54  if (!this->m_dispatchTable.entries[i].enabled) {
55  continue;
56  }
57 
58  auto loc = Fw::StringUtils::substring_find_last(file_name.toChar(), file_name.length(),
59  this->m_dispatchTable.entries[i].fileExt.toChar(),
60  this->m_dispatchTable.entries[i].fileExt.length());
61 
62  if ((loc != -1) && // matches at all
63  (file_name.length() - this->m_dispatchTable.entries[i].fileExt.length() ==
64  static_cast<FwSizeType>(loc)) // match at end of string
65  ) {
66  // dispatch on this port, if connected
67  if (this->isConnected_fileDispatch_OutputPort(this->m_dispatchTable.entries[i].port.e)) {
68  this->fileDispatch_out(this->m_dispatchTable.entries[i].port.e, file_name);
69  this->log_ACTIVITY_HI_FileDispatched(file_name, this->m_dispatchTable.entries[i].port);
70  } else {
71  this->log_WARNING_LO_FileDispatchPortNotConnected(file_name, this->m_dispatchTable.entries[i].port);
72  }
73  }
74  }
75 }
76 
77 // ----------------------------------------------------------------------
78 // Handler implementations for commands
79 // ----------------------------------------------------------------------
80 
81 void FileDispatcher ::ENABLE_DISPATCH_cmdHandler(FwOpcodeType opCode,
82  U32 cmdSeq,
84  const Fw::Enabled& enable) {
86  static_cast<FwAssertArgType>(this->m_dispatchTable.numEntries));
87  for (FwSizeType i = 0; i < this->m_dispatchTable.numEntries; i++) {
88  if (this->m_dispatchTable.entries[i].port == file_type) {
89  this->m_dispatchTable.entries[i].enabled = (enable == Fw::Enabled::ENABLED);
90  }
91  }
92  this->log_ACTIVITY_HI_FileDispatchState(file_type, enable);
93  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
94 }
95 
96 void FileDispatcher ::pingIn_handler(FwIndexType portNum, U32 key) {
97  // return key
98  this->pingOut_out(0, key);
99 }
100 
101 } // namespace Svc
bool enabled
FwIdType FwOpcodeType
The type of a command opcode.
bool isConnected_fileDispatch_OutputPort(FwIndexType portNum) const
PlatformSizeType FwSizeType
void configure(const FileDispatcherTable &table)
configure the component
Enabled state.
FileDispatcherEntry entries[Svc::FileDispatcherCfg::FILE_DISPATCHER_MAX_TABLE_SIZE]
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
FileDispatcher(const char *const compName)
Construct FileDispatcher object.
Svc::FileDispatcherCfg::FileDispatchPort port
void log_WARNING_LO_FileDispatchPortNotConnected(const Fw::StringBase &file_name, const Svc::FileDispatcherCfg::FileDispatchPort &file_type)
Log event FileDispatchPortNotConnected.
void log_ACTIVITY_HI_FileDispatchState(const Svc::FileDispatcherCfg::FileDispatchPort &file_type, const Fw::Enabled &enabled) const
Log event FileDispatchState.
const char * toChar() const
Convert to a C-style char*.
void pingOut_out(FwIndexType portNum, U32 key) const
Invoke output port pingOut.
Enabled and disabled states.
Command successfully executed.
FwSignedSizeType substring_find_last(const CHAR *source_string, FwSizeType source_size, const CHAR *sub_string, FwSizeType sub_size)
find the last occurrence of a substring
Definition: StringUtils.cpp:85
void log_ACTIVITY_HI_FileDispatched(const Fw::StringBase &file_name, const Svc::FileDispatcherCfg::FileDispatchPort &file_type) const
Log event FileDispatched.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
PlatformIndexType FwIndexType
Auto-generated base for FileDispatcher component.
bool isValid() const
Check raw enum value for validity.
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
Fw::String fileExt
void fileDispatch_out(FwIndexType portNum, Fw::StringBase &file_name) const
Invoke output port fileDispatch.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
~FileDispatcher()
Destroy FileDispatcher object.