address_space_internal.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include "address_space_addon.h"
14 
17 #include <opc/ua/protocol/view.h>
20 
21 #include <boost/thread/locks.hpp>
22 #include <boost/thread/shared_mutex.hpp>
23 #include <ctime>
24 #include <limits>
25 #include <list>
26 #include <map>
27 #include <queue>
28 #include <deque>
29 #include <set>
30 #include <thread>
31 
32 
33 
34 namespace OpcUa
35 {
36 namespace Internal
37 {
38 
39 class InternalSubscription;
40 
42 {
45  NodeAttribute(NodeId node, AttributeId attribute) : Node(node), Attribute(attribute) {}
46  NodeAttribute() {} //seems compiler wants this one
47 };
48 
49 typedef std::map<uint32_t, NodeAttribute> ClientIdToAttributeMapType;
50 
52 {
53  std::function<Server::DataChangeCallback> Callback;
55 };
56 
57 typedef std::map<uint32_t, DataChangeCallbackData> DataChangeCallbackMap;
58 
59 //Store an attribute value together with a link to all its suscriptions
61 {
63  DataChangeCallbackMap DataChangeCallbacks;
64  std::function<DataValue(void)> GetValueCallback;
65 };
66 
67 typedef std::map<AttributeId, AttributeValue> AttributesMap;
68 
69 //Store all data related to a Node
70 struct NodeStruct
71 {
72  AttributesMap Attributes;
73  std::vector<ReferenceDescription> References;
74  std::function<std::vector<OpcUa::Variant> (NodeId, std::vector<OpcUa::Variant>)> Method;
75 };
76 
77 typedef std::map<NodeId, NodeStruct> NodesMap;
78 
79 //In memory storage of server opc-ua data model
81 {
82 public:
83  AddressSpaceInMemory(const Common::Logger::SharedPtr & logger);
84 
86 
87  //Services implementation
88  virtual std::vector<AddNodesResult> AddNodes(const std::vector<AddNodesItem> & items);
89  virtual std::vector<StatusCode> AddReferences(const std::vector<AddReferencesItem> & items);
90  virtual std::vector<BrowsePathResult> TranslateBrowsePathsToNodeIds(const TranslateBrowsePathsParameters & params) const;
91  virtual std::vector<BrowseResult> Browse(const OpcUa::NodesQuery & query) const;
92  virtual std::vector<BrowseResult> BrowseNext() const;
93  virtual std::vector<NodeId> RegisterNodes(const std::vector<NodeId> & params) const;
94  virtual void UnregisterNodes(const std::vector<NodeId> & params) const;
95  virtual std::vector<DataValue> Read(const ReadParameters & params) const;
96  virtual std::vector<StatusCode> Write(const std::vector<OpcUa::WriteValue> & values);
97  virtual std::vector<OpcUa::CallMethodResult> Call(const std::vector<OpcUa::CallMethodRequest> & methodsToCall);
98 
99  //Server side methods
100 
103  uint32_t AddDataChangeCallback(const NodeId & node, AttributeId attribute, std::function<Server::DataChangeCallback> callback);
104 
106  void DeleteDataChangeCallback(uint32_t serverhandle);
107 
109  StatusCode SetValueCallback(const NodeId & node, AttributeId attribute, std::function<DataValue(void)> callback);
110 
112  void SetMethod(const NodeId & node, std::function<std::vector<OpcUa::Variant> (NodeId context, std::vector<OpcUa::Variant> arguments)> callback);
113 
114 private:
115  std::tuple<bool, NodeId> FindElementInNode(const NodeId & nodeid, const RelativePathElement & element) const;
116  BrowsePathResult TranslateBrowsePath(const BrowsePath & browsepath) const;
117  DataValue GetValue(const NodeId & node, AttributeId attribute) const;
118  StatusCode SetValue(const NodeId & node, AttributeId attribute, const DataValue & data);
119  bool IsSuitableReference(const BrowseDescription & desc, const ReferenceDescription & reference) const;
120  bool IsSuitableReferenceType(const ReferenceDescription & reference, const NodeId & typeId, bool includeSubtypes) const;
121  std::vector<NodeId> SelectNodesHierarchy(std::vector<NodeId> sourceNodes) const;
122  AddNodesResult AddNode(const AddNodesItem & item);
123  StatusCode AddReference(const AddReferencesItem & item);
124  NodeId GetNewNodeId(const NodeId & id);
125  CallMethodResult CallMethod(CallMethodRequest method);
126 
127 private:
128  Common::Logger::SharedPtr Logger;
129  mutable boost::shared_mutex DbMutex;
130  NodesMap Nodes;
131  ClientIdToAttributeMapType ClientIdToAttributeMap; //Use to find callback using callback subcsriptionid
132  uint32_t MaxNodeIdNum = 2000;
133  uint32_t DefaultIdx = 2;
134  std::atomic<uint32_t> DataChangeCallbackHandle;
135 };
136 }
137 
138 namespace Server
139 {
140 AddressSpace::UniquePtr CreateAddressSpace(const Common::Logger::SharedPtr & logger);
141 }
142 }
143 
std::map< AttributeId, AttributeValue > AttributesMap
ClientIdToAttributeMapType ClientIdToAttributeMap
std::vector< T > Browse(const NodeId &node, NodeClass nodeClassMask, Services::SharedPtr services)
Definition: model_impl.h:31
std::vector< ReferenceDescription > References
NodeAttribute(NodeId node, AttributeId attribute)
std::function< Server::DataChangeCallback > Callback
std::map< uint32_t, NodeAttribute > ClientIdToAttributeMapType
DataChangeCallbackMap DataChangeCallbacks
OPC UA Address space part. GNU LGPL.
std::map< NodeId, NodeStruct > NodesMap
std::map< uint32_t, DataChangeCallbackData > DataChangeCallbackMap
AddressSpace::UniquePtr CreateAddressSpace(const Common::Logger::SharedPtr &logger)
std::function< DataValue(void)> GetValueCallback
const char Server[]
Definition: strings.h:121


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