Skip to content

Commit

Permalink
Merge pull request #497 from mtconnect/add_hooks_to_sink_contract
Browse files Browse the repository at this point in the history
Added access to agent hooks in sink contract
  • Loading branch information
wsobel authored Nov 18, 2024
2 parents e7f77e2 + 815bccd commit ccb0e40
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 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 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
Expand Down
1 change: 0 additions & 1 deletion demo/agent/mazak.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/mtconnect/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
48 changes: 48 additions & 0 deletions src/mtconnect/agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ namespace mtconnect {
/// @brief Hooks to run when before the agent starts all the soures and sinks
/// @return configuration::HookManager<Agent>&
auto &beforeStartHooks() { return m_beforeStartHooks; }

/// @brief Hooks to run when after the agent starts all the soures and sinks
/// @return configuration::HookManager<Agent>&
auto &afterStartHooks() { return m_afterStartHooks; }

/// @brief Hooks before the agent stops all the sources and sinks
/// @return configuration::HookManager<Agent>&
Expand Down Expand Up @@ -546,6 +550,7 @@ namespace mtconnect {
configuration::HookManager<Agent> m_beforeInitializeHooks;
configuration::HookManager<Agent> m_afterInitializeHooks;
configuration::HookManager<Agent> m_beforeStartHooks;
configuration::HookManager<Agent> m_afterStartHooks;
configuration::HookManager<Agent> m_beforeStopHooks;
configuration::HookManager<Agent> m_beforeDeviceXmlUpdateHooks;
configuration::HookManager<Agent> m_afterDeviceXmlUpdateHooks;
Expand Down Expand Up @@ -655,6 +660,49 @@ namespace mtconnect {
}

buffer::CircularBuffer &getCircularBuffer() override { return m_agent->getCircularBuffer(); }

configuration::HookManager<Agent> &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<Agent> NullHooks;
return NullHooks;
}


protected:
Agent *m_agent;
Expand Down
17 changes: 17 additions & 0 deletions src/mtconnect/sink/sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -46,13 +47,24 @@ namespace mtconnect {
namespace buffer {
class CircularBuffer;
}
class Agent;

/// @brief The Sink namespace for outgoing data from the agent
namespace sink {
/// @brief Interface required by sinks
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
Expand Down Expand Up @@ -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<Agent> &getHooks(HookType type) = 0;

/// @brief Shared pointer to the pipeline context
std::shared_ptr<pipeline::PipelineContext> m_pipelineContext;
Expand Down
6 changes: 3 additions & 3 deletions styles/styles.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ccb0e40

Please sign in to comment.