-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSubscription.hpp
68 lines (49 loc) · 2.69 KB
/
Subscription.hpp
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2019-2021 (c) Christian von Arnim, ISW University of Stuttgart (for umati and VDW e.V.)
* Copyright 2020 (c) Dominik Basner, Sotec GmbH (for VDW e.V.)
* Copyright 2021 (c) Marius Dege, basysKom GmbH
* Copyright 2021 (c) Frank Meerkoetter, basysKom GmbH
*/
#pragma once
#include <open62541/client.h>
#include <open62541/client_highlevel.h>
#include <open62541/client_subscriptions.h>
#include <Open62541Cpp/UA_NodeId.hpp>
#include <ModelOpcUa/ModelDefinition.hpp>
#include <atomic>
#include <IDashboardDataClient.hpp>
#include "OpcUaSubscriptionInterface.hpp"
#include <mutex>
namespace Umati {
namespace OpcUa {
class Subscription {
public:
~Subscription();
Subscription(const std::map<std::string, uint16_t> &m_uriToIndexCache, const std::map<uint16_t, std::string> &m_indexToUriCache);
void subscriptionStatusChanged(UA_Client *client, UA_Int32 clientSubscriptionHandle, const UA_StatusCode &status);
void dataChange(UA_Int32 clientSubscriptionHandle, const UA_DataChangeNotification &dataNotifications, const UA_DiagnosticInfo &diagnosticInfos);
void newEvents(UA_Int32 clientSubscriptionHandle, UA_EventFieldList &eventFieldList);
virtual std::shared_ptr<Dashboard::IDashboardDataClient::ValueSubscriptionHandle> Subscribe(
UA_Client *client, ModelOpcUa::NodeId_t, Dashboard::IDashboardDataClient::newValueCallbackFunction_t callback);
void Unsubscribe(UA_Client *client, std::vector<int32_t> monItemIds, std::vector<int32_t> clientHandles);
void createSubscription(UA_Client *client);
void deleteSubscription(UA_Client *client);
void setSubscriptionWrapper(Umati::OpcUa::OpcUaSubscriptionInterface *pSubscriptionWrapper);
protected:
std::shared_ptr<UA_SessionState> _pSession;
friend class ValueSubscriptionHandle;
const std::map<std::string, uint16_t> &m_uriToIndexCache;
const std::map<uint16_t, std::string> &m_indexToUriCache;
static std::atomic_uint nextId;
UA_Int32 m_pSubscriptionID;
Umati::OpcUa::OpcUaSubscriptionInterface *m_pSubscriptionWrapper = new OpcUaSubscriptionWrapper();
std::mutex m_callbacks_mutex;
std::map<UA_Int32, Dashboard::IDashboardDataClient::newValueCallbackFunction_t> m_callbacks;
UA_MonitoredItemCreateRequest &prepareMonItemCreateReq(const ModelOpcUa::NodeId_t &nodeId, UA_MonitoredItemCreateRequest &monItemCreateReq) const;
static void validateMonitorItemResult(const UA_StatusCode &uaResult, UA_MonitoredItemCreateResult monItemCreateResult, const ModelOpcUa::NodeId_t &nodeId);
};
} // namespace OpcUa
} // namespace Umati