variable_node.hpp
1 #pragma once
2 
3 #include "../global.hpp"
4 
5 #include "opcua.hpp"
6 #include "exception.hpp"
7 
8 #include "base_node.hpp"
9 
10 namespace Cvb
11 {
12 CVB_BEGIN_INLINE_NS
13 namespace OpcUa
14 {
15 
26 {
27  friend class Client;
28  friend class Server;
29 
30  friend class FloatNode;
31  friend class IntegerNode;
32  friend class StringNode;
33 
34 public:
35 
42  {
43  return static_cast<OpcUa::DataType>(GetAttributeAsInt(AttributeID::DataType));
44  }
45 
46 
55  {
56  auto holder = Internal::CbCarrier<void()>::Create(handler);
57  return writeCarrierContainer_.Register(holder);
58  }
59 
68  {
69  auto holder = Internal::CbCarrier<void()>::Create(handler);
70  return readCarrierContainer_.Register(holder);
71  }
72 
79  void UnregisterCallback(EventCookie eventCookie)
80  {
81  readCarrierContainer_.Unregister(eventCookie);
82  writeCarrierContainer_.Unregister(eventCookie);
83  }
84 
85 protected:
87  explicit VariableNode(OpcUa::BaseNode && node) noexcept
88  : OpcUa::BaseNode(std::move(node))
89  {
90  }
91 
92 private:
93  size_t callbackCookie_ = 0;
94  Internal::CarrierContainer writeCarrierContainer_;
95  Internal::CarrierContainer readCarrierContainer_;
96 
97  static void __stdcall ReadCallback(CExports::CVOPCNODE, void * pPrivate)
98  {
99  try
100  {
101  auto node = reinterpret_cast<VariableNode *>(pPrivate);
102  node->readCarrierContainer_.Call<void()>();
103  }
104  catch (...)
105  {
106  // swallow exception so they don't propagate to native library.
107  }
108  }
109 
110  static void __stdcall WriteCallback(CExports::CVOPCNODE, void * pPrivate)
111  {
112  try
113  {
114  auto node = reinterpret_cast<VariableNode*>(pPrivate);
115  node->writeCarrierContainer_.Call<void()>();
116  }
117  catch (...)
118  {
119  // swallow exception so they don't propagate to native library.
120  }
121  }
123 };
124 
125 }
126 
127 CVB_END_INLINE_NS
128 
129 }
A node object with string values, provides an interface for storage and manipulation of strings (defa...
Definition: string_node.hpp:24
void UnregisterCallback(EventCookie eventCookie)
Definition: variable_node.hpp:79
OpcUa::DataType DataType() const
Definition: variable_node.hpp:41
Root namespace for the Image Manager interface.
Definition: version.hpp:11
A FloatNode object provides an interface for storage and manipulation of floating point numbers.
Definition: float_node.hpp:23
A Node with integer values provides an interface for storage and manipulation of integer (default int...
Definition: integer_node.hpp:24
Datatype of the node contents (VariableNode (integer See OpcUa::DataType))
std::int64_t GetAttributeAsInt(AttributeID attributeID) const
Return specific Information about a Opcua::BaseNode.
Definition: decl_base_node.hpp:162
An OPCUA VariableNode object. It handles the data modeling acording to the OPCUA specification.
Definition: variable_node.hpp:25
An OPCUA Client object. This class handles the client side of the OPCUA client/server interaction.
Definition: decl_client.hpp:33
An OPCUA server object.
Definition: decl_server.hpp:33
EventCookie RegisterReadCallback(std::function< void()> handler)
Definition: variable_node.hpp:67
EventCookie RegisterWriteCallback(std::function< void()> handler)
Definition: variable_node.hpp:54
An OPCUA BaseNode. This is the base for all other node classes. For instantiation of a specific node ...
Definition: decl_base_node.hpp:34
DataType
Describes the contents of a VariableNode.
Definition: opcua.hpp:186