forked from open62541pp/open62541pp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices_subscription.cpp
97 lines (82 loc) · 3.2 KB
/
services_subscription.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "open62541pp/services/subscription.hpp"
#ifdef UA_ENABLE_SUBSCRIPTIONS
#include <memory>
#include "open62541pp/client.hpp"
#include "open62541pp/detail/client_context.hpp"
#include "open62541pp/detail/open62541/client.h"
#include "open62541pp/detail/open62541/common.h"
#include "open62541pp/services/detail/response_handling.hpp"
#include "open62541pp/services/detail/subscription_context.hpp"
#include "open62541pp/ua/types.hpp"
namespace opcua::services {
namespace detail {
std::unique_ptr<SubscriptionContext> createSubscriptionContext(
Client& connection,
StatusChangeNotificationCallback&& statusChangeCallback,
DeleteSubscriptionCallback&& deleteCallback
) {
auto context = std::make_unique<SubscriptionContext>();
context->catcher = &opcua::detail::getContext(connection).exceptionCatcher;
context->statusChangeCallback = std::move(statusChangeCallback);
context->deleteCallback = std::move(deleteCallback);
return context;
}
void storeSubscriptionContext(
Client& connection, IntegerId subscriptionId, std::unique_ptr<SubscriptionContext>&& context
) {
opcua::detail::getContext(connection).subscriptions.insert(subscriptionId, std::move(context));
}
} // namespace detail
CreateSubscriptionResponse createSubscription(
Client& connection,
const CreateSubscriptionRequest& request,
StatusChangeNotificationCallback statusChangeCallback,
DeleteSubscriptionCallback deleteCallback
) {
auto context = detail::createSubscriptionContext(
connection, std::move(statusChangeCallback), std::move(deleteCallback)
);
CreateSubscriptionResponse response = UA_Client_Subscriptions_create(
connection.handle(),
request,
context.get(),
detail::SubscriptionContext::statusChangeCallbackNative,
detail::SubscriptionContext::deleteCallbackNative
);
if (detail::getServiceResult(response).isGood()) {
detail::storeSubscriptionContext(connection, response.subscriptionId(), std::move(context));
}
return response;
}
CreateSubscriptionResponse createSubscription(
Client& connection,
const SubscriptionParameters& parameters,
bool publishingEnabled,
StatusChangeNotificationCallback statusChangeCallback,
DeleteSubscriptionCallback deleteCallback
) noexcept {
const auto request = detail::createCreateSubscriptionRequest(parameters, publishingEnabled);
return createSubscription(
connection,
asWrapper<CreateSubscriptionRequest>(request),
std::move(statusChangeCallback),
std::move(deleteCallback)
);
}
ModifySubscriptionResponse modifySubscription(
Client& connection, const ModifySubscriptionRequest& request
) noexcept {
return UA_Client_Subscriptions_modify(connection.handle(), request);
}
SetPublishingModeResponse setPublishingMode(
Client& connection, const SetPublishingModeRequest& request
) noexcept {
return UA_Client_Subscriptions_setPublishingMode(connection.handle(), request);
}
DeleteSubscriptionsResponse deleteSubscriptions(
Client& connection, const DeleteSubscriptionsRequest& request
) noexcept {
return UA_Client_Subscriptions_delete(connection.handle(), request);
}
} // namespace opcua::services
#endif