diff --git a/CMakeLists.txt b/CMakeLists.txt index 996cf2bc..1420880c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ set(AGENT_VERSION_MAJOR 2) set(AGENT_VERSION_MINOR 4) set(AGENT_VERSION_PATCH 0) -set(AGENT_VERSION_BUILD 4) +set(AGENT_VERSION_BUILD 5) set(AGENT_VERSION_RC "") # This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent diff --git a/demo/agent/mazak.txt b/demo/agent/mazak.txt index f293f5f5..1720b21e 100644 --- a/demo/agent/mazak.txt +++ b/demo/agent/mazak.txt @@ -1,4 +1,3 @@ -=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2022.02.02 14:04:20 =~=~=~=~=~=~=~=~=~=~=~= * uuid: 342072d3-5a0b-f184-2de1-d6f24108c59f * manufacturer: Mazak_Corporation * description: Variaxis w/SMooth-AI diff --git a/src/mtconnect/agent.cpp b/src/mtconnect/agent.cpp index d350f92c..a14c15cb 100644 --- a/src/mtconnect/agent.cpp +++ b/src/mtconnect/agent.cpp @@ -232,6 +232,8 @@ namespace mtconnect { // Start all the sources for (auto source : m_sources) source->start(); + + m_afterStartHooks.exec(*this); } catch (std::runtime_error &e) { diff --git a/src/mtconnect/agent.hpp b/src/mtconnect/agent.hpp index c827d7cf..9179c8ce 100644 --- a/src/mtconnect/agent.hpp +++ b/src/mtconnect/agent.hpp @@ -112,6 +112,10 @@ namespace mtconnect { /// @brief Hooks to run when before the agent starts all the soures and sinks /// @return configuration::HookManager& auto &beforeStartHooks() { return m_beforeStartHooks; } + + /// @brief Hooks to run when after the agent starts all the soures and sinks + /// @return configuration::HookManager& + auto &afterStartHooks() { return m_afterStartHooks; } /// @brief Hooks before the agent stops all the sources and sinks /// @return configuration::HookManager& @@ -546,6 +550,7 @@ namespace mtconnect { configuration::HookManager m_beforeInitializeHooks; configuration::HookManager m_afterInitializeHooks; configuration::HookManager m_beforeStartHooks; + configuration::HookManager m_afterStartHooks; configuration::HookManager m_beforeStopHooks; configuration::HookManager m_beforeDeviceXmlUpdateHooks; configuration::HookManager m_afterDeviceXmlUpdateHooks; @@ -655,6 +660,49 @@ namespace mtconnect { } buffer::CircularBuffer &getCircularBuffer() override { return m_agent->getCircularBuffer(); } + + configuration::HookManager &getHooks(HookType type) override + { + using namespace sink; + switch (type) + { + case BEFORE_START: + return m_agent->beforeStartHooks(); + break; + + case AFTER_START: + return m_agent->afterStartHooks(); + break; + + case BEFORE_STOP: + return m_agent->beforeStopHooks(); + break; + + case BEFORE_DEVICE_XML_UPDATE: + return m_agent->beforeDeviceXmlUpdateHooks(); + break; + + case AFTER_DEVICE_XML_UPDATE: + return m_agent->afterDeviceXmlUpdateHooks(); + break; + + case BEFORE_INITIALIZE: + return m_agent->beforeInitializeHooks(); + break; + + case AFTER_INITIALIZE: + return m_agent->afterInitializeHooks(); + break; + } + + LOG(error) << "getHooks: Bad hook manager type given to sink contract"; + throw std::runtime_error("getHooks: Bad hook manager type"); + + // Never gets here. + static configuration::HookManager NullHooks; + return NullHooks; + } + protected: Agent *m_agent; diff --git a/src/mtconnect/sink/sink.hpp b/src/mtconnect/sink/sink.hpp index 1e517284..14d38e1f 100644 --- a/src/mtconnect/sink/sink.hpp +++ b/src/mtconnect/sink/sink.hpp @@ -31,6 +31,7 @@ #include "mtconnect/device_model/device.hpp" #include "mtconnect/observation/observation.hpp" #include "mtconnect/printer//printer.hpp" +#include "mtconnect/configuration/hook_manager.hpp" namespace mtconnect { namespace printer { @@ -46,6 +47,7 @@ namespace mtconnect { namespace buffer { class CircularBuffer; } + class Agent; /// @brief The Sink namespace for outgoing data from the agent namespace sink { @@ -53,6 +55,16 @@ namespace mtconnect { class AGENT_LIB_API SinkContract { public: + enum HookType { + BEFORE_STOP, + BEFORE_START, + AFTER_START, + BEFORE_DEVICE_XML_UPDATE, + AFTER_DEVICE_XML_UPDATE, + BEFORE_INITIALIZE, + AFTER_INITIALIZE + }; + virtual ~SinkContract() = default; /// @brief get the printer for a mime type. Current options: `xml` or `json`. /// @param[in] aType a string for the type @@ -102,6 +114,11 @@ namespace mtconnect { /// @brief Get a pointer to the asset storage /// @return a pointer to the asset storage. virtual const asset::AssetStorage *getAssetStorage() = 0; + + /// @brief Get a reference to the hook manager for the agent. + /// @param[in] type the type manager to retrieve + /// @return a reference to the hook manager + virtual configuration::HookManager &getHooks(HookType type) = 0; /// @brief Shared pointer to the pipeline context std::shared_ptr m_pipelineContext; diff --git a/styles/styles.xsl b/styles/styles.xsl index 06627723..2be09db2 100644 --- a/styles/styles.xsl +++ b/styles/styles.xsl @@ -4,9 +4,9 @@ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" - xmlns:m="urn:mtconnect.org:MTConnectDevices:2.2" - xmlns:s="urn:mtconnect.org:MTConnectStreams:2.2" - xmlns:e="urn:mtconnect.org:MTConnectError:2.2" + xmlns:m="urn:mtconnect.org:MTConnectDevices:2.3" + xmlns:s="urn:mtconnect.org:MTConnectStreams:2.3" + xmlns:e="urn:mtconnect.org:MTConnectError:2.3" xmlns:js="urn:custom-javascript" exclude-result-prefixes="msxsl js" xmlns:msxsl="urn:schemas-microsoft-com:xslt"