Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a name only constructor to ComLogger #1983

Merged
merged 7 commits into from May 16, 2023

Conversation

kubiak-jpl
Copy link
Contributor

Originating Project/Creator @kubiak-jpl
Affected Component ComLogger
Affected Architectures(s) N/A
Related Issue(s) N/A
Has Unit Tests (y/n) y
Builds Without Errors (y/n) y
Unit Tests Pass (y/n) y
Documentation Included (y/n) n

Change Description

Updated ComLogger to include a name-only constructor and an additional initialization method

ComLogger(const char* compName);
      // filePrefix: string to prepend the file name with, ie. "thermal_telemetry"
      // maxFileSize: the maximum size a file should reach before being closed and a new one opened
      // storeBufferLength: if true, store the length of each com buffer before storing the buffer itself,
      //                    otherwise just store the com buffer. false might be advantageous in a system
      //                    where you can ensure that all buffers given to the ComLogger are the same size
      //                    in which case you do not need the overhead. Or you store an id which you can
      //                    match to an expected size on the ground during post processing.
      void init_log_file(const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);

Added a new internal state to keep track of initialization. The ComLogger file will not open if init_log_file is not called and a WARNING_LO event will be created. Using the old constructor sets this state to initialized by default

Added unit tests to cover the new constructor.

Rationale

The name-only constructor is necessary to use ComLogger without the need for phases in the topology fpp.

Testing/Review Recommendations

Updated unit tests

Future Work

None

Svc/ComLogger/ComLogger.hpp Dismissed Show dismissed Hide dismissed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
Svc/ComLogger/ComLogger.hpp Dismissed Show dismissed Hide dismissed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
Svc/ComLogger/ComLogger.cpp Fixed Show resolved Hide resolved
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
void ComLogger ::
init_log_file(const char* incomingFilePrefix, U32 maxFileSize, bool storeBufferLength)
{
this->maxFileSize = maxFileSize;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter maxFileSize has not been checked.
init_log_file(const char* incomingFilePrefix, U32 maxFileSize, bool storeBufferLength)
{
this->maxFileSize = maxFileSize;
this->storeBufferLength = storeBufferLength;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter storeBufferLength has not been checked.
Svc/ComLogger/ComLogger.cpp Fixed Show resolved Hide resolved
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, but looks correct!

Svc/ComLogger/ComLogger.cpp Dismissed Show dismissed Hide dismissed
Svc/ComLogger/ComLogger.cpp Dismissed Show dismissed Hide dismissed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
Svc/ComLogger/ComLogger.cpp Fixed Show fixed Hide fixed
@@ -49,6 +67,25 @@
ComLoggerComponentBase::init(queueDepth, instance);
}

void ComLogger ::
init_log_file(const char* incomingFilePrefix, U32 maxFileSize, bool storeBufferLength)

Check notice

Code scanning / CodeQL

Use of basic integral type Note

incomingFilePrefix uses the basic integral type char rather than a typedef with size and signedness.
@@ -49,6 +67,25 @@
ComLoggerComponentBase::init(queueDepth, instance);
}

void ComLogger ::
init_log_file(const char* incomingFilePrefix, U32 maxFileSize, bool storeBufferLength)

Check notice

Code scanning / CodeQL

Use of basic integral type Note

storeBufferLength uses the basic integral type bool rather than a typedef with size and signedness.
Comment on lines +70 to +71
void ComLogger ::
init_log_file(const char* incomingFilePrefix, U32 maxFileSize, bool storeBufferLength)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
@LeStarch
Copy link
Collaborator

@kubiak-jpl this looks good. I did three things:

  1. Initialized the other missing variables
  2. added a not-null assert
  3. From the with-arguments constructor, I delegated to your new init function to prevent code duplication.

If you are ok with this, we can merge!

}
FW_ASSERT(Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)) < sizeof(this->filePrefix),
Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)), sizeof(this->filePrefix)); // ensure that file prefix is not too big
this->init_log_file(incomingFilePrefix, maxFileSize, storeBufferLength);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter incomingFilePrefix has not been checked.
}
FW_ASSERT(Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)) < sizeof(this->filePrefix),
Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)), sizeof(this->filePrefix)); // ensure that file prefix is not too big
this->init_log_file(incomingFilePrefix, maxFileSize, storeBufferLength);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter maxFileSize has not been checked.
}
FW_ASSERT(Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)) < sizeof(this->filePrefix),
Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)), sizeof(this->filePrefix)); // ensure that file prefix is not too big
this->init_log_file(incomingFilePrefix, maxFileSize, storeBufferLength);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter storeBufferLength has not been checked.
@kubiak-jpl
Copy link
Contributor Author

@kubiak-jpl this looks good. I did three things:

  1. Initialized the other missing variables
  2. added a not-null assert
  3. From the with-arguments constructor, I delegated to your new init function to prevent code duplication.

If you are ok with this, we can merge!

Looks good to me

@LeStarch LeStarch merged commit 08a2c68 into nasa:devel May 16, 2023
20 of 21 checks passed
@LeStarch
Copy link
Collaborator

@kubiak-jpl merged!

Boehm-Michael pushed a commit to Boehm-Michael/fprime that referenced this pull request Jun 22, 2023
* Added a name only constructor to ComLogger

* Minor fixup of CodeQL warnings

* Fixing ctor warnings, checking arg

* Reusing init_log_file in constructor

* sp

* NULL -> nullptr

* Adding throttle

---------

Co-authored-by: M Starch <LeStarch@googlemail.com>
thomas-bc pushed a commit that referenced this pull request Aug 4, 2023
* Added a name only constructor to ComLogger

* Minor fixup of CodeQL warnings

* Fixing ctor warnings, checking arg

* Reusing init_log_file in constructor

* sp

* NULL -> nullptr

* Adding throttle

---------

Co-authored-by: M Starch <LeStarch@googlemail.com>
thomas-bc added a commit that referenced this pull request Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants