internal_subscription.h
Go to the documentation of this file.
00001 
00002 #pragma once
00003 
00004 //#include "address_space_internal.h"
00005 #include "subscription_service_internal.h"
00006 
00007 #include <opc/ua/event.h>
00008 #include <opc/ua/server/address_space.h>
00009 #include <opc/ua/protocol/monitored_items.h>
00010 #include <opc/ua/protocol/strings.h>
00011 #include <opc/ua/protocol/string_utils.h>
00012 #include <opc/ua/services/attributes.h>
00013 
00014 #include <boost/asio.hpp>
00015 #include <boost/thread/shared_mutex.hpp>
00016 #include <chrono>
00017 #include <iostream>
00018 #include <list>
00019 #include <vector>
00020 
00021 
00022 namespace OpcUa
00023 {
00024   namespace Internal
00025   {
00026 
00027     class SubscriptionServiceInternal;
00028 
00029     //Structure to store description of a MonitoredItems
00030     struct MonitoredDataChange
00031     {
00032       uint32_t MonitoredItemId;
00033       MonitoringMode Mode;
00034       time_t LastTrigger;
00035       MonitoredItemCreateResult Parameters;
00036       uint32_t ClientHandle;
00037       uint32_t CallbackHandle;
00038     };
00039 
00040     struct TriggeredDataChange
00041     {
00042       uint32_t MonitoredItemId;
00043       MonitoredItems Data;
00044     };
00045 
00046     struct TriggeredEvent
00047     {
00048       uint32_t MonitoredItemId;
00049       EventFieldList Data;
00050     };
00051 
00052     //typedef std::pair<NodeId, AttributeId> MonitoredItemsIndex;
00053     typedef std::map<uint32_t, MonitoredDataChange> MonitoredDataChangeMap;
00054     typedef std::map<NodeId, uint32_t> MonitoredEventsMap;
00055 
00056     class AddressSpaceInMemory; //pre-declaration
00057 
00058     
00059     class InternalSubscription : public std::enable_shared_from_this<InternalSubscription>
00060     {
00061       public:
00062         InternalSubscription(SubscriptionServiceInternal& service, const SubscriptionData& data, const NodeId& SessionAuthenticationToken, std::function<void (PublishResult)> Callback, bool debug=false);
00063         ~InternalSubscription();
00064         void Start();
00065         void Stop();
00066 
00067         void NewAcknowlegment(const SubscriptionAcknowledgement& ack);
00068         std::vector<StatusCode> DeleteMonitoredItemsIds(const std::vector<uint32_t>& ids);
00069         bool EnqueueEvent(uint32_t monitoreditemid, const Event& event);
00070         bool EnqueueDataChange(uint32_t monitoreditemid, const DataValue& value);
00071         MonitoredItemCreateResult CreateMonitoredItem(const MonitoredItemCreateRequest& request);
00072         void DataChangeCallback(const uint32_t&, const DataValue& value);
00073         bool HasExpired();
00074         void TriggerEvent(NodeId node, Event event);
00075         RepublishResponse Republish(const RepublishParameters& params);
00076 
00077       private:
00078         void DeleteAllMonitoredItems(); 
00079         bool DeleteMonitoredEvent(uint32_t handle);
00080         bool DeleteMonitoredDataChange(uint32_t handle);
00081         std::vector<PublishResult> PopPublishResult(); 
00082         bool HasPublishResult(); 
00083         NotificationData GetNotificationData();
00084         void PublishResults(const boost::system::error_code& error);
00085         std::vector<Variant> GetEventFields(const EventFilter& filter, const Event& event);
00086         void TriggerDataChangeEvent(MonitoredDataChange monitoreditems, ReadValueId attrval);
00087 
00088       private:
00089         SubscriptionServiceInternal& Service;
00090         Server::AddressSpace& AddressSpace;
00091         mutable boost::shared_mutex DbMutex;
00092         SubscriptionData Data;
00093         const NodeId CurrentSession;
00094         std::function<void (PublishResult)> Callback;
00095 
00096         uint32_t NotificationSequence = 1; //NotificationSequence start at 1! not 0
00097         uint32_t KeepAliveCount = 0; 
00098         bool Startup = true; //To force specific behaviour at startup
00099         uint32_t LastMonitoredItemId = 100;
00100         MonitoredDataChangeMap MonitoredDataChanges; 
00101         MonitoredEventsMap MonitoredEvents;
00102         std::list<PublishResult> NotAcknowledgedResults; //result that have not be acknowledeged and may have to be resent
00103         std::list<TriggeredDataChange> TriggeredDataChangeEvents; 
00104         std::list<TriggeredEvent> TriggeredEvents; 
00105         boost::asio::io_service& io;
00106         boost::asio::deadline_timer Timer;
00107         bool TimerStopped = false;
00108         uint32_t LifeTimeCount;
00109         bool Debug = false;
00110          
00111     };
00112 
00113 
00114   }
00115 }
00116 
00117  


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:56