Skip to content

Commit

Permalink
(opcua): backports from uniset2
Browse files Browse the repository at this point in the history
  • Loading branch information
vpashka committed Jan 4, 2024
1 parent 938b712 commit 46c934b
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
# due broken comedi
export CXXFLAGS="$CXXFLAGS -Wl,--unresolved-symbols=ignore-in-shared-libs"
autoreconf -fiv
./configure --disable-netdata --disable-python --disable-pgsql
./configure --disable-netdata --disable-python --disable-pgsql --disable-opcua --disable-tests
make
- name: Show summary of ccache configuration and statistics counters
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
libcomedi-devel libmariadb-devel libpqxx-devel libsqlite3-devel \
libxml2-devel libsigc++2-devel libpoco-devel libev-devel libprotobuf-devel grpc-plugins libgrpc++-devel \
libmosquitto-devel libprotobuf-devel \
libopen62541-devel libopen62541pp-devel \
xsltproc python3-dev python-module-distribute swig iputils
- name: cache
Expand Down
44 changes: 39 additions & 5 deletions conf/libuniset3.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
%def_enable logdb
%def_enable opentsdb
%def_enable uwebsocket
%def_enable opcua

%ifarch %ix86
%def_enable com485f
Expand Down Expand Up @@ -68,6 +69,11 @@ BuildRequires: libpqxx-devel >= 7.6.0
BuildRequires: libmosquitto-devel
%endif

%if_enabled opcua
BuildRequires: libopen62541-devel libopen62541pp-devel >= 0.3.0-alt1
%endif


%if_enabled netdata
BuildRequires: netdata
%endif
Expand All @@ -84,10 +90,6 @@ BuildRequires(pre): rpm-build-python3
BuildRequires: doxygen graphviz ImageMagick-tools
%endif

%if_enabled tests
BuildRequires: catch
%endif

#set_verify_elf_method textrel=strict,rpath=strict,unresolved=strict

%description
Expand Down Expand Up @@ -331,6 +333,24 @@ Requires: %name-extension-common-devel = %version-%release
Libraries needed to develop for uniset MQTT extension
%endif

%if_enabled opcua
%package extension-opcua
Group: Development/C++
Summary: OPC UA support for %{name}
Requires: %name-extension-common = %version-%release

%description extension-opcua
OPC UA support for %{name}

%package extension-opcua-devel
Group: Development/C++
Summary: Libraries needed to develop for uniset OPC UA extension
Requires: %name-extension-common-devel = %version-%release

%description extension-opcua-devel
Libraries needed to develop for uniset OPC UA extension
%endif

%if_enabled api
%package extension-api-gateway
Group: Development/C++
Expand All @@ -354,7 +374,10 @@ Libraries needed to develop for uniset HTTP API Gateway extension

%build
%autoreconf
%configure %{subst_enable docs} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests} %{subst_enable mqtt} %{subst_enable api} %{subst_enable netdata} %{subst_enable logdb} %{subst_enable com485f} %{subst_enable opentsdb} %{subst_enable uwebsocket}
%if "%__gcc_version_major" < "12"
%add_optflags -std=c++17
%endif
%configure %{subst_enable docs} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests} %{subst_enable mqtt} %{subst_enable api} %{subst_enable netdata} %{subst_enable logdb} %{subst_enable com485f} %{subst_enable opentsdb} %{subst_enable uwebsocket} %{subst_enable opcua}
%make_build

