diff --git a/CMakeLists.txt b/CMakeLists.txt index 71bb9269..18db0cb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ set(AGENT_VERSION_MAJOR 2) set(AGENT_VERSION_MINOR 3) set(AGENT_VERSION_PATCH 0) -set(AGENT_VERSION_BUILD 1) +set(AGENT_VERSION_BUILD 2) set(AGENT_VERSION_RC "") # This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent diff --git a/src/mtconnect/device_model/agent_device.cpp b/src/mtconnect/device_model/agent_device.cpp index 30c0edaa..b48b5fed 100644 --- a/src/mtconnect/device_model/agent_device.cpp +++ b/src/mtconnect/device_model/agent_device.cpp @@ -45,6 +45,15 @@ namespace mtconnect { } return factory; } + + entity::FactoryPtr AgentDevice::getRoot() + { + static auto factory = make_shared( + Requirements {{"Agent", ValueType::ENTITY, getFactory(), 1, Requirement::Infinite}}); + + return factory; + } + AgentDevice::AgentDevice(const std::string &name, entity::Properties &props) : Device(name, props) diff --git a/src/mtconnect/device_model/agent_device.hpp b/src/mtconnect/device_model/agent_device.hpp index d02b0a07..6bbe3455 100644 --- a/src/mtconnect/device_model/agent_device.hpp +++ b/src/mtconnect/device_model/agent_device.hpp @@ -42,6 +42,7 @@ namespace mtconnect { AgentDevice(const std::string &name, entity::Properties &props); ~AgentDevice() override = default; static entity::FactoryPtr getFactory(); + static entity::FactoryPtr getRoot(); /// @brief initialize the agent device and add the device changed and removed data items void initialize() override diff --git a/src/mtconnect/sink/mqtt_sink/mqtt2_service.hpp b/src/mtconnect/sink/mqtt_sink/mqtt2_service.hpp index 2ed241c2..0e1ddbab 100644 --- a/src/mtconnect/sink/mqtt_sink/mqtt2_service.hpp +++ b/src/mtconnect/sink/mqtt_sink/mqtt2_service.hpp @@ -144,7 +144,7 @@ namespace mtconnect { uuid = *(device->getUuid()); if (std::dynamic_pointer_cast(device)) { - uuid.insert(0, "Agent."); + uuid.insert(0, "Agent_"); } } diff --git a/test_package/mqtt_sink_2_test.cpp b/test_package/mqtt_sink_2_test.cpp index df4ec838..bbd0370b 100644 --- a/test_package/mqtt_sink_2_test.cpp +++ b/test_package/mqtt_sink_2_test.cpp @@ -388,3 +388,38 @@ TEST_F(MqttSink2Test, mqtt_sink_should_publish_Probe_no_device_in_format) ASSERT_TRUE(waitFor(1s, [&gotDevice]() { return gotDevice; })); } + +TEST_F(MqttSink2Test, mqtt_sink_should_publish_agent_device) +{ + ConfigOptions options; + createServer(options); + startServer(); + ASSERT_NE(0, m_port); + + entity::JsonParser parser; + + DevicePtr ad; + string agent_topic; + + auto handler = make_unique(); + bool gotDevice = false; + handler->m_receive = [&gotDevice, &parser, &agent_topic, &ad ](std::shared_ptr client, + const std::string &topic, const std::string &payload) { + EXPECT_EQ(agent_topic, topic); + gotDevice = true; + }; + + createClient(options, std::move(handler)); + ASSERT_TRUE(startClient()); + createAgent(); + + ad = m_agentTestHelper->m_agent->getAgentDevice(); + agent_topic = "MTConnect/Probe/Agent_"s + *ad->getUuid(); + m_client->subscribe(agent_topic); + + auto service = m_agentTestHelper->getMqtt2Service(); + + ASSERT_TRUE(waitFor(60s, [&service]() { return service->isConnected(); })); + + ASSERT_TRUE(waitFor(1s, [&gotDevice]() { return gotDevice; })); +}