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
49 
50  // walk table to find match
51  for (FwSizeType i = 0; i < this->m_dispatchTable.numEntries; i++) {
52  if (!this->m_dispatchTable.entries[i].enabled) {
53  continue;
54  }
55 
56  auto loc = Fw::StringUtils::substring_find_last(file_name.toChar(), file_name.length(),
57  this->m_dispatchTable.entries[i].fileExt.toChar(),
58  this->m_dispatchTable.entries[i].fileExt.length());
59 
60  if ((loc != -1) && // matches at all
61  (file_name.length() - this->m_dispatchTable.entries[i].fileExt.length() ==
62  static_cast<FwSizeType>(loc)) // match at end of string
63  ) {
64  // dispatch on this port
65  this->fileDispatch_out(this->m_dispatchTable.entries[i].port.e, file_name);
66  this->log_ACTIVITY_HI_FileDispatched(file_name, this->m_dispatchTable.entries[i].port);
67  }
68  }
69 }
70 
71 // ----------------------------------------------------------------------
72 // Handler implementations for commands
73 // ----------------------------------------------------------------------
74 
75 void FileDispatcher ::ENABLE_DISPATCH_cmdHandler(FwOpcodeType opCode,
76  U32 cmdSeq,
78  Fw::Enabled enable) {
79  for (FwSizeType i = 0; i < this->m_dispatchTable.numEntries; i++) {
80  if (this->m_dispatchTable.entries[i].port == file_type) {
81  this->m_dispatchTable.entries[i].enabled = (enable == Fw::Enabled::ENABLED);
82  }
83  }
84  this->log_ACTIVITY_HI_FileDispatchState(file_type, enable);
85  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
86 }
87 
88 void FileDispatcher ::pingIn_handler(FwIndexType portNum, U32 key) {
89  // return key
90  this->pingOut_out(0, key);
91 }
92 
93 } // namespace Svc
bool enabled
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
void configure(const FileDispatcherTable &table)
configure the component
Enabled state.
const char * toChar() const
Convert to a C-style char*.
Definition: String.hpp:50
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.
void log_ACTIVITY_HI_FileDispatchState(Svc::FileDispatcherCfg::FileDispatchPort file_type, Fw::Enabled enabled) const
Log event FileDispatchState.
Svc::FileDispatcherCfg::FileDispatchPort port
void fileDispatch_out(FwIndexType portNum, Fw::StringBase &file_name)
Invoke output port fileDispatch.
Enabled and disabled states.
Command successfully executed.
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
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:77
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 log_ACTIVITY_HI_FileDispatched(const Fw::StringBase &file_name, Svc::FileDispatcherCfg::FileDispatchPort file_type) const
Log event FileDispatched.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
~FileDispatcher()
Destroy FileDispatcher object.