Skip to content

Commit d13c7bf

Browse files
authored
Fixes #1708 by Completing the work In Fw (#3173)
* Making string formatting into a fprime implementation choice * Removing printf from Fw and cleaning-up toString methods * Fixes to get UTs to compile * Reverting test change to assert * Removing error console and restoring assert functionality * Create empty library to avoid 3.16 limitations on interface libs * Turning off unused check on intentionally unused variable * sp * Fixing recursive calls and other CI problems * Fixing compile issues
1 parent 0cec629 commit d13c7bf

34 files changed

+264
-177
lines changed

Fw/Buffer/Buffer.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <Fw/Types/Serializable.hpp>
1717
#if FW_SERIALIZABLE_TO_STRING
1818
#include <Fw/Types/StringType.hpp>
19-
#include <cstdio> // snprintf
2019
#ifdef BUILD_UT
2120
#include <iostream>
2221
#include <Fw/Types/String.hpp>

Fw/Comp/ActiveComponentBase.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <Fw/Comp/ActiveComponentBase.hpp>
33
#include <Fw/Types/Assert.hpp>
44
#include <Os/TaskString.hpp>
5-
#include <cstdio>
65

76
namespace Fw {
87

@@ -38,14 +37,9 @@ namespace Fw {
3837
QueuedComponentBase::init(instance);
3938
}
4039

41-
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
42-
void ActiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
43-
FW_ASSERT(size > 0);
44-
FW_ASSERT(buffer != nullptr);
45-
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "ActComp: %s", this->m_objName.toChar());
46-
if (status < 0) {
47-
buffer[0] = 0;
48-
}
40+
#if FW_OBJECT_TO_STRING == 1
41+
const char* ActiveComponentBase::getToStringFormatString() {
42+
return "ActComp: %s";
4943
}
5044
#endif
5145

