Skip to content

Commit

Permalink
Merge pull request #405 from mtconnect/should_set_device_uuid_when_sp…
Browse files Browse the repository at this point in the history
…ecified_in_adapter_config
  • Loading branch information
wsobel authored Jan 25, 2024
2 parents 595c0e0 + f4e4a80 commit d34eb02
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mtconnect/configuration/agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,18 @@ namespace mtconnect::configuration {
{
adapterOptions[configuration::Device] = *device->getUuid();
}

if (!device)
{
LOG(warning) << "Cannot locate device name '" << deviceName << "', assuming dynamic";
}
else if (auto uuid = GetOption<string>(adapterOptions, configuration::UUID))
{
// Set the UUID of the device
auto oldUuid = *device->getUuid();
device->setUuid(*uuid);
m_agent->deviceChanged(device, oldUuid, *device->getComponentName());
}

auto additional = block.second.get_optional<string>(configuration::AdditionalDevices);
if (additional)
Expand Down
41 changes: 41 additions & 0 deletions test_package/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2257,4 +2257,45 @@ AgentDeviceUUID = SOME_UUID
const auto &ad = m_config->getAgent()->getAgentDevice();
ASSERT_EQ("SOME_UUID", *(ad->getUuid()));
}

TEST_F(ConfigTest, should_set_device_uuid_when_specified_in_adapter_config)
{
string config(R"DOC(
SchemaVersion=2.3
Adapters {
Simplest {
UUID = NEW-UUID
Port = 7878
}
}
)DOC");

m_config->setDebug(true);
m_config->loadConfig(config);

auto dev = m_config->getAgent()->getDeviceByName("Simplest");
ASSERT_TRUE(dev);
ASSERT_EQ("NEW-UUID", *(dev->getUuid()));
}

TEST_F(ConfigTest, should_set_default_device_uuid_when_specified_in_adapter_config)
{
string config(R"DOC(
SchemaVersion=2.3
Adapters {
Adapter {
UUID = NEW-UUID
Port = 7878
}
}
)DOC");

m_config->setDebug(true);
m_config->loadConfig(config);

auto dev = m_config->getAgent()->getDeviceByName("Simplest");
ASSERT_TRUE(dev);
ASSERT_EQ("NEW-UUID", *(dev->getUuid()));
}

} // namespace

0 comments on commit d34eb02

Please sign in to comment.