%install
Expand Down Expand Up @@ -519,6 +542,17 @@ rm -f %buildroot%_docdir/%oname/html/*.md5
%_includedir/%oname/extensions/mqtt/
%endif

%if_enabled opcua
%files extension-opcua
%_bindir/%oname-opcua*
%_libdir/libUniSet3OPCUA*.so.*

%files extension-opcua-devel
%_pkgconfigdir/libUniSet3OPCUA*.pc
%_libdir/libUniSet3OPCUA*.so
%_includedir/%oname/extensions/opcua/
%endif

%if_enabled api
%if_enabled uwebsocket
%files extension-wsgate
Expand Down
27 changes: 26 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ fi
AM_CONDITIONAL(DISABLE_OPENTSDB, test ${buildtsdb} = false)
AM_CONDITIONAL(ENABLE_OPENTSDB, test ${buildtsdb} = true)

#check opc-ua support
AC_MSG_CHECKING([opc-ua support])
buildopcua=true
AC_ARG_ENABLE(opcua, AC_HELP_STRING([--disable-opcua], [disable OPC-UA support]),
[ if test $enableval = yes; then buildopcua=true; else buildopcua=false; fi],[ buildopcua=true; ])

if test ${buildopcua} = true; then
AC_MSG_RESULT([enabled])
PKG_CHECK_MODULES(OPEN62541PP, open62541pp)
PKG_CHECK_MODULES(OPEN62541, open62541)
else
AC_MSG_RESULT([disabled])
fi

AM_CONDITIONAL(DISABLE_OPCUA, test ${buildopcua} = false)
AM_CONDITIONAL(ENABLE_OPCUA, test ${buildopcua} = true)

#check io support
AC_MSG_CHECKING([io support])
buildio=true
Expand Down Expand Up @@ -259,7 +276,6 @@ fi

AM_CONDITIONAL(HAVE_EXTENTIONS, test ${ext} = true)


#check python support
AC_MSG_CHECKING([python support])
buildpython=true
Expand Down Expand Up @@ -432,6 +448,8 @@ if test ${buildtests} = true; then
AC_CONFIG_TESTDIR(extensions/URepository/tests)
AC_CONFIG_TESTDIR(extensions/HttpAPIGateway/tests)
AC_CONFIG_TESTDIR(extensions/UWebSocketGate/tests)
AC_CONFIG_TESTDIR(extensions/OPCUAServer/tests)
AC_CONFIG_TESTDIR(extensions/OPCUAExchange/tests)

TESTSUITE_DIR="\$(top_builddir)/testsuite"
AC_SUBST(TESTSUITE_DIR)
Expand Down Expand Up @@ -542,6 +560,7 @@ AC_CONFIG_FILES([Makefile
tests/PocoTest/Makefile
tests/UHttpTest/Makefile
tests/TCPSocketTest/Makefile
tests/Open62541Test/Makefile
docs/Makefile
docs/UniSetDox.cfg
docs/UniSetDoxDevel.cfg
Expand Down Expand Up @@ -602,6 +621,12 @@ AC_CONFIG_FILES([Makefile
extensions/UWebSocketGate/Makefile
extensions/UWebSocketGate/tests/Makefile
extensions/UWebSocketGate/libUniSet3UWebSocketGate.pc
extensions/OPCUAServer/Makefile
extensions/OPCUAServer/tests/Makefile
extensions/OPCUAServer/libUniSet3OPCUAServer.pc
extensions/OPCUAExchange/Makefile
extensions/OPCUAExchange/tests/Makefile
extensions/OPCUAExchange/libUniSet3OPCUAExchange.pc
extensions/HttpAPIGateway/Makefile
extensions/HttpAPIGateway/tests/Makefile
extensions/HttpAPIGateway/libUniSet3HttpAPIGateway.pc
Expand Down
1 change: 1 addition & 0 deletions extensions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SUBDIRS = lib include SharedMemory SharedMemory/tests IOControl IOControl/tests
DBServer-MySQL DBServer-SQLite DBServer-PostgreSQL MQTTPublisher \
tests ModbusMaster/tests ModbusSlave/tests LogDB LogDB/tests \
Backend-OpenTSDB URepository URepository/tests UWebSocketGate UWebSocketGate/tests \
OPCUAServer OPCUAServer/tests OPCUAExchange OPCUAExchange/tests \
HttpAPIGateway HttpAPIGateway/tests


Expand Down
1 change: 1 addition & 0 deletions extensions/OPCUAExchange/tests/testsuite-functions.sh
1 change: 1 addition & 0 deletions extensions/OPCUAExchange/tests/uniset3-functions.sh
1 change: 1 addition & 0 deletions extensions/OPCUAExchange/tests/uniset3-start.sh
1 change: 1 addition & 0 deletions extensions/OPCUAExchange/uniset3-functions.sh
1 change: 1 addition & 0 deletions extensions/OPCUAExchange/uniset3-start.sh
1 change: 1 addition & 0 deletions extensions/OPCUAServer/stop.sh
1 change: 1 addition & 0 deletions extensions/OPCUAServer/tests/testsuite-functions.sh
1 change: 1 addition & 0 deletions extensions/OPCUAServer/tests/uniset3-functions.sh
1 change: 1 addition & 0 deletions extensions/OPCUAServer/tests/uniset3-start.sh
1 change: 1 addition & 0 deletions extensions/OPCUAServer/uniset3-functions.sh
1 change: 1 addition & 0 deletions extensions/OPCUAServer/uniset3-start.sh
4 changes: 3 additions & 1 deletion include/UniSetTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <ostream>
#include <chrono>
#include <thread>
#include <regex>

#include "UniSetTypes.pb.h"
#include "IOController.pb.h"
Expand Down Expand Up @@ -123,7 +124,7 @@ namespace uniset3

IDList( const std::vector<std::string>& v );
#if __cplusplus >= 201703L
IDList( const std::vector<std::string_view>& v );
IDList( const std::vector<std::string_view>& v );
#endif
IDList();
~IDList();
Expand Down Expand Up @@ -370,6 +371,7 @@ namespace uniset3
// Проверка xml-узла на соответствие <...f_prop="f_val">,
// если не задано f_val, то проверяется, что просто f_prop!=""
bool check_filter( UniXML::iterator& it, const std::string& f_prop, const std::string& f_val = "" ) noexcept;
bool check_filter_re( UniXML::iterator& it, const std::string& f_prop, const std::regex& re ) noexcept;

// RAII для флагов форматирования ostream..
class ios_fmt_restorer
Expand Down
8 changes: 8 additions & 0 deletions src/Core/UniSetTypes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,14 @@ std::ostream& uniset3::operator<<( std::ostream& os, const uniset3::IOType t )
return os << iotype2str(t);
}
// ------------------------------------------------------------------------------------------
bool uniset3::check_filter_re( UniXML::iterator& it, const std::string& f_prop, const std::regex& re ) noexcept
{
if( f_prop.empty() )
return true;

return std::regex_search(it.getProp(f_prop), re);
}
// ------------------------------------------------------------------------------------------
bool uniset3::check_filter( UniXML::iterator& it, const std::string& f_prop, const std::string& f_val ) noexcept
{
if( f_prop.empty() )
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SUBDIRS=MQPerfTest PocoTest UHttpTest GRPCTest
SUBDIRS=MQPerfTest PocoTest UHttpTest GRPCTest Open62541Test

#TCPSocketTest
if HAVE_TESTS
############################################################################
Expand Down
17 changes: 17 additions & 0 deletions tests/test_utypes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ TEST_CASE("UniSetTypes: check_filter", "[utypes][check_filter]" )
CHECK_FALSE( check_filter(it, "fprop", "badvalue") );
}
// -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: check_filter_re", "[utypes][check_filter_re]" )
{
// <test_check_filter_re name="test_check_filter_re" fprop="1|2"/>
auto xml = uniset_conf()->getConfXML();

xmlNode* xnode = xml->findNode(xml->getFirstNode(), "test_check_filter_re");
REQUIRE(xnode);

UniXML::iterator it(xnode);

auto re = std::regex("1|2");

REQUIRE( check_filter_re(it, "fprop1", re) );
REQUIRE( check_filter_re(it, "fprop2", re) );
REQUIRE_FALSE( check_filter_re(it, "fprop3", re) );
}
// -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: findArgParam", "[utypes][findArgParam]" )
{
// int findArgParam( const std::string& name, int _argc, const char* const* _argv )
Expand Down
2 changes: 2 additions & 0 deletions testsuite/testsuite.at
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ m4_include(../extensions/LogDB/tests/logdb-tests.at)
m4_include(../extensions/HttpAPIGateway/tests/apigateway-tests.at)
m4_include(../extensions/UWebSocketGate/tests/uwebsocketgate-tests.at)
m4_include(../extensions/URepository/tests/urepository-tests.at)
m4_include(../extensions/OPCUAServer/tests/opcua-server-tests.at)
m4_include(../extensions/OPCUAExchange/tests/opcua-exchange-tests.at)

0 comments on commit 46c934b

Please sign in to comment.