diff --git a/conanfile.py b/conanfile.py index b21afe7f..14b68369 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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" diff --git a/src/mtconnect/pipeline/convert_sample.hpp b/src/mtconnect/pipeline/convert_sample.hpp index 82f9415a..854109bb 100644 --- a/src/mtconnect/pipeline/convert_sample.hpp +++ b/src/mtconnect/pipeline/convert_sample.hpp @@ -32,7 +32,7 @@ namespace mtconnect::pipeline { using namespace observation; m_guard = TypeGuard(RUN) || TypeGuard(SKIP); } - const entity::EntityPtr operator()(const entity::EntityPtr entity) override + entity::EntityPtr operator()(entity::EntityPtr &&entity) override { using namespace observation; using namespace entity; @@ -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 diff --git a/src/mtconnect/pipeline/deliver.cpp b/src/mtconnect/pipeline/deliver.cpp index 02ce087b..f07630af 100644 --- a/src/mtconnect/pipeline/deliver.cpp +++ b/src/mtconnect/pipeline/deliver.cpp @@ -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(entity); @@ -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(entity); if (!a) @@ -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); diff --git a/src/mtconnect/pipeline/deliver.hpp b/src/mtconnect/pipeline/deliver.hpp index cca9d3ee..26191374 100644 --- a/src/mtconnect/pipeline/deliver.hpp +++ b/src/mtconnect/pipeline/deliver.hpp @@ -136,7 +136,7 @@ namespace mtconnect::pipeline { { m_guard = TypeGuard(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 @@ -150,7 +150,7 @@ namespace mtconnect::pipeline { { m_guard = TypeGuard(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 @@ -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; @@ -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; @@ -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; diff --git a/src/mtconnect/pipeline/delta_filter.hpp b/src/mtconnect/pipeline/delta_filter.hpp index f1d8f968..d84a8084 100644 --- a/src/mtconnect/pipeline/delta_filter.hpp +++ b/src/mtconnect/pipeline/delta_filter.hpp @@ -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; @@ -68,7 +68,7 @@ namespace mtconnect { if (o->isUnavailable()) { m_state->m_lastSampleValue.erase(id); - return next(entity); + return next(std::move(entity)); } auto filter = *di->getMinimumDelta(); @@ -76,7 +76,7 @@ namespace mtconnect { if (filterMinimumDelta(id, value, filter)) return EntityPtr(); - return next(entity); + return next(std::move(entity)); } protected: diff --git a/src/mtconnect/pipeline/duplicate_filter.hpp b/src/mtconnect/pipeline/duplicate_filter.hpp index 9ca9bfdd..21f5e49d 100644 --- a/src/mtconnect/pipeline/duplicate_filter.hpp +++ b/src/mtconnect/pipeline/duplicate_filter.hpp @@ -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; @@ -52,7 +55,7 @@ namespace mtconnect::pipeline { if (!o2) return entity::EntityPtr(); else - return next(o2); + return next(std::move(o2)); } protected: diff --git a/src/mtconnect/pipeline/guard.hpp b/src/mtconnect/pipeline/guard.hpp index f9589552..6b252605 100644 --- a/src/mtconnect/pipeline/guard.hpp +++ b/src/mtconnect/pipeline/guard.hpp @@ -31,7 +31,7 @@ namespace mtconnect { }; /// @brief Guard is a lambda function returning a `GuardAction` taking an entity - using Guard = std::function; + using Guard = std::function; /// @brief A simple GuardClass returning a simple match /// @@ -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 @@ -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; @@ -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(entity.get()); } + constexpr bool matches(const entity::Entity *entity) { return match(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; @@ -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(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; @@ -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; @@ -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(entity.get()); + auto o = dynamic_cast(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; diff --git a/src/mtconnect/pipeline/message_mapper.hpp b/src/mtconnect/pipeline/message_mapper.hpp index 15a8e0db..9200d1f2 100644 --- a/src/mtconnect/pipeline/message_mapper.hpp +++ b/src/mtconnect/pipeline/message_mapper.hpp @@ -44,7 +44,7 @@ namespace mtconnect::pipeline { m_guard = TypeGuard(RUN); } - const EntityPtr operator()(const EntityPtr entity) override + EntityPtr operator()(entity::EntityPtr &&entity) override { auto json = std::dynamic_pointer_cast(entity); @@ -67,7 +67,7 @@ namespace mtconnect::pipeline { m_guard = TypeGuard(RUN); } - const EntityPtr operator()(const EntityPtr entity) override + EntityPtr operator()(entity::EntityPtr &&entity) override { auto data = std::dynamic_pointer_cast(entity); if (data->m_dataItem) @@ -99,7 +99,7 @@ namespace mtconnect::pipeline { // Try processing as shdr data auto entity = make_shared( "Data", Properties {{"VALUE", data->getValue()}, {"source", string("")}}); - next(entity); + next(std::move(entity)); } else { diff --git a/src/mtconnect/pipeline/mtconnect_xml_transform.hpp b/src/mtconnect/pipeline/mtconnect_xml_transform.hpp index 94225067..5cf7d55b 100644 --- a/src/mtconnect/pipeline/mtconnect_xml_transform.hpp +++ b/src/mtconnect/pipeline/mtconnect_xml_transform.hpp @@ -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; @@ -90,7 +90,7 @@ namespace mtconnect::pipeline { for (auto &entity : rd.m_entities) { - next(entity); + next(std::move(entity)); } return std::make_shared("Entities", Properties {{"VALUE", rd.m_entities}}); diff --git a/src/mtconnect/pipeline/period_filter.hpp b/src/mtconnect/pipeline/period_filter.hpp index ca3e4f46..4becceff 100644 --- a/src/mtconnect/pipeline/period_filter.hpp +++ b/src/mtconnect/pipeline/period_filter.hpp @@ -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; diff --git a/src/mtconnect/pipeline/pipeline.hpp b/src/mtconnect/pipeline/pipeline.hpp index e746091b..20a0044f 100644 --- a/src/mtconnect/pipeline/pipeline.hpp +++ b/src/mtconnect/pipeline/pipeline.hpp @@ -81,6 +81,7 @@ namespace mtconnect { } } + /// @brief remove all transforms from the pipeline void clear() { using namespace std::chrono_literals; @@ -108,6 +109,7 @@ namespace mtconnect { } } + /// @brief start all the transforms that require asynchronous operations virtual void start() { if (m_start) @@ -117,6 +119,9 @@ namespace mtconnect { } } + /// @brief Find all transforms that match the target + /// @param[in] target the named transforms to find + /// @return a list of all matching transforms Transform::ListOfTransforms find(const std::string &target) { Transform::ListOfTransforms xforms; @@ -124,6 +129,11 @@ namespace mtconnect { return xforms; } + /// @brief add a transform before the target. + /// @param[in] target the named transforms to insert this transform before + /// @param[in] transform the transform to add before + /// @param[in] reapplied `true` if the pipeline is being rebuilt + /// @returns `true` if the target is found and spliced bool spliceBefore(const std::string &target, TransformPtr transform, bool reapplied = false) { Transform::ListOfTransforms xforms; @@ -145,6 +155,13 @@ namespace mtconnect { return true; } + + + /// @brief add a transform after the target. + /// @param[in] target the named transforms to insert this transform after + /// @param[in] transform the transform to add before + /// @param[in] reapplied `true` if the pipeline is being rebuilt + /// @returns `true` if the target is found and spliced bool spliceAfter(const std::string &target, TransformPtr transform, bool reapplied = false) { Transform::ListOfTransforms xforms; @@ -166,6 +183,12 @@ namespace mtconnect { return true; } + + /// @brief splices the transform as the first option in targets next list. + /// @param[in] target the named transforms to insert this transform after + /// @param[in] transform the transform to add before + /// @param[in] reapplied `true` if the pipeline is being rebuilt + /// @returns `true` if the target is found and spliced bool firstAfter(const std::string &target, TransformPtr transform, bool reapplied = false) { Transform::ListOfTransforms xforms; @@ -186,6 +209,11 @@ namespace mtconnect { return true; } + /// @brief splices the transform as the last option in targets next list. + /// @param[in] target the named transforms to insert this transform after + /// @param[in] transform the transform to add before + /// @param[in] reapplied `true` if the pipeline is being rebuilt + /// @returns `true` if the target is found and spliced bool lastAfter(const std::string &target, TransformPtr transform, bool reapplied = false) { Transform::ListOfTransforms xforms; @@ -206,6 +234,11 @@ namespace mtconnect { return true; } + /// @brief replaces each occurence of target with transform. + /// @param[in] target the named transforms to replace + /// @param[in] transform the transform to add before + /// @param[in] reapplied `true` if the pipeline is being rebuilt + /// @returns `true` if the target is found and spliced bool replace(const std::string &target, TransformPtr transform, bool reapplied = false) { Transform::ListOfTransforms xforms; @@ -228,6 +261,9 @@ namespace mtconnect { return true; } + /// @brief removes the named transform. + /// @param[in] target the named transforms to replace + /// @returns `true` if the target is found and spliced bool remove(const std::string &target) { Transform::ListOfTransforms xforms; @@ -245,17 +281,35 @@ namespace mtconnect { return true; } - const entity::EntityPtr run(const entity::EntityPtr entity) { return m_start->next(entity); } + /// @brief Sends the entity through the pipeline + /// @param[in] entity the entity to send through the pipeline + /// @return the entity returned from the transform + entity::EntityPtr run(entity::EntityPtr &&entity) + { + return m_start->next(std::move(entity)); + } + /// @brief Bind the transform to the start + /// @param[in] transform the transform to bind + /// @return returns `transform` TransformPtr bind(TransformPtr transform) { m_start->bind(transform); return transform; } + /// @brief check if the pipeline has a pipeline context + /// @returns `true` if there is a context bool hasContext() const { return bool(m_context); } + + /// @brief check if the pipeline has a pipeline contract + /// @returns `true` if there is a contract bool hasContract() const { return bool(m_context) && bool(m_context->m_contract); } + /// @brief gets the pipeline context + /// @returns a shared pointer to the pipeline context PipelineContextPtr getContext() { return m_context; } + /// @brief gets the pipeline contract + /// @returns the pipeline contract const auto &getContract() { return m_context->m_contract; } protected: @@ -264,11 +318,11 @@ namespace mtconnect { public: Start() : Transform("Start") { - m_guard = [](const entity::EntityPtr entity) { return SKIP; }; + m_guard = [](const entity::Entity *entity) { return SKIP; }; } ~Start() override = default; - const entity::EntityPtr operator()(const entity::EntityPtr entity) override + entity::EntityPtr operator()(entity::EntityPtr &&entity) override { return entity::EntityPtr(); } diff --git a/src/mtconnect/pipeline/pipeline_context.hpp b/src/mtconnect/pipeline/pipeline_context.hpp index 89d3b58f..99d506a0 100644 --- a/src/mtconnect/pipeline/pipeline_context.hpp +++ b/src/mtconnect/pipeline/pipeline_context.hpp @@ -73,5 +73,7 @@ namespace mtconnect::pipeline { using SharedState = std::unordered_map; SharedState m_sharedState; }; + + /// @brief Alias for a shared pointer to the pipeline context using PipelineContextPtr = std::shared_ptr; } // namespace mtconnect::pipeline diff --git a/src/mtconnect/pipeline/pipeline_contract.hpp b/src/mtconnect/pipeline/pipeline_contract.hpp index 76c345d4..4baf2e0c 100644 --- a/src/mtconnect/pipeline/pipeline_contract.hpp +++ b/src/mtconnect/pipeline/pipeline_contract.hpp @@ -101,6 +101,11 @@ namespace mtconnect { /// @param[in] identity the identity of the source virtual void sourceFailed(const std::string &identity) = 0; + /// @brief Check the observation with the current cache to determine if this is a + /// duplicate + /// @param[in] obs the observation to check + /// @returns `obs` if it is not a duplicate, `nullptr` if it is. The observation + /// may be modified if the observation needs to be subset. virtual const ObservationPtr checkDuplicate(const ObservationPtr &obs) const = 0; }; } // namespace pipeline diff --git a/src/mtconnect/pipeline/shdr_token_mapper.cpp b/src/mtconnect/pipeline/shdr_token_mapper.cpp index 3c878d43..5c022236 100644 --- a/src/mtconnect/pipeline/shdr_token_mapper.cpp +++ b/src/mtconnect/pipeline/shdr_token_mapper.cpp @@ -327,7 +327,7 @@ namespace mtconnect { return res; } - const EntityPtr ShdrTokenMapper::operator()(const EntityPtr entity) + EntityPtr ShdrTokenMapper::operator()(EntityPtr &&entity) { NAMED_SCOPE("DataItemMapper.ShdrTokenMapper.operator"); if (auto timestamped = std::dynamic_pointer_cast(entity)) @@ -362,7 +362,7 @@ namespace mtconnect { if (out && errors.empty()) { - auto fwd = next(out); + auto fwd = next(std::move(out)); if (fwd) entities.emplace_back(fwd); } diff --git a/src/mtconnect/pipeline/shdr_token_mapper.hpp b/src/mtconnect/pipeline/shdr_token_mapper.hpp index 8294282d..45829781 100644 --- a/src/mtconnect/pipeline/shdr_token_mapper.hpp +++ b/src/mtconnect/pipeline/shdr_token_mapper.hpp @@ -49,7 +49,7 @@ namespace mtconnect::pipeline { { m_guard = TypeGuard(RUN); } - const EntityPtr operator()(const EntityPtr entity) override; + EntityPtr operator()(entity::EntityPtr &&entity) override; /// @brief Takes a tokenized set of fields and maps them data items /// @param[in] timestamp the timestamp from prior extraction diff --git a/src/mtconnect/pipeline/shdr_tokenizer.hpp b/src/mtconnect/pipeline/shdr_tokenizer.hpp index b9f48f1d..5512d7ca 100644 --- a/src/mtconnect/pipeline/shdr_tokenizer.hpp +++ b/src/mtconnect/pipeline/shdr_tokenizer.hpp @@ -47,7 +47,7 @@ namespace mtconnect::pipeline { ShdrTokenizer() : Transform("ShdrTokenizer") { m_guard = EntityNameGuard("Data", RUN); } ~ShdrTokenizer() = default; - const entity::EntityPtr operator()(const entity::EntityPtr data) override + entity::EntityPtr operator()(entity::EntityPtr &&data) override { auto &body = data->getValue(); entity::Properties props; diff --git a/src/mtconnect/pipeline/timestamp_extractor.hpp b/src/mtconnect/pipeline/timestamp_extractor.hpp index 3ea04855..86dc5825 100644 --- a/src/mtconnect/pipeline/timestamp_extractor.hpp +++ b/src/mtconnect/pipeline/timestamp_extractor.hpp @@ -63,7 +63,7 @@ namespace mtconnect::pipeline { ~ExtractTimestamp() override = default; using Now = std::function; - const EntityPtr operator()(const EntityPtr ptr) override + EntityPtr operator()(entity::EntityPtr &&ptr) override { TimestampedPtr res; std::optional token; @@ -109,7 +109,7 @@ namespace mtconnect::pipeline { IgnoreTimestamp(const IgnoreTimestamp &) = default; ~IgnoreTimestamp() override = default; - const EntityPtr operator()(const EntityPtr ptr) override + EntityPtr operator()(entity::EntityPtr &&ptr) override { TimestampedPtr res; std::optional token; diff --git a/src/mtconnect/pipeline/topic_mapper.hpp b/src/mtconnect/pipeline/topic_mapper.hpp index 8fe9e922..48b7c143 100644 --- a/src/mtconnect/pipeline/topic_mapper.hpp +++ b/src/mtconnect/pipeline/topic_mapper.hpp @@ -138,7 +138,7 @@ namespace mtconnect::pipeline { return std::make_tuple(device, dataItem); } - const EntityPtr operator()(const EntityPtr entity) override + EntityPtr operator()(entity::EntityPtr &&entity) override { auto &body = entity->getValue(); DataItemPtr dataItem; diff --git a/src/mtconnect/pipeline/transform.hpp b/src/mtconnect/pipeline/transform.hpp index 7ee889cb..ac3948b6 100644 --- a/src/mtconnect/pipeline/transform.hpp +++ b/src/mtconnect/pipeline/transform.hpp @@ -90,7 +90,7 @@ namespace mtconnect { /// @brief the transform method must be overloaded /// @param entity the entity /// @return the resulting entity - virtual const entity::EntityPtr operator()(const entity::EntityPtr entity) = 0; + virtual entity::EntityPtr operator()(entity::EntityPtr &&entity) = 0; TransformPtr getptr() { return shared_from_this(); } /// @brief get the list of next transforms @@ -100,7 +100,7 @@ namespace mtconnect { /// @brief Find the next transform to forward the entity on to /// @param entity the entity /// @return return the result of the transformation - const entity::EntityPtr next(const entity::EntityPtr entity) + entity::EntityPtr next(entity::EntityPtr &&entity) { if (m_next.empty()) return entity; @@ -110,13 +110,13 @@ namespace mtconnect { for (auto &t : m_next) { - switch (t->check(entity)) + switch (t->check(entity.get())) { case RUN: - return (*t)(entity); + return (*t)(std::move(entity)); case SKIP: - return t->next(entity); + return t->next(std::move(entity)); case CONTINUE: // Move on to the next @@ -141,7 +141,7 @@ namespace mtconnect { /// @brief get the guard action for an entity /// @param[in] entity the entity /// @return the action to perform - GuardAction check(const entity::EntityPtr entity) + GuardAction check(const entity::Entity *entity) { if (!m_guard) return RUN; @@ -271,7 +271,7 @@ namespace mtconnect { { public: NullTransform(Guard guard) : Transform("NullTransform") { m_guard = guard; } - const entity::EntityPtr operator()(const entity::EntityPtr entity) override { return entity; } + entity::EntityPtr operator()(entity::EntityPtr &&entity) override { return entity; } }; } // namespace pipeline diff --git a/src/mtconnect/pipeline/upcase_value.hpp b/src/mtconnect/pipeline/upcase_value.hpp index a860803a..b95bb24a 100644 --- a/src/mtconnect/pipeline/upcase_value.hpp +++ b/src/mtconnect/pipeline/upcase_value.hpp @@ -45,7 +45,7 @@ namespace mtconnect::pipeline { m_guard = ExactTypeGuard(RUN) || TypeGuard(SKIP); } - const EntityPtr operator()(const EntityPtr entity) override + EntityPtr operator()(entity::EntityPtr &&entity) override { using namespace observation; auto event = std::dynamic_pointer_cast(entity); diff --git a/src/mtconnect/ruby/ruby_pipeline.hpp b/src/mtconnect/ruby/ruby_pipeline.hpp index c71f611e..beb10a3c 100644 --- a/src/mtconnect/ruby/ruby_pipeline.hpp +++ b/src/mtconnect/ruby/ruby_pipeline.hpp @@ -197,7 +197,7 @@ namespace mtconnect::ruby { mrb_get_args(mrb, "d", &entity, MRubySharedPtr::type()); EntityPtr ptr = *entity; - ptr = pipeline->run(ptr); + ptr = pipeline->run(std::move(ptr)); return MRubySharedPtr::wrap(mrb, "Entity", ptr); }, diff --git a/src/mtconnect/ruby/ruby_transform.hpp b/src/mtconnect/ruby/ruby_transform.hpp index 0c836884..c679b71c 100644 --- a/src/mtconnect/ruby/ruby_transform.hpp +++ b/src/mtconnect/ruby/ruby_transform.hpp @@ -51,7 +51,7 @@ namespace mtconnect::ruby { EntityPtr *ent; mrb_get_args(mrb, "d", &ent, MRubySharedPtr::type()); - auto r = (*trans)(*ent); + auto r = (*trans)(std::move(*ent)); return MRubySharedPtr::wrap(mrb, "Entity", r); }, MRB_ARGS_REQ(1)); @@ -91,7 +91,7 @@ namespace mtconnect::ruby { EntityPtr *ent; mrb_get_args(mrb, "d", &ent, MRubySharedPtr::type()); - auto nxt = trans->next(*ent); + auto nxt = trans->next(std::move(*ent)); return MRubySharedPtr::wrap(mrb, "Entity", nxt); }, MRB_ARGS_REQ(1)); @@ -179,7 +179,7 @@ namespace mtconnect::ruby { if (!mrb_nil_p(m_guardBlock)) { - m_guard = [this, old = m_guard](const entity::EntityPtr entity) -> GuardAction { + m_guard = [this, old = m_guard](const entity::Entity *entity) -> GuardAction { using namespace entity; using namespace observation; std::lock_guard guard(RubyVM::rubyVM()); @@ -187,7 +187,8 @@ namespace mtconnect::ruby { auto mrb = RubyVM::rubyVM().state(); int save = mrb_gc_arena_save(mrb); - mrb_value ev = MRubySharedPtr::wrap(mrb, "Entity", entity); + entity::EntityPtr ptr = entity->getptr(); + mrb_value ev = MRubySharedPtr::wrap(mrb, "Entity", ptr); mrb_bool state = false; mrb_value values[] = {m_guardBlock, ev}; @@ -223,7 +224,7 @@ namespace mtconnect::ruby { using calldata = pair; - const entity::EntityPtr operator()(const entity::EntityPtr entity) override + entity::EntityPtr operator()(entity::EntityPtr &&entity) override { NAMED_SCOPE("RubyTransform::operator()"); diff --git a/src/mtconnect/source/adapter/adapter_pipeline.cpp b/src/mtconnect/source/adapter/adapter_pipeline.cpp index fb841f5e..ce6f83c8 100644 --- a/src/mtconnect/source/adapter/adapter_pipeline.cpp +++ b/src/mtconnect/source/adapter/adapter_pipeline.cpp @@ -47,32 +47,32 @@ namespace mtconnect { handler->m_connecting = [this](const std::string &id) { auto entity = make_shared("ConnectionStatus", Properties {{"VALUE", "CONNECTING"s}, {"source", id}}); - run(entity); + run(std::move(entity)); }; handler->m_connected = [this](const std::string &id) { auto entity = make_shared("ConnectionStatus", Properties {{"VALUE", "CONNECTED"s}, {"source", id}}); - run(entity); + run(std::move(entity)); }; handler->m_disconnected = [this](const std::string &id) { auto entity = make_shared("ConnectionStatus", Properties {{"VALUE", "DISCONNECTED"s}, {"source", id}}); - run(entity); + run(std::move(entity)); }; handler->m_processData = [this](const std::string &data, const std::string &source) { auto entity = make_shared("Data", Properties {{"VALUE", data}, {"source", source}}); - run(entity); + run(std::move(entity)); }; handler->m_processMessage = [this](const std::string &topic, const std::string &data, const std::string &source) { auto entity = make_shared( "Message", Properties {{"VALUE", data}, {"topic", topic}, {"source", source}}); - run(entity); + run(std::move(entity)); }; handler->m_command = [this](const std::string &data, const std::string &source) { auto entity = make_shared("Command", Properties {{"VALUE", data}, {"source", source}}); - run(entity); + run(std::move(entity)); }; return handler; diff --git a/src/mtconnect/source/loopback_source.cpp b/src/mtconnect/source/loopback_source.cpp index 3ea7da94..05acd1de 100644 --- a/src/mtconnect/source/loopback_source.cpp +++ b/src/mtconnect/source/loopback_source.cpp @@ -94,7 +94,7 @@ namespace mtconnect::source { SequenceNumber_t LoopbackSource::receive(const std::string &data) { auto ent = make_shared("Data", Properties {{"VALUE", data}, {"source", getIdentity()}}); - auto res = m_pipeline.run(ent); + auto res = m_pipeline.run(std::move(ent)); if (auto obs = std::dynamic_pointer_cast(res)) { return obs->getSequence(); diff --git a/test/embedded_ruby_test.cpp b/test/embedded_ruby_test.cpp index e5aa6df2..4056960b 100644 --- a/test/embedded_ruby_test.cpp +++ b/test/embedded_ruby_test.cpp @@ -379,7 +379,7 @@ p $source )"s}}; auto entity = make_shared("Data", props); - loopback->getPipeline()->run(entity); + loopback->getPipeline()->run(std::move(entity)); auto contract = static_cast(m_context->m_contract.get()); ASSERT_TRUE(contract->m_observation); @@ -412,7 +412,7 @@ p $source Properties props {{"VALUE", "PLC1002:MACHINE ON FIRE"s}}; auto entity = make_shared("Data", props); - loopback->getPipeline()->run(entity); + loopback->getPipeline()->run(std::move(entity)); auto contract = static_cast(m_context->m_contract.get()); @@ -427,7 +427,7 @@ p $source Properties props2 {{"VALUE", "NC155:SORRY, I DON'T WANT TO"s}}; entity = make_shared("Data", props2); - loopback->getPipeline()->run(entity); + loopback->getPipeline()->run(std::move(entity)); ASSERT_TRUE(contract->m_observation); cond = dynamic_pointer_cast(contract->m_observation); diff --git a/test/mtconnect_xml_transform_test.cpp b/test/mtconnect_xml_transform_test.cpp index 2e8f947a..dbdc1bc3 100644 --- a/test/mtconnect_xml_transform_test.cpp +++ b/test/mtconnect_xml_transform_test.cpp @@ -99,7 +99,7 @@ TEST_F(MTConnectXmlTransformTest, should_add_next_to_the_context) auto entity = make_shared("Data", Properties {{"VALUE", data}, {"source", "adapter"s}}); - auto res1 = (*m_xform)(entity); + auto res1 = (*m_xform)(std::move(entity)); ASSERT_EQ(1649989201, m_feedback.m_instanceId); ASSERT_EQ(4992049, m_feedback.m_next); @@ -117,7 +117,7 @@ TEST_F(MTConnectXmlTransformTest, should_return_errors) auto entity = make_shared("Data", Properties {{"VALUE", data}, {"source", "adapter"s}}); - EXPECT_THROW((*m_xform)(entity), std::system_error); + EXPECT_THROW((*m_xform)(std::move(entity)), std::system_error); ASSERT_EQ(1, m_feedback.m_errors.size()); auto &error = m_feedback.m_errors.front(); @@ -136,7 +136,7 @@ TEST_F(MTConnectXmlTransformTest, should_throw_when_instances_change) auto entity = make_shared("Data", Properties {{"VALUE", data}, {"source", "adapter"s}}); - auto res1 = (*m_xform)(entity); + auto res1 = (*m_xform)(std::move(entity)); ASSERT_EQ(1649989201, m_feedback.m_instanceId); ASSERT_EQ(4992049, m_feedback.m_next); @@ -150,7 +150,7 @@ TEST_F(MTConnectXmlTransformTest, should_throw_when_instances_change) entity = make_shared("Data", Properties {{"VALUE", recover}, {"source", "adapter"s}}); - EXPECT_THROW((*m_xform)(entity), std::system_error); + EXPECT_THROW((*m_xform)(std::move(entity)), std::system_error); ASSERT_EQ(1649989201, m_feedback.m_instanceId); ASSERT_EQ(4992049, m_feedback.m_next); } diff --git a/test/pipeline_edit_test.cpp b/test/pipeline_edit_test.cpp index b2ea1c83..130c0976 100644 --- a/test/pipeline_edit_test.cpp +++ b/test/pipeline_edit_test.cpp @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) return RUN_ALL_TESTS(); } -using TransformFun = std::function; +using TransformFun = std::function; class TestTransform : public Transform { public: @@ -59,7 +59,7 @@ class TestTransform : public Transform TestTransform(const std::string &name, Guard guard) : Transform(name) { m_guard = guard; } TestTransform(const std::string &name) : Transform(name) {} - const EntityPtr operator()(const EntityPtr ptr) override { return m_function(ptr); } + EntityPtr operator()(EntityPtr &&ptr) override { return m_function(std::move(ptr)); } void setGuard(Guard &guard) { m_guard = guard; } TransformFun m_function; @@ -85,17 +85,17 @@ class PipelineEditTest : public testing::Test m_pipeline = make_unique(m_context, strand); TestTransformPtr ta = make_shared("A"s, EntityNameGuard("X", RUN)); - ta->m_function = [ta](const EntityPtr entity) { + ta->m_function = [ta](EntityPtr &&entity) { EntityPtr ret = shared_ptr(new Entity(*entity)); ret->setValue(ret->getValue() + "A"s); - return ta->next(ret); + return ta->next(std::move(ret)); }; TestTransformPtr tb = make_shared("B"s, EntityNameGuard("X", RUN)); - tb->m_function = [tb](const EntityPtr entity) { + tb->m_function = [tb](EntityPtr &&entity) { EntityPtr ret = shared_ptr(new Entity(*entity)); ret->setValue(ret->getValue() + "B"s); - return tb->next(ret); + return tb->next(std::move(ret)); }; TestTransformPtr tc = make_shared("C"s, EntityNameGuard("X", RUN)); @@ -124,7 +124,7 @@ class PipelineEditTest : public testing::Test TEST_F(PipelineEditTest, run_three_transforms) { auto entity = shared_ptr(new Entity("X", Properties {{"VALUE", "S"s}})); - auto result = m_pipeline->run(entity); + auto result = m_pipeline->run(std::move(entity)); ASSERT_EQ("SABC", result->getValue()); } @@ -132,16 +132,16 @@ TEST_F(PipelineEditTest, run_three_transforms) TEST_F(PipelineEditTest, insert_R_before_B) { TestTransformPtr tr = make_shared("R"s, EntityNameGuard("X", RUN)); - tr->m_function = [&tr](const EntityPtr entity) { + tr->m_function = [&tr](EntityPtr &&entity) { EntityPtr ret = shared_ptr(new Entity(*entity)); ret->setValue(ret->getValue() + "R"s); - return tr->next(ret); + return tr->next(std::move(ret)); }; ASSERT_TRUE(m_pipeline->spliceBefore("B", tr)); auto entity = shared_ptr(new Entity("X", Properties {{"VALUE", "S"s}})); - auto result = m_pipeline->run(entity); + auto result = m_pipeline->run(std::move(entity)); ASSERT_EQ("SARBC", result->getValue()); } @@ -149,16 +149,16 @@ TEST_F(PipelineEditTest, insert_R_before_B) TEST_F(PipelineEditTest, insert_R_after_B) { TestTransformPtr tr = make_shared("R"s, EntityNameGuard("X", RUN)); - tr->m_function = [&tr](const EntityPtr entity) { + tr->m_function = [&tr](EntityPtr &&entity) { EntityPtr ret = shared_ptr(new Entity(*entity)); ret->setValue(ret->getValue() + "R"s); - return tr->next(ret); + return tr->next(std::move(ret)); }; ASSERT_TRUE(m_pipeline->spliceAfter("B", tr)); auto entity = shared_ptr(new Entity("X", Properties {{"VALUE", "S"s}})); - auto result = m_pipeline->run(entity); + auto result = m_pipeline->run(std::move(entity)); ASSERT_EQ("SABRC", result->getValue()); } @@ -175,7 +175,7 @@ TEST_F(PipelineEditTest, append_R_first_after_B) ASSERT_TRUE(m_pipeline->firstAfter("B", tr)); auto entity = shared_ptr(new Entity("X", Properties {{"VALUE", "S"s}})); - auto result = m_pipeline->run(entity); + auto result = m_pipeline->run(std::move(entity)); ASSERT_EQ("SABR", result->getValue()); } @@ -192,7 +192,7 @@ TEST_F(PipelineEditTest, append_R_last_after_B) ASSERT_TRUE(m_pipeline->lastAfter("B"s, tr)); auto entity = shared_ptr(new Entity("X", Properties {{"VALUE", "S"s}})); - auto result = m_pipeline->run(entity); + auto result = m_pipeline->run(std::move(entity)); ASSERT_EQ("SABC", result->getValue()); } diff --git a/test/shdr_tokenizer_test.cpp b/test/shdr_tokenizer_test.cpp index 1e426eb2..47b022df 100644 --- a/test/shdr_tokenizer_test.cpp +++ b/test/shdr_tokenizer_test.cpp @@ -83,7 +83,7 @@ TEST_F(ShdrTokenizerTest, SimpleTokens) for (const auto &test : data) { auto data = std::make_shared("Data", Properties {{"VALUE", test.first}}); - auto entity = (*m_tokenizer)(data); + auto entity = (*m_tokenizer)(std::move(data)); ASSERT_TRUE(entity); auto tokens = dynamic_pointer_cast(entity); ASSERT_TRUE(tokens); @@ -146,7 +146,7 @@ TEST_F(ShdrTokenizerTest, escaped_line) for (const auto &test : data) { auto data = std::make_shared("Data", Properties {{"VALUE", test.first}}); - auto entity = (*m_tokenizer)(data); + auto entity = (*m_tokenizer)(std::move(data)); ASSERT_TRUE(entity); auto tokens = dynamic_pointer_cast(entity); ASSERT_TRUE(tokens);