open62541pp 0.17.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
session.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <utility> // move
4
6
7namespace opcua {
8
9class Server;
10
11/**
12 * High-level session class to manage client sessions.
13 *
14 * Sessions are identified by a server-assigned session id (of type NodeId).
15 * A session carries attributes in a key-value list. Custom attributes/meta-data can be attached to
16 * a session as key-value pairs of QualifiedName and Variant.
17 *
18 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.7
19 */
20class Session {
21public:
22 Session(Server& connection, NodeId sessionId, void* sessionContext) noexcept
23 : connection_(&connection),
24 id_(std::move(sessionId)),
25 context_(sessionContext) {}
26
27 /// Get the server instance.
28 Server& connection() noexcept {
29 return *connection_;
30 }
31
32 /// Get the server instance.
33 const Server& connection() const noexcept {
34 return *connection_;
35 }
36
37 /// Get the session identifier.
38 const NodeId& id() const noexcept {
39 return id_;
40 }
41
42 /// Get the session context.
43 void* context() noexcept {
44 return context_;
45 }
46
47 /// Get the session context.
48 const void* context() const noexcept {
49 return context_;
50 }
51
52 /// Get a session attribute by its key.
53 /// @note Supported since open62541 v1.3
55
56 /// Attach a session attribute as a key-value pair.
57 /// @note Supported since open62541 v1.3
58 void setSessionAttribute(const QualifiedName& key, const Variant& value);
59
60 /// Delete a session attribute by its key.
61 /// @note Supported since open62541 v1.3
63
64 /// Manually close this session.
65 /// @note Supported since open62541 v1.3
66 void close();
67
68private:
69 Server* connection_;
70 NodeId id_;
71 void* context_;
72};
73
74/// @relates Session
75bool operator==(const Session& lhs, const Session& rhs) noexcept;
76
77/// @relates Session
78bool operator!=(const Session& lhs, const Session& rhs) noexcept;
79
80} // namespace opcua
UA_NodeId wrapper class.
Definition types.hpp:666
UA_QualifiedName wrapper class.
Definition types.hpp:1011
High-level server class.
Definition server.hpp:132
High-level session class to manage client sessions.
Definition session.hpp:20
Session(Server &connection, NodeId sessionId, void *sessionContext) noexcept
Definition session.hpp:22
void setSessionAttribute(const QualifiedName &key, const Variant &value)
Attach a session attribute as a key-value pair.
const NodeId & id() const noexcept
Get the session identifier.
Definition session.hpp:38
void * context() noexcept
Get the session context.
Definition session.hpp:43
const Server & connection() const noexcept
Get the server instance.
Definition session.hpp:33
Variant getSessionAttribute(const QualifiedName &key)
Get a session attribute by its key.
Server & connection() noexcept
Get the server instance.
Definition session.hpp:28
bool operator!=(const Session &lhs, const Session &rhs) noexcept
void close()
Manually close this session.
void deleteSessionAttribute(const QualifiedName &key)
Delete a session attribute by its key.
bool operator==(const Session &lhs, const Session &rhs) noexcept
const void * context() const noexcept
Get the session context.
Definition session.hpp:48
UA_Variant wrapper class.
Definition types.hpp:1176