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
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class MTConnectAgentConan(ConanFile):
name = "mtconnect_agent"
version = "2.1"
version = "2.2"
generators = "cmake"
url = "https://github.com/mtconnect/cppagent.git"
license = "Apache License 2.0"
Expand Down
10 changes: 3 additions & 7 deletions src/mtconnect/pipeline/convert_sample.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace mtconnect::pipeline {
using namespace observation;
m_guard = TypeGuard<Sample>(RUN) || TypeGuard<Observation>(SKIP);
}
const entity::EntityPtr operator()(const entity::EntityPtr entity) override
entity::EntityPtr operator()(entity::EntityPtr &&entity) override
{
using namespace observation;
using namespace entity;
Expand All @@ -41,13 +41,9 @@ namespace mtconnect::pipeline {
{
auto &converter = sample->getDataItem()->getConverter();
if (converter)
{
auto ns = sample->copy();
converter->convertValue(ns->getValue());
return next(ns);
}
converter->convertValue(sample->getValue());
}
return next(entity);
return next(std::move(entity));
}
};
} // namespace mtconnect::pipeline
10 changes: 5 additions & 5 deletions src/mtconnect/pipeline/deliver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace mtconnect {
using namespace entity;

namespace pipeline {
const EntityPtr DeliverObservation::operator()(const EntityPtr entity)
EntityPtr DeliverObservation::operator()(entity::EntityPtr &&entity)
{
using namespace observation;
auto o = std::dynamic_pointer_cast<Observation>(entity);
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace mtconnect {
}
}

const EntityPtr DeliverAsset::operator()(const EntityPtr entity)
EntityPtr DeliverAsset::operator()(entity::EntityPtr &&entity)
{
auto a = std::dynamic_pointer_cast<asset::Asset>(entity);
if (!a)
Expand All @@ -135,19 +135,19 @@ namespace mtconnect {
return entity;
}

const entity::EntityPtr DeliverConnectionStatus::operator()(const entity::EntityPtr entity)
entity::EntityPtr DeliverConnectionStatus::operator()(entity::EntityPtr &&entity)
{
m_contract->deliverConnectStatus(entity, m_devices, m_autoAvailable);
return entity;
}

const entity::EntityPtr DeliverAssetCommand::operator()(const entity::EntityPtr entity)
entity::EntityPtr DeliverAssetCommand::operator()(entity::EntityPtr &&entity)
{
m_contract->deliverAssetCommand(entity);
return entity;
}

const entity::EntityPtr DeliverCommand::operator()(const entity::EntityPtr entity)
entity::EntityPtr DeliverCommand::operator()(entity::EntityPtr &&entity)
{
if (m_defaultDevice)
entity->setProperty("device", *m_defaultDevice);
Expand Down
10 changes: 5 additions & 5 deletions src/mtconnect/pipeline/deliver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace mtconnect::pipeline {
{
m_guard = TypeGuard<observation::Observation>(RUN);
}
const entity::EntityPtr operator()(const entity::EntityPtr entity) override;
entity::EntityPtr operator()(entity::EntityPtr &&entity) override;
};

/// @brief A transform to deliver and meter asset delivery
Expand All @@ -150,7 +150,7 @@ namespace mtconnect::pipeline {
{
m_guard = TypeGuard<asset::Asset>(RUN);
}
const entity::EntityPtr operator()(const entity::EntityPtr entity) override;
entity::EntityPtr operator()(entity::EntityPtr &&entity) override;
};

/// @brief deliver the connection status of an adapter
Expand All @@ -167,7 +167,7 @@ namespace mtconnect::pipeline {
{
m_guard = EntityNameGuard("ConnectionStatus", RUN);
}
const entity::EntityPtr operator()(const entity::EntityPtr entity) override;
entity::EntityPtr operator()(entity::EntityPtr &&entity) override;

protected:
PipelineContract *m_contract;
Expand All @@ -185,7 +185,7 @@ namespace mtconnect::pipeline {
{
m_guard = EntityNameGuard("AssetCommand", RUN);
}
const entity::EntityPtr operator()(const entity::EntityPtr entity) override;
entity::EntityPtr operator()(entity::EntityPtr &&entity) override;

protected:
PipelineContract *m_contract;
Expand All @@ -201,7 +201,7 @@ namespace mtconnect::pipeline {
{
m_guard = EntityNameGuard("Command", RUN);
}
const entity::EntityPtr operator()(const entity::EntityPtr entity) override;
entity::EntityPtr operator()(entity::EntityPtr &&entity) override;

protected:
PipelineContract *m_contract;
Expand Down
6 changes: 3 additions & 3 deletions src/mtconnect/pipeline/delta_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace mtconnect {

~DeltaFilter() override = default;

const entity::EntityPtr operator()(const entity::EntityPtr entity) override
entity::EntityPtr operator()(entity::EntityPtr &&entity) override
{
using namespace std;
using namespace observation;
Expand All @@ -68,15 +68,15 @@ namespace mtconnect {
if (o->isUnavailable())
{
m_state->m_lastSampleValue.erase(id);
return next(entity);
return next(std::move(entity));
}

auto filter = *di->getMinimumDelta();
double value = o->getValue<double>();
if (filterMinimumDelta(id, value, filter))
return EntityPtr();

return next(entity);
return next(std::move(entity));
}

protected:
Expand Down
7 changes: 5 additions & 2 deletions src/mtconnect/pipeline/duplicate_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ namespace mtconnect::pipeline {
}
~DuplicateFilter() override = default;

const entity::EntityPtr operator()(const entity::EntityPtr entity) override
/// @brief check if the entity is a duplicate
/// @param[in] entity the entity to check
/// @return the result of the transform if not a duplicate or an empty entity
entity::EntityPtr operator()(entity::EntityPtr &&entity) override
{
using namespace observation;

Expand All @@ -52,7 +55,7 @@ namespace mtconnect::pipeline {
if (!o2)
return entity::EntityPtr();
else
return next(o2);
return next(std::move(o2));
}

protected:
Expand Down
45 changes: 32 additions & 13 deletions src/mtconnect/pipeline/guard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace mtconnect {
};

/// @brief Guard is a lambda function returning a `GuardAction` taking an entity
using Guard = std::function<GuardAction(const entity::EntityPtr entity)>;
using Guard = std::function<GuardAction(const entity::Entity *entity)>;

/// @brief A simple GuardClass returning a simple match
///
Expand All @@ -44,7 +44,7 @@ namespace mtconnect {
GuardCls(GuardAction match) : m_match(match) {}
GuardCls(const GuardCls &) = default;

GuardAction operator()(const entity::EntityPtr entity) { return m_match; }
GuardAction operator()(const entity::Entity *entity) { return m_match; }

/// @brief set the alternative guard
/// @param alt alternative
Expand All @@ -54,7 +54,7 @@ namespace mtconnect {
/// @param matched if `true` return the action otherwise check an alternative
/// @param entity an entity
/// @return the guard action
GuardAction check(bool matched, const entity::EntityPtr entity)
GuardAction check(bool matched, const entity::Entity *entity)
{
if (matched)
return m_match;
Expand Down Expand Up @@ -113,13 +113,17 @@ namespace mtconnect {
/// @brief constexpr expanded type match
/// @param entity the entity
/// @return `true` if matches
constexpr bool matches(const entity::EntityPtr &entity) { return match<Ts...>(entity.get()); }
constexpr bool matches(const entity::Entity *entity) { return match<Ts...>(entity); }

GuardAction operator()(const entity::EntityPtr entity)
/// @brief Check if the entity matches one of the types
/// @param[in] entity pointer to the entity
/// @returns the actionn to take if the types match
GuardAction operator()(const entity::Entity *entity)
{
return check(matches(entity), entity);
}

/// @brief set the alternative action if this guard does not match
auto &operator||(Guard other)
{
m_alternative = other;
Expand Down Expand Up @@ -152,17 +156,22 @@ namespace mtconnect {
/// @brief constexpr expanded type match
/// @param entity the entity
/// @return `true` if matches
constexpr bool matches(const entity::EntityPtr &entity)
constexpr bool matches(const entity::Entity *entity)
{
auto &e = *entity.get();
auto &e = *entity;
auto &ti = typeid(e);
return match<Ts...>(ti);
}

GuardAction operator()(const entity::EntityPtr entity)
/// @brief Check if the entity exactly matches one of the types
/// @param[in] entity pointer to the entity
/// @returns the action to take if the types match
GuardAction operator()(const entity::Entity *entity)
{
return check(matches(entity), entity);
}

/// @brief set the alternative action if this guard does not match
auto &operator||(Guard other)
{
m_alternative = other;
Expand All @@ -176,12 +185,17 @@ namespace mtconnect {
public:
EntityNameGuard(const std::string &name, GuardAction match) : GuardCls(match), m_name(name) {}

bool matches(const entity::EntityPtr &entity) { return entity->getName() == m_name; }
bool matches(const entity::Entity *entity) { return entity->getName() == m_name; }

GuardAction operator()(const entity::EntityPtr entity)
/// @brief Check if the entity name matches
/// @param[in] entity pointer to the entity
/// @returns the action to take if the types match
GuardAction operator()(const entity::Entity *entity)
{
return check(matches(entity), entity);
}

/// @brief set the alternative action if this guard does not match
auto &operator||(Guard other)
{
m_alternative = other;
Expand Down Expand Up @@ -211,22 +225,27 @@ namespace mtconnect {
/// @brief call the `B::matches()` method with the entity
/// @param entity the entity
/// @return `true` if matched
bool matches(const entity::EntityPtr &entity)
bool matches(const entity::Entity *entity)
{
bool matched = B::matches(entity);
if (matched)
{
auto o = dynamic_cast<const L *>(entity.get());
auto o = dynamic_cast<const L *>(entity);
matched = o != nullptr && m_lambda(*o);
}

return matched;
}

GuardAction operator()(const entity::EntityPtr entity)
/// @brief Check if the entity name matches the base guard and the lambda
/// @param[in] entity pointer to the entity
/// @returns the action to take if the types match
GuardAction operator()(const entity::Entity *entity)
{
return B::check(matches(entity), entity);
}

/// @brief set the alternative action if this guard does not match
auto &operator||(Guard other)
{
B::m_alternative = other;
Expand Down
6 changes: 3 additions & 3 deletions src/mtconnect/pipeline/message_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace mtconnect::pipeline {
m_guard = TypeGuard<JsonMessage>(RUN);
}

const EntityPtr operator()(const EntityPtr entity) override
EntityPtr operator()(entity::EntityPtr &&entity) override
{
auto json = std::dynamic_pointer_cast<JsonMessage>(entity);

Expand All @@ -67,7 +67,7 @@ namespace mtconnect::pipeline {
m_guard = TypeGuard<DataMessage>(RUN);
}

const EntityPtr operator()(const EntityPtr entity) override
EntityPtr operator()(entity::EntityPtr &&entity) override
{
auto data = std::dynamic_pointer_cast<DataMessage>(entity);
if (data->m_dataItem)
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace mtconnect::pipeline {
// Try processing as shdr data
auto entity = make_shared<Entity>(
"Data", Properties {{"VALUE", data->getValue()}, {"source", string("")}});
next(entity);
next(std::move(entity));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/mtconnect/pipeline/mtconnect_xml_transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace mtconnect::pipeline {
m_guard = EntityNameGuard("Data", RUN);
}

const EntityPtr operator()(const EntityPtr entity) override
EntityPtr operator()(EntityPtr &&entity) override
{
using namespace pipeline;
using namespace entity;
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace mtconnect::pipeline {

for (auto &entity : rd.m_entities)
{
next(entity);
next(std::move(entity));
}

return std::make_shared<Entity>("Entities", Properties {{"VALUE", rd.m_entities}});
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/pipeline/period_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace mtconnect::pipeline {
}
~PeriodFilter() override = default;

const entity::EntityPtr operator()(const entity::EntityPtr entity) override
entity::EntityPtr operator()(entity::EntityPtr &&entity) override
{
using namespace std;
using namespace observation;
Expand Down
Loading