-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from ASNeG/fix_monitor_item_callbacks
Fix calling stop monitored item callback.
- Loading branch information
Showing
4 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2015-2018 Kai Huebl ([email protected]) | ||
Copyright 2015-2019 Kai Huebl ([email protected]) | ||
Lizenziert gemäß Apache Licence Version 2.0 (die „Lizenz“); Nutzung dieser | ||
Datei nur in Übereinstimmung mit der Lizenz erlaubt. | ||
|
@@ -12,7 +12,7 @@ | |
Informationen über die jeweiligen Bedingungen für Genehmigungen und Einschränkungen | ||
im Rahmen der Lizenz finden Sie in der Lizenz. | ||
Autor: Kai Huebl ([email protected]) | ||
Autor: Kai Huebl ([email protected]), Aleksey Timin ([email protected]) | ||
*/ | ||
|
||
#include "OpcUaStackCore/Base/Log.h" | ||
|
@@ -582,8 +582,9 @@ namespace OpcUaStackServer | |
} | ||
|
||
// check monitored item list | ||
monitoredItemIds_.erase(it1); | ||
if (newMonitoredItemIds.size() > 0) { | ||
monitoredItemIds_.insert(std::make_pair(baseNodeClass->nodeId().data(), monitoredItemIds)); | ||
monitoredItemIds_.insert(std::make_pair(baseNodeClass->nodeId().data(), newMonitoredItemIds)); | ||
return; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2015-2018 Kai Huebl ([email protected]) | ||
Copyright 2015-2019 Kai Huebl ([email protected]) | ||
Lizenziert gemäß Apache Licence Version 2.0 (die „Lizenz“); Nutzung dieser | ||
Datei nur in Übereinstimmung mit der Lizenz erlaubt. | ||
|
@@ -12,7 +12,7 @@ | |
Informationen über die jeweiligen Bedingungen für Genehmigungen und Einschränkungen | ||
im Rahmen der Lizenz finden Sie in der Lizenz. | ||
Autor: Kai Huebl ([email protected]) | ||
Autor: Kai Huebl ([email protected]), Aleksey Timin ([email protected]) | ||
*/ | ||
|
||
#ifndef __OpcUaStackServer_MonitorManager_h__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#include "unittest.h" | ||
|
||
#include "OpcUaStackServer/ServiceSet/MonitorManager.h" | ||
#include "OpcUaStackServer/AddressSpaceModel/VariableNodeClass.h" | ||
#include "OpcUaStackCore/Application/ApplicationMonitoredItemStartContext.h" | ||
#include "OpcUaStackCore/Application/ApplicationMonitoredItemStopContext.h" | ||
|
||
using namespace OpcUaStackServer; | ||
|
||
|
||
struct F { | ||
F() : mm() | ||
, informationModel(constructSPtr<InformationModel>()) | ||
, ioThread(constructSPtr<IOThread>()) | ||
, createMonitoredItemTransaction(constructSPtr<ServiceTransactionCreateMonitoredItems>()) | ||
, startMonitoredItemCallCount(0) | ||
, stopMonitoredItemCallCount(0) | ||
{ | ||
|
||
mm.informationModel(informationModel); | ||
|
||
ioThread = constructSPtr<IOThread>(); | ||
ioThread->slotTimer(constructSPtr<SlotTimer>()); | ||
mm.ioThread(ioThread.get()); | ||
|
||
auto nodeToMonitor = constructSPtr<VariableNodeClass>(); | ||
OpcUaNodeId nodeToMonitorId(0, 0); | ||
nodeToMonitor->setNodeId(nodeToMonitorId); | ||
OpcUaDataValue value(0); | ||
nodeToMonitor->setValue(value); | ||
|
||
auto sync = constructSPtr<ForwardNodeSync>(); | ||
auto startMonitoredItemCallback = Callback(boost::bind(&F::startMonitored, this, _1)); | ||
auto stopMonitoredItemCallback = Callback(boost::bind(&F::stopMonitored, this, _1)); | ||
sync->monitoredItemStartService().setCallback(startMonitoredItemCallback); | ||
sync->monitoredItemStopService().setCallback(stopMonitoredItemCallback); | ||
|
||
nodeToMonitor->forwardNodeSync(sync); | ||
|
||
informationModel->insert(nodeToMonitor); | ||
|
||
auto monitoredItemCreateRequest = constructSPtr<MonitoredItemCreateRequest>(); | ||
|
||
ReadValueId readValueId; | ||
readValueId.nodeId(0, 0); | ||
readValueId.attributeId(AttributeId_Value); | ||
monitoredItemCreateRequest->itemToMonitor(readValueId); | ||
|
||
|
||
auto itemsToCreate = constructSPtr<MonitoredItemCreateRequestArray>(); | ||
itemsToCreate->resize(1); | ||
itemsToCreate->push_back(monitoredItemCreateRequest); | ||
|
||
createMonitoredItemTransaction->request()->itemsToCreate(itemsToCreate); | ||
} | ||
|
||
void | ||
startMonitored(ApplicationMonitoredItemStartContext* context) | ||
{ | ||
startMonitoredItemCallCount++; | ||
} | ||
|
||
void | ||
stopMonitored(ApplicationMonitoredItemStopContext* context) | ||
{ | ||
stopMonitoredItemCallCount++; | ||
} | ||
|
||
ServiceTransactionDeleteMonitoredItems::SPtr makeDeleteMonitredItemTransaction(CreateMonitoredItemsResponse::SPtr response) { | ||
MonitoredItemCreateResult::SPtr result; | ||
response->results()->get(0, result); | ||
|
||
auto ids = constructSPtr<OpcUaUInt32Array>(); | ||
ids->resize(1); | ||
ids->push_back(result->monitoredItemId()); | ||
|
||
auto deleteMonitoredItemTransaction = constructSPtr<ServiceTransactionDeleteMonitoredItems>(); | ||
deleteMonitoredItemTransaction->request()->monitoredItemIds(ids); | ||
|
||
return deleteMonitoredItemTransaction; | ||
} | ||
|
||
~F() { } | ||
|
||
MonitorManager mm; | ||
InformationModel::SPtr informationModel; | ||
IOThread::SPtr ioThread; | ||
|
||
ServiceTransactionCreateMonitoredItems::SPtr createMonitoredItemTransaction; | ||
|
||
size_t startMonitoredItemCallCount; | ||
size_t stopMonitoredItemCallCount; | ||
|
||
}; | ||
|
||
|
||
BOOST_FIXTURE_TEST_SUITE(MonitorManager_, F) | ||
|
||
BOOST_AUTO_TEST_CASE(MonitorManager_) | ||
{ | ||
std::cout << "MonitorManager_t" << std::endl; | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(MonitorManager_CallStartMonitoredItemCallback) | ||
{ | ||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(createMonitoredItemTransaction)); | ||
|
||
MonitoredItemCreateResult::SPtr result; | ||
createMonitoredItemTransaction->response()->results()->get(0, result); | ||
|
||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, result->statusCode()); | ||
BOOST_REQUIRE_EQUAL(1, startMonitoredItemCallCount); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(MonitorManager_CallStartMonitoredItemCallbackOnlyOnce) | ||
{ | ||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(createMonitoredItemTransaction)); | ||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(createMonitoredItemTransaction)); | ||
|
||
MonitoredItemCreateResult::SPtr result; | ||
createMonitoredItemTransaction->response()->results()->get(0, result); | ||
|
||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, result->statusCode()); | ||
BOOST_REQUIRE_EQUAL(1, startMonitoredItemCallCount); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(MonitorManager_CallStopMonitoredItemCallback) | ||
{ | ||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(createMonitoredItemTransaction)); | ||
|
||
auto deleteMonitoredItemTransaction = | ||
makeDeleteMonitredItemTransaction(createMonitoredItemTransaction->response()); | ||
|
||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(deleteMonitoredItemTransaction)); | ||
|
||
OpcUaStatusCode status; | ||
deleteMonitoredItemTransaction->response()->results()->get(0, status); | ||
|
||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, status); | ||
BOOST_REQUIRE_EQUAL(1, stopMonitoredItemCallCount); | ||
} | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(MonitorManager_CallStopMonitoredItemCallbackOnlyOnce) | ||
{ | ||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(createMonitoredItemTransaction)); | ||
|
||
auto deleteMonitoredItemTransaction1 = | ||
makeDeleteMonitredItemTransaction(createMonitoredItemTransaction->response()); | ||
|
||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(createMonitoredItemTransaction)); | ||
|
||
auto deleteMonitoredItemTransaction2 = | ||
makeDeleteMonitredItemTransaction(createMonitoredItemTransaction->response()); | ||
|
||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(deleteMonitoredItemTransaction1)); | ||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, mm.receive(deleteMonitoredItemTransaction2)); | ||
|
||
OpcUaStatusCode status; | ||
deleteMonitoredItemTransaction2->response()->results()->get(0, status); | ||
|
||
BOOST_REQUIRE_EQUAL(OpcUaStatusCode::Success, status); | ||
BOOST_REQUIRE_EQUAL(1, stopMonitoredItemCallCount); | ||
} | ||
|
||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
|
||
|