Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #pragma once
00012
00013 #include "address_space_addon.h"
00014
00015 #include <opc/ua/protocol/strings.h>
00016 #include <opc/ua/protocol/string_utils.h>
00017 #include <opc/ua/protocol/view.h>
00018 #include <opc/ua/services/attributes.h>
00019 #include <opc/ua/services/node_management.h>
00020
00021 #include <boost/thread/locks.hpp>
00022 #include <boost/thread/shared_mutex.hpp>
00023 #include <ctime>
00024 #include <limits>
00025 #include <list>
00026 #include <map>
00027 #include <queue>
00028 #include <deque>
00029 #include <set>
00030 #include <thread>
00031
00032
00033
00034 namespace OpcUa
00035 {
00036 namespace Internal
00037 {
00038
00039 class InternalSubscription;
00040
00041 struct NodeAttribute
00042 {
00043 NodeId Node;
00044 AttributeId Attribute;
00045 NodeAttribute(NodeId node, AttributeId attribute) : Node(node), Attribute(attribute) {}
00046 NodeAttribute() {}
00047 };
00048
00049 typedef std::map<uint32_t, NodeAttribute> ClientIdToAttributeMapType;
00050
00051 struct DataChangeCallbackData
00052 {
00053 std::function<Server::DataChangeCallback> Callback;
00054 IntegerId ClientHandle;
00055 };
00056
00057 typedef std::map<uint32_t, DataChangeCallbackData> DataChangeCallbackMap;
00058
00059
00060 struct AttributeValue
00061 {
00062 DataValue Value;
00063 DataChangeCallbackMap DataChangeCallbacks;
00064 std::function<DataValue(void)> GetValueCallback;
00065 };
00066
00067 typedef std::map<AttributeId, AttributeValue> AttributesMap;
00068
00069
00070 struct NodeStruct
00071 {
00072 AttributesMap Attributes;
00073 std::vector<ReferenceDescription> References;
00074 std::function<std::vector<OpcUa::Variant> (std::vector<OpcUa::Variant>)> Method;
00075 };
00076
00077 typedef std::map<NodeId, NodeStruct> NodesMap;
00078
00079
00080 class AddressSpaceInMemory : public Server::AddressSpace
00081 {
00082 public:
00083 AddressSpaceInMemory(bool debug);
00084
00085 ~AddressSpaceInMemory();
00086
00087
00088 virtual std::vector<AddNodesResult> AddNodes(const std::vector<AddNodesItem>& items);
00089 virtual std::vector<StatusCode> AddReferences(const std::vector<AddReferencesItem>& items);
00090 virtual std::vector<BrowsePathResult> TranslateBrowsePathsToNodeIds(const TranslateBrowsePathsParameters& params) const;
00091 virtual std::vector<BrowseResult> Browse(const OpcUa::NodesQuery& query) const;
00092 virtual std::vector<BrowseResult> BrowseNext() const;
00093 virtual std::vector<NodeId> RegisterNodes(const std::vector<NodeId>& params) const;
00094 virtual void UnregisterNodes(const std::vector<NodeId>& params) const;
00095 virtual std::vector<DataValue> Read(const ReadParameters& params) const;
00096 virtual std::vector<StatusCode> Write(const std::vector<OpcUa::WriteValue>& values);
00097 virtual std::vector<OpcUa::CallMethodResult> Call(std::vector<OpcUa::CallMethodRequest> methodsToCall);
00098
00099
00100
00103 uint32_t AddDataChangeCallback(const NodeId& node, AttributeId attribute, std::function<Server::DataChangeCallback> callback);
00104
00106 void DeleteDataChangeCallback(uint32_t serverhandle);
00107
00109 StatusCode SetValueCallback(const NodeId& node, AttributeId attribute, std::function<DataValue(void)> callback);
00110
00112 void SetMethod(const NodeId& node, std::function<std::vector<OpcUa::Variant> (std::vector<OpcUa::Variant> arguments)> callback);
00113
00114 private:
00115 std::tuple<bool, NodeId> FindElementInNode(const NodeId& nodeid, const RelativePathElement& element) const;
00116 BrowsePathResult TranslateBrowsePath(const BrowsePath& browsepath) const;
00117 DataValue GetValue(const NodeId& node, AttributeId attribute) const;
00118 StatusCode SetValue(const NodeId& node, AttributeId attribute, const DataValue& data);
00119 bool IsSuitableReference(const BrowseDescription& desc, const ReferenceDescription& reference) const;
00120 bool IsSuitableReferenceType(const ReferenceDescription& reference, const NodeId& typeId, bool includeSubtypes) const;
00121 std::vector<NodeId> SelectNodesHierarchy(std::vector<NodeId> sourceNodes) const;
00122 AddNodesResult AddNode( const AddNodesItem& item );
00123 StatusCode AddReference(const AddReferencesItem& item);
00124 NodeId GetNewNodeId(const NodeId& id);
00125 CallMethodResult CallMethod(CallMethodRequest method);
00126
00127 private:
00128 bool Debug = false;
00129 mutable boost::shared_mutex DbMutex;
00130 NodesMap Nodes;
00131 ClientIdToAttributeMapType ClientIdToAttributeMap;
00132 uint32_t MaxNodeIdNum = 2000;
00133 uint32_t DefaultIdx = 2;
00134 std::atomic<uint32_t> DataChangeCallbackHandle;
00135 };
00136 }
00137
00138 namespace Server
00139 {
00140 AddressSpace::UniquePtr CreateAddressSpace(bool debug);
00141 }
00142 }
00143