Skip to content

Commit d911fb9

Browse files
ianbraultIan Braultthomas-bcLeStarch
authored
Add event ID filters to text logger components (#4028)
* Add event ID filter to PassiveConsoleTextLogger * Add event ID filter to ActiveTextLogger * Add const qualifier to filtered event list pointers * Fix assert argument types * Fix clang format errors * Fix copy-paste error on include file Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com> * Add missing initialization to ActiveTextLogger constructor --------- Co-authored-by: Ian Brault <ian.r.brault@jpl.nasa.gov> Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com> Co-authored-by: M Starch <LeStarch@googlemail.com>
1 parent 373f81d commit d911fb9

File tree

7 files changed

+75
-2
lines changed

7 files changed

+75
-2
lines changed

Svc/ActiveTextLogger/ActiveTextLogger.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,28 @@
99
#include <ctime>
1010

1111
namespace Svc {
12+
static_assert(std::numeric_limits<FwSizeType>::max() >= ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE,
13+
"ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE must fit within range of FwSizeType");
1214

1315
// ----------------------------------------------------------------------
1416
// Initialization/Exiting
1517
// ----------------------------------------------------------------------
1618

17-
ActiveTextLogger::ActiveTextLogger(const char* name) : ActiveTextLoggerComponentBase(name), m_log_file() {}
19+
ActiveTextLogger::ActiveTextLogger(const char* name)
20+
: ActiveTextLoggerComponentBase(name), m_log_file(), m_numFilteredIDs(0) {}
1821

1922
ActiveTextLogger::~ActiveTextLogger() {}
2023

24+
void ActiveTextLogger::configure(const FwEventIdType* filteredIds, FwSizeType count) {
25+
FW_ASSERT(count < ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE, static_cast<FwAssertArgType>(count),
26+
ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE);
27+
28+
this->m_numFilteredIDs = count;
29+
for (FwSizeType entry = 0; entry < count; entry++) {
30+
this->m_filteredIDs[entry] = filteredIds[entry];
31+
}
32+
}
33+
2134
// ----------------------------------------------------------------------
2235
// Handlers to implement for typed input ports
2336
// ----------------------------------------------------------------------
@@ -32,6 +45,12 @@ void ActiveTextLogger::TextLogger_handler(FwIndexType portNum,
3245
if (Fw::LogSeverity::DIAGNOSTIC == severity.e) {
3346
return;
3447
}
48+
// Check event ID filters
49+
for (FwSizeType i = 0; i < this->m_numFilteredIDs; i++) {
50+
if (this->m_filteredIDs[i] == id) {
51+
return;
52+
}
53+
}
3554

3655
// Format the string here, so that it is done in the task context
3756
// of the caller. Format doc borrowed from PassiveTextLogger.

Svc/ActiveTextLogger/ActiveTextLogger.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <Svc/ActiveTextLogger/ActiveTextLoggerComponentAc.hpp>
1010
#include <Svc/ActiveTextLogger/LogFile.hpp>
11+
#include <config/ActiveTextLoggerCfg.hpp>
1112

1213
namespace Svc {
1314

@@ -49,6 +50,9 @@ class ActiveTextLogger final : public ActiveTextLoggerComponentBase {
4950
//! \return true if creating the file was successful, false otherwise
5051
bool set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups = 10);
5152

53+
//! Configure component with event ID filters
54+
void configure(const FwEventIdType* filteredIds, FwSizeType count);
55+
5256
private:
5357
// ----------------------------------------------------------------------
5458
// Prohibit Copying
@@ -100,6 +104,10 @@ class ActiveTextLogger final : public ActiveTextLoggerComponentBase {
100104

101105
// The optional file to text logs to:
102106
LogFile m_log_file;
107+
108+
// Event ID filters
109+
FwSizeType m_numFilteredIDs;
110+
FwEventIdType m_filteredIDs[ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE];
103111
};
104112

105113
} // namespace Svc

Svc/PassiveConsoleTextLogger/ConsoleTextLoggerImpl.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define SVC_TEXT_LOGGER_IMPL_HPP
33

44
#include <Svc/PassiveConsoleTextLogger/PassiveTextLoggerComponentAc.hpp>
5+
#include <config/PassiveTextLoggerCfg.hpp>
56

67
namespace Svc {
78

@@ -11,13 +12,20 @@ class ConsoleTextLoggerImpl final : public PassiveTextLoggerComponentBase {
1112
ConsoleTextLoggerImpl(const char* compName);
1213
~ConsoleTextLoggerImpl();
1314

15+
//! Configure component with event ID filters
16+
void configure(const FwEventIdType* filteredIds, FwSizeType count);
17+
1418
private:
1519
// downcalls for input ports
1620
void TextLogger_handler(FwIndexType portNum,
1721
FwEventIdType id,
1822
Fw::Time& timeTag,
1923
const Fw::LogSeverity& severity,
2024
Fw::TextLogString& text);
25+
26+
// Event ID filters
27+
FwSizeType m_numFilteredIDs;
28+
FwEventIdType m_filteredIDs[PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE];
2129
};
2230

2331
} // namespace Svc

Svc/PassiveConsoleTextLogger/ConsoleTextLoggerImplCommon.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,36 @@
44
#include <Svc/PassiveConsoleTextLogger/ConsoleTextLoggerImpl.hpp>
55

66
namespace Svc {
7+
static_assert(std::numeric_limits<FwSizeType>::max() >= PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE,
8+
"PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE must fit within range of FwSizeType");
79

8-
ConsoleTextLoggerImpl::ConsoleTextLoggerImpl(const char* compName) : PassiveTextLoggerComponentBase(compName) {}
10+
ConsoleTextLoggerImpl::ConsoleTextLoggerImpl(const char* compName)
11+
: PassiveTextLoggerComponentBase(compName), m_numFilteredIDs(0) {}
912

1013
ConsoleTextLoggerImpl::~ConsoleTextLoggerImpl() {}
1114

15+
void ConsoleTextLoggerImpl::configure(const FwEventIdType* filteredIds, FwSizeType count) {
16+
FW_ASSERT(count < PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE, static_cast<FwAssertArgType>(count),
17+
PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE);
18+
19+
this->m_numFilteredIDs = count;
20+
for (FwSizeType entry = 0; entry < count; entry++) {
21+
this->m_filteredIDs[entry] = filteredIds[entry];
22+
}
23+
}
24+
1225
void ConsoleTextLoggerImpl::TextLogger_handler(FwIndexType portNum,
1326
FwEventIdType id,
1427
Fw::Time& timeTag,
1528
const Fw::LogSeverity& severity,
1629
Fw::TextLogString& text) {
30+
// Check event ID filters
31+
for (FwSizeType i = 0; i < this->m_numFilteredIDs; i++) {
32+
if (this->m_filteredIDs[i] == id) {
33+
return;
34+
}
35+
}
36+
1737
const char* severityString = nullptr;
1838
switch (severity.e) {
1939
case Fw::LogSeverity::FATAL:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef Config_ActiveTextLoggerCfg_HPP_
2+
#define Config_ActiveTextLoggerCfg_HPP_
3+
4+
enum {
5+
ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE = 25, //!< Size of event ID filter
6+
};
7+
8+
#endif /* Config_ActiveTextLoggerCfg_HPP_ */

default/config/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ register_fprime_config(
1515
HEADERS
1616
"${CMAKE_CURRENT_LIST_DIR}/EventManagerCfg.hpp"
1717
"${CMAKE_CURRENT_LIST_DIR}/ActiveRateGroupCfg.hpp"
18+
"${CMAKE_CURRENT_LIST_DIR}/ActiveTextLoggerCfg.hpp"
1819
"${CMAKE_CURRENT_LIST_DIR}/BufferManagerComponentImplCfg.hpp"
1920
"${CMAKE_CURRENT_LIST_DIR}/CommandDispatcherImplCfg.hpp"
2021
"${CMAKE_CURRENT_LIST_DIR}/DpCatalogCfg.hpp"
@@ -24,6 +25,7 @@ register_fprime_config(
2425
"${CMAKE_CURRENT_LIST_DIR}/FpConfig.hpp"
2526
"${CMAKE_CURRENT_LIST_DIR}/FPrimeNumericalConfig.h"
2627
"${CMAKE_CURRENT_LIST_DIR}/IpCfg.hpp"
28+
"${CMAKE_CURRENT_LIST_DIR}/PassiveTextLoggerCfg.hpp"
2729
"${CMAKE_CURRENT_LIST_DIR}/PrmDbImplCfg.hpp"
2830
"${CMAKE_CURRENT_LIST_DIR}/PrmDbImplTesterCfg.hpp"
2931
"${CMAKE_CURRENT_LIST_DIR}/StaticMemoryConfig.hpp"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef Config_PassiveTextLoggerCfg_HPP_
2+
#define Config_PassiveTextLoggerCfg_HPP_
3+
4+
enum {
5+
PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE = 25, //!< Size of event ID filter
6+
};
7+
8+
#endif /* Config_PassiveTextLoggerCfg_HPP_ */

0 commit comments

Comments
 (0)