diff --git a/Fw/Cfg/SerIds.hpp b/Fw/Cfg/SerIds.hpp index de1474f696..9082db658e 100644 --- a/Fw/Cfg/SerIds.hpp +++ b/Fw/Cfg/SerIds.hpp @@ -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 }; } diff --git a/Fw/Comp/ActiveComponentBase.cpp b/Fw/Comp/ActiveComponentBase.cpp index abd7631aec..0ec0a8bb41 100644 --- a/Fw/Comp/ActiveComponentBase.cpp +++ b/Fw/Comp/ActiveComponentBase.cpp @@ -45,7 +45,9 @@ namespace Fw { #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) { + FW_ASSERT(buffer != nullptr); + PlatformIntType status = snprintf(buffer, size, "ActComp: %s", this->m_objName.toChar()); + if (status < 0) { buffer[0] = 0; } } diff --git a/Fw/Comp/PassiveComponentBase.cpp b/Fw/Comp/PassiveComponentBase.cpp index 185f29da9c..65cc3ca9ad 100644 --- a/Fw/Comp/PassiveComponentBase.cpp +++ b/Fw/Comp/PassiveComponentBase.cpp @@ -11,9 +11,10 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1 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) { + FW_ASSERT(buffer != nullptr); + PlatformIntType status = snprintf(buffer, size, "Comp: %s", this->m_objName.toChar()); + if (status < 0) { buffer[0] = 0; } } diff --git a/Fw/Comp/QueuedComponentBase.cpp b/Fw/Comp/QueuedComponentBase.cpp index 5e568c686b..da94dc6ef4 100644 --- a/Fw/Comp/QueuedComponentBase.cpp +++ b/Fw/Comp/QueuedComponentBase.cpp @@ -22,7 +22,9 @@ namespace Fw { #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) { + FW_ASSERT(buffer != nullptr); + PlatformIntType status = snprintf(buffer, size, "QueueComp: %s", this->m_objName.toChar()); + if (status < 0) { buffer[0] = 0; } } diff --git a/Fw/Obj/ObjBase.cpp b/Fw/Obj/ObjBase.cpp index 1f89740fbb..494f225512 100644 --- a/Fw/Obj/ObjBase.cpp +++ b/Fw/Obj/ObjBase.cpp @@ -38,17 +38,18 @@ namespace Fw { #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; } #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) { + FW_ASSERT(str != nullptr); + PlatformIntType status = snprintf(str, size, "Obj: %s", this->m_objName.toChar()); + if (status < 0) { str[0] = 0; } } diff --git a/Fw/Obj/ObjBase.hpp b/Fw/Obj/ObjBase.hpp index ac06088d83..b0b30d18ab 100644 --- a/Fw/Obj/ObjBase.hpp +++ b/Fw/Obj/ObjBase.hpp @@ -14,6 +14,9 @@ #define FW_OBJ_BASE_HPP #include +#if FW_OBJECT_NAMES == 1 +#include +#endif namespace Fw { @@ -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 diff --git a/Fw/Port/InputPortBase.cpp b/Fw/Port/InputPortBase.cpp index b82aedcf94..eb880b9017 100644 --- a/Fw/Port/InputPortBase.cpp +++ b/Fw/Port/InputPortBase.cpp @@ -29,8 +29,10 @@ namespace Fw { 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, - this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { + FW_ASSERT(buffer != nullptr); + PlatformIntType status = snprintf(buffer, size, "InputPort: %s->%s", this->m_objName.toChar(), + this->isConnected() ? this->m_connObj->getObjName() : "None"); + if (status < 0) { buffer[0] = 0; } #else diff --git a/Fw/Port/InputSerializePort.cpp b/Fw/Port/InputSerializePort.cpp index 6201fa3857..ca2f154675 100644 --- a/Fw/Port/InputSerializePort.cpp +++ b/Fw/Port/InputSerializePort.cpp @@ -40,7 +40,7 @@ namespace Fw { 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) { buffer[0] = 0; } diff --git a/Fw/Port/OutputPortBase.cpp b/Fw/Port/OutputPortBase.cpp index 0ac06fd3ae..4018eb2d06 100644 --- a/Fw/Port/OutputPortBase.cpp +++ b/Fw/Port/OutputPortBase.cpp @@ -38,7 +38,7 @@ namespace Fw { 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) { buffer[0] = 0; } diff --git a/Fw/Port/OutputSerializePort.cpp b/Fw/Port/OutputSerializePort.cpp index aa825af647..477784009c 100644 --- a/Fw/Port/OutputSerializePort.cpp +++ b/Fw/Port/OutputSerializePort.cpp @@ -22,7 +22,7 @@ namespace Fw { 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) { buffer[0] = 0; } diff --git a/Fw/Port/PortBase.cpp b/Fw/Port/PortBase.cpp index 34b51322a2..4a13b47bc2 100644 --- a/Fw/Port/PortBase.cpp +++ b/Fw/Port/PortBase.cpp @@ -57,7 +57,7 @@ namespace Fw { if (do_trace) { #if FW_OBJECT_NAMES == 1 - Fw::Logger::logMsg("Trace: %s\n", reinterpret_cast(this->m_objName), 0, 0, 0, 0, 0); + Fw::Logger::logMsg("Trace: %s\n", reinterpret_cast(this->m_objName.toChar()), 0, 0, 0, 0, 0); #else Fw::Logger::logMsg("Trace: %p\n", reinterpret_cast(this), 0, 0, 0, 0, 0); #endif @@ -79,7 +79,7 @@ namespace Fw { #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) { buffer[0] = 0; } diff --git a/Fw/Types/CMakeLists.txt b/Fw/Types/CMakeLists.txt index b9105f640c..7dc88339e8 100644 --- a/Fw/Types/CMakeLists.txt +++ b/Fw/Types/CMakeLists.txt @@ -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" diff --git a/Fw/Types/ObjectName.cpp b/Fw/Types/ObjectName.cpp new file mode 100644 index 0000000000..a3c2171e5d --- /dev/null +++ b/Fw/Types/ObjectName.cpp @@ -0,0 +1,55 @@ +#include +#include + +namespace Fw { + + ObjectName::ObjectName(const CHAR* src) : StringBase() { + (void) Fw::StringUtils::string_copy(this->m_buf, src, sizeof(this->m_buf)); + } + + ObjectName::ObjectName(const StringBase& src) : StringBase() { + (void) Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); + } + + ObjectName::ObjectName(const ObjectName& src) : StringBase() { + (void) Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); + } + + ObjectName::ObjectName() : StringBase() { + this->m_buf[0] = 0; + } + + ObjectName& ObjectName::operator=(const ObjectName& other) { + if(this == &other) { + return *this; + } + + (void) Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); + return *this; + } + + ObjectName& ObjectName::operator=(const StringBase& other) { + if(this == &other) { + return *this; + } + + (void) Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); + return *this; + } + + ObjectName& ObjectName::operator=(const CHAR* other) { + (void) Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf)); + return *this; + } + + ObjectName::~ObjectName() { + } + + const CHAR* ObjectName::toChar() const { + return this->m_buf; + } + + NATIVE_UINT_TYPE ObjectName::getCapacity() const { + return STRING_SIZE; + } +} diff --git a/Fw/Types/ObjectName.hpp b/Fw/Types/ObjectName.hpp new file mode 100644 index 0000000000..1fb770d4d1 --- /dev/null +++ b/Fw/Types/ObjectName.hpp @@ -0,0 +1,37 @@ +#ifndef FW_OBJECT_NAME_TYPE_HPP +#define FW_OBJECT_NAME_TYPE_HPP + +#include +#include +#include + +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 + }; +} + +#endif diff --git a/Fw/Types/StringUtils.cpp b/Fw/Types/StringUtils.cpp index e6de10de2c..069bce8655 100644 --- a/Fw/Types/StringUtils.cpp +++ b/Fw/Types/StringUtils.cpp @@ -7,6 +7,8 @@ char* Fw::StringUtils::string_copy(char* destination, const char* source, U32 nu if(destination == source || num == 0) { return destination; } + FW_ASSERT(source != nullptr); + FW_ASSERT(destination != nullptr); // Copying an overlapping range is undefined U32 source_len = string_length(source, num) + 1; diff --git a/Fw/Types/test/ut/TypesTest.cpp b/Fw/Types/test/ut/TypesTest.cpp index 7f329a3af9..339f357a8c 100644 --- a/Fw/Types/test/ut/TypesTest.cpp +++ b/Fw/Types/test/ut/TypesTest.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include // @@ -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"); diff --git a/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp b/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp index 120960814e..3ac4ca37cd 100644 --- a/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp +++ b/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp @@ -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", diff --git a/Ref/SendBuffApp/SendBuffComponentImpl.cpp b/Ref/SendBuffApp/SendBuffComponentImpl.cpp index d8f5cb789e..6dc43b056f 100644 --- a/Ref/SendBuffApp/SendBuffComponentImpl.cpp +++ b/Ref/SendBuffApp/SendBuffComponentImpl.cpp @@ -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 diff --git a/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp b/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp index a1b2f2db29..0c349e832c 100644 --- a/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp +++ b/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp @@ -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 } @@ -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 } diff --git a/requirements.txt b/requirements.txt index a82f537e91..7efca76fcd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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