fprime/Svc/ActiveTextLogger/ActiveTextLogger.hpp
Ian Brault d911fb903f
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>
2025-08-27 12:22:53 -07:00

115 lines
4.2 KiB
C++

// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
#ifndef ACTIVETEXTLOGGERIMPL_HPP_
#define ACTIVETEXTLOGGERIMPL_HPP_
#include <Svc/ActiveTextLogger/ActiveTextLoggerComponentAc.hpp>
#include <Svc/ActiveTextLogger/LogFile.hpp>
#include <config/ActiveTextLoggerCfg.hpp>
namespace Svc {
//! \class ActiveTextLoggerComponent
//! \brief Active text logger component class
//!
//! Similarly to the PassiveTextLogger, this component takes log texts
//! and prints them to the console, but does so from a thread to keep
//! consistent ordering. It also provides the option to write the text
//! to a file as well.
class ActiveTextLogger final : public ActiveTextLoggerComponentBase {
friend class ActiveTextLoggerTester;
public:
//! \brief Component constructor
//!
//! The constructor initializes the state of the component.
//!
//! Note: Making constructor explicit to prevent implicit
//! type conversion.
//!
//! \param compName the component instance name
explicit ActiveTextLogger(const char* compName);
//! \brief Component destructor
//!
virtual ~ActiveTextLogger(); //!< destructor
//! \brief Set log file and max size
//!
//! This is to create an optional log file to write all the messages to.
//! The file will not be written to once the max size is hit.
//!
//! \param fileName The name of the file to create. Must be less than 80 characters.
//! \param maxSize The max size of the file
//! \param maxBackups The maximum backups of the log file. Default: 10
//!
//! \return true if creating the file was successful, false otherwise
bool set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups = 10);
//! Configure component with event ID filters
void configure(const FwEventIdType* filteredIds, FwSizeType count);
private:
// ----------------------------------------------------------------------
// Prohibit Copying
// ----------------------------------------------------------------------
/*! \brief Copy constructor
*
*/
ActiveTextLogger(const ActiveTextLogger&);
/*! \brief Copy assignment operator
*
*/
ActiveTextLogger& operator=(const ActiveTextLogger&);
// ----------------------------------------------------------------------
// Constants/Types
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Member Functions
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Handlers to implement for typed input ports
// ----------------------------------------------------------------------
//! Handler for input port TextLogger
//
virtual void TextLogger_handler(FwIndexType portNum, /*!< The port number*/
FwEventIdType id, /*!< Log ID*/
Fw::Time& timeTag, /*!< Time Tag*/
const Fw::LogSeverity& severity, /*!< The severity argument*/
Fw::TextLogString& text /*!< Text of log message*/
);
// ----------------------------------------------------------------------
// Internal interface handlers
// ----------------------------------------------------------------------
//! Internal Interface handler for TextQueue
//!
virtual void TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString& text /*!< The text string*/
);
// ----------------------------------------------------------------------
// Member Variables
// ----------------------------------------------------------------------
// The optional file to text logs to:
LogFile m_log_file;
// Event ID filters
FwSizeType m_numFilteredIDs;
FwEventIdType m_filteredIDs[ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE];
};
} // namespace Svc
#endif /* ACTIVETEXTLOGGERIMPL_HPP_ */