30 , DataChangeCallbackHandle(0)
53 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
55 std::vector<AddNodesResult> results;
59 results.push_back(
AddNode(item));
67 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
69 std::vector<StatusCode> results;
71 for (
const auto & item : items)
81 boost::shared_lock<boost::shared_mutex> lock(
DbMutex);
83 std::vector<BrowsePathResult> results;
88 results.push_back(result);
96 boost::shared_lock<boost::shared_mutex> lock(
DbMutex);
100 std::vector<BrowseResult> results;
108 Logger->trace(
"address_space_internal| browsing");
113 Logger->trace(
" ResultMask: {:#x}", (
unsigned)browseDescription.
ResultMask);
118 if (node_it ==
Nodes.end())
125 std::copy_if(node_it->second.References.begin(), node_it->second.References.end(), std::back_inserter(result.
Referencies),
128 results.push_back(result);
136 boost::shared_lock<boost::shared_mutex> lock(
DbMutex);
138 return std::vector<BrowseResult>();
143 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
150 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
157 boost::shared_lock<boost::shared_mutex> lock(
DbMutex);
159 std::vector<DataValue> values;
171 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
173 std::vector<StatusCode> statuses;
179 statuses.push_back(
SetValue(value.NodeId, value.AttributeId, value.Value));
191 NodesMap::const_iterator nodeit =
Nodes.find(nodeid);
193 if (nodeit !=
Nodes.end())
195 for (
auto reference : nodeit->second.References)
198 if (reference.BrowseName == element.
TargetName)
217 if (std::get<0>(res) ==
false)
223 current = std::get<1>(res);
227 std::vector<BrowsePathTarget> targets;
229 target.
Node = current;
231 targets.push_back(target);
238 NodesMap::const_iterator nodeit =
Nodes.find(node);
240 if (nodeit ==
Nodes.end())
247 AttributesMap::const_iterator attrit = nodeit->second.Attributes.find(attribute);
249 if (attrit == nodeit->second.Attributes.end())
256 if (attrit->second.GetValueCallback)
258 LOG_DEBUG(
Logger,
"address_space_internal| invoke registered callback");
260 return attrit->second.GetValueCallback();
265 return attrit->second.Value;
277 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
279 LOG_DEBUG(
Logger,
"address_space_internal| set data changes callback for node {} and attribute {}", node, (
unsigned)attribute);
281 NodesMap::iterator it =
Nodes.find(node);
283 if (it ==
Nodes.end())
285 LOG_ERROR(
Logger,
"address_space_internal| Node: '{}' not found", node);
286 throw std::runtime_error(
"address_space_internal| NodeId not found");
289 AttributesMap::iterator ait = it->second.Attributes.find(attribute);
291 if (ait == it->second.Attributes.end())
293 LOG_ERROR(
Logger,
"address_space_internal| Attribute: {} of node: ‘{}‘ not found", (
unsigned)attribute, node);
294 throw std::runtime_error(
"Attribute not found");
300 ait->second.DataChangeCallbacks[
handle] = data;
307 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
309 LOG_DEBUG(
Logger,
"address_space_internal| deleting callback with client id: {}", serverhandle);
315 LOG_WARN(
Logger,
"address_space_internal| request to delete a callback using unknown handle: {1}", serverhandle);
319 NodesMap::iterator nodeit =
Nodes.find(it->second.Node);
321 if (nodeit !=
Nodes.end())
323 AttributesMap::iterator ait = nodeit->second.Attributes.find(it->second.Attribute);
325 if (ait != nodeit->second.Attributes.end())
327 size_t nb = ait->second.DataChangeCallbacks.erase(serverhandle);
336 throw std::runtime_error(
"address_space_internal| NodeId or attribute nor found");
341 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
343 NodesMap::iterator it =
Nodes.find(node);
345 if (it !=
Nodes.end())
347 AttributesMap::iterator ait = it->second.Attributes.find(attribute);
349 if (ait != it->second.Attributes.end())
351 ait->second.GetValueCallback = callback;
361 boost::unique_lock<boost::shared_mutex> lock(
DbMutex);
363 NodesMap::iterator it =
Nodes.find(node);
365 if (it !=
Nodes.end())
367 it->second.Method = callback;
372 throw std::runtime_error(
"address_space_internal| while setting node callback: node does not exist.");
378 boost::shared_lock<boost::shared_mutex> lock(
DbMutex);
380 std::vector<OpcUa::CallMethodResult> results;
382 for (
auto method : methodsToCall)
395 if (node_it ==
Nodes.end())
403 if (method_it ==
Nodes.end())
409 if (! method_it->second.Method)
421 catch (std::exception & ex)
423 LOG_ERROR(
Logger,
"address_space_internal| exception while calling method: {}: {}", request.
MethodId, ex.what());
439 NodesMap::iterator it =
Nodes.find(node);
441 if (it !=
Nodes.end())
443 AttributesMap::iterator ait = it->second.Attributes.find(attribute);
445 if (ait != it->second.Attributes.end())
449 ait->second.Value = value;
452 for (
auto pair : ait->second.DataChangeCallbacks)
454 pair.second.Callback(it->first, ait->first, ait->second.Value);
492 if (!includeSubtypes)
498 const auto resultIt = std::find(suitableTypes.begin(), suitableTypes.end(), reference.
ReferenceTypeId);
500 return resultIt != suitableTypes.end();
505 std::vector<NodeId> subNodes;
507 for (
NodeId nodeid : sourceNodes)
509 NodesMap::const_iterator node_it =
Nodes.find(nodeid);
511 if (node_it !=
Nodes.end())
513 for (
auto & ref : node_it->second.References)
517 subNodes.push_back(ref.TargetNodeId);
523 if (subNodes.empty())
529 sourceNodes.insert(sourceNodes.end(), allChilds.begin(), allChilds.end());
543 LOG_ERROR(
Logger,
"address_space_internal| NodeId: '{}' already exists", resultId);
548 NodesMap::iterator parent_node_it =
Nodes.end();
554 if (parent_node_it ==
Nodes.end())
572 attval.
Value = attr.second;
574 nodestruct.
Attributes.insert(std::make_pair(attr.first, attval));
577 Nodes.insert(std::make_pair(resultId, nodestruct));
579 if (parent_node_it !=
Nodes.end())
629 if (node_it ==
Nodes.end())
636 if (targetnode_it ==
Nodes.end())
670 node_it->second.References.push_back(desc);
685 if (
id.HasNullIdentifier())
687 idx =
id.GetNamespaceIndex();
712 if (
MaxNodeIdNum == std::numeric_limits<uint32_t>::max())
714 throw std::runtime_error(
"address_space_internal| unable to assign new NodeId: range exceeded");
virtual std::vector< DataValue > Read(const ReadParameters ¶ms) const
std::vector< OpcUa::ReadValueId > AttributesToRead
#define LOG_TRACE(__logger__,...)
AddressSpaceInMemory(const Common::Logger::SharedPtr &logger)
#define LOG_WARN(__logger__,...)
virtual std::vector< StatusCode > Write(const std::vector< OpcUa::WriteValue > &values)
std::vector< OpcUa::Variant > OutputArguments
StatusCode AddReference(const AddReferencesItem &item)
bool IsSuitableReferenceType(const ReferenceDescription &reference, const NodeId &typeId, bool includeSubtypes) const
std::vector< BrowseDescription > NodesToBrowse
const uint8_t DATA_VALUE_STATUS_CODE
std::vector< OpcUa::StatusCode > InputArgumentResults
std::map< AttributeId, Variant > Attributes
std::vector< BrowsePath > BrowsePaths
std::vector< OpcUa::Variant > InputArguments
#define LOG_ERROR(__logger__,...)
IntegerId MonitoredItemId
#define LOG_DEBUG(__logger__,...)
NodeId GetNewNodeId(const NodeId &id)
ClientIdToAttributeMapType ClientIdToAttributeMap
LocalizedText DisplayName
std::tuple< bool, NodeId > FindElementInNode(const NodeId &nodeid, const RelativePathElement &element) const
NodeId RequestedNewNodeId
void DeleteDataChangeCallback(uint32_t serverhandle)
Delete data change callback assosioated with handle.
Common::Logger::SharedPtr Logger
StatusCode SetValue(const NodeId &node, AttributeId attribute, const DataValue &data)
virtual std::vector< StatusCode > AddReferences(const std::vector< AddReferencesItem > &items)
virtual std::vector< AddNodesResult > AddNodes(const std::vector< AddNodesItem > &items)
std::vector< NodeId > SelectNodesHierarchy(std::vector< NodeId > sourceNodes) const
std::vector< ReferenceDescription > References
DataValue GetValue(const NodeId &node, AttributeId attribute) const
BrowsePathResult TranslateBrowsePath(const BrowsePath &browsepath) const
std::atomic< uint32_t > DataChangeCallbackHandle
std::function< Server::DataChangeCallback > Callback
virtual std::vector< BrowsePathResult > TranslateBrowsePathsToNodeIds(const TranslateBrowsePathsParameters ¶ms) const
MonitoringParameters Parameters
std::vector< RelativePathElement > Elements
CallMethodResult CallMethod(CallMethodRequest method)
virtual std::vector< BrowseResult > BrowseNext() const
NodeClass TargetNodeClass
virtual void UnregisterNodes(const std::vector< NodeId > ¶ms) const
uint32_t AddDataChangeCallback(const NodeId &node, AttributeId attribute, std::function< Server::DataChangeCallback > callback)
Add callback which will be called when values of attribute is changed.
OPC UA Address space part. GNU LGPL.
NodeClass TargetNodeClass
NodeId TargetNodeTypeDefinition
BrowseResultMask ResultMask
void SetMethod(const NodeId &node, std::function< std::vector< OpcUa::Variant >(NodeId context, std::vector< OpcUa::Variant > arguments)> callback)
Set method function for a method node.
std::map< IntegerId, std::shared_ptr< InternalSubscription > > SubscriptionsIdMap
virtual std::vector< BrowseResult > Browse(const OpcUa::NodesQuery &query) const
uint32_t RemainingPathIndex
std::string ToString(const AttributeId &value)
static DateTime Current()
virtual std::vector< OpcUa::CallMethodResult > Call(const std::vector< OpcUa::CallMethodRequest > &methodsToCall)
void SetServerTimestamp(const DateTime &t)
BrowseDirection Direction
NodeAttributes Attributes
OpcUa::AttributeId AttributeId
virtual std::vector< NodeId > RegisterNodes(const std::vector< NodeId > ¶ms) const
std::vector< ReferenceDescription > Referencies
AddressSpace::UniquePtr CreateAddressSpace(const Common::Logger::SharedPtr &logger)
std::vector< BrowsePathTarget > Targets
NodeId NumericNodeId(uint32_t value, uint16_t namespaceIndex=0)
AddNodesResult AddNode(const AddNodesItem &item)
boost::shared_mutex DbMutex
bool IsSuitableReference(const BrowseDescription &desc, const ReferenceDescription &reference) const
StatusCode SetValueCallback(const NodeId &node, AttributeId attribute, std::function< DataValue(void)> callback)
Set callback which will be called to read new value of the attribue.