@@ -55,9 +49,7 @@ namespace Fw {
5549
#if FW_OBJECT_NAMES == 1
5650
taskName = this->getObjName();
5751
#else
58-
char taskNameChar[FW_TASK_NAME_BUFFER_SIZE];
59-
(void)snprintf(taskNameChar,sizeof(taskNameChar),"ActComp_%" PRI_FwSizeType,Os::Task::getNumTasks());
60-
taskName = taskNameChar;
52+
(void) taskName.format("ActComp_%" PRI_FwSizeType, Os::Task::getNumTasks());
6153
#endif
6254
// Cooperative threads tasks externalize the task loop, and as such use the state machine as their task function
6355
// Standard multithreading tasks use the task loop to respectively call the state machine

Fw/Comp/ActiveComponentBase.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ActiveComponentBase : public QueuedComponentBase {
5050
Os::Task m_task; //!< task object for active component
5151

5252
#if FW_OBJECT_TO_STRING == 1
53-
virtual void toString(char* str, NATIVE_INT_TYPE size); //!< create string description of component
53+
virtual const char* getToStringFormatString(); //!< Format string for toString function
5454
#endif
5555
PRIVATE:
5656
Lifecycle m_stage; //!< Lifecycle stage of the component

Fw/Comp/PassiveComponentBase.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22
#include <Fw/Types/Assert.hpp>
33
#include <FpConfig.hpp>
44

5-
#include <cstdio>
5+
#include <Fw/Types/ExternalString.hpp>
66

77
namespace Fw {
88

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

12-
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
12+
#if FW_OBJECT_TO_STRING == 1
13+
const char* PassiveComponentBase::getToStringFormatString() {
14+
return "Comp: %s";
15+
}
16+
1317
void PassiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
1418
FW_ASSERT(size > 0);
1519
FW_ASSERT(buffer != nullptr);
16-
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "Comp: %s", this->m_objName.toChar());
17-
if (status < 0) {
20+
Fw::FormatStatus status = Fw::ExternalString(buffer, static_cast<Fw::ExternalString::SizeType>(size)).format(
21+
this->getToStringFormatString(),
22+
#if FW_OBJECT_NAMES == 1
23+
this->m_objName.toChar()
24+
#else
25+
"UNKNOWN"
26+
#endif
27+
);
28+
if (status != Fw::FormatStatus::SUCCESS) {
1829
buffer[0] = 0;
1930
}
2031
}

Fw/Comp/PassiveComponentBase.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ namespace Fw {
2222
virtual ~PassiveComponentBase(); //!< Destructor
2323
void init(NATIVE_INT_TYPE instance); //!< Initialization function
2424
NATIVE_INT_TYPE getInstance() const;
25+
26+
2527
#if FW_OBJECT_TO_STRING == 1
26-
virtual void toString(char* str, NATIVE_INT_TYPE size); //!< returns string description of component
28+
virtual const char* getToStringFormatString(); //!< Return the format for a generic component toString
29+
void toString(char* str, NATIVE_INT_TYPE size) override; //!< returns string description of component
2730
#endif
2831
PRIVATE:
2932
U32 m_idBase; //!< ID base for opcodes etc.

Fw/Comp/QueuedComponentBase.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@ namespace Fw {
1919
PassiveComponentBase::init(instance);
2020
}
2121

22-
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
23-
void QueuedComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
24-
FW_ASSERT(size > 0);
25-
FW_ASSERT(buffer != nullptr);
26-
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "QueueComp: %s", this->m_objName.toChar());
27-
if (status < 0) {
28-
buffer[0] = 0;
29-
}
22+
#if FW_OBJECT_TO_STRING == 1
23+
const char* QueuedComponentBase::getToStringFormatString() {
24+
return "QueueComp: %s";
3025
}
3126
#endif
3227

@@ -36,9 +31,7 @@ namespace Fw {
3631
#if FW_OBJECT_NAMES == 1
3732
queueName = this->m_objName;
3833
#else
39-
char queueNameChar[FW_QUEUE_NAME_BUFFER_SIZE];
40-
(void)snprintf(queueNameChar,sizeof(queueNameChar),"CompQ_%" PRI_FwSizeType,Os::Queue::getNumQueues());
41-
queueName = queueNameChar;
34+
queueName.format("CompQ_%" PRI_FwSizeType,Os::Queue::getNumQueues());
4235
#endif
4336
return this->m_queue.create(queueName, depth, msgSize);
4437
}

Fw/Comp/QueuedComponentBase.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Fw {
3737
Os::Queue::Status createQueue(FwSizeType depth, FwSizeType msgSize);
3838
virtual MsgDispatchStatus doDispatch()=0; //!< method to dispatch a single message in the queue.
3939
#if FW_OBJECT_TO_STRING == 1
40-
virtual void toString(char* str, NATIVE_INT_TYPE size); //!< dump string representation of component
40+
virtual const char* getToStringFormatString(); //!< Format string for toString function
4141
#endif
4242
NATIVE_INT_TYPE getNumMsgsDropped(); //!< return number of messages dropped
4343
void incNumMsgDropped(); //!< increment the number of messages dropped

Fw/Obj/ObjBase.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include <FpConfig.hpp>
22
#include <Fw/Obj/ObjBase.hpp>
3-
#include <cstring>
4-
#include <cstdio>
53
#include <Fw/Types/Assert.hpp>
4+
#include <Fw/Types/ExternalString.hpp>
65

76
namespace Fw {
87

@@ -48,8 +47,8 @@ namespace Fw {
4847
void ObjBase::toString(char* str, NATIVE_INT_TYPE size) {
4948
FW_ASSERT(size > 0);
5049
FW_ASSERT(str != nullptr);
51-
PlatformIntType status = snprintf(str, static_cast<size_t>(size), "Obj: %s", this->m_objName.toChar());
52-
if (status < 0) {
50+
Fw::FormatStatus formatStatus = Fw::ExternalString(str, static_cast<Fw::ExternalString::SizeType>(size)).format("Obj: %s", this->m_objName.toChar());
51+
if (formatStatus != Fw::FormatStatus::SUCCESS) {
5352
str[0] = 0;
5453
}
5554
}

Fw/Port/InputPortBase.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,8 @@ namespace Fw {
2626
}
2727

2828
#if FW_OBJECT_TO_STRING == 1
29-
void InputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
30-
#if FW_OBJECT_NAMES == 1
31-
FW_ASSERT(size > 0);
32-
FW_ASSERT(buffer != nullptr);
33-
PlatformIntType status = snprintf(buffer, static_cast<size_t>(size), "InputPort: %s->%s", this->m_objName.toChar(),
34-
this->isConnected() ? this->m_connObj->getObjName() : "None");
35-
if (status < 0) {
36-
buffer[0] = 0;
37-
}
38-
#else
39-
(void)snprintf(buffer,size,"%s","Unnamed Input port");
40-
#endif
29+
const char* InputPortBase::getToStringFormatString() {
30+
return "Input Port: %s %s->(%s)";
4131
}
4232
#endif
4333

Fw/Port/InputPortBase.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace Fw {
2121

2222
InputPortBase(); // Constructor
2323
virtual ~InputPortBase(); // Destructor
24-
virtual void init();
24+
void init() override;
2525

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

3232
private:

0 commit comments

Comments
 (0)