GCC Code Coverage Report


Directory: ./
File: Svc/FileDispatcher/FileDispatcher.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 42 43 97.7%
Functions: 6 6 100.0%
Branches: 25 31 80.6%

Line Branch Exec Source
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
1/1
✓ Branch 10 taken 6 times.
6 FileDispatcher ::FileDispatcher(const char* const compName) : FileDispatcherComponentBase(compName) {
17 // disable entries
18
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 6 times.
66 for (FwSizeType i = 0; i < Svc::FileDispatcherCfg::FILE_DISPATCHER_MAX_TABLE_SIZE; i++) {
19 60 this->m_dispatchTable.entries[i].enabled = false;
20 }
21 6 this->m_dispatchTable.numEntries = 0;
22 6 }
23
24 12 FileDispatcher ::~FileDispatcher() {}
25
26 5 void FileDispatcher ::configure(const FileDispatcherTable& table) {
27 // validate table
28 5 FW_ASSERT(table.numEntries <= Svc::FileDispatcherCfg::FILE_DISPATCHER_MAX_TABLE_SIZE);
29
2/2
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 5 times.
55 for (FwSizeType entry = 0; entry < table.numEntries; entry++) {
30 50 FW_ASSERT(table.entries[entry].port.e < Svc::FileDispatcherCfg::FileDispatchPort::MAX_FILE_DISPATCH_PORTS,
31 table.entries[entry].port.e); // valid, non-sentinel output port
32 50 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 50 this->m_dispatchTable.entries[entry].port = table.entries[entry].port;
36 50 this->m_dispatchTable.entries[entry].fileExt = table.entries[entry].fileExt;
37
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 50 times.
50 this->m_dispatchTable.entries[entry].enabled = table.entries[entry].enabled;
38 }
39 // Set number of entries
40 5 this->m_dispatchTable.numEntries = table.numEntries;
41 5 }
42
43 // ----------------------------------------------------------------------
44 // Handler implementations for typed input ports
45 // ----------------------------------------------------------------------
46
47 41 void FileDispatcher ::fileAnnounceRecv_handler(FwIndexType portNum, Fw::StringBase& file_name) {
48 // determine file extension and dispatch accordingly
49 41 FW_ASSERT(this->m_dispatchTable.numEntries <= Svc::FileDispatcherCfg::FILE_DISPATCHER_MAX_TABLE_SIZE,
50 static_cast<FwAssertArgType>(this->m_dispatchTable.numEntries));
51
52 // walk table to find match
53
2/2
✓ Branch 4 taken 410 times.
✓ Branch 5 taken 41 times.
451 for (FwSizeType i = 0; i < this->m_dispatchTable.numEntries; i++) {
54
3/4
✗ Branch 4 not taken.
✓ Branch 5 taken 410 times.
✓ Branch 6 taken 200 times.
✓ Branch 7 taken 210 times.
410 if (!this->m_dispatchTable.entries[i].enabled) {
55 200 continue;
56 }
57
58 420 auto loc = Fw::StringUtils::substring_find_last(file_name.toChar(), file_name.length(),
59 210 this->m_dispatchTable.entries[i].fileExt.toChar(),
60 210 this->m_dispatchTable.entries[i].fileExt.length());
61
62
4/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 189 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 189 times.
231 if ((loc != -1) && // matches at all
63 21 (file_name.length() - this->m_dispatchTable.entries[i].fileExt.length() ==
64
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 static_cast<FwSizeType>(loc)) // match at end of string
65 ) {
66 // dispatch on this port, if connected
67
2/4
✗ Branch 12 not taken.
✓ Branch 13 taken 21 times.
✓ Branch 15 taken 21 times.
✗ Branch 16 not taken.
21 if (this->isConnected_fileDispatch_OutputPort(this->m_dispatchTable.entries[i].port.e)) {
68
1/2
✗ Branch 12 not taken.
✓ Branch 13 taken 21 times.
21 this->fileDispatch_out(this->m_dispatchTable.entries[i].port.e, file_name);
69 21 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 41 }
76
77 // ----------------------------------------------------------------------
78 // Handler implementations for commands
79 // ----------------------------------------------------------------------
80
81 6 void FileDispatcher ::ENABLE_DISPATCH_cmdHandler(FwOpcodeType opCode,
82 U32 cmdSeq,
83 const Svc::FileDispatcherCfg::FileDispatchPort& file_type,
84 const Fw::Enabled& enable) {
85 6 FW_ASSERT(this->m_dispatchTable.numEntries <= Svc::FileDispatcherCfg::FILE_DISPATCHER_MAX_TABLE_SIZE,
86 static_cast<FwAssertArgType>(this->m_dispatchTable.numEntries));
87
2/2
✓ Branch 4 taken 60 times.
✓ Branch 5 taken 6 times.
66 for (FwSizeType i = 0; i < this->m_dispatchTable.numEntries; i++) {
88
2/2
✓ Branch 11 taken 20 times.
✓ Branch 12 taken 40 times.
60 if (this->m_dispatchTable.entries[i].port == file_type) {
89 20 this->m_dispatchTable.entries[i].enabled = (enable == Fw::Enabled::ENABLED);
90 }
91 }
92 6 this->log_ACTIVITY_HI_FileDispatchState(file_type, enable);
93
2/2
✓ Branch 6 taken 6 times.
✓ Branch 9 taken 6 times.
6 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
94 6 }
95
96 1 void FileDispatcher ::pingIn_handler(FwIndexType portNum, U32 key) {
97 // return key
98 1 this->pingOut_out(0, key);
99 1 }
100
101 } // namespace Svc
102