Skip to content

Commit

Permalink
Merge pull request #466 from mtconnect/460_461_mqtt_adapter_issues
Browse files Browse the repository at this point in the history
associate source with adapter in json and topic mappers
  • Loading branch information
wsobel committed Jun 19, 2024
2 parents 7b48e5d + 5dac7d0 commit 43331b2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 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 13)
set(AGENT_VERSION_BUILD 14)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
7 changes: 5 additions & 2 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# ---------------------------------------------------------------------

# base image - alpine 3.18
FROM alpine:3.18 AS os
FROM alpine:3.19 AS os

# ---------------------------------------------------------------------
# build
Expand Down Expand Up @@ -63,7 +63,9 @@ RUN apk --update add \
python3 \
ruby \
ruby-rake \
&& PIP_ROOT_USER_ACTION='ignore' pip install conan
&& python3 -m venv /python/conan \
&& . /python/conan/bin/activate \
&& PIP_ROOT_USER_ACTION='ignore' pip install conan

# make an agent directory and cd into it
WORKDIR /root/agent
Expand All @@ -80,6 +82,7 @@ RUN if [ -z "$WITH_TESTS" ] || [ "$WITH_TESTS" = "false" ]; then \
else \
WITH_TESTS_ARG=""; \
fi \
&& . /python/conan/bin/activate \
&& conan profile detect \
&& conan create cppagent \
--build=missing \
Expand Down
5 changes: 5 additions & 0 deletions src/mtconnect/pipeline/json_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ namespace mtconnect::pipeline {
}
else
{
if (m_source)
dataItem->setDataSource(*m_source);
m_entities.push_back(obs);
m_forward(std::move(obs));
}
Expand Down Expand Up @@ -169,6 +171,7 @@ namespace mtconnect::pipeline {
DevicePtr m_defaultDevice;
optional<Timestamp> m_timestamp;
optional<double> m_duration;
optional<string> m_source;

EntityList m_entities;
PipelineContextPtr m_pipelineContext;
Expand Down Expand Up @@ -1014,6 +1017,7 @@ namespace mtconnect::pipeline {
{
static const auto GetParseError = rj::GetParseError_En;

auto source = entity->maybeGet<string>("source");
auto json = std::dynamic_pointer_cast<JsonMessage>(entity);
DevicePtr device = json->m_device.lock();
auto &body = entity->getValue<std::string>();
Expand All @@ -1023,6 +1027,7 @@ namespace mtconnect::pipeline {
reader.IterativeParseInit();
ParserContext context(m_context);
context.m_forward = [this](entity::EntityPtr &&entity) { next(std::move(entity)); };
context.m_source = source;

TopLevelHandler handler(context);
if (device)
Expand Down
5 changes: 5 additions & 0 deletions src/mtconnect/pipeline/message_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace mtconnect::pipeline {

EntityPtr operator()(entity::EntityPtr &&entity) override
{
auto source = entity->maybeGet<string>("source");
auto data = std::dynamic_pointer_cast<DataMessage>(entity);
if (data->m_dataItem)
{
Expand All @@ -56,7 +57,11 @@ namespace mtconnect::pipeline {
auto obs = observation::Observation::make(data->m_dataItem, props,
std::chrono::system_clock::now(), errors);
if (errors.empty())
{
if (source)
data->m_dataItem->setDataSource(*source);
return next(std::move(obs));
}
}
catch (entity::EntityError &e)
{
Expand Down

0 comments on commit 43331b2

Please sign in to comment.