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

Fixes #1708 by Completing the work In Fw #3173

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Fw/Buffer/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <Fw/Types/Serializable.hpp>
#if FW_SERIALIZABLE_TO_STRING
#include <Fw/Types/StringType.hpp>
#include <cstdio> // snprintf
#ifdef BUILD_UT
#include <iostream>
#include <Fw/Types/String.hpp>
Expand Down
16 changes: 4 additions & 12 deletions Fw/Comp/ActiveComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <Fw/Comp/ActiveComponentBase.hpp>
#include <Fw/Types/Assert.hpp>
#include <Os/TaskString.hpp>
#include <cstdio>

namespace Fw {

Expand Down Expand Up @@ -38,14 +37,9 @@
QueuedComponentBase::init(instance);
}

#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void ActiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
FW_ASSERT(buffer != nullptr);
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "ActComp: %s", this->m_objName.toChar());
if (status < 0) {
buffer[0] = 0;
}
#if FW_OBJECT_TO_STRING == 1

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
const char* ActiveComponentBase::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "ActComp: %s";
}
#endif

Expand All @@ -55,9 +49,7 @@
#if FW_OBJECT_NAMES == 1
taskName = this->getObjName();
#else
char taskNameChar[FW_TASK_NAME_BUFFER_SIZE];
(void)snprintf(taskNameChar,sizeof(taskNameChar),"ActComp_%" PRI_FwSizeType,Os::Task::getNumTasks());
taskName = taskNameChar;
(void) taskName.format("ActComp_%" PRI_FwSizeType, Os::Task::getNumTasks());
#endif
// Cooperative threads tasks externalize the task loop, and as such use the state machine as their task function
// Standard multithreading tasks use the task loop to respectively call the state machine
Expand Down
2 changes: 1 addition & 1 deletion Fw/Comp/ActiveComponentBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ActiveComponentBase : public QueuedComponentBase {
Os::Task m_task; //!< task object for active component

#if FW_OBJECT_TO_STRING == 1
virtual void toString(char* str, NATIVE_INT_TYPE size); //!< create string description of component
virtual const char* getToStringFormatString(); //!< Format string for toString function
#endif
PRIVATE:
Lifecycle m_stage; //!< Lifecycle stage of the component
Expand Down
19 changes: 15 additions & 4 deletions Fw/Comp/PassiveComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
#include <Fw/Types/Assert.hpp>
#include <FpConfig.hpp>

#include <cstdio>
#include <Fw/Types/ExternalString.hpp>

namespace Fw {

PassiveComponentBase::PassiveComponentBase(const char* name) : Fw::ObjBase(name), m_idBase(0), m_instance(0) {
}

#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
#if FW_OBJECT_TO_STRING == 1

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
const char* PassiveComponentBase::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "Comp: %s";
}

void PassiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
FW_ASSERT(buffer != nullptr);
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "Comp: %s", this->m_objName.toChar());
if (status < 0) {
Fw::FormatStatus status = Fw::ExternalString(buffer, static_cast<Fw::ExternalString::SizeType>(size)).format(
this->getToStringFormatString(),
#if FW_OBJECT_NAMES == 1

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
this->m_objName.toChar()
#else
"UNKNOWN"
#endif
);
if (status != Fw::FormatStatus::SUCCESS) {
buffer[0] = 0;
}
}
Expand Down
5 changes: 4 additions & 1 deletion Fw/Comp/PassiveComponentBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ namespace Fw {
virtual ~PassiveComponentBase(); //!< Destructor
void init(NATIVE_INT_TYPE instance); //!< Initialization function
NATIVE_INT_TYPE getInstance() const;


#if FW_OBJECT_TO_STRING == 1
virtual void toString(char* str, NATIVE_INT_TYPE size); //!< returns string description of component
virtual const char* getToStringFormatString(); //!< Return the format for a generic component toString
void toString(char* str, NATIVE_INT_TYPE size) override; //!< returns string description of component
#endif
PRIVATE:
U32 m_idBase; //!< ID base for opcodes etc.
Expand Down
15 changes: 4 additions & 11 deletions Fw/Comp/QueuedComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
PassiveComponentBase::init(instance);
}

#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void QueuedComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
FW_ASSERT(buffer != nullptr);
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "QueueComp: %s", this->m_objName.toChar());
if (status < 0) {
buffer[0] = 0;
}
#if FW_OBJECT_TO_STRING == 1

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
const char* QueuedComponentBase::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "QueueComp: %s";
}
#endif

