Skip to content

Commit ccb0e40

Browse files
authored
Merge pull request mtconnect#497 from mtconnect/add_hooks_to_sink_contract
Added access to agent hooks in sink contract
2 parents e7f77e2 + 815bccd commit ccb0e40

File tree

6 files changed

+71
-5
lines changed

6 files changed

+71
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set(AGENT_VERSION_MAJOR 2)
33
set(AGENT_VERSION_MINOR 4)
44
set(AGENT_VERSION_PATCH 0)
5-
set(AGENT_VERSION_BUILD 4)
5+
set(AGENT_VERSION_BUILD 5)
66
set(AGENT_VERSION_RC "")
77

88
# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent

demo/agent/mazak.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2022.02.02 14:04:20 =~=~=~=~=~=~=~=~=~=~=~=
21
* uuid: 342072d3-5a0b-f184-2de1-d6f24108c59f
32
* manufacturer: Mazak_Corporation
43
* description: Variaxis w/SMooth-AI

src/mtconnect/agent.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ namespace mtconnect {
232232
// Start all the sources
233233
for (auto source : m_sources)
234234
source->start();
235+
236+
m_afterStartHooks.exec(*this);
235237
}
236238
catch (std::runtime_error &e)
237239
{

src/mtconnect/agent.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ namespace mtconnect {
112112
/// @brief Hooks to run when before the agent starts all the soures and sinks
113113
/// @return configuration::HookManager<Agent>&
114114
auto &beforeStartHooks() { return m_beforeStartHooks; }
115+
116+
/// @brief Hooks to run when after the agent starts all the soures and sinks
117+
/// @return configuration::HookManager<Agent>&
118+
auto &afterStartHooks() { return m_afterStartHooks; }
115119

116120
/// @brief Hooks before the agent stops all the sources and sinks
117121
/// @return configuration::HookManager<Agent>&
@@ -546,6 +550,7 @@ namespace mtconnect {
546550
configuration::HookManager<Agent> m_beforeInitializeHooks;
547551
configuration::HookManager<Agent> m_afterInitializeHooks;
548552
configuration::HookManager<Agent> m_beforeStartHooks;
553+
configuration::HookManager<Agent> m_afterStartHooks;
549554
configuration::HookManager<Agent> m_beforeStopHooks;
550555
configuration::HookManager<Agent> m_beforeDeviceXmlUpdateHooks;
551556
configuration::HookManager<Agent> m_afterDeviceXmlUpdateHooks;
@@ -655,6 +660,49 @@ namespace mtconnect {
655660
}
656661

657662
buffer::CircularBuffer &getCircularBuffer() override { return m_agent->getCircularBuffer(); }
663+
664+
configuration::HookManager<Agent> &getHooks(HookType type) override
665+
{
666+
using namespace sink;
667+
switch (type)
668+
{
669+
case BEFORE_START:
670+
return m_agent->beforeStartHooks();
671+
break;
672+
673+
case AFTER_START:
674+
return m_agent->afterStartHooks();
675+
break;
676+
677+
case BEFORE_STOP:
678+
return m_agent->beforeStopHooks();
679+
break;
680+
681+
case BEFORE_DEVICE_XML_UPDATE:
682+
return m_agent->beforeDeviceXmlUpdateHooks();
683+
break;
684+
685+
case AFTER_DEVICE_XML_UPDATE:
686+
return m_agent->afterDeviceXmlUpdateHooks();
687+
break;
688+
689+
case BEFORE_INITIALIZE:
690+
return m_agent->beforeInitializeHooks();
691+
break;
692+
693+
case AFTER_INITIALIZE:
694+
return m_agent->afterInitializeHooks();
695+
break;
696+
}
697+
698+
LOG(error) << "getHooks: Bad hook manager type given to sink contract";
699+
throw std::runtime_error("getHooks: Bad hook manager type");
700+
701+
// Never gets here.
702+
static configuration::HookManager<Agent> NullHooks;
703+
return NullHooks;
704+
}
705+
658706

659707
protected:
660708
Agent *m_agent;

src/mtconnect/sink/sink.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "mtconnect/device_model/device.hpp"
3232
#include "mtconnect/observation/observation.hpp"
3333
#include "mtconnect/printer//printer.hpp"
34+
#include "mtconnect/configuration/hook_manager.hpp"
3435

3536
namespace mtconnect {
3637
namespace printer {
@@ -46,13 +47,24 @@ namespace mtconnect {
4647
namespace buffer {
4748
class CircularBuffer;
4849
}
50+
class Agent;
4951

5052
/// @brief The Sink namespace for outgoing data from the agent
5153
namespace sink {
5254
/// @brief Interface required by sinks
5355
class AGENT_LIB_API SinkContract
5456
{
5557
public:
58+
enum HookType {
59+
BEFORE_STOP,
60+
BEFORE_START,
61+
AFTER_START,
62+
BEFORE_DEVICE_XML_UPDATE,
63+
AFTER_DEVICE_XML_UPDATE,
64+
BEFORE_INITIALIZE,
65+
AFTER_INITIALIZE
66+
};
67+
5668
virtual ~SinkContract() = default;
5769
/// @brief get the printer for a mime type. Current options: `xml` or `json`.
5870
/// @param[in] aType a string for the type
@@ -102,6 +114,11 @@ namespace mtconnect {
102114
/// @brief Get a pointer to the asset storage
103115
/// @return a pointer to the asset storage.
104116
virtual const asset::AssetStorage *getAssetStorage() = 0;
117+
118+
/// @brief Get a reference to the hook manager for the agent.
119+
/// @param[in] type the type manager to retrieve
120+
/// @return a reference to the hook manager
121+
virtual configuration::HookManager<Agent> &getHooks(HookType type) = 0;
105122

106123
/// @brief Shared pointer to the pipeline context
107124
std::shared_ptr<pipeline::PipelineContext> m_pipelineContext;

styles/styles.xsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
55
xmlns:xs="http://www.w3.org/2001/XMLSchema"
66
xmlns:fn="http://www.w3.org/2005/xpath-functions"
7-
xmlns:m="urn:mtconnect.org:MTConnectDevices:2.2"
8-
xmlns:s="urn:mtconnect.org:MTConnectStreams:2.2"
9-
xmlns:e="urn:mtconnect.org:MTConnectError:2.2"
7+
xmlns:m="urn:mtconnect.org:MTConnectDevices:2.3"
8+
xmlns:s="urn:mtconnect.org:MTConnectStreams:2.3"
9+
xmlns:e="urn:mtconnect.org:MTConnectError:2.3"
1010
xmlns:js="urn:custom-javascript"
1111
exclude-result-prefixes="msxsl js"
1212
xmlns:msxsl="urn:schemas-microsoft-com:xslt"

0 commit comments

Comments
 (0)