24 #include <boost/asio.hpp> 30 : Server(server),
Client(callback), Logger(logger)
34 Services::SharedPtr serverptr =
Server;
43 std::vector<StatusCode> results =
Server->Subscriptions()->DeleteSubscriptions(std::vector<uint32_t> {
Data.
SubscriptionId});
45 for (
auto res : results)
74 LOG_DEBUG(
Logger,
"subscription | notification is of type StatusChange");
90 server->Subscriptions()->Publish(request);
97 std::unique_lock<std::mutex> lock(
Mutex);
109 Node node = mapit->second.TargetNode;
112 LOG_DEBUG(
Logger,
"subscription | calling DataChange user callback: {} and node: {}", item.
ClientHandle, mapit->second.TargetNode);
129 std::unique_lock<std::mutex> lock(
Mutex);
143 if (mapit->second.Filter.Event.SelectClauses.size() != ef.
EventFields.size())
145 throw std::runtime_error(
"subscription | receive event format does not match requested filter");
240 if (results.size() != 1) {
throw std::runtime_error(
"subscription | SubscribeDataChange should have returned exactly one result"); }
242 return results.front();
247 std::unique_lock<std::mutex> lock(
Mutex);
253 for (
auto req : request)
258 return Server->Subscriptions()->CreateMonitoredItems(itemsParams);
263 std::unique_lock<std::mutex> lock(
Mutex);
283 std::vector<MonitoredItemCreateResult> results =
Server->Subscriptions()->CreateMonitoredItems(itemsParams);
285 if (results.size() != attributes.size())
287 throw (std::runtime_error(
"subscription | server did not send answer for all MonitoredItem requests"));
290 std::vector<uint32_t> monitoredItemsIds;
293 for (
const auto & res : results)
297 LOG_DEBUG(
Logger,
"subscription | storing monitoreditem with handle: {} and id: {}", itemsParams.
ItemsToCreate[i].RequestedParameters.ClientHandle, res.MonitoredItemId);
301 mdata.
Attribute = attributes[i].AttributeId;
304 monitoredItemsIds.push_back(res.MonitoredItemId);
308 return monitoredItemsIds;
323 return UnSubscribe(std::vector<uint32_t>(1, handle));
328 std::unique_lock<std::mutex> lock(
Mutex);
332 std::vector<uint32_t> mids;
334 for (
auto id : handles)
336 LOG_DEBUG(
Logger,
"subscription | sending unsubscribe for MonitoredItem id: {}",
id);
337 mids.push_back(uint32_t(
id));
342 if (pair.second.MonitoredItemId ==
id)
344 AttributeValueMap.erase(pair.first);
351 auto results =
Server->Subscriptions()-> DeleteMonitoredItems(params);
353 for (
auto res : results)
368 LOG_DEBUG(
Logger,
"subscription | subscribing events with filter for:");
372 auto propertyName =
child.GetBrowseName();
378 op.
BrowsePath = std::vector<QualifiedName>({propertyName});
387 std::unique_lock<std::mutex> lock(
Mutex);
402 params.
QueueSize = std::numeric_limits<uint32_t>::max();
411 std::vector<MonitoredItemCreateResult> results =
Server->Subscriptions()->CreateMonitoredItems(itemsParams);
413 if (results.size() != 1)
415 throw (std::runtime_error(
"subscription | CreateMonitoredItems should return one result"));
418 auto result = results[0];
420 if (result.FilterResult.Event.SelectClauses.empty())
422 result.FilterResult.Event.SelectClauses = eventfilter.
SelectClauses;
424 if (result.FilterResult.Event.WhereClause.empty())
426 result.FilterResult.Event.WhereClause = eventfilter.
WhereClause;
432 mdata.
Filter = result.FilterResult;
437 return result.MonitoredItemId;
void CheckStatusCode(StatusCode code)
OpcUa Error codes. GNU LGPL.
#define LOG_WARN(__logger__,...)
void CallEventCallback(const NotificationData &data)
OpcUa::CreateSubscriptionParameters Parameters
Subscription(Services::SharedPtr server, const CreateSubscriptionParameters ¶ms, SubscriptionHandler &callback, const Common::Logger::SharedPtr &logger=nullptr)
std::vector< OpcUa::NotificationData > NotificationData
virtual void DataChange(uint32_t handle, const Node &node, const Variant &val, AttributeId attribute)
uint32_t RetransmitSequenceNumber
virtual void Event(uint32_t handle, const Event &event)
std::vector< QualifiedName > BrowsePath
#define LOG_DEBUG(__logger__,...)
void CallDataChangeCallback(const NotificationData &data)
std::vector< Node > GetProperties() const
OpcUa::MonitoringFilter Filter
uint32_t LastMonitoredItemHandle
std::vector< SimpleAttributeOperand > SelectClauses
std::vector< Variant > EventFields
void UnSubscribe(uint32_t handle)
RepublishResponse Republish(uint32_t sequenceNumber)
double RevisedPublishingInterval
virtual void DataValueChange(uint32_t handle, const Node &node, const DataValue &val, AttributeId attribute)
Services::SharedPtr Server
std::vector< ContentFilterElement > WhereClause
UserData * getUsrPtr(uint32_t handle)
uint32_t SubscribeDataChange(const Node &node, AttributeId attr=AttributeId::Value)
SimpleAttOpMap SimpleAttributeOperandMap
EventNotificationList Events
ExtensionObjectHeader Header
AttValMap AttributeValueMap
OPC UA Address space part. GNU LGPL.
std::vector< EventFieldList > Events
SubscriptionHandler & Client
Common::Logger::SharedPtr Logger
void setUsrPtr(uint32_t handle, UserData *usr)
A Node object represent an OPC-UA node. It is high level object intended for developper who want to e...
std::vector< MonitoredItemCreateResult > Subscribe(std::vector< MonitoredItemCreateRequest > request)
IntegerId MonitoredItemId
std::vector< uint32_t > MonitoredItemIds
DataChangeNotification DataChange
OpcUa::AttributeId AttributeId
OpcUa::MonitoringParameters RequestedParameters
OpcUa::NotificationMessage NotificationMessage
void CallStatusChangeCallback(const NotificationData &data)
virtual void StatusChange(StatusCode status)
OpcUa::ReadValueId ItemToMonitor
void SetValue(const std::vector< QualifiedName > &path, Variant value)
std::vector< MonitoredItems > Notification
std::vector< OpcUa::SubscriptionAcknowledgement > SubscriptionAcknowledgements
uint32_t SubscribeEvents()
virtual void PublishCallback(Services::SharedPtr serverLocalPtr, const PublishResult result)
StatusChangeNotification StatusChange
OpcUa::TimestampsToReturn TimestampsToReturn
OpcUa::MonitoringMode MonitoringMode
std::vector< OpcUa::MonitoredItemCreateRequest > ItemsToCreate