subscription_service_addon.cpp
Go to the documentation of this file.
1 
12 
18 
19 #include <iostream>
20 
21 namespace
22 {
23 
24 class SubscriptionAddon:
25  public Common::Addon,
27 {
28 public:
29  void Initialize(Common::AddonsManager & manager, const Common::AddonParameters & parameters)
30  {
31  Logger = manager.GetLogger();
32  ApplyAddonParameters(parameters);
34  OpcUa::Server::AddressSpace::SharedPtr addressSpace = manager.GetAddon<OpcUa::Server::AddressSpace>(OpcUa::Server::AddressSpaceRegistryAddonId);
35  OpcUa::Server::AsioAddon::SharedPtr asio = manager.GetAddon<OpcUa::Server::AsioAddon>(OpcUa::Server::AsioAddonId);
36  Subscriptions = OpcUa::Server::CreateSubscriptionService(addressSpace, asio->GetIoService(), Logger);
37  Services->RegisterSubscriptionServices(Subscriptions);
38  }
39 
40  void Stop()
41  {
42  Services->UnregisterSubscriptionServices();
43  Subscriptions.reset();
44  Services.reset();
45  }
46 
47 public:
48  void TriggerEvent(OpcUa::NodeId node, OpcUa::Event event)
49  {
50  Subscriptions->TriggerEvent(node, event);
51  }
52 
53 public:
55  {
56  return Subscriptions->CreateSubscription(request, callback);
57  }
58 
60  {
61  return Subscriptions->ModifySubscription(parameters);
62  }
63 
64  std::vector<OpcUa::StatusCode> DeleteSubscriptions(const std::vector<uint32_t> & subscriptions)
65  {
66  return Subscriptions->DeleteSubscriptions(subscriptions);
67  }
68 
69  void Publish(const OpcUa::PublishRequest & request)
70  {
71  Subscriptions->Publish(request);
72  }
73 
75  {
76  return Subscriptions->Republish(request);
77  }
78 
79  std::vector<OpcUa::MonitoredItemCreateResult> CreateMonitoredItems(const OpcUa::MonitoredItemsParameters & parameters)
80  {
81  return Subscriptions->CreateMonitoredItems(parameters);
82  }
83 
84  std::vector<OpcUa::StatusCode> DeleteMonitoredItems(const OpcUa::DeleteMonitoredItemsParameters & parameters)
85  {
86  return Subscriptions->DeleteMonitoredItems(parameters);
87  }
88 
89 
90 private:
91  void ApplyAddonParameters(const Common::AddonParameters & addons)
92  {
93  /*
94  for (const Common::Parameter parameter : addons.Parameters)
95  {
96  if (parameter.Name == "debug" && !parameter.Value.empty() && parameter.Value != "0")
97  {
98  std::cout << "SubscriptionService | Debug mode enabled." << std::endl;
99  }
100  }
101  */
102  }
103 
104 private:
105  SubscriptionService::SharedPtr Subscriptions;
106  OpcUa::Server::ServicesRegistry::SharedPtr Services;
107  Common::Logger::SharedPtr Logger;
108 };
109 
110 }
111 
112 namespace OpcUa
113 {
114 namespace Server
115 {
117 {
118  return Common::Addon::UniquePtr(new SubscriptionAddon());
119 }
120 }
121 }
virtual void TriggerEvent(NodeId node, Event event)=0
Common::Addon * CreateAddon()
Addon interface definition GNU LGPL.
virtual const Logger::SharedPtr & GetLogger() const
Definition: addon_manager.h:90
virtual std::vector< MonitoredItemCreateResult > CreateMonitoredItems(const MonitoredItemsParameters &parameters)=0
virtual SubscriptionData CreateSubscription(const CreateSubscriptionRequest &, std::function< void(PublishResult)> callbackPublish)=0
virtual std::shared_ptr< Addon > GetAddon(const AddonId &id) const =0
getting addon by id
virtual std::vector< StatusCode > DeleteSubscriptions(const std::vector< uint32_t > &subscriptions)=0
const char AddressSpaceRegistryAddonId[]
virtual void Stop()=0
Stopping addon work. After calling this method addon should throw exception on any calls...
const char ServicesRegistryAddonId[]
const char AsioAddonId[]
Definition: asio_addon.h:31
virtual ModifySubscriptionResponse ModifySubscription(const ModifySubscriptionParameters &parameters)=0
virtual void Publish(const PublishRequest &request)=0
virtual void Initialize(AddonsManager &manager, const AddonParameters &parameters)=0
initialize addon.
SubscriptionService::UniquePtr CreateSubscriptionService(std::shared_ptr< AddressSpace > addressspace, boost::asio::io_service &io, const Common::Logger::SharedPtr &logger)
OPC UA Address space part. GNU LGPL.
virtual std::vector< StatusCode > DeleteMonitoredItems(const DeleteMonitoredItemsParameters &params)=0
virtual RepublishResponse Republish(const RepublishParameters &params)=0
const char Server[]
Definition: strings.h:121


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08