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

Add Fw::ObjectName to hold Fw::ObjBase name #2497

Merged
merged 11 commits into from
Mar 5, 2024
1 change: 1 addition & 0 deletions Fw/Cfg/SerIds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Fw {
FW_TYPEID_EIGHTY_CHAR_STRING = 50, //!< 80 char string Buffer type id
FW_TYPEID_INTERNAL_INTERFACE_STRING = 51, //!< interface string Buffer type id
FW_TYPEID_FIXED_LENGTH_STRING = 52, //!< 256 char string Buffer type id
FW_TYPEID_OBJECT_NAME = 53, //!< ObjectName string Buffer type id
};
}

Expand Down
2 changes: 1 addition & 1 deletion Fw/Comp/ActiveComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void ActiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "ActComp: %s", this->m_objName) < 0) {
if (snprintf(buffer, size, "ActComp: %s", this->m_objName.toChar()) < 0) {
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
buffer[0] = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Fw/Comp/PassiveComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
void PassiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(buffer);
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "Comp: %s", this->m_objName) < 0) {
if (snprintf(buffer, size, "Comp: %s", this->m_objName.toChar()) < 0) {
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
buffer[0] = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Fw/Comp/QueuedComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void QueuedComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(buffer, size,"QueueComp: %s", this->m_objName) < 0) {
if (snprintf(buffer, size,"QueueComp: %s", this->m_objName.toChar()) < 0) {
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
buffer[0] = 0;
}
}
Expand Down
7 changes: 3 additions & 4 deletions Fw/Obj/ObjBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@

#if FW_OBJECT_NAMES == 1
const char* ObjBase::getObjName() {
return this->m_objName;
return this->m_objName.toChar();
}

void ObjBase::setObjName(const char* name) {
strncpy(this->m_objName, name, sizeof(this->m_objName));
this->m_objName[sizeof(this->m_objName)-1] = 0;
this->m_objName = name;
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter name has not been checked.
}
#if FW_OBJECT_TO_STRING == 1
void ObjBase::toString(char* str, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(str, size, "Obj: %s",this->m_objName) < 0) {
if (snprintf(str, size, "Obj: %s",this->m_objName.toChar()) < 0) {
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
str[0] = 0;
}
}
Expand Down
5 changes: 4 additions & 1 deletion Fw/Obj/ObjBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define FW_OBJ_BASE_HPP

#include <FpConfig.hpp>
#if FW_OBJECT_NAMES == 1
#include <Fw/Types/ObjectName.hpp>
#endif

namespace Fw {

Expand Down Expand Up @@ -79,7 +82,7 @@ namespace Fw {
protected:

#if FW_OBJECT_NAMES == 1
char m_objName[FW_OBJ_NAME_MAX_SIZE]; //!< stores object name
Fw::ObjectName m_objName; //!< stores object name
#endif

//! \brief ObjBase constructor
Expand Down
2 changes: 1 addition & 1 deletion Fw/Port/InputPortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
void InputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "InputPort: %s->%s", this->m_objName,
if (snprintf(buffer, size, "InputPort: %s->%s", this->m_objName.toChar(),
thomas-bc marked this conversation as resolved.
Show resolved Hide resolved
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
buffer[0] = 0;
}
#else
Expand Down
2 changes: 1 addition & 1 deletion Fw/Port/InputSerializePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
void InputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "Input Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC",
if (snprintf(buffer, size, "Input Serial Port: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
buffer[0] = 0;
}
#else
Expand Down
2 changes: 1 addition & 1 deletion Fw/Port/OutputPortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
void OutputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC",
if (snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
buffer[0] = 0;
}
#else
Expand Down
2 changes: 1 addition & 1 deletion Fw/Port/OutputSerializePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
void OutputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "Output Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC",
if (snprintf(buffer, size, "Output Serial Port: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
buffer[0] = 0;
}
#else
Expand Down
4 changes: 2 additions & 2 deletions Fw/Port/PortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

if (do_trace) {
#if FW_OBJECT_NAMES == 1
Fw::Logger::logMsg("Trace: %s\n", reinterpret_cast<POINTER_CAST>(this->m_objName), 0, 0, 0, 0, 0);
Fw::Logger::logMsg("Trace: %s\n", reinterpret_cast<POINTER_CAST>(this->m_objName.toChar()), 0, 0, 0, 0, 0);
#else
Fw::Logger::logMsg("Trace: %p\n", reinterpret_cast<POINTER_CAST>(this), 0, 0, 0, 0, 0);
#endif
Expand All @@ -79,8 +79,8 @@
#if FW_OBJECT_TO_STRING == 1
void PortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName, this->m_connObj ? "C" : "NC",
if (snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName.toChar(), this->m_connObj ? "C" : "NC",
this->m_connObj ? this->m_connObj->getObjName() : "None") < 0) {

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
buffer[0] = 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions Fw/Types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Types.fpp"
"${CMAKE_CURRENT_LIST_DIR}/InternalInterfaceString.cpp"
"${CMAKE_CURRENT_LIST_DIR}/MallocAllocator.cpp"
"${CMAKE_CURRENT_LIST_DIR}/MemAllocator.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ObjectName.cpp"
"${CMAKE_CURRENT_LIST_DIR}/PolyType.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SerialBuffer.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Serializable.cpp"
Expand Down
55 changes: 55 additions & 0 deletions Fw/Types/ObjectName.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <Fw/Types/ObjectName.hpp>
#include <Fw/Types/StringUtils.hpp>

namespace Fw {

ObjectName::ObjectName(const CHAR* src) : StringBase() {
Fixed Show fixed Hide fixed
Dismissed Show dismissed Hide dismissed
Fw::StringUtils::string_copy(this->m_buf, src, sizeof(this->m_buf));
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
LeStarch marked this conversation as resolved.
Show resolved Hide resolved
}

ObjectName::ObjectName(const StringBase& src) : StringBase() {
Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf));
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}

ObjectName::ObjectName(const ObjectName& src) : StringBase() {
Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf));
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}

ObjectName::ObjectName() : StringBase() {
this->m_buf[0] = 0;
}

ObjectName& ObjectName::operator=(const ObjectName& other) {
if(this == &other) {
return *this;
}

Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf));
Fixed Show fixed Hide fixed
return *this;
}

ObjectName& ObjectName::operator=(const StringBase& other) {
if(this == &other) {
return *this;
}

Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf));
Fixed Show fixed Hide fixed
return *this;
}