Expand All @@ -36,9 +31,7 @@
#if FW_OBJECT_NAMES == 1
queueName = this->m_objName;
#else
char queueNameChar[FW_QUEUE_NAME_BUFFER_SIZE];
(void)snprintf(queueNameChar,sizeof(queueNameChar),"CompQ_%" PRI_FwSizeType,Os::Queue::getNumQueues());
queueName = queueNameChar;
queueName.format("CompQ_%" PRI_FwSizeType,Os::Queue::getNumQueues());
#endif
return this->m_queue.create(queueName, depth, msgSize);
}
Expand Down
2 changes: 1 addition & 1 deletion Fw/Comp/QueuedComponentBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Fw {
Os::Queue::Status createQueue(FwSizeType depth, FwSizeType msgSize);
virtual MsgDispatchStatus doDispatch()=0; //!< method to dispatch a single message in the queue.
#if FW_OBJECT_TO_STRING == 1
virtual void toString(char* str, NATIVE_INT_TYPE size); //!< dump string representation of component
virtual const char* getToStringFormatString(); //!< Format string for toString function
#endif
NATIVE_INT_TYPE getNumMsgsDropped(); //!< return number of messages dropped
void incNumMsgDropped(); //!< increment the number of messages dropped
Expand Down
7 changes: 3 additions & 4 deletions Fw/Obj/ObjBase.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <FpConfig.hpp>
#include <Fw/Obj/ObjBase.hpp>
#include <cstring>
#include <cstdio>
#include <Fw/Types/Assert.hpp>
#include <Fw/Types/ExternalString.hpp>

namespace Fw {

Expand Down Expand Up @@ -48,8 +47,8 @@ namespace Fw {
void ObjBase::toString(char* str, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
FW_ASSERT(str != nullptr);
PlatformIntType status = snprintf(str, static_cast<size_t>(size), "Obj: %s", this->m_objName.toChar());
if (status < 0) {
Fw::FormatStatus formatStatus = Fw::ExternalString(str, static_cast<Fw::ExternalString::SizeType>(size)).format("Obj: %s", this->m_objName.toChar());
if (formatStatus != Fw::FormatStatus::SUCCESS) {
str[0] = 0;
}
}
Expand Down
14 changes: 2 additions & 12 deletions Fw/Port/InputPortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,8 @@
}

#if FW_OBJECT_TO_STRING == 1
void InputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
FW_ASSERT(buffer != nullptr);
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "InputPort: %s->%s", this->m_objName.toChar(),
this->isConnected() ? this->m_connObj->getObjName() : "None");
if (status < 0) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","Unnamed Input port");
#endif
const char* InputPortBase::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "Input Port: %s %s->(%s)";
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions Fw/Port/InputPortBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ namespace Fw {

InputPortBase(); // Constructor
virtual ~InputPortBase(); // Destructor
virtual void init();
void init() override;

PassiveComponentBase* m_comp; // !< pointer to containing component
NATIVE_INT_TYPE m_portNum; // !< port number in containing object
#if FW_OBJECT_TO_STRING == 1
virtual void toString(char* str, NATIVE_INT_TYPE size);
const char* getToStringFormatString() override; //!< Get format string for toString call
#endif

private:
Expand Down
12 changes: 2 additions & 10 deletions Fw/Port/InputSerializePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@
}

#if FW_OBJECT_TO_STRING == 1
void InputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, static_cast<size_t>(size), "Input Serial Port: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","InputSerializePort");
#endif
const char* InputSerializePort::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "Input Serial Port: %s %s->(%s)";
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions Fw/Port/InputSerializePort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ namespace Fw {
InputSerializePort();
virtual ~InputSerializePort();

void init();
void init() override;

SerializeStatus invokeSerial(SerializeBufferBase &buffer); // !< invoke the port with a serialized version of the call
SerializeStatus invokeSerial(SerializeBufferBase &buffer) override; // !< invoke the port with a serialized version of the call

typedef void (*CompFuncPtr)(Fw::PassiveComponentBase* callComp, NATIVE_INT_TYPE portNum, SerializeBufferBase &arg); //!< port callback definition
void addCallComp(Fw::PassiveComponentBase* callComp, CompFuncPtr funcPtr); //!< call to register a component

protected:

#if FW_OBJECT_TO_STRING == 1
virtual void toString(char* str, NATIVE_INT_TYPE size);
const char* getToStringFormatString() override; //!< Get format string for toString call
#endif

private:
Expand Down
13 changes: 2 additions & 11 deletions Fw/Port/OutputPortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,8 @@
#endif

#if FW_OBJECT_TO_STRING == 1
void OutputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, static_cast<size_t>(size), "OutputPort: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","OutputPort");
#endif

const char* OutputPortBase::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "Output Port: %s %s->(%s)";
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions Fw/Port/OutputPortBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace Fw {

OutputPortBase(); // constructor
virtual ~OutputPortBase(); // destructor
virtual void init();
void init() override;

#if FW_OBJECT_TO_STRING == 1
virtual void toString(char* str, NATIVE_INT_TYPE size);
const char* getToStringFormatString() override; //!< Get format string for toString call
#endif

#if FW_PORT_SERIALIZATION == 1
Expand Down
12 changes: 2 additions & 10 deletions Fw/Port/OutputSerializePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,8 @@
}

#if FW_OBJECT_TO_STRING == 1
void OutputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, static_cast<size_t>(size), "Output Serial Port: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","OutputSerializePort");
#endif
const char* OutputSerializePort::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "Output Serial Port: %s %s->(%s)";
}
#endif

