internal_subscription.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 //#include "address_space_internal.h"
6 
7 #include <opc/ua/event.h>
13 
14 #include <boost/asio.hpp>
15 #include <boost/thread/shared_mutex.hpp>
16 #include <chrono>
17 #include <iostream>
18 #include <list>
19 #include <vector>
20 
21 
22 namespace OpcUa
23 {
24 namespace Internal
25 {
26 
27 class SubscriptionServiceInternal;
28 
29 //Structure to store description of a MonitoredItems
31 {
32  uint32_t MonitoredItemId;
34  time_t LastTrigger;
35  uint32_t TriggerCount;
37  uint32_t ClientHandle;
38  uint32_t CallbackHandle;
39 };
40 
42 {
43  uint32_t MonitoredItemId;
45 };
46 
48 {
49  uint32_t MonitoredItemId;
51 };
52 
53 //typedef std::pair<NodeId, AttributeId> MonitoredItemsIndex;
54 typedef std::map<uint32_t, MonitoredDataChange> MonitoredDataChangeMap;
55 typedef std::map<NodeId, uint32_t> MonitoredEventsMap;
56 
57 class AddressSpaceInMemory; //pre-declaration
58 
59 
60 class InternalSubscription : public std::enable_shared_from_this<InternalSubscription>
61 {
62 public:
63  InternalSubscription(SubscriptionServiceInternal & service, const SubscriptionData & data, const NodeId & SessionAuthenticationToken, std::function<void (PublishResult)> Callback, const Common::Logger::SharedPtr & logger);
65  void Start();
66  void Stop();
67 
68  void NewAcknowlegment(const SubscriptionAcknowledgement & ack);
69  std::vector<StatusCode> DeleteMonitoredItemsIds(const std::vector<uint32_t> & ids);
70  bool EnqueueEvent(uint32_t monitoreditemid, const Event & event);
71  bool EnqueueDataChange(uint32_t monitoreditemid, const DataValue & value);
72  MonitoredItemCreateResult CreateMonitoredItem(const MonitoredItemCreateRequest & request);
73  void DataChangeCallback(const uint32_t &, const DataValue & value);
74  bool HasExpired();
75  void TriggerEvent(NodeId node, Event event);
76  RepublishResponse Republish(const RepublishParameters & params);
77  ModifySubscriptionResult ModifySubscription(const ModifySubscriptionParameters & data);
78 
79 private:
80  void DeleteAllMonitoredItems();
81  bool DeleteMonitoredEvent(uint32_t handle);
82  bool DeleteMonitoredDataChange(uint32_t handle);
83  std::vector<PublishResult> PopPublishResult();
84  bool HasPublishResult();
85  NotificationData GetNotificationData();
86  void PublishResults(const boost::system::error_code & error);
87  std::vector<Variant> GetEventFields(const EventFilter & filter, const Event & event);
88  void TriggerDataChangeEvent(MonitoredDataChange monitoreditems, ReadValueId attrval);
89 
90 private:
93  mutable boost::shared_mutex DbMutex;
96  std::function<void (PublishResult)> Callback;
97 
98  uint32_t NotificationSequence = 1; //NotificationSequence start at 1! not 0
99  uint32_t KeepAliveCount = 0;
100  bool Startup = true; //To force specific behaviour at startup
101  uint32_t LastMonitoredItemId = 100;
102  MonitoredDataChangeMap MonitoredDataChanges;
103  MonitoredEventsMap MonitoredEvents;
104  std::list<PublishResult> NotAcknowledgedResults; //result that have not be acknowledeged and may have to be resent
105  std::list<TriggeredDataChange> TriggeredDataChangeEvents;
106  std::list<TriggeredEvent> TriggeredEvents;
107  boost::asio::io_service & io;
108  boost::asio::deadline_timer Timer;
109  bool TimerStopped = false;
110  uint32_t LifeTimeCount;
111  Common::Logger::SharedPtr Logger;
112 
113 };
114 
115 
116 }
117 }
118 
119 
std::list< PublishResult > NotAcknowledgedResults
std::function< void(PublishResult)> Callback
std::list< TriggeredEvent > TriggeredEvents
SubscriptionServiceInternal & Service
handle
Definition: client.py:58
std::map< uint32_t, MonitoredDataChange > MonitoredDataChangeMap
OPC UA Address space part. GNU LGPL.
MonitoringMode
Definition: enums.h:270
void DataChangeCallback(const NodeId &node, AttributeId attribute, DataValue)
Definition: address_space.h:26
std::list< TriggeredDataChange > TriggeredDataChangeEvents
std::map< NodeId, uint32_t > MonitoredEventsMap


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