Skip to content

Commit

Permalink
Merge pull request #400 from mtconnect/remove_period_from_agent_devic…
Browse files Browse the repository at this point in the history
…e_id
  • Loading branch information
wsobel authored Feb 19, 2024
2 parents 329ad1b + 62a4c0a commit 569753a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/mtconnect/device_model/agent_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ namespace mtconnect {
}
return factory;
}

entity::FactoryPtr AgentDevice::getRoot()
{
static auto factory = make_shared<Factory>(
Requirements {{"Agent", ValueType::ENTITY, getFactory(), 1, Requirement::Infinite}});

return factory;
}


AgentDevice::AgentDevice(const std::string &name, entity::Properties &props)
: Device(name, props)
Expand Down
1 change: 1 addition & 0 deletions src/mtconnect/device_model/agent_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/sink/mqtt_sink/mqtt2_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace mtconnect {
uuid = *(device->getUuid());
if (std::dynamic_pointer_cast<device_model::AgentDevice>(device))
{
uuid.insert(0, "Agent.");
uuid.insert(0, "Agent_");
}
}

Expand Down
35 changes: 35 additions & 0 deletions test_package/mqtt_sink_2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientHandler>();
bool gotDevice = false;
handler->m_receive = [&gotDevice, &parser, &agent_topic, &ad ](std::shared_ptr<MqttClient> 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; }));
}

0 comments on commit 569753a

Please sign in to comment.