From ba01a70c0709c8b8aa76f6f814264fc943d83e6a Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Tue, 24 Sep 2024 09:45:55 -0400 Subject: [PATCH] Refactored Entity op == to equal() method to work around op == in children --- CMakeLists.txt | 2 +- conan/profiles/macos | 2 +- conan/profiles/xcode | 2 +- src/mtconnect/agent.cpp | 4 ++-- src/mtconnect/buffer/circular_buffer.hpp | 4 ++-- src/mtconnect/entity/entity.hpp | 19 ++++++++++++------- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96401981..d746f3d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(AGENT_PREFIX "" CACHE STRING "Prefix for the name of the agent and the agent set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/mtconnect") message(INFO " Shared build: ${SHARED_AGENT_LIB}") -set(CMAKE_OSX_DEPLOYMENT_TARGET 13.2) +set(CMAKE_OSX_DEPLOYMENT_TARGET 13.3) project(cppagent LANGUAGES C CXX) diff --git a/conan/profiles/macos b/conan/profiles/macos index 5ed2d929..ccec9a4c 100644 --- a/conan/profiles/macos +++ b/conan/profiles/macos @@ -3,7 +3,7 @@ include(default) [settings] compiler=apple-clang compiler.cppstd=20 -os.version=14.0 +os.version=13.3 [system_tools] cmake/>3.26.0 \ No newline at end of file diff --git a/conan/profiles/xcode b/conan/profiles/xcode index 701188c3..0e2ea6f8 100644 --- a/conan/profiles/xcode +++ b/conan/profiles/xcode @@ -2,7 +2,7 @@ include(default) [settings] compiler.cppstd=20 -os.version=14.0 +os.version=13.3 [system_tools] cmake/>3.23.0 diff --git a/src/mtconnect/agent.cpp b/src/mtconnect/agent.cpp index d350f92c..02de75eb 100644 --- a/src/mtconnect/agent.cpp +++ b/src/mtconnect/agent.cpp @@ -446,7 +446,7 @@ namespace mtconnect { return; } - auto callback = [=](config::AsyncContext &context) { + auto callback = [=, this](config::AsyncContext &context) { try { bool changed = false; @@ -573,7 +573,7 @@ namespace mtconnect { createUniqueIds(device); LOG(info) << "Checking if device " << *uuid << " has changed"; - if (*device != *oldDev) + if (!device->equal(*oldDev)) { LOG(info) << "Device " << *uuid << " changed, updating model"; diff --git a/src/mtconnect/buffer/circular_buffer.hpp b/src/mtconnect/buffer/circular_buffer.hpp index e9b934ae..c87faf89 100644 --- a/src/mtconnect/buffer/circular_buffer.hpp +++ b/src/mtconnect/buffer/circular_buffer.hpp @@ -326,8 +326,8 @@ namespace mtconnect::buffer { mutable std::recursive_mutex m_sequenceLock; // Sequence number - volatile SequenceNumber_t m_sequence; - volatile SequenceNumber_t m_firstSequence; + SequenceNumber_t m_sequence; + SequenceNumber_t m_firstSequence; // The sliding/circular buffer to hold all of the events/sample data unsigned int m_slidingBufferSize; diff --git a/src/mtconnect/entity/entity.hpp b/src/mtconnect/entity/entity.hpp index b56eec38..15d2e254 100644 --- a/src/mtconnect/entity/entity.hpp +++ b/src/mtconnect/entity/entity.hpp @@ -352,16 +352,21 @@ namespace mtconnect { /// @brief get the attributes for XML generation /// @return attribute set const auto &getAttributes() const { return m_attributes; } - + /// @brief compare two entities for equality /// @param other the other entity /// @return `true` if they have equal name and properties - bool operator==(const Entity &other) const; + bool equal(const Entity &other) const; + + /// @brief cover method for equal + /// @param other the other entity + /// @return `true` if they have equal name and properties + bool operator==(const Entity &other) const { return equal(other); } /// @brief compare two entities for inequality /// @param other the other entity /// @return `true` if they have unequal name and properties - bool operator!=(const Entity &other) const { return !(*this == other); } + bool operator!=(const Entity &other) const { return !equal(other); } /// @brief update this entity to be the same as other /// @param other the other entity @@ -446,7 +451,7 @@ namespace mtconnect { bool operator()(const EntityPtr &other) { - return *std::get(m_this) == *(other.get()); + return std::get(m_this)->equal(*(other.get())); } bool operator()(const EntityList &other) @@ -463,7 +468,7 @@ namespace mtconnect { auto id = (*it)->getIdentity(); auto oit = boost::find_if(other, [&id](const auto &e) { return id == e->getIdentity(); }); - if (oit == other.end() || *(it->get()) != *(oit->get())) + if (oit == other.end() || !(it->get())->equal(*(oit->get()))) return false; } } @@ -471,7 +476,7 @@ namespace mtconnect { { for (auto oit = other.cbegin(); it != list.cend(); it++, oit++) { - if (*(it->get()) != *(oit->get())) + if (!(it->get())->equal(*(oit->get()))) return false; } } @@ -499,7 +504,7 @@ namespace mtconnect { inline bool operator!=(const Value &v1, const Value &v2) { return !(v1 == v2); } - inline bool Entity::operator==(const Entity &other) const + inline bool Entity::equal(const Entity &other) const { if (m_name != other.m_name) return false;