Skip to content

Commit 198cdce

Browse files
authored
Merge pull request #7 from openDAQ/openDAQ/PR-1074/feature/public-input-ports
Changes required for openDAQ PR 1074
2 parents cc3011b + b0fa960 commit 198cdce

3 files changed

Lines changed: 111 additions & 6 deletions

File tree

modules/opcua_server_module/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(MODULE_NAME opcua_server_module)
22
set(TEST_APP test_${MODULE_NAME})
33

44
set(TEST_SOURCES test_opcua_server_module.cpp
5+
test_opcua_component_filtering.cpp
56
test_app.cpp
67
)
78

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <coreobjects/authentication_provider_factory.h>
2+
#include <coretypes/common.h>
3+
#include <opcua_server_module/module_dll.h>
4+
#include <opcua_server_module/version.h>
5+
#include <opcuaclient/opcuaclient.h>
6+
#include <opendaq/context_factory.h>
7+
#include <opendaq/instance_factory.h>
8+
#include <opendaq/instance_ptr.h>
9+
#include <opendaq/mock/mock_device_module.h>
10+
#include <opendaq/mock/mock_fb_module.h>
11+
#include <opendaq/module_manager_factory.h>
12+
#include <opendaq/module_ptr.h>
13+
#include <opendaq/opendaq.h>
14+
15+
#include <testutils/testutils.h>
16+
17+
using OpcUaComponentFilteringTest = testing::Test;
18+
19+
using namespace daq;
20+
21+
static ModulePtr CreateModule(ContextPtr context = NullContext())
22+
{
23+
ModulePtr module;
24+
createOpcUaServerModule(&module, context);
25+
return module;
26+
}
27+
28+
static InstancePtr CreateServerInstance()
29+
{
30+
const auto logger = Logger();
31+
const auto moduleManager = ModuleManager("[[none]]");
32+
const auto authenticationProvider = AuthenticationProvider();
33+
const auto context = Context(Scheduler(logger), logger, TypeManager(), moduleManager, authenticationProvider);
34+
35+
const ModulePtr deviceModule(MockDeviceModule_Create(context));
36+
moduleManager.addModule(deviceModule);
37+
38+
const ModulePtr fbModule(MockFunctionBlockModule_Create(context));
39+
moduleManager.addModule(fbModule);
40+
41+
const ModulePtr opcuaServerModule = CreateModule(context);
42+
moduleManager.addModule(opcuaServerModule);
43+
44+
auto instance = InstanceBuilder().setContext(context).setDefaultRootDeviceLocalId("local").build();
45+
46+
instance.addDevice("daqmock://phys_device");
47+
FunctionBlockPtr fb = instance.addFunctionBlock("mock_fb_uid");
48+
// Set first input port to private
49+
auto inputPort = fb.getInputPorts(search::LocalId("TestInputPort1"))[0];
50+
inputPort.setPublic(false);
51+
52+
instance.addServer("OpenDAQOPCUA", nullptr);
53+
return instance;
54+
}
55+
56+
static InstancePtr CreateClientInstance()
57+
{
58+
auto instance = InstanceBuilder().build();
59+
60+
auto config = instance.createDefaultAddDeviceConfig();
61+
PropertyObjectPtr general = config.getPropertyValue("General");
62+
general.setPropertyValue("StreamingConnectionHeuristic", 2);
63+
64+
instance.addDevice("daq.opcua://127.0.0.1", config);
65+
return instance;
66+
}
67+
68+
TEST_F(OpcUaComponentFilteringTest, FilterComponents)
69+
{
70+
auto serverDevice = CreateServerInstance();
71+
auto client = CreateClientInstance();
72+
auto clientDevice = client.getDevices(search::LocalId("local"))[0];
73+
ASSERT_TRUE(clientDevice.assigned());
74+
75+
auto childDevicesServer = serverDevice.getDevices(search::LocalId("mockdev"));
76+
ASSERT_EQ(childDevicesServer.getCount(), 1u);
77+
auto childDevicesClient = clientDevice.getDevices(search::LocalId("mockdev"));
78+
ASSERT_EQ(childDevicesClient.getCount(), 1u);
79+
80+
auto signalsServer = childDevicesServer[0].getSignals(search::LocalId("devicetimesigprivate"));
81+
ASSERT_EQ(signalsServer.getCount(), 1u);
82+
ASSERT_EQ(signalsServer[0].getPublic(), False);
83+
84+
// Not available on client
85+
auto signalsClient = childDevicesClient[0].getSignals(search::LocalId("devicetimesigprivate"));
86+
ASSERT_EQ(signalsClient.getCount(), 0u);
87+
88+
auto fbsServer = serverDevice.getFunctionBlocks();
89+
ASSERT_EQ(fbsServer.getCount(), 1u);
90+
auto fbsClient = clientDevice.getFunctionBlocks();
91+
ASSERT_EQ(fbsClient.getCount(), 1u);
92+
93+
auto portsServer = fbsServer[0].getInputPorts(search::LocalId("TestInputPort1"));
94+
ASSERT_EQ(portsServer.getCount(), 1u);
95+
ASSERT_FALSE(portsServer[0].getPublic());
96+
97+
// Not available on client
98+
auto portsClient = fbsClient[0].getInputPorts(search::LocalId("TestInputPort1"));
99+
ASSERT_EQ(portsClient.getCount(), 0u);
100+
}

shared/libraries/opcuatms/opcuatms_server/src/objects/tms_server_function_block.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,31 @@ void TmsServerFunctionBlock<T>::addChildNodes()
4949
{
5050
auto signalsNodeId = this->getChildNodeId("Sig");
5151
assert(!signalsNodeId.isNull());
52-
52+
5353
uint32_t numberInList = 0;
5454
for (const auto& signal : this->object.getSignals(search::Any()))
5555
{
5656
if (signal.getPublic())
5757
{
58-
auto tmsSignal = this->template registerTmsObjectOrAddReference<TmsServerSignal>(signalsNodeId, signal, numberInList++);
58+
auto tmsSignal = this->template registerTmsObjectOrAddReference<TmsServerSignal>(signalsNodeId, signal, numberInList++);
5959
signals.push_back(std::move(tmsSignal));
6060
}
6161
}
6262

6363
auto inputPortsNodeId = this->getChildNodeId("IP");
6464
assert(!inputPortsNodeId.isNull());
65-
65+
6666
numberInList = 0;
6767
for (const auto& inputPort : this->object.getInputPorts(search::Any()))
6868
{
69-
auto tmsInputPort = this->template registerTmsObjectOrAddReference<TmsServerInputPort>(inputPortsNodeId, inputPort, numberInList++);
70-
inputPorts.push_back(std::move(tmsInputPort));
69+
if (inputPort.getPublic())
70+
{
71+
auto tmsInputPort =
72+
this->template registerTmsObjectOrAddReference<TmsServerInputPort>(inputPortsNodeId, inputPort, numberInList++);
73+
inputPorts.push_back(std::move(tmsInputPort));
74+
}
7175
}
72-
76+
7377
numberInList = 0;
7478
for (const auto& fb : this->object.getFunctionBlocks(search::Any()))
7579
{

0 commit comments

Comments
 (0)