ObjectName& ObjectName::operator=(const CHAR* other) {
Fixed Show fixed Hide fixed
Dismissed Show dismissed Hide dismissed
Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf));
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
Fixed Show fixed Hide fixed
LeStarch marked this conversation as resolved.
Show resolved Hide resolved
return *this;
}

ObjectName::~ObjectName() {
}

const CHAR* ObjectName::toChar() const {
Dismissed Show dismissed Hide dismissed
return this->m_buf;
}

NATIVE_UINT_TYPE ObjectName::getCapacity() const {
Dismissed Show dismissed Hide dismissed
return STRING_SIZE;
}
}
37 changes: 37 additions & 0 deletions Fw/Types/ObjectName.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef FW_OBJECT_NAME_TYPE_HPP
#define FW_OBJECT_NAME_TYPE_HPP

#include <FpConfig.hpp>
#include <Fw/Types/StringType.hpp>
#include <Fw/Cfg/SerIds.hpp>

namespace Fw {

class ObjectName : public Fw::StringBase {
public:

enum {
SERIALIZED_TYPE_ID = FW_TYPEID_OBJECT_NAME, //!< typeid for string type
STRING_SIZE = FW_OBJ_NAME_MAX_SIZE, //!< Storage for string
SERIALIZED_SIZE = STRING_SIZE + sizeof(FwBuffSizeType) //!< Serialized size is size of buffer + size field
};

explicit ObjectName(const CHAR* src); //!< char* source constructor
explicit ObjectName(const StringBase& src); //!< StringBase string constructor
ObjectName(const ObjectName& src); //!< ObjectName string constructor
ObjectName(); //!< default constructor
ObjectName& operator=(const ObjectName& other); //!< assignment operator
ObjectName& operator=(const StringBase& other); //!< StringBase string assignment operator
ObjectName& operator=(const CHAR* other); //!< char* assignment operator
~ObjectName(); //!< destructor

const CHAR* toChar() const; //!< gets char buffer
NATIVE_UINT_TYPE getCapacity() const; //!< return buffer size

private:

CHAR m_buf[STRING_SIZE]; //!< storage for string data
Dismissed Show dismissed Hide dismissed
};
}

#endif
31 changes: 31 additions & 0 deletions Fw/Types/test/ut/TypesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Fw/Types/Assert.hpp>
#include <Fw/Types/String.hpp>
#include <Fw/Types/InternalInterfaceString.hpp>
#include <Fw/Types/ObjectName.hpp>
#include <Fw/Types/PolyType.hpp>
#include <Fw/Types/MallocAllocator.hpp>
//
Expand Down Expand Up @@ -1194,6 +1195,36 @@ TEST(TypesTest,EightyCharTest) {

}

