Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added access to agent hooks in sink contract #497

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
39 changes: 39 additions & 0 deletions src/mtconnect/agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,45 @@ 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 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
16 changes: 16 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,23 @@ 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,
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 +113,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
Loading