Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
f35bfd43
Commit
f35bfd43
authored
Jun 03, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Рефакторинг некоторых интерфейсов и названий функций.
Вместо run(..., bool thread) сделал две функции: run(..) async_run(...)
parent
809d62c7
Show whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
124 additions
and
65 deletions
+124
-65
MBTCPServer.cc
Utilities/MBTester/MBTCPServer.cc
+1
-1
log-stdin.cc
Utilities/ULog/log-stdin.cc
+1
-1
log-wrap.cc
Utilities/ULog/log-wrap.cc
+1
-1
logserver.cc
Utilities/ULog/logserver.cc
+1
-1
ctl-cpp-common.xsl
Utilities/codegen/ctl-cpp-common.xsl
+1
-1
libuniset2.spec
conf/libuniset2.spec
+4
-1
IOControl.cc
extensions/IOControl/IOControl.cc
+1
-1
MBExchange.cc
extensions/ModbusMaster/MBExchange.cc
+1
-1
MBTCPTestServer.cc
extensions/ModbusMaster/tests/MBTCPTestServer.cc
+1
-1
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+2
-2
SharedMemory.cc
extensions/SharedMemory/SharedMemory.cc
+1
-1
UNetExchange.cc
extensions/UNetUDP/UNetExchange.cc
+1
-1
UNetReceiver.cc
extensions/UNetUDP/UNetReceiver.cc
+1
-2
UObject_SK.h
extensions/include/UObject_SK.h
+1
-1
UObject_SK.cc
extensions/lib/UObject_SK.cc
+2
-2
TestProc.cc
extensions/tests/MBSlaveTest/TestProc.cc
+1
-1
CommonEventLoop.h
include/CommonEventLoop.h
+10
-8
EventLoopServer.h
include/EventLoopServer.h
+14
-4
LogServer.h
include/LogServer.h
+3
-1
ModbusTCPServer.h
include/modbus/ModbusTCPServer.h
+11
-5
ModbusTCPServer.cc
src/Communications/Modbus/ModbusTCPServer.cc
+8
-2
LogServer.cc
src/Log/LogServer.cc
+15
-2
CommonEventLoop.cc
src/Processes/CommonEventLoop.cc
+26
-8
EventLoopServer.cc
src/Processes/EventLoopServer.cc
+13
-13
DBServer.cc
src/Services/DBServer.cc
+1
-1
test_logserver.cc
tests/test_logserver.cc
+2
-2
No files found.
Utilities/MBTester/MBTCPServer.cc
View file @
f35bfd43
...
@@ -75,7 +75,7 @@ void MBTCPServer::setMaxSessions( size_t max )
...
@@ -75,7 +75,7 @@ void MBTCPServer::setMaxSessions( size_t max )
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
MBTCPServer
::
execute
()
void
MBTCPServer
::
execute
()
{
{
sslot
->
run
(
vaddr
,
false
);
sslot
->
run
(
vaddr
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
MBTCPServer
::
sigterm
(
int
signo
)
void
MBTCPServer
::
sigterm
(
int
signo
)
...
...
Utilities/ULog/log-stdin.cc
View file @
f35bfd43
...
@@ -74,7 +74,7 @@ int main( int argc, char* argv[], char* envp[] )
...
@@ -74,7 +74,7 @@ int main( int argc, char* argv[], char* envp[] )
auto
log
=
make_shared
<
DebugStream
>
();
auto
log
=
make_shared
<
DebugStream
>
();
LogServer
ls
(
log
);
LogServer
ls
(
log
);
ls
.
run
(
addr
,
port
,
true
);
ls
.
async_run
(
addr
,
port
);
char
buf
[
10000
];
char
buf
[
10000
];
...
...
Utilities/ULog/log-wrap.cc
View file @
f35bfd43
...
@@ -80,7 +80,7 @@ int main( int argc, char* argv[], char* envp[] )
...
@@ -80,7 +80,7 @@ int main( int argc, char* argv[], char* envp[] )
LogServer
ls
(
zlog
);
LogServer
ls
(
zlog
);
cout
<<
"wrap: server "
<<
addr
<<
":"
<<
port
<<
endl
;
cout
<<
"wrap: server "
<<
addr
<<
":"
<<
port
<<
endl
;
ls
.
run
(
addr
,
port
,
true
);
ls
.
async_run
(
addr
,
port
);
char
buf
[
5000
];
char
buf
[
5000
];
...
...
Utilities/ULog/logserver.cc
View file @
f35bfd43
...
@@ -182,7 +182,7 @@ int main( int argc, char** argv )
...
@@ -182,7 +182,7 @@ int main( int argc, char** argv )
dlog3
->
addLevel
(
Debug
::
ANY
);
dlog3
->
addLevel
(
Debug
::
ANY
);
dlog4
->
addLevel
(
Debug
::
ANY
);
dlog4
->
addLevel
(
Debug
::
ANY
);
ls
.
run
(
addr
,
port
,
true
);
ls
.
async_run
(
addr
,
port
);
if
(
verb
)
if
(
verb
)
ls
.
setSessionLog
(
Debug
::
ANY
);
ls
.
setSessionLog
(
Debug
::
ANY
);
...
...
Utilities/codegen/ctl-cpp-common.xsl
View file @
f35bfd43
...
@@ -491,7 +491,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSysCommand( const SystemMessage*
...
@@ -491,7 +491,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSysCommand( const SystemMessage*
{
{
ostate = "StartUp: run log server...";
ostate = "StartUp: run log server...";
myinfo
<<
myname
<<
"(preSysCommand): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl;
myinfo
<<
myname
<<
"(preSysCommand): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl;
logserv-
>
run(logserv_host, logserv_port, true
);
logserv-
>
async_run(logserv_host, logserv_port
);
}
}
}
}
catch( std::exception
&
ex )
catch( std::exception
&
ex )
...
...
conf/libuniset2.spec
View file @
f35bfd43
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
Name: libuniset2
Name: libuniset2
Version: 2.6
Version: 2.6
Release: alt3
1
Release: alt3
2
Summary: UniSet - library for building distributed industrial control systems
Summary: UniSet - library for building distributed industrial control systems
License: LGPL
License: LGPL
...
@@ -508,6 +508,9 @@ rm -f %buildroot%_libdir/*.la
...
@@ -508,6 +508,9 @@ rm -f %buildroot%_libdir/*.la
# history of current unpublished changes
# history of current unpublished changes
%changelog
%changelog
* Sat Jun 03 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt32
- refactoring function names
* Sat Jun 03 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt31
* Sat Jun 03 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt31
- (EventLoopServer): refactoring start process
- (EventLoopServer): refactoring start process
...
...
extensions/IOControl/IOControl.cc
View file @
f35bfd43
...
@@ -1261,7 +1261,7 @@ namespace uniset
...
@@ -1261,7 +1261,7 @@ namespace uniset
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
{
{
ioinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
ioinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
logserv
->
run
(
logserv_host
,
logserv_port
,
true
);
logserv
->
async_run
(
logserv_host
,
logserv_port
);
}
}
PassiveTimer
ptAct
(
activateTimeout
);
PassiveTimer
ptAct
(
activateTimeout
);
...
...
extensions/ModbusMaster/MBExchange.cc
View file @
f35bfd43
...
@@ -2808,7 +2808,7 @@ namespace uniset
...
@@ -2808,7 +2808,7 @@ namespace uniset
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
{
{
mbinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
mbinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
logserv
->
run
(
logserv_host
,
logserv_port
,
true
);
logserv
->
async_run
(
logserv_host
,
logserv_port
);
}
}
if
(
devices
.
empty
()
)
if
(
devices
.
empty
()
)
...
...
extensions/ModbusMaster/tests/MBTCPTestServer.cc
View file @
f35bfd43
...
@@ -97,7 +97,7 @@ void MBTCPTestServer::setLog( std::shared_ptr<DebugStream> dlog )
...
@@ -97,7 +97,7 @@ void MBTCPTestServer::setLog( std::shared_ptr<DebugStream> dlog )
void
MBTCPTestServer
::
execute
()
void
MBTCPTestServer
::
execute
()
{
{
if
(
sslot
)
if
(
sslot
)
sslot
->
run
(
vaddr
,
true
);
sslot
->
async_run
(
vaddr
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
MBTCPTestServer
::
sigterm
(
int
signo
)
void
MBTCPTestServer
::
sigterm
(
int
signo
)
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
f35bfd43
...
@@ -654,7 +654,7 @@ namespace uniset
...
@@ -654,7 +654,7 @@ namespace uniset
{
{
try
try
{
{
if
(
tcpserver
->
run
(
vaddr
,
true
)
)
if
(
tcpserver
->
async_run
(
vaddr
)
)
break
;
break
;
if
(
tcpBreakIfFailRun
)
if
(
tcpBreakIfFailRun
)
...
@@ -901,7 +901,7 @@ namespace uniset
...
@@ -901,7 +901,7 @@ namespace uniset
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
{
{
mbinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
mbinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
logserv
->
run
(
logserv_host
,
logserv_port
,
true
);
logserv
->
async_run
(
logserv_host
,
logserv_port
);
}
}
waitSMReady
();
waitSMReady
();
...
...
extensions/SharedMemory/SharedMemory.cc
View file @
f35bfd43
...
@@ -236,7 +236,7 @@ namespace uniset
...
@@ -236,7 +236,7 @@ namespace uniset
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
{
{
sminfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
sminfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
logserv
->
run
(
logserv_host
,
logserv_port
,
true
);
logserv
->
async_run
(
logserv_host
,
logserv_port
);
}
}
PassiveTimer
ptAct
(
activateTimeout
);
PassiveTimer
ptAct
(
activateTimeout
);
...
...
extensions/UNetUDP/UNetExchange.cc
View file @
f35bfd43
...
@@ -596,7 +596,7 @@ void UNetExchange::sysCommand( const uniset::SystemMessage* sm )
...
@@ -596,7 +596,7 @@ void UNetExchange::sysCommand( const uniset::SystemMessage* sm )
try
try
{
{
unetinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
unetinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
logserv
->
run
(
logserv_host
,
logserv_port
,
true
);
logserv
->
async_run
(
logserv_host
,
logserv_port
);
}
}
catch
(
std
::
exception
&
ex
)
catch
(
std
::
exception
&
ex
)
{
{
...
...
extensions/UNetUDP/UNetReceiver.cc
View file @
f35bfd43
...
@@ -229,7 +229,7 @@ void UNetReceiver::start()
...
@@ -229,7 +229,7 @@ void UNetReceiver::start()
if
(
!
activated
)
if
(
!
activated
)
{
{
activated
=
true
;
activated
=
true
;
if
(
!
loop
.
evrun
(
this
,
true
,
evrunTimeout
)
)
if
(
!
loop
.
async_evrun
(
this
,
evrunTimeout
)
)
{
{
unetcrit
<<
myname
<<
"(start): evrun FAILED! (timeout="
<<
evrunTimeout
<<
" msec)"
<<
endl
;
unetcrit
<<
myname
<<
"(start): evrun FAILED! (timeout="
<<
evrunTimeout
<<
" msec)"
<<
endl
;
std
::
terminate
();
std
::
terminate
();
...
@@ -251,7 +251,6 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) noexcept
...
@@ -251,7 +251,6 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) noexcept
if
(
upStrategy
==
useUpdateEventLoop
)
if
(
upStrategy
==
useUpdateEventLoop
)
{
{
evUpdate
.
set
(
eloop
);
evUpdate
.
set
(
eloop
);
evUpdate
.
start
();
evUpdate
.
start
(
0
,
((
float
)
updatepause
/
1000.
)
);
evUpdate
.
start
(
0
,
((
float
)
updatepause
/
1000.
)
);
}
}
...
...
extensions/include/UObject_SK.h
View file @
f35bfd43
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// generate timestamp: 2017-0
5-29
+03:00
// generate timestamp: 2017-0
6-03
+03:00
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#ifndef UObject_SK_H_
#define UObject_SK_H_
#define UObject_SK_H_
...
...
extensions/lib/UObject_SK.cc
View file @
f35bfd43
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// generate timestamp: 2017-0
5-29
+03:00
// generate timestamp: 2017-0
6-03
+03:00
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include <memory>
#include <memory>
#include <iomanip>
#include <iomanip>
...
@@ -429,7 +429,7 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
...
@@ -429,7 +429,7 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
{
{
ostate
=
"StartUp: run log server..."
;
ostate
=
"StartUp: run log server..."
;
myinfo
<<
myname
<<
"(preSysCommand): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
myinfo
<<
myname
<<
"(preSysCommand): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
logserv
->
run
(
logserv_host
,
logserv_port
,
true
);
logserv
->
async_run
(
logserv_host
,
logserv_port
);
}
}
}
}
catch
(
std
::
exception
&
ex
)
catch
(
std
::
exception
&
ex
)
...
...
extensions/tests/MBSlaveTest/TestProc.cc
View file @
f35bfd43
...
@@ -225,7 +225,7 @@ void TestProc::mbThread()
...
@@ -225,7 +225,7 @@ void TestProc::mbThread()
mylog9
<<
myname
<<
"(mbThread): run tcpserver.."
<<
endl
;
mylog9
<<
myname
<<
"(mbThread): run tcpserver.."
<<
endl
;
ModbusRTU
::
ModbusAddr
mba
(
mbADDR
);
ModbusRTU
::
ModbusAddr
mba
(
mbADDR
);
auto
vaddr
=
mbslave
->
addr2vaddr
(
mba
);
auto
vaddr
=
mbslave
->
addr2vaddr
(
mba
);
mbslave
->
run
(
vaddr
,
false
);
// true - создаёт поток
mbslave
->
run
(
vaddr
);
// async_run()?
mylog9
<<
myname
<<
"ModbusSlave stopped.."
<<
endl
;
mylog9
<<
myname
<<
"ModbusSlave stopped.."
<<
endl
;
}
}
...
...
include/CommonEventLoop.h
View file @
f35bfd43
...
@@ -60,14 +60,17 @@ namespace uniset
...
@@ -60,14 +60,17 @@ namespace uniset
bool
evIsActive
()
const
noexcept
;
bool
evIsActive
()
const
noexcept
;
/*! \return TRUE - если всё удалось. return актуален только для случая когда thread = true
/*! Синхронный запуск. Функция возвращает управление (false), только если запуск не удался,
* \param thread - создать отдельный (асинхронный) поток для event loop.
* либо был остановлен вызовом evstop();
* Если thread=false - функция не вернёт управление и будет ждать завершения работы ( см. evstop())
* \param prepareTimeout_msec - сколько ждать активации, либо функция вернёт false.
* \param waitPrepareTimeout_msec - сколько ждать активации, либо функция вернёт false.
* Даже если thread = false, но wather не сможет быть "активирован" функция вернёт управление
* с return false.
*/
*/
bool
evrun
(
EvWatcher
*
w
,
bool
thread
=
true
,
size_t
waitPrepareTimeout_msec
=
60000
);
bool
evrun
(
EvWatcher
*
w
,
size_t
prepareTimeout_msec
=
60000
);
/*! Асинхронный запуск (запуск в отдельном потоке)
* \return TRUE - если всё удалось.
* \param prepareTimeout_msec - сколько ждать активации, либо функция вернёт false.
*/
bool
async_evrun
(
EvWatcher
*
w
,
size_t
prepareTimeout_msec
=
60000
);
/*! \return TRUE - если это был последний EvWatcher и loop остановлен */
/*! \return TRUE - если это был последний EvWatcher и loop остановлен */
bool
evstop
(
EvWatcher
*
w
);
bool
evstop
(
EvWatcher
*
w
);
...
@@ -117,7 +120,6 @@ namespace uniset
...
@@ -117,7 +120,6 @@ namespace uniset
std
::
mutex
looprunOK_mutex
;
std
::
mutex
looprunOK_mutex
;
std
::
condition_variable
looprunOK_event
;
std
::
condition_variable
looprunOK_event
;
std
::
atomic_bool
looprunOK_state
;
ev
::
timer
evruntimer
;
ev
::
timer
evruntimer
;
};
};
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
...
include/EventLoopServer.h
View file @
f35bfd43
...
@@ -33,8 +33,18 @@ namespace uniset
...
@@ -33,8 +33,18 @@ namespace uniset
virtual
void
evprepare
()
{}
virtual
void
evprepare
()
{}
// Управление потоком событий
// Управление потоком событий
bool
evrun
(
bool
thread
=
true
,
size_t
waitRunningTimeout_msec
=
60000
);
void
evstop
();
/*! асинхронный запуск (создаётся отдельный поток)
* \return true - если всё хорошо
*/
bool
async_evrun
(
size_t
waitRunningTimeout_msec
=
60000
);
/*! синхронный запуск
* функция вернёт управление, только в случае неудачного запуска
*/
bool
evrun
();
void
evstop
();
/*!< остановить раннее запущенный поток (event loop) */
ev
::
dynamic_loop
loop
;
ev
::
dynamic_loop
loop
;
...
@@ -46,14 +56,14 @@ namespace uniset
...
@@ -46,14 +56,14 @@ namespace uniset
void
onLoopOK
(
ev
::
timer
&
t
,
int
revents
)
noexcept
;
void
onLoopOK
(
ev
::
timer
&
t
,
int
revents
)
noexcept
;
std
::
atomic_bool
cancelled
=
{
false
};
std
::
atomic_bool
cancelled
=
{
false
};
std
::
atomic_bool
is
running
=
{
false
};
std
::
atomic_bool
is
active
=
{
false
};
ev
::
async
evterm
;
ev
::
async
evterm
;
std
::
shared_ptr
<
std
::
thread
>
thr
;
std
::
shared_ptr
<
std
::
thread
>
thr
;
std
::
mutex
looprunOK_mutex
;
std
::
mutex
looprunOK_mutex
;
std
::
condition_variable
looprunOK_event
;
std
::
condition_variable
looprunOK_event
;
std
::
atomic_bool
looprunOK_state
;
std
::
atomic_bool
isrunning
;
ev
::
timer
evruntimer
;
ev
::
timer
evruntimer
;
};
};
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
...
include/LogServer.h
View file @
f35bfd43
...
@@ -112,7 +112,9 @@ namespace uniset
...
@@ -112,7 +112,9 @@ namespace uniset
sessMaxCount
=
num
;
sessMaxCount
=
num
;
}
}
void
run
(
const
std
::
string
&
addr
,
Poco
::
UInt16
port
,
bool
thread
=
true
);
bool
async_run
(
const
std
::
string
&
addr
,
Poco
::
UInt16
port
);
bool
run
(
const
std
::
string
&
addr
,
Poco
::
UInt16
port
);
void
terminate
();
void
terminate
();
inline
bool
isRunning
()
const
noexcept
inline
bool
isRunning
()
const
noexcept
...
...
include/modbus/ModbusTCPServer.h
View file @
f35bfd43
...
@@ -34,11 +34,19 @@ namespace uniset
...
@@ -34,11 +34,19 @@ namespace uniset
ModbusTCPServer
(
const
std
::
string
&
addr
,
int
port
=
502
);
ModbusTCPServer
(
const
std
::
string
&
addr
,
int
port
=
502
);
virtual
~
ModbusTCPServer
();
virtual
~
ModbusTCPServer
();
/*! Запуск сервера
/*! Запуск сервера. Функция не возвращет управление.
* \param thread - создавать ли отдельный поток
* Но может быть прервана вызовом terminate()
* \return FALSE - если не удалось запустить
*/
bool
run
(
const
std
::
unordered_set
<
ModbusRTU
::
ModbusAddr
>&
vmbaddr
);
/*! Асинхронный запуск сервера (создаётся отдельный поток)
* \return TRUE - если поток успешно удалось запустить
* \return TRUE - если поток успешно удалось запустить
*/
*/
bool
run
(
const
std
::
unordered_set
<
ModbusRTU
::
ModbusAddr
>&
vmbaddr
,
bool
thread
=
false
);
bool
async_run
(
const
std
::
unordered_set
<
ModbusRTU
::
ModbusAddr
>&
vmbaddr
);
/*! остановить поток выполнения (см. run или async_run) */
virtual
void
terminate
();
virtual
bool
isActive
()
const
override
;
virtual
bool
isActive
()
const
override
;
...
@@ -67,8 +75,6 @@ namespace uniset
...
@@ -67,8 +75,6 @@ namespace uniset
return
ignoreAddr
;
return
ignoreAddr
;
}
}
virtual
void
terminate
();
// Сбор статистики по соединениям...
// Сбор статистики по соединениям...
struct
SessionInfo
struct
SessionInfo
{
{
...
...
src/Communications/Modbus/ModbusTCPServer.cc
View file @
f35bfd43
...
@@ -81,10 +81,16 @@ namespace uniset
...
@@ -81,10 +81,16 @@ namespace uniset
sessTimeout
=
msec
;
sessTimeout
=
msec
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
ModbusTCPServer
::
run
(
const
std
::
unordered_set
<
ModbusAddr
>&
_vmbaddr
,
bool
thread
)
bool
ModbusTCPServer
::
run
(
const
std
::
unordered_set
<
ModbusAddr
>&
_vmbaddr
)
{
{
vmbaddr
=
&
_vmbaddr
;
vmbaddr
=
&
_vmbaddr
;
return
evrun
(
thread
);
return
evrun
();
}
// -------------------------------------------------------------------------
bool
ModbusTCPServer
::
async_run
(
const
std
::
unordered_set
<
ModbusAddr
>&
_vmbaddr
)
{
vmbaddr
=
&
_vmbaddr
;
return
async_evrun
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
ModbusTCPServer
::
isActive
()
const
bool
ModbusTCPServer
::
isActive
()
const
...
...
src/Log/LogServer.cc
View file @
f35bfd43
...
@@ -111,7 +111,7 @@ namespace uniset
...
@@ -111,7 +111,7 @@ namespace uniset
mylog
.
info
()
<<
myname
<<
"(LogServer): finished."
<<
endl
;
mylog
.
info
()
<<
myname
<<
"(LogServer): finished."
<<
endl
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LogServer
::
run
(
const
std
::
string
&
_addr
,
Poco
::
UInt16
_port
,
bool
thread
)
bool
LogServer
::
run
(
const
std
::
string
&
_addr
,
Poco
::
UInt16
_port
)
{
{
addr
=
_addr
;
addr
=
_addr
;
port
=
_port
;
port
=
_port
;
...
@@ -122,7 +122,20 @@ namespace uniset
...
@@ -122,7 +122,20 @@ namespace uniset
myname
=
s
.
str
();
myname
=
s
.
str
();
}
}
loop
.
evrun
(
this
,
thread
);
return
loop
.
evrun
(
this
);
}
// -------------------------------------------------------------------------
bool
LogServer
::
async_run
(
const
std
::
string
&
_addr
,
Poco
::
UInt16
_port
)
{
addr
=
_addr
;
port
=
_port
;
{
ostringstream
s
;
s
<<
_addr
<<
":"
<<
_port
;
myname
=
s
.
str
();
}
return
loop
.
async_evrun
(
this
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LogServer
::
terminate
()
void
LogServer
::
terminate
()
...
...
src/Processes/CommonEventLoop.cc
View file @
f35bfd43
...
@@ -46,10 +46,10 @@ namespace uniset
...
@@ -46,10 +46,10 @@ namespace uniset
std
::
unique_lock
<
std
::
mutex
>
lock2
(
looprunOK_mutex
);
std
::
unique_lock
<
std
::
mutex
>
lock2
(
looprunOK_mutex
);
looprunOK_event
.
wait_for
(
lock2
,
std
::
chrono
::
milliseconds
(
waitTimeout_msec
),
[
&
]()
looprunOK_event
.
wait_for
(
lock2
,
std
::
chrono
::
milliseconds
(
waitTimeout_msec
),
[
&
]()
{
{
return
(
looprunOK_state
==
true
);
return
(
isrunning
==
true
);
}
);
}
);
return
looprunOK_state
;
return
isrunning
;
}
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
bool
CommonEventLoop
::
activateWatcher
(
EvWatcher
*
w
,
size_t
waitTimeout_msec
)
bool
CommonEventLoop
::
activateWatcher
(
EvWatcher
*
w
,
size_t
waitTimeout_msec
)
...
@@ -88,12 +88,12 @@ namespace uniset
...
@@ -88,12 +88,12 @@ namespace uniset
if
(
EV_ERROR
&
revents
)
if
(
EV_ERROR
&
revents
)
return
;
return
;
looprunOK_state
=
true
;
isrunning
=
true
;
looprunOK_event
.
notify_all
();
looprunOK_event
.
notify_all
();
t
.
stop
();
t
.
stop
();
}
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
bool
CommonEventLoop
::
evrun
(
EvWatcher
*
w
,
bool
thread
,
size_t
waitTimeout_msec
)
bool
CommonEventLoop
::
evrun
(
EvWatcher
*
w
,
size_t
waitTimeout_msec
)
{
{
if
(
w
==
nullptr
)
if
(
w
==
nullptr
)
return
false
;
return
false
;
...
@@ -113,9 +113,8 @@ namespace uniset
...
@@ -113,9 +113,8 @@ namespace uniset
bool
defaultLoopOK
=
runDefaultLoop
(
waitTimeout_msec
);
bool
defaultLoopOK
=
runDefaultLoop
(
waitTimeout_msec
);
bool
ret
=
defaultLoopOK
&&
activateWatcher
(
w
,
waitTimeout_msec
);
bool
ret
=
defaultLoopOK
&&
activateWatcher
(
w
,
waitTimeout_msec
);
// если ждать завершения не надо (thread=true)
// или activateWatcher не удалось.. выходим..
// или activateWatcher не удалось.. выходим..
if
(
thread
||
!
ret
)
if
(
!
ret
)
return
ret
;
return
ret
;
// ожидаем завершения основного потока..
// ожидаем завершения основного потока..
...
@@ -130,6 +129,27 @@ namespace uniset
...
@@ -130,6 +129,27 @@ namespace uniset
return
true
;
return
true
;
}
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
bool
CommonEventLoop
::
async_evrun
(
EvWatcher
*
w
,
size_t
waitTimeout_msec
)
{
if
(
w
==
nullptr
)
return
false
;
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
wlist_mutex
);
if
(
std
::
find
(
wlist
.
begin
(),
wlist
.
end
(),
w
)
!=
wlist
.
end
()
)
{
cerr
<<
"(CommonEventLoop::evrun): "
<<
w
->
wname
()
<<
" ALREADY ADDED.."
<<
endl
;
return
false
;
}
wlist
.
push_back
(
w
);
}
bool
defaultLoopOK
=
runDefaultLoop
(
waitTimeout_msec
);
return
defaultLoopOK
&&
activateWatcher
(
w
,
waitTimeout_msec
);
}
// ---------------------------------------------------------------------------
bool
CommonEventLoop
::
evIsActive
()
const
noexcept
bool
CommonEventLoop
::
evIsActive
()
const
noexcept
{
{
return
isrunning
;
return
isrunning
;
...
@@ -250,8 +270,6 @@ namespace uniset
...
@@ -250,8 +270,6 @@ namespace uniset
// т.к. нам надо просто зафиксировать, что loop начал работать
// т.к. нам надо просто зафиксировать, что loop начал работать
evruntimer
.
start
(
0
);
evruntimer
.
start
(
0
);
isrunning
=
true
;
while
(
!
cancelled
)
while
(
!
cancelled
)
{
{
try
try
...
...
src/Processes/EventLoopServer.cc
View file @
f35bfd43
...
@@ -22,18 +22,18 @@ namespace uniset
...
@@ -22,18 +22,18 @@ namespace uniset
evstop
();
evstop
();
}
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
bool
EventLoopServer
::
evrun
(
bool
thread
,
size_t
timeout_msec
)
bool
EventLoopServer
::
evrun
()
{
if
(
isrunning
)
return
true
;
isrunning
=
true
;
if
(
!
thread
)
{
{
defaultLoop
();
// <-- здесь бесконечный цикл..
defaultLoop
();
// <-- здесь бесконечный цикл..
return
false
;
return
false
;
}
}
// ---------------------------------------------------------------------------
bool
EventLoopServer
::
async_evrun
(
size_t
timeout_msec
)
{
if
(
isactive
)
return
true
;
isactive
=
true
;
if
(
!
thr
)
if
(
!
thr
)
thr
=
make_shared
<
std
::
thread
>
(
[
&
]
{
defaultLoop
();
}
);
thr
=
make_shared
<
std
::
thread
>
(
[
&
]
{
defaultLoop
();
}
);
...
@@ -111,10 +111,10 @@ namespace uniset
...
@@ -111,10 +111,10 @@ namespace uniset
cerr
<<
"(EventLoopServer::defaultLoop): "
<<
ex
.
what
()
<<
endl
;
cerr
<<
"(EventLoopServer::defaultLoop): "
<<
ex
.
what
()
<<
endl
;
}
}
looprunOK_state
=
false
;
isrunning
=
false
;
looprunOK_event
.
notify_all
();
looprunOK_event
.
notify_all
();
is
running
=
false
;
is
active
=
false
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
EventLoopServer
::
waitDefaultLoopRunning
(
size_t
waitTimeout_msec
)
bool
EventLoopServer
::
waitDefaultLoopRunning
(
size_t
waitTimeout_msec
)
...
@@ -122,10 +122,10 @@ namespace uniset
...
@@ -122,10 +122,10 @@ namespace uniset
std
::
unique_lock
<
std
::
mutex
>
lock
(
looprunOK_mutex
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
looprunOK_mutex
);
looprunOK_event
.
wait_for
(
lock
,
std
::
chrono
::
milliseconds
(
waitTimeout_msec
),
[
&
]()
looprunOK_event
.
wait_for
(
lock
,
std
::
chrono
::
milliseconds
(
waitTimeout_msec
),
[
&
]()
{
{
return
(
looprunOK_state
==
true
);
return
(
isrunning
==
true
);
}
);
}
);
return
looprunOK_state
;
return
isrunning
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
EventLoopServer
::
onLoopOK
(
ev
::
timer
&
t
,
int
revents
)
noexcept
void
EventLoopServer
::
onLoopOK
(
ev
::
timer
&
t
,
int
revents
)
noexcept
...
@@ -133,7 +133,7 @@ namespace uniset
...
@@ -133,7 +133,7 @@ namespace uniset
if
(
EV_ERROR
&
revents
)
if
(
EV_ERROR
&
revents
)
return
;
return
;
looprunOK_state
=
true
;
isrunning
=
true
;
looprunOK_event
.
notify_all
();
looprunOK_event
.
notify_all
();
t
.
stop
();
t
.
stop
();
}
}
...
...
src/Services/DBServer.cc
View file @
f35bfd43
...
@@ -116,7 +116,7 @@ void DBServer::sysCommand( const uniset::SystemMessage* sm )
...
@@ -116,7 +116,7 @@ void DBServer::sysCommand( const uniset::SystemMessage* sm )
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
{
{
dbinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
dbinfo
<<
myname
<<
"(init): run log server "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
logserv
->
run
(
logserv_host
,
logserv_port
,
true
);
logserv
->
async_run
(
logserv_host
,
logserv_port
);
}
}
}
}
}
}
...
...
tests/test_logserver.cc
View file @
f35bfd43
...
@@ -146,7 +146,7 @@ TEST_CASE("LogServer", "[LogServer]" )
...
@@ -146,7 +146,7 @@ TEST_CASE("LogServer", "[LogServer]" )
LogServer
ls
(
la
);
LogServer
ls
(
la
);
//ls.setSessionLog(Debug::ANY);
//ls.setSessionLog(Debug::ANY);
ls
.
run
(
ip
,
port
,
true
);
ls
.
async_run
(
ip
,
port
);
for
(
int
i
=
0
;
i
<
3
&&
!
ls
.
isRunning
();
i
++
)
for
(
int
i
=
0
;
i
<
3
&&
!
ls
.
isRunning
();
i
++
)
msleep
(
600
);
msleep
(
600
);
...
@@ -213,7 +213,7 @@ TEST_CASE("MaxSessions", "[LogServer]" )
...
@@ -213,7 +213,7 @@ TEST_CASE("MaxSessions", "[LogServer]" )
ls
.
setCmdTimeout
(
100
);
ls
.
setCmdTimeout
(
100
);
//ls.setSessionLog(Debug::ANY);
//ls.setSessionLog(Debug::ANY);
ls
.
setMaxSessionCount
(
1
);
ls
.
setMaxSessionCount
(
1
);
ls
.
run
(
ip
,
port
,
true
);
ls
.
async_run
(
ip
,
port
);
for
(
int
i
=
0
;
i
<
4
&&
!
ls
.
isRunning
();
i
++
)
for
(
int
i
=
0
;
i
<
4
&&
!
ls
.
isRunning
();
i
++
)
msleep
(
600
);
msleep
(
600
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment