Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some issues in the tests and upgraded to Boost 1.85 to address some logger issues #457

Merged
merged 7 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
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 9)
set(AGENT_VERSION_BUILD 10)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
2 changes: 1 addition & 1 deletion conan/mqtt_cpp/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MqttcppConan(ConanFile):
url = "https://github.com/redboltz/mqtt_cpp"
description = "MQTT client/server for C++14 based on Boost.Asio"
topics = ("mqtt")
requires = ["boost/1.82.0"]
requires = ["boost/1.85.0"]
no_copy_source = True
exports_sources = "include/*"

Expand Down
8 changes: 6 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MTConnectAgentConan(ConanFile):
"with_ruby": True,
"development": False,
"shared": False,
"winver": "0x600",
"winver": "0x0602",
"with_docs": False,
"cpack": False,
"agent_prefix": None,
Expand Down Expand Up @@ -118,7 +118,7 @@ def build_requirements(self):
self.tool_requires_version("doxygen", [1, 9, 4])

def requirements(self):
self.requires("boost/1.82.0", headers=True, libs=True, transitive_headers=True, transitive_libs=True)
self.requires("boost/1.85.0", headers=True, libs=True, transitive_headers=True, transitive_libs=True)
self.requires("libxml2/2.10.3", headers=True, libs=True, visible=True, transitive_headers=True, transitive_libs=True)
self.requires("date/2.4.1", headers=True, libs=True, transitive_headers=True, transitive_libs=True)
self.requires("nlohmann_json/3.9.1", headers=True, libs=False, transitive_headers=True, transitive_libs=False)
Expand All @@ -139,6 +139,9 @@ def configure(self):
if self.options.shared:
self.options["boost/*"].shared = True
self.package_type = "shared-library"

if is_msvc(self):
self.options["boost/*"].extra_b2_flags = ("define=BOOST_USE_WINAPI_VERSION=" + str(self.options.winver))

# Make sure shared builds use shared boost
if is_msvc(self) and self.options.shared:
Expand Down Expand Up @@ -227,6 +230,7 @@ def package_info(self):
winver=str(self.options.winver)
self.cpp_info.defines.append("WINVER=" + winver)
self.cpp_info.defines.append("_WIN32_WINNT=" + winver)
self.cpp_info.defines.append("BOOST_USE_WINAPI_VERSION=" + winver)