TEST(TypesTest,ObjectNameTest) {
Fw::ObjectName str;
str = "foo";
Fw::ObjectName str2;
str2 = "foo";
ASSERT_EQ(str,str2);
ASSERT_EQ(str,"foo");
str2 = "_bar";
ASSERT_NE(str,str2);

Fw::ObjectName str3 = str;
str3 += str2;
ASSERT_EQ(str3,"foo_bar");

str3 += "_foo";
ASSERT_EQ(str3,"foo_bar_foo");


Fw::ObjectName copyStr("ASTRING");
ASSERT_EQ(copyStr,"ASTRING");
Fw::ObjectName copyStr2(copyStr);
ASSERT_EQ(copyStr2,"ASTRING");

Fw::InternalInterfaceString ifstr("IfString");
Fw::ObjectName if2(ifstr);

ASSERT_EQ(ifstr,if2);
ASSERT_EQ(if2,"IfString");
}

TEST(TypesTest,StringFormatTest) {
Fw::String str;
str.format("Int %d String %s",10,"foo");
Expand Down
2 changes: 1 addition & 1 deletion Ref/RecvBuffApp/RecvBuffComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Ref {

void RecvBuffImpl::toString(char* str, I32 buffer_size) {
#if FW_OBJECT_NAMES == 1
(void)snprintf(str, buffer_size, "RecvBuffImpl: %s: ATM recd count: %d", this->m_objName,
(void)snprintf(str, buffer_size, "RecvBuffImpl: %s: ATM recd count: %d", this->m_objName.toChar(),
(int) this->m_buffsReceived);
#else
(void)snprintf(str, buffer_size, "RecvBuffImpl: ATM recd count: %d",
Expand Down
2 changes: 1 addition & 1 deletion Ref/SendBuffApp/SendBuffComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace Ref {

void SendBuffImpl::toString(char* str, I32 buffer_size) {
#if FW_OBJECT_NAMES == 1
(void) snprintf(str, buffer_size, "Send Buff Component: %s: count: %d Buffs: %d", this->m_objName,
(void) snprintf(str, buffer_size, "Send Buff Component: %s: count: %d Buffs: %d", this->m_objName.toChar(),
(int) this->m_invocations, (int) this->m_buffsSent);
str[buffer_size-1] = 0;
#else
Expand Down
4 changes: 2 additions & 2 deletions Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Svc {
this->m_getValue_OutputPort[port].init();
#if FW_OBJECT_NAMES == 1
char portName[120];
snprintf(portName, sizeof(portName), "%s_getValue_OutputPort[%d]", this->m_objName, port);
snprintf(portName, sizeof(portName), "%s_getValue_OutputPort[%d]", this->m_objName.toChar(), port);
this->m_getValue_OutputPort[port].setObjName(portName);
#endif
}
Expand All @@ -45,7 +45,7 @@ namespace Svc {
this->m_setValue_OutputPort[port].init();
#if FW_OBJECT_NAMES == 1
char portName[120];
snprintf(portName, sizeof(portName), "%s_setValue_OutputPort[%d]", this->m_objName, port);
snprintf(portName, sizeof(portName), "%s_setValue_OutputPort[%d]", this->m_objName.toChar(), port);
this->m_setValue_OutputPort[port].setObjName(portName);
#endif
}
Expand Down
22 changes: 11 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ fprime-fpl-convert-xml==1.0.3
fprime-fpl-extract-xml==1.0.3
fprime-fpl-layout==1.0.3
fprime-fpl-write-pic==1.0.3
fprime-fpp-check==2.1.0a3
fprime-fpp-depend==2.1.0a3
fprime-fpp-filenames==2.1.0a3
fprime-fpp-format==2.1.0a3
fprime-fpp-from-xml==2.1.0a3
fprime-fpp-locate-defs==2.1.0a3
fprime-fpp-locate-uses==2.1.0a3
fprime-fpp-syntax==2.1.0a3
fprime-fpp-to-cpp==2.1.0a3
fprime-fpp-to-json==2.1.0a3
fprime-fpp-to-xml==2.1.0a3
fprime-fpp-check==2.1.0a4
fprime-fpp-depend==2.1.0a4
fprime-fpp-filenames==2.1.0a4
fprime-fpp-format==2.1.0a4
fprime-fpp-from-xml==2.1.0a4
fprime-fpp-locate-defs==2.1.0a4
fprime-fpp-locate-uses==2.1.0a4
fprime-fpp-syntax==2.1.0a4
fprime-fpp-to-cpp==2.1.0a4
fprime-fpp-to-json==2.1.0a4
fprime-fpp-to-xml==2.1.0a4
fprime-gds==3.4.3
fprime-tools==3.4.4
fprime-visual==1.0.2
Expand Down
Loading