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
d5b8a3d2
Commit
d5b8a3d2
authored
Nov 23, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(EventLoop): исправил ошибку в wait_for(),
рефакторинг UNetExchange, правка тестов.
parent
8eade6a3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
30 deletions
+54
-30
libuniset2.spec
conf/libuniset2.spec
+4
-1
UNetExchange.cc
extensions/UNetUDP/UNetExchange.cc
+12
-1
test_unetudp.cc
extensions/UNetUDP/tests/test_unetudp.cc
+7
-4
unetudp-test-configure.xml
extensions/UNetUDP/tests/unetudp-test-configure.xml
+3
-3
CommonEventLoop.h
include/CommonEventLoop.h
+6
-3
CommonEventLoop.cc
src/Processes/CommonEventLoop.cc
+20
-12
test_passivetimer.cc
tests/test_passivetimer.cc
+2
-6
No files found.
conf/libuniset2.spec
View file @
d5b8a3d2
...
...
@@ -16,7 +16,7 @@
Name: libuniset2
Version: 2.6
Release: alt3
Release: alt3
.1
Summary: UniSet - library for building distributed industrial control systems
License: LGPL
...
...
@@ -508,6 +508,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# history of current unpublished changes
%changelog
* Tue Nov 22 2016 Pavel Vainerman <pv@altlinux.ru> 2.6-alt3.1
- CommonEventLoop: refactoring prepare process (part. 2)
* Tue Nov 22 2016 Pavel Vainerman <pv@altlinux.ru> 2.6-alt3
- CommonEventLoop: refactoring prepare process
...
...
extensions/UNetUDP/UNetExchange.cc
View file @
d5b8a3d2
...
...
@@ -955,7 +955,18 @@ uniset::SimpleInfo* UNetExchange::getInfo( CORBA::Long userparam )
inf
<<
i
->
info
<<
endl
;
inf
<<
vmon
.
pretty_str
()
<<
endl
;
inf
<<
endl
;
inf
<<
"LogServer: "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
if
(
logserv
)
{
inf
<<
"LogServer: "
<<
logserv_host
<<
":"
<<
logserv_port
<<
(
logserv
->
isRunning
()
?
" [RUNNIG]"
:
" [STOPPED]"
)
<<
endl
<<
" "
<<
logserv
->
getShortInfo
()
<<
endl
;
}
else
inf
<<
"LogServer: NONE"
<<
endl
;
inf
<<
endl
;
inf
<<
"Receivers: "
<<
endl
;
...
...
extensions/UNetUDP/tests/test_unetudp.cc
View file @
d5b8a3d2
...
...
@@ -198,9 +198,12 @@ TEST_CASE("[UNetUDP]: respond sensor", "[unetudp]")
{
InitTest
();
// в запускающем файле стоит --unet-recv-timeout 2000
msleep
(
2500
);
ObjectId
node1_not_respond_s
=
1
;
CHECK
(
ui
->
getValue
(
node1_not_respond_s
)
==
0
);
// в запускающем файле стоит --unet-recv-timeout 1000
// ждём больше, чтобы сработал timeout
msleep
(
5000
);
REQUIRE
(
ui
->
getValue
(
node1_not_respond_s
)
==
1
);
}
// -----------------------------------------------------------------------------
...
...
@@ -295,7 +298,7 @@ TEST_CASE("[UNetUDP]: check receiver", "[unetudp][receiver]")
REQUIRE
(
ui
->
getValue
(
11
)
==
0
);
send
(
pack
);
msleep
(
12
0
);
msleep
(
20
0
);
REQUIRE
(
ui
->
getValue
(
8
)
==
100
);
REQUIRE
(
ui
->
getValue
(
9
)
==
-
100
);
REQUIRE
(
ui
->
getValue
(
10
)
==
1
);
...
...
@@ -313,7 +316,7 @@ TEST_CASE("[UNetUDP]: check receiver", "[unetudp][receiver]")
pack
.
addDData
(
10
,
false
);
pack
.
addDData
(
11
,
true
);
send
(
pack
);
msleep
(
12
0
);
msleep
(
20
0
);
REQUIRE
(
ui
->
getValue
(
8
)
==
10
);
REQUIRE
(
ui
->
getValue
(
9
)
==
-
10
);
REQUIRE
(
ui
->
getValue
(
10
)
==
0
);
...
...
extensions/UNetUDP/tests/unetudp-test-configure.xml
View file @
d5b8a3d2
...
...
@@ -35,14 +35,14 @@
<nodes
port=
"2809"
unet_broadcast_ip=
"127.255.255.255"
unet_broadcast_ip2=
"badip"
>
<item
id=
"3000"
ip=
"127.0.0.1"
name=
"localhost"
textname=
"Локальный узел"
unet_ignore=
"0"
unet_port=
"3000"
/>
<item
id=
"3001"
ip=
"127.0.0.1"
name=
"localhost1"
textname=
"Локальный узел"
unet_ignore=
"1"
unet_port=
"3001"
/>
<item
id=
"3002"
ip=
"192.168.56.10"
name=
"Node1"
textname=
"Node1"
unet_ignore=
"0"
unet_
ip=
"192.168.56.255"
unet_respond_id=
"Node1
_Respond_S"
unet_respond_invert=
"1"
/>
<item
id=
"3003"
ip=
"192.168.56.11"
name=
"Node2"
textname=
"Node2"
unet_ignore=
"0"
unet_
ip=
"192.168.56.255"
unet_
respond_id=
"Node2_Respond_S"
unet_lostpackets_id=
"Node2_LostPackets_AS"
unet_numchannel_id=
"Node2_NumChannel_AS"
/>
<item
id=
"3002"
ip=
"192.168.56.10"
name=
"Node1"
textname=
"Node1"
unet_ignore=
"0"
unet_
respond_id=
"Node1_Not
_Respond_S"
unet_respond_invert=
"1"
/>
<item
id=
"3003"
ip=
"192.168.56.11"
name=
"Node2"
textname=
"Node2"
unet_ignore=
"0"
unet_respond_id=
"Node2_Respond_S"
unet_lostpackets_id=
"Node2_LostPackets_AS"
unet_numchannel_id=
"Node2_NumChannel_AS"
/>
</nodes>
<!-- ************************ Датчики ********************** -->
<sensors
name=
"Sensors"
>
<item
id=
"100"
iotype=
"DI"
name=
"TestMode_S"
textname=
"Test sensor"
/>
<item
id=
"1"
iotype=
"DI"
name=
"Node1_
Respond_S"
textname=
"Node1
respond"
/>
<item
id=
"1"
iotype=
"DI"
name=
"Node1_
Not_Respond_S"
textname=
"Node1 not
respond"
/>
<item
id=
"2"
iotype=
"AI"
name=
"AI1_S"
textname=
"AI sensor 1"
unet=
"1"
default=
"1"
/>
<item
id=
"3"
iotype=
"AI"
name=
"AI2_S"
textname=
"AI sensor 2"
unet=
"1"
default=
"2"
/>
<item
id=
"4"
iotype=
"AI"
name=
"AI3_S"
textname=
"AI sensor 3"
unet=
"1"
default=
"3"
/>
...
...
include/CommonEventLoop.h
View file @
d5b8a3d2
...
...
@@ -7,7 +7,7 @@
#include <thread>
#include <mutex>
#include <condition_variable>
#include <
list
>
#include <
vector
>
// -------------------------------------------------------------------------
namespace
uniset
{
...
...
@@ -65,7 +65,7 @@ class CommonEventLoop
* Даже если thread = false, но wather не сможет быть "активирован" функция вернёт управление
* с return false.
*/
bool
evrun
(
EvWatcher
*
w
,
bool
thread
=
true
,
size_t
waitPrepareTimeout_msec
=
5
000
);
bool
evrun
(
EvWatcher
*
w
,
bool
thread
=
true
,
size_t
waitPrepareTimeout_msec
=
8
000
);
/*! \return TRUE - если это был последний EvWatcher и loop остановлен */
bool
evstop
(
EvWatcher
*
w
);
...
...
@@ -75,6 +75,9 @@ class CommonEventLoop
return
loop
;
}
// количество зарегистрированных wather-ов
size_t
size
()
const
;
protected
:
private
:
...
...
@@ -96,7 +99,7 @@ class CommonEventLoop
std
::
atomic_bool
term_notify
=
{
false
};
std
::
mutex
wlist_mutex
;
std
::
list
<
EvWatcher
*>
wlist
;
std
::
vector
<
EvWatcher
*>
wlist
;
// готовящийся Watcher..он может быть только один в единицу времени
// это гарантирует prep_mutex
...
...
src/Processes/CommonEventLoop.cc
View file @
d5b8a3d2
#include <iostream>
#include <chrono>
#include <algorithm>
#include "CommonEventLoop.h"
// -------------------------------------------------------------------------
using
namespace
std
;
...
...
@@ -33,20 +34,17 @@ CommonEventLoop::~CommonEventLoop()
// ---------------------------------------------------------------------------
bool
CommonEventLoop
::
evrun
(
EvWatcher
*
w
,
bool
thread
,
size_t
waitTimeout_msec
)
{
if
(
!
w
)
if
(
w
==
nullptr
)
return
false
;
bool
ret
=
false
;
{
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
wlist_mutex
);
for
(
auto
&
e
:
wlist
)
if
(
std
::
find
(
wlist
.
begin
(),
wlist
.
end
(),
w
)
!=
wlist
.
end
()
)
{
if
(
e
==
w
)
{
cerr
<<
"(CommonEventLoop::evrun): "
<<
w
->
wname
()
<<
" ALREADY ADDED.."
<<
endl
;
return
false
;
}
cerr
<<
"(CommonEventLoop::evrun): "
<<
w
->
wname
()
<<
" ALREADY ADDED.."
<<
endl
;
return
false
;
}
wlist
.
push_back
(
w
);
}
...
...
@@ -62,7 +60,7 @@ bool CommonEventLoop::evrun( EvWatcher* w, bool thread, size_t waitTimeout_msec
// иначе evprep.send() улетит в никуда
prep_event
.
wait_for
(
locker
,
std
::
chrono
::
milliseconds
(
waitTimeout_msec
),
[
=
]()
{
return
(
isrunning
==
false
);
return
(
isrunning
==
true
);
}
);
if
(
!
isrunning
)
...
...
@@ -70,6 +68,10 @@ bool CommonEventLoop::evrun( EvWatcher* w, bool thread, size_t waitTimeout_msec
cerr
<<
"(CommonEventLoop::evrun): "
<<
w
->
wname
()
<<
" evloop NOT RUN!.."
<<
endl
;
return
false
;
}
// небольшая пауза после запуск event loop
// чтобы "надёжнее" сработал evprep.send() (см. ниже)
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
50
));
}
}
...
...
@@ -86,7 +88,7 @@ bool CommonEventLoop::evrun( EvWatcher* w, bool thread, size_t waitTimeout_msec
// ожидаем обработки evprepare (которая будет в defaultLoop)
prep_event
.
wait_for
(
locker
,
std
::
chrono
::
milliseconds
(
waitTimeout_msec
),
[
=
]()
{
return
(
prep_notify
==
true
);
return
(
prep_notify
==
true
);
}
);
// сбрасываем флаг
...
...
@@ -134,7 +136,8 @@ bool CommonEventLoop::evstop( EvWatcher* w )
cerr
<<
"(CommonEventLoop::evfinish): evfinish err: "
<<
ex
.
what
()
<<
endl
;
}
wlist
.
remove
(
w
);
wlist
.
erase
(
std
::
remove
(
wlist
.
begin
(),
wlist
.
end
(),
w
),
wlist
.
end
()
);
// wlist.remove(w);
if
(
!
wlist
.
empty
()
)
return
false
;
...
...
@@ -157,6 +160,11 @@ bool CommonEventLoop::evstop( EvWatcher* w )
return
true
;
}
// -------------------------------------------------------------------------
size_t
CommonEventLoop
::
size
()
const
{
return
wlist
.
size
();
}
// -------------------------------------------------------------------------
void
CommonEventLoop
::
onPrepare
()
noexcept
{
prep_notify
=
false
;
...
...
@@ -208,11 +216,11 @@ void CommonEventLoop::onStop() noexcept
void
CommonEventLoop
::
defaultLoop
()
noexcept
{
isrunning
=
true
;
evterm
.
start
();
evprep
.
start
();
isrunning
=
true
;
while
(
!
cancelled
)
{
try
...
...
tests/test_passivetimer.cc
View file @
d5b8a3d2
...
...
@@ -109,9 +109,7 @@ TEST_CASE("UniSetTimer: conv to Poco", "[PassiveTimer][poco]" )
{
Poco
::
Timespan
tm
=
UniSetTimer
::
millisecToPoco
(
UniSetTimer
::
WaitUpTime
);
REQUIRE
(
tm
.
seconds
()
==
-
1
);
REQUIRE
(
tm
.
microseconds
()
==
0
);
REQUIRE
(
tm
.
totalMilliseconds
()
<
0
);
REQUIRE
(
tm
.
days
()
==
12443823
/* std::numeric_limits<int>::max() */
);
}
{
...
...
@@ -125,9 +123,7 @@ TEST_CASE("UniSetTimer: conv to Poco", "[PassiveTimer][poco]" )
// usec --> Poco::Timespan
{
Poco
::
Timespan
tm
=
UniSetTimer
::
microsecToPoco
(
UniSetTimer
::
WaitUpTime
);
REQUIRE
(
tm
.
seconds
()
==
-
1
);
REQUIRE
(
tm
.
microseconds
()
==
0
);
REQUIRE
(
tm
.
totalMilliseconds
()
<
0
);
REQUIRE
(
tm
.
days
()
==
12443823
/* std::numeric_limits<int>::max() */
);
}
{
Poco
::
Timespan
tm
=
UniSetTimer
::
microsecToPoco
(
2000000
);
...
...
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