Expand Down
6 changes: 2 additions & 4 deletions Fw/Port/OutputSerializePort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ namespace Fw {
public:
OutputSerializePort();
virtual ~OutputSerializePort();
virtual void init();
void init() override;

protected:


#if FW_OBJECT_TO_STRING == 1
virtual void toString(char* str, NATIVE_INT_TYPE size);
const char* getToStringFormatString() override; //!< Get format string for toString call
#endif

private:
Expand Down
35 changes: 31 additions & 4 deletions Fw/Port/PortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Fw/Logger/Logger.hpp>
#include <cstdio>
#include "Fw/Types/Assert.hpp"
#include "Fw/Types/ExternalString.hpp"

#if FW_PORT_TRACING
void setConnTrace(bool trace) {
Expand Down Expand Up @@ -75,17 +76,43 @@

#endif // FW_PORT_TRACING

#if FW_OBJECT_NAMES == 1
#if FW_OBJECT_TO_STRING == 1
const char* PortBase::getToStringFormatString() {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
return "Port: %s %s->(%s)";
}

void PortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(buffer, static_cast<size_t>(size), "Port: %s %s->(%s)", this->m_objName.toChar(), this->m_connObj ? "C" : "NC",
this->m_connObj ? this->m_connObj->getObjName() : "None") < 0) {
// Get the port-custom format string
const char* formatString = this->getToStringFormatString();

Check notice

Code scanning / CodeQL

Use of basic integral type Note

formatString uses the basic integral type char rather than a typedef with size and signedness.
// Determine this port object name (or use "UNKOWN")

Check warning on line 88 in Fw/Port/PortBase.cpp

View workflow job for this annotation

GitHub Actions / Check Spelling

`UNKOWN` is not a recognized word. (unrecognized-spelling)
const char* object_name =

Check notice

Code scanning / CodeQL

Use of basic integral type Note

object_name uses the basic integral type char rather than a typedef with size and signedness.
#if FW_OBJECT_NAMES == 1

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
this->m_objName.toChar();
#else
"UNKNOWN";
#endif
// Get the C/NC for connected or not
const char* this_is_connected = this->isConnected() ? "C" : "NC";

Check notice

Code scanning / CodeQL

Use of basic integral type Note

this_is_connected uses the basic integral type char rather than a typedef with size and signedness.

// Get the name of the connectioned object, "UNKNNOWN" or "NONE"

Check warning on line 98 in Fw/Port/PortBase.cpp

View workflow job for this annotation

GitHub Actions / Check Spelling

`connectioned` is not a recognized word. (unrecognized-spelling)

Check warning on line 98 in Fw/Port/PortBase.cpp

View workflow job for this annotation

GitHub Actions / Check Spelling

`UNKNNOWN` is not a recognized word. (unrecognized-spelling)
const char* connected_to = this->isConnected() ?

Check notice

Code scanning / CodeQL

Use of basic integral type Note

connected_to uses the basic integral type char rather than a typedef with size and signedness.
#if FW_OBJECT_NAMES == 1

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
this->m_connObj->getObjName()
#else
"UNKNOWN"
#endif
: "None";
// Format the external string or use "" on error
if (Fw::ExternalString(buffer, static_cast<Fw::ExternalString::SizeType>(size)).format(
formatString,
object_name,
this_is_connected,
connected_to) != Fw::FormatStatus::SUCCESS) {
buffer[0] = 0;
}
}
#endif // FW_OBJECT_TO_STRING
#endif // FW_OBJECT_NAMES


}
Expand Down
4 changes: 3 additions & 1 deletion Fw/Port/PortBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ namespace Fw {
Fw::ObjBase* m_connObj; // !< object port is connected to

#if FW_OBJECT_TO_STRING
virtual void toString(char* str, NATIVE_INT_TYPE size);
virtual const char* getToStringFormatString(); //!< Get format string for toString call

void toString(char* str, NATIVE_INT_TYPE size) override; //!< Unified port toString method
#endif


Expand Down
Loading
Loading