From dc57f1b5a36e2ead0f67b12139a7bdb3aed05dc8 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Fri, 29 Mar 2024 11:59:46 -0400 Subject: [PATCH] Do not change device uuid if preserve uuid is set on the device. --- .../source/adapter/shdr/shdr_adapter.cpp | 15 ++++++++++++--- test_package/agent_test.cpp | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp index 4fdd0624..d3c685ab 100644 --- a/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp +++ b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp @@ -224,11 +224,20 @@ namespace mtconnect::source::adapter::shdr { else if (m_handler && m_handler->m_command) { m_handler->m_command(command, value, getIdentity()); + if (command == "uuid") { - m_pipeline.setDevice(value); - options[configuration::Device] = value; - setOptions(options); + DevicePtr dp; + if (auto dev = GetOption(m_options, configuration::Device); + dev && (dp = m_pipeline.getContext()->m_contract->findDevice(*dev))) + { + if (!dp->preserveUuid()) + { + m_pipeline.setDevice(value); + options[configuration::Device] = value; + setOptions(options); + } + } } } } diff --git a/test_package/agent_test.cpp b/test_package/agent_test.cpp index 42f797f7..3e03e8d5 100644 --- a/test_package/agent_test.cpp +++ b/test_package/agent_test.cpp @@ -1681,6 +1681,9 @@ TEST_F(AgentTest, adapter_should_receive_commands) PARSE_XML_RESPONSE("/probe"); ASSERT_XML_PATH_EQUAL(doc, "//m:Device@uuid", "MK-1234"); } + + auto &options = m_agentTestHelper->m_adapter->getOptions(); + ASSERT_EQ("MK-1234", *GetOption(options, configuration::Device)); } TEST_F(AgentTest, adapter_should_receive_device_commands)