GCC Code Coverage Report


Directory: Svc/BufferLogger/
File: BufferLogger.cpp
Date: 2026-09-03 21:16:16
Exec Total Coverage
Lines: 35 43 81.4%
Functions: 8 10 80.0%
Branches: 13 20 65.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title BufferLogger.cpp
3 // \author bocchino, dinkel, mereweth
4 // \brief Svc BufferLogger implementation
5 //
6 // \copyright
7 // Copyright (C) 2015-2017 California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include "Svc/BufferLogger/BufferLogger.hpp"
14
15 namespace Svc {
16
17 typedef BufferLogger_LogState LogState;
18 // ----------------------------------------------------------------------
19 // Construction, initialization, and destruction
20 // ----------------------------------------------------------------------
21
22 14 BufferLogger ::BufferLogger(const char* const compName)
23
2/2
✓ Branch 9 taken 14 times.
✓ Branch 16 taken 14 times.
14 : BufferLoggerComponentBase(compName), m_state(LogState::LOGGING_ON), m_file(*this) {}
24
25 // ----------------------------------------------------------------------
26 // Public methods
27 // ----------------------------------------------------------------------
28
29 // TODO(mereweth) - only allow calling this once?
30 13 void BufferLogger ::initLog(const char* const logFilePrefix,
31 const char* const logFileSuffix,
32 const FwSizeType maxFileSize,
33 const U8 sizeOfSize) {
34 13 m_file.init(logFilePrefix, logFileSuffix, maxFileSize, sizeOfSize);
35 13 }
36
37 // ----------------------------------------------------------------------
38 // Handler implementations for user-defined typed input ports
39 // ----------------------------------------------------------------------
40
41 16 void BufferLogger ::bufferSendIn_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
42
1/2
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
16 if (m_state == LogState::LOGGING_ON) {
43 16 const U8* const addr = fwBuffer.getData();
44 16 const FwSizeType size = fwBuffer.getSize();
45 16 m_file.logBuffer(addr, size);
46 }
47 16 this->bufferSendOut_out(0, fwBuffer);
48 16 }
49
50 50 void BufferLogger ::comIn_handler(FwIndexType portNum, Fw::ComBuffer& data, U32 context) {
51
2/2
✓ Branch 6 taken 45 times.
✓ Branch 7 taken 5 times.
50 if (m_state == LogState::LOGGING_ON) {
52 45 const U8* const addr = data.getBuffAddr();
53 45 const FwSizeType size = data.getSize();
54 45 m_file.logBuffer(addr, size);
55 }
56 50 }
57
58 1 void BufferLogger ::pingIn_handler(FwIndexType portNum, U32 key) {
59 1 this->pingOut_out(0, key);
60 1 }
61
62 void BufferLogger ::schedIn_handler(const FwIndexType portNum, U32 context) {
63 // TODO
64 }
65
66 // ----------------------------------------------------------------------
67 // Command handler implementations
68 // ----------------------------------------------------------------------
69
70 // TODO(mereweth) - should this command only set the base name?
71 2 void BufferLogger ::BL_OpenFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& file) {
72 2 m_file.setBaseName(file);
73
2/2
✓ Branch 6 taken 2 times.
✓ Branch 9 taken 2 times.
2 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
74 2 }
75
76 9 void BufferLogger ::BL_CloseFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq) {
77 9 m_file.closeAndEmitEvent();
78
2/2
✓ Branch 6 taken 9 times.
✓ Branch 9 taken 9 times.
9 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
79 9 }
80
81 3 void BufferLogger ::BL_SetLogging_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, const LogState& state) {
82 3 m_state = state;
83
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
3 if (state == LogState::LOGGING_OFF) {
84 2 m_file.closeAndEmitEvent();
85 }
86
2/2
✓ Branch 6 taken 3 times.
✓ Branch 9 taken 3 times.
3 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
87 3 }
88
89 void BufferLogger ::BL_FlushFile_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq) {
90 const bool status = m_file.flush();
91 if (status) {
92 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
93 } else {
94 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
95 }
96 }
97
98 } // namespace Svc
99