def package(self):
cmake = CMake(self)
Expand Down
28 changes: 18 additions & 10 deletions src/mtconnect/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,18 @@ namespace mtconnect {
for (auto source : m_sources)
source->stop();

LOG(info) << "Shutting down sinks";
for (auto sink : m_sinks)
sink->stop();

// Signal all observers
// Signal all observers
LOG(info) << "Signaling observers to close sessions";
for (auto di : m_dataItemMap)
{
auto ldi = di.second.lock();
if (ldi)
ldi->signalObservers(0);
}

LOG(info) << "Shutting down sinks";
for (auto sink : m_sinks)
sink->stop();

LOG(info) << "Shutting down completed";

Expand Down Expand Up @@ -1469,11 +1469,19 @@ namespace mtconnect {
LOG(warning) << "Cannot find data item to calibrate for " << name;
else
{
double fact_value = stod(factor);
double off_value = stod(offset);

device_model::data_item::UnitConversion conv(fact_value, off_value);
di->setConverter(conv);
try
{
double fact_value = stod(factor);
double off_value = stod(offset);

device_model::data_item::UnitConversion conv(fact_value, off_value);
di->setConverter(conv);
}
catch (std::exception e)
{
LOG(error) << "Cannot convert factor " << factor << " or " << offset
<< " to double: " << e.what();
}
}
}
}}};
Expand Down
40 changes: 24 additions & 16 deletions src/mtconnect/device_model/data_item/unit_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,33 @@ namespace mtconnect::device_model::data_item {
{
double power = 1.0, scale = 1.0;

if (unit.compare(0, 4, "KILO") == 0)
try
{
scale = 1000;
unit.remove_prefix(4);
}
else if (unit.compare(0, 6, "CUBIC_") == 0)
{
unit.remove_prefix(6);
power = 3.0;
}
else if (unit.compare(0, 7, "SQUARE_") == 0)
{
unit.remove_prefix(7);
power = 2.0;
if (unit.compare(0, 4, "KILO") == 0)
{
scale = 1000;
unit.remove_prefix(4);
}
else if (unit.compare(0, 6, "CUBIC_") == 0)
{
unit.remove_prefix(6);
power = 3.0;
}
else if (unit.compare(0, 7, "SQUARE_") == 0)
{
unit.remove_prefix(7);
power = 2.0;
}
else if (auto p = unit.find('^'); p != string_view::npos)
{
power = stod(string(unit.substr(p + 1)));
unit.remove_suffix(unit.length() - p);
}
}
else if (auto p = unit.find('^'); p != string_view::npos)
catch (std::exception e)
{
power = stod(string(unit.substr(p + 1)));
unit.remove_suffix(unit.length() - p);
LOG(error) << "Invalid unit: " << unit << " -- " << e.what();
LOG(error) << " ignoring";
}

return {scale, power};
Expand Down
18 changes: 0 additions & 18 deletions src/mtconnect/pipeline/shdr_token_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,6 @@ namespace mtconnect {
return {key, nullopt};
}

inline optional<double> getDuration(std::string &timestamp)
{
optional<double> duration;

auto pos = timestamp.find('@');
if (pos != string::npos)
{
auto read = pos + 1;
;
duration = std::stod(timestamp, &read);
if (read == pos + 1)
duration.reset();
timestamp = timestamp.erase(pos);
}

return duration;
}

// --------------------------------------
// Mapping to data items
static entity::Requirements s_condition {{"level", true},
Expand Down
5 changes: 4 additions & 1 deletion src/mtconnect/pipeline/timestamp_extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ namespace mtconnect::pipeline {
{
char *end {0};
off = std::strtod(timestamp.data(), &end);
;
if (end == timestamp.data())
{
return {n, duration};
}
}

if (!base)
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/ruby/ruby_vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace mtconnect::ruby {

void lock() { m_mutex.lock(); }
void unlock() { m_mutex.unlock(); }
void try_lock() { m_mutex.try_lock(); }
[[nodiscard]] bool try_lock() { return m_mutex.try_lock(); }

static auto &rubyVM() { return *m_vm; }
static bool hasVM() { return m_vm != nullptr; }
Expand Down
6 changes: 3 additions & 3 deletions src/mtconnect/sink/rest_sink/rest_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ namespace mtconnect {
auto removed = *request->parameter<bool>("removed");
auto count = *request->parameter<int32_t>("count");
auto printer = printerForAccepts(request->m_accepts);
auto pretty = *request->parameter<bool>("pretty");
auto pretty = request->parameter<bool>("pretty").value_or(false);

respond(session, assetRequest(printer, count, removed, request->parameter<string>("type"),
request->parameter<string>("device"), pretty));
Expand All @@ -532,11 +532,11 @@ namespace mtconnect {

auto idHandler = [&](SessionPtr session, RequestPtr request) -> bool {
auto asset = request->parameter<string>("assetIds");
auto pretty = *request->parameter<bool>("pretty");
auto pretty = request->parameter<bool>("pretty").value_or(false);
if (asset)
{
auto printer = m_sinkContract->getPrinter(acceptFormat(request->m_accepts));

list<string> ids;
stringstream str(*asset);
string id;
Expand Down
10 changes: 5 additions & 5 deletions test_package/mqtt_sink_2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,20 @@ TEST_F(MqttSink2Test, mqtt_sink_should_publish_Sample)
auto handler = make_unique<ClientHandler>();
bool gotSample = false;
bool first = true;
handler->m_receive = [&gotSample, &first](std::shared_ptr<MqttClient> client, const std::string &topic,
const std::string &payload) {
handler->m_receive = [&gotSample, &first](std::shared_ptr<MqttClient> client,
const std::string &topic, const std::string &payload) {
if (first)
{
first = false;
}
else
{
EXPECT_EQ("MTConnect/Sample/000", topic);

auto jdoc = json::parse(payload);
auto streams = jdoc.at("/MTConnectStreams/Streams/0/DeviceStream"_json_pointer);
EXPECT_EQ(string("LinuxCNC"), streams.at("/name"_json_pointer).get<string>());

gotSample = true;
}
};
Expand All @@ -277,7 +277,7 @@ TEST_F(MqttSink2Test, mqtt_sink_should_publish_Sample)

ASSERT_TRUE(waitFor(60s, [&first]() { return !first; }));
ASSERT_FALSE(first);

m_agentTestHelper->m_adapter->processData("2021-02-01T12:00:00Z|line|204");
ASSERT_TRUE(waitFor(10s, [&gotSample]() { return gotSample; }));
}
Expand Down
5 changes: 3 additions & 2 deletions test_package/mqtt_sink_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class MqttSinkTest : public testing::Test
m_agentTestHelper->m_ioContext.run_for(500ms);
m_server.reset();
}

m_service.reset();
m_agentTestHelper.reset();
m_jsonPrinter.reset();
}
Expand Down Expand Up @@ -291,8 +293,7 @@ TEST_F(MqttSinkTest, mqtt_sink_should_publish_Streams)

auto jdoc = json::parse(payload);
string value = jdoc.at("/value"_json_pointer).get<string>();
EXPECT_EQ("204", value);
foundLineDataItem = true;
foundLineDataItem = value == "204";
};
createClient(options, std::move(handler));
ASSERT_TRUE(startClient());
Expand Down
Loading