open62541pp 0.16.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.6
19 */
20class Session {
21public:
22 Session(Server& connection, NodeId sessionId) noexcept
23 : connection_(&connection),
24 sessionId_(std::move(sessionId)) {}
25
26 /// Get the server instance.
27 Server& connection() noexcept {
28 return *connection_;
29 }
30
31 /// Get the server instance.
32 const Server& connection() const noexcept {
33 return *connection_;
34 }
35
36 /// Get the session identifier.
37 const NodeId& id() const noexcept {
38 return sessionId_;
39 }
40
41 /// Get a session attribute by its key.
42 /// @note Supported since open62541 v1.3
44
45 /// Attach a session attribute as a key-value pair.
46 /// @note Supported since open62541 v1.3
47 void setSessionAttribute(const QualifiedName& key, const Variant& value);
48
49 /// Delete a session attribute by its key.
50 /// @note Supported since open62541 v1.3
52
53 /// Manually close this session.
54 /// @note Supported since open62541 v1.3
55 void close();
56
57private:
58 Server* connection_;
59 NodeId sessionId_;
60};
61
62bool operator==(const Session& lhs, const Session& rhs) noexcept;
63bool operator!=(const Session& lhs, const Session& rhs) noexcept;
64
65} // namespace opcua
UA_NodeId wrapper class.
Definition types.hpp:590
UA_QualifiedName wrapper class.
Definition types.hpp:800
High-level server class.
Definition server.hpp:132
High-level session class to manage client sessions.
Definition session.hpp:20
void setSessionAttribute(const QualifiedName &key, const Variant &value)
Attach a session attribute as a key-value pair.
Session(Server &connection, NodeId sessionId) noexcept
Definition session.hpp:22
const NodeId & id() const noexcept
Get the session identifier.
Definition session.hpp:37
const Server & connection() const noexcept
Get the server instance.
Definition session.hpp:32
Variant getSessionAttribute(const QualifiedName &key)
Get a session attribute by its key.
Server & connection() noexcept
Get the server instance.
Definition session.hpp:27
void close()
Manually close this session.
void deleteSessionAttribute(const QualifiedName &key)
Delete a session attribute by its key.
UA_Variant wrapper class.
Definition types.hpp:887
bool operator!=(const Client &lhs, const Client &rhs) noexcept
Definition client.hpp:295
bool operator==(const Client &lhs, const Client &rhs) noexcept
Definition client.hpp:291