|
| 1 | +// ====================================================================== |
| 2 | +// \title FileDispatcher.cpp |
| 3 | +// \author tcanham |
| 4 | +// \brief cpp file for FileDispatcher component implementation class |
| 5 | +// ====================================================================== |
| 6 | + |
| 7 | +#include "Svc/FileDispatcher/FileDispatcher.hpp" |
| 8 | +#include "Fw/Types/StringUtils.hpp" |
| 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 |
| 18 | + for (FwSizeType i = 0; i < Svc::FileDispatcherCfg::FILE_DISPATCHER_MAX_TABLE_SIZE; i++) { |
| 19 | + this->m_dispatchTable.entries[i].enabled = false; |
| 20 | + } |
| 21 | + this->m_dispatchTable.numEntries = 0; |
| 22 | +} |
| 23 | + |
| 24 | +FileDispatcher ::~FileDispatcher() {} |
| 25 | + |
| 26 | +void FileDispatcher ::configure(const FileDispatcherTable& table) { |
| 27 | + // validate table |
| 28 | + FW_ASSERT(table.numEntries <= Svc::FileDispatcherCfg::FILE_DISPATCHER_MAX_TABLE_SIZE); |
| 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, |
| 77 | + Svc::FileDispatcherCfg::FileDispatchPort file_type, |
| 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 |
0 commit comments