Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set(AGENT_VERSION_MAJOR 2)
set(AGENT_VERSION_MINOR 0)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 12)
set(AGENT_VERSION_RC "_RC25")
set(AGENT_VERSION_BUILD 13)
set(AGENT_VERSION_RC "_RC1")

# This minimum version is to support Visual Studio 2017 and C++ feature checking and FetchContent
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
Expand Down
39 changes: 19 additions & 20 deletions src/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ namespace mtconnect {
m_context(context),
m_strand(m_context),
m_xmlParser(make_unique<parser::XmlParser>()),
m_schemaVersion(
GetOption<string>(options, config::SchemaVersion)),
m_schemaVersion(GetOption<string>(options, config::SchemaVersion)),
m_deviceXmlPath(deviceXmlPath),
m_circularBuffer(GetOption<int>(options, config::BufferSize).value_or(17),
GetOption<int>(options, config::CheckpointFrequency).value_or(1000)),
Expand All @@ -104,7 +103,7 @@ namespace mtconnect {
// Create the Printers
m_printers["xml"] = make_unique<printer::XmlPrinter>(m_pretty);
m_printers["json"] = make_unique<printer::JsonPrinter>(jsonVersion, m_pretty);

if (m_schemaVersion)
{
for (auto &[k, pr] : m_printers)
Expand All @@ -125,7 +124,7 @@ namespace mtconnect {
{
m_schemaVersion.emplace(StrDefaultSchemaVersion());
}

auto version = IntSchemaVersion(*m_schemaVersion);
for (auto &[k, pr] : m_printers)
pr->setSchemaVersion(*m_schemaVersion);
Expand All @@ -135,7 +134,7 @@ namespace mtconnect {
{
createAgentDevice();
}

// For the DeviceAdded event for each device
for (auto device : devices)
addDevice(device);
Expand Down Expand Up @@ -298,9 +297,9 @@ namespace mtconnect {
// Load the configuration for the Agent
auto devices = m_xmlParser->parseFile(
deviceFile, dynamic_cast<printer::XmlPrinter *>(m_printers["xml"].get()));

if (m_xmlParser->getSchemaVersion() &&
IntSchemaVersion(*m_xmlParser->getSchemaVersion()) != IntSchemaVersion(*m_schemaVersion))
IntSchemaVersion(*m_xmlParser->getSchemaVersion()) != IntSchemaVersion(*m_schemaVersion))
{
LOG(info) << "Got version: " << *(m_xmlParser->getSchemaVersion());
LOG(warning) << "Schema version does not match agent schema version, restarting the agent";
Expand All @@ -315,7 +314,7 @@ namespace mtconnect {
}
if (changed)
loadCachedProbe();

return true;
}
catch (runtime_error &e)
Expand Down Expand Up @@ -600,7 +599,8 @@ namespace mtconnect {

// Create the Agent Device
ErrorList errors;
Properties ps {{"uuid", uuid}, {"id", id}, {"name", "Agent"s}, {"mtconnectVersion", *m_schemaVersion}};
Properties ps {
{"uuid", uuid}, {"id", id}, {"name", "Agent"s}, {"mtconnectVersion", *m_schemaVersion}};
m_agentDevice =
dynamic_pointer_cast<AgentDevice>(AgentDevice::getFactory()->make("Agent", ps, errors));
if (!errors.empty())
Expand All @@ -616,7 +616,7 @@ namespace mtconnect {
// Device management and Initialization
// ----------------------------------------------

std::list<device_model::DevicePtr> Agent::loadXMLDeviceFile(const std::string &configXmlPath)
std::list<device_model::DevicePtr> Agent::loadXMLDeviceFile(const std::string &configXmlPath)
{
NAMED_SCOPE("Agent::loadXMLDeviceFile");

Expand All @@ -634,7 +634,7 @@ namespace mtconnect {
{
m_schemaVersion = StrDefaultSchemaVersion();
}

return devices;
}
catch (runtime_error &e)
Expand All @@ -651,14 +651,14 @@ namespace mtconnect {
cerr << f.what() << endl;
throw f;
}

return {};
}

void Agent::verifyDevice(DevicePtr device)
{
NAMED_SCOPE("Agent::verifyDevice");

auto version = IntSchemaVersion(*m_schemaVersion);

// Add the devices to the device map and create availability and
Expand Down Expand Up @@ -1200,31 +1200,30 @@ namespace mtconnect {
if (type)
{
auto count = m_assetStorage->getCountForDeviceAndType(*device->getUuid(), *type);

DataSet set;
if (count > 0)
set.emplace(*type, int64_t(count));
else
set.emplace(*type, DataSetValue(), true);

m_loopback->receive(dc, {{"VALUE", set}});
}
else
{
auto counts = m_assetStorage->getCountsByTypeForDevice(*device->getUuid());

DataSet set;

for (auto &[t, count] : counts)
{
if (count > 0)
set.emplace(t, int64_t(count));
else
set.emplace(t, DataSetValue(), true);
}

m_loopback->receive(dc, {{"resetTriggered", "RESET_COUNTS"s},
{"VALUE", set}});

m_loopback->receive(dc, {{"resetTriggered", "RESET_COUNTS"s}, {"VALUE", set}});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace mtconnect {
const auto &getSinks() const { return m_sinks; }

const auto &getSchemaVersion() const { return m_schemaVersion; }

// Get device from device map
DevicePtr getDeviceByName(const std::string &name);
DevicePtr getDeviceByName(const std::string &name) const;
Expand Down
9 changes: 4 additions & 5 deletions src/configuration/agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/dll.hpp>
#include <boost/dll/import.hpp>
#include <boost/filesystem.hpp>
#include <boost/function.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/core.hpp>
Expand All @@ -30,7 +31,6 @@
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/filesystem.hpp>

#ifdef __APPLE__
#include <mach-o/dyld.h>
Expand Down Expand Up @@ -278,7 +278,7 @@ namespace mtconnect::configuration {
LOG(warning)
<< "Detected change in configuration files. Will reload when youngest file is at least "
<< m_monitorDelay.count() << " seconds old";

if (devTime != *m_deviceTime)
{
auto t = bfs::last_write_time(m_devicesFile);
Expand All @@ -303,8 +303,7 @@ namespace mtconnect::configuration {
{
if (cfgTime != *m_configTime)
{
LOG(warning)
<< "Monitor thread has detected change in configuration files.";
LOG(warning) << "Monitor thread has detected change in configuration files.";
LOG(warning) << ".... Restarting agent: " << m_configFile;

m_agent->stop();
Expand Down Expand Up @@ -720,7 +719,7 @@ namespace mtconnect::configuration {

// Make the Agent
m_agent = make_unique<Agent>(getAsyncContext(), m_devicesFile, options);

// Make the PipelineContext
m_pipelineContext = std::make_shared<pipeline::PipelineContext>();
m_pipelineContext->m_contract = m_agent->makePipelineContract();
Expand Down
42 changes: 21 additions & 21 deletions src/mqtt/mqtt_client_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ namespace mtconnect {
mqtt::protocol_version>;
using mqtt_tls_client = mqtt_tls_client_ptr<boost::asio::io_context &, std::string,
std::uint16_t, mqtt::protocol_version>;
using mqtt_tls_client_ws = mqtt_tls_client_ws_ptr<boost::asio::io_context &, std::string, std::uint16_t, std::string,
using mqtt_tls_client_ws =
mqtt_tls_client_ws_ptr<boost::asio::io_context &, std::string, std::uint16_t, std::string,
mqtt::protocol_version>;

template <typename Derived>
Expand All @@ -63,13 +64,11 @@ namespace mtconnect {
: MqttClient(ioContext, move(handler)),
m_options(options),
m_host(GetOption<std::string>(options, configuration::MqttHost).value_or("localhost")),
m_port(GetOption<int>(options, configuration::MqttPort).value_or(1883)),
m_port(GetOption<int>(options, configuration::MqttPort).value_or(1883)),
m_reconnectTimer(ioContext)
{
if (auto userName = GetOption<std::string>(options, configuration::MqttUserName))
m_username = *userName;
if (auto pswd = GetOption<std::string>(options, configuration::MqttPassword))
m_password = *pswd;
m_username = GetOption<std::string>(options, configuration::MqttUserName);
m_password = GetOption<std::string>(options, configuration::MqttPassword);

std::stringstream url;
url << "mqtt://" << m_host << ':' << m_port;
Expand All @@ -78,7 +77,8 @@ namespace mtconnect {
// Some brokers require specific ClientID provided.
// If not specified in configuration then generate random one.
auto client_id = GetOption<string>(options, configuration::MqttClientId);
if (client_id) {
if (client_id)
{
m_identity = *client_id;
}
else
Expand Down Expand Up @@ -328,9 +328,9 @@ namespace mtconnect {

std::uint16_t m_clientId {0};

std::string m_username = "";
std::optional<std::string> m_username;

std::string m_password = "";
std::optional<std::string> m_password;

boost::asio::steady_timer m_reconnectTimer;
};
Expand All @@ -346,10 +346,10 @@ namespace mtconnect {
if (!m_client)
{
m_client = mqtt::make_async_client(m_ioContext, m_host, m_port);
if (!m_username.empty())
m_client->set_user_name(m_username);
if (!m_password.empty())
m_client->set_password(m_password);
if (m_username)
m_client->set_user_name(*m_username);
if (m_password)
m_client->set_password(*m_password);
}

return m_client;
Expand All @@ -370,10 +370,10 @@ namespace mtconnect {
if (!m_client)
{
m_client = mqtt::make_tls_async_client(m_ioContext, m_host, m_port);
if (!m_username.empty())
m_client->set_user_name(m_username);
if (!m_password.empty())
m_client->set_password(m_password);
if (m_username)
m_client->set_user_name(*m_username);
if (m_password)
m_client->set_password(*m_password);

auto cacert = GetOption<string>(m_options, configuration::MqttCaCert);
if (cacert)
Expand Down Expand Up @@ -410,10 +410,10 @@ namespace mtconnect {
if (!m_client)
{
m_client = mqtt::make_tls_async_client_ws(m_ioContext, m_host, m_port);
if (!m_username.empty())
m_client->set_user_name(m_username);
if (!m_password.empty())
m_client->set_password(m_password);
if (m_username)
m_client->set_user_name(*m_username);
if (m_password)
m_client->set_password(*m_password);

auto cacert = GetOption<string>(m_options, configuration::MqttCaCert);
if (cacert)
Expand Down
14 changes: 7 additions & 7 deletions src/mqtt/mqtt_server_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ namespace mtconnect {
// including close_handler and error_handler.
ep.start_session(std::make_tuple(std::move(spep), std::move(g)));
ep.set_connect_handler([this, wp](MQTT_NS::buffer client_id,
MQTT_NS::optional<MQTT_NS::buffer> username,
MQTT_NS::optional<MQTT_NS::buffer> password,
MQTT_NS::optional<MQTT_NS::will>,
bool clean_session, std::uint16_t keep_alive) {
MQTT_NS::optional<MQTT_NS::buffer> username,
MQTT_NS::optional<MQTT_NS::buffer> password,
MQTT_NS::optional<MQTT_NS::will>, bool clean_session,
std::uint16_t keep_alive) {
using namespace MQTT_NS::literals;
LOG(info) << "Server: Client_id : " << client_id << std::endl;
LOG(info) << "Server: User Name : " << (username ? username.value() : "none"_mb)
Expand Down Expand Up @@ -303,9 +303,9 @@ namespace mtconnect {
auto serverPrivateKey = GetOption<string>(m_options, configuration::TlsPrivateKey);
auto serverCert = GetOption<string>(m_options, configuration::TlsCertificateChain);
ctx.use_certificate_chain_file(*serverCert);
//ctx.use_tmp_dh_file(*GetOption<string>(m_options, configuration::TlsDHKey));
// ctx.use_tmp_dh_file(*GetOption<string>(m_options, configuration::TlsDHKey));
ctx.use_private_key_file(*serverPrivateKey, boost::asio::ssl::context::pem);

if (HasOption(m_options, configuration::TlsCertificatePassword))
{
ctx.set_password_callback(
Expand Down Expand Up @@ -349,7 +349,7 @@ namespace mtconnect {
auto serverPrivateKey = GetOption<string>(m_options, configuration::TlsPrivateKey);
auto serverCert = GetOption<string>(m_options, configuration::TlsCertificateChain);
ctx.use_certificate_chain_file(*serverCert);
//ctx.use_tmp_dh_file(*GetOption<string>(m_options, configuration::TlsDHKey));
// ctx.use_tmp_dh_file(*GetOption<string>(m_options, configuration::TlsDHKey));
ctx.use_private_key_file(*serverPrivateKey, boost::asio::ssl::context::pem);

/*if (IsOptionSet(m_options, configuration::TlsVerifyClientCertificate))
Expand Down
2 changes: 1 addition & 1 deletion src/parser/xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace mtconnect::parser {
{
auto version = ns.substr(colon + 1);
LOG(info) << "MTConnect Schema Version of file: " << filePath << " = " << version;
m_schemaVersion.emplace(version);
m_schemaVersion.emplace(version);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/xml_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace mtconnect::parser {
// Get std::list of data items in path
void getDataItems(FilterSet &filterSet, const std::string &path, xmlNodePtr node = nullptr);
const auto &getSchemaVersion() const { return m_schemaVersion; }

protected:
// LibXML XML Doc
xmlDocPtr m_doc = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/printer/json_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ namespace mtconnect::printer {
const asset::AssetList &asset) const
{
defaultSchemaVersion();

entity::JsonPrinter printer(m_jsonVersion);
json assetDoc;
if (m_jsonVersion == 1)
Expand Down
13 changes: 7 additions & 6 deletions src/printer/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ namespace mtconnect {

void setModelChangeTime(const std::string &t) { m_modelChangeTime = t; }
const std::string &getModelChangeTime() { return m_modelChangeTime; }

void setSchemaVersion(const std::string &s) { m_schemaVersion = s; }
const auto &getSchemaVersion() const { return m_schemaVersion; }

void defaultSchemaVersion() const {

void defaultSchemaVersion() const
{
if (!m_schemaVersion)
{
std::string ver = std::to_string(AGENT_VERSION_MAJOR) + "."
+ std::to_string(AGENT_VERSION_MINOR);
const_cast<Printer*>(this)->m_schemaVersion.emplace(ver);
std::string ver =
std::to_string(AGENT_VERSION_MAJOR) + "." + std::to_string(AGENT_VERSION_MINOR);
const_cast<Printer *>(this)->m_schemaVersion.emplace(ver);
}
}

Expand Down
Loading