server_operations.cpp
Go to the documentation of this file.
2 
3 namespace OpcUa
4 {
5 ServerOperations::ServerOperations(Services::SharedPtr Server) : Server(Server)
6 {
7 }
8 
9 void ServerOperations::WriteAttributes(std::vector<WriteValue> & updates)
10 {
11  std::vector<StatusCode> codes = Server->Attributes()->Write(updates);
12  CheckStatusCode(codes.front());
13 }
14 
15 std::vector<DataValue> ServerOperations::ReadAttributes(std::vector<ReadValueId> & attributes)
16 {
17  ReadParameters params;
18  params.AttributesToRead = attributes;
19  auto vec = Server->Attributes()->Read(params);
20  return vec;
21 }
22 
23 std::vector<DataValue> ServerOperations::ReadAttributes(std::vector<Node> & nodes, AttributeId attr)
24 {
25  std::vector<ReadValueId> request;
26 
27  for (auto & n : nodes)
28  {
29  ReadValueId r;
30  r.NodeId = n.GetId();
31  r.AttributeId = attr;
32  request.push_back(r);
33  }
34 
35  return ReadAttributes(request);
36 }
37 
38 std::vector<Node> ServerOperations::RegisterNodes(std::vector<Node> & nodes)
39 {
40  std::vector<OpcUa::NodeId> ids;
41 
42  for (auto & node : nodes)
43  {
44  ids.push_back(node.GetId());
45  }
46 
47  auto result = Server->Views()->RegisterNodes(ids);
48  auto rit = result.begin();
49  std::vector<Node> out;
50 
51  for (auto nit = nodes.begin(); nit != nodes.end() && rit != result.end(); ++nit, ++rit)
52  {
53  out.push_back(Node(nit->GetServices(), *rit));
54  }
55 
56  return out;
57 }
58 
59 void ServerOperations::UnregisterNodes(std::vector<Node> & nodes)
60 {
61  std::vector<OpcUa::NodeId> ids;
62 
63  for (auto & node : nodes)
64  {
65  ids.push_back(node.GetId());
66  }
67 
68  Server->Views()->UnregisterNodes(ids);
69 }
70 }
std::vector< OpcUa::ReadValueId > AttributesToRead
void CheckStatusCode(StatusCode code)
OpcUa Error codes. GNU LGPL.
Services::SharedPtr Server
void WriteAttributes(std::vector< WriteValue > &)
std::vector< Node > RegisterNodes(std::vector< Node > &)
ServerOperations(Services::SharedPtr Server)
OPC UA Address space part. GNU LGPL.
void UnregisterNodes(std::vector< Node > &)
OpcUa::AttributeId AttributeId
std::vector< DataValue > ReadAttributes(std::vector< ReadValueId > &attributes)
OpcUa::NodeId NodeId


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