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
465d626e
Commit
465d626e
authored
Feb 20, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Различные "флаги" ф процессах переведены на использование std::atomic_bool
Реализовано корректное завершение потоков в MBTCPMultiSlave Различные мелки исправления
parent
56f35e19
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
247 additions
and
69 deletions
+247
-69
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+36
-3
MBSlave.h
extensions/ModbusSlave/MBSlave.h
+2
-0
MBTCPMultiSlave.cc
extensions/ModbusSlave/MBTCPMultiSlave.cc
+29
-1
MBTCPMultiSlave.h
extensions/ModbusSlave/MBTCPMultiSlave.h
+2
-0
start_tcp_multi_fg.sh
extensions/ModbusSlave/start_tcp_multi_fg.sh
+2
-0
SharedMemory.cc
extensions/SharedMemory/SharedMemory.cc
+1
-3
Extensions.h
extensions/include/Extensions.h
+14
-14
Configuration.h
include/Configuration.h
+14
-14
Mutex.h
include/Mutex.h
+1
-3
UniSetManager.h
include/UniSetManager.h
+2
-1
UniSetObject.h
include/UniSetObject.h
+1
-1
ModbusTCPServer.h
include/modbus/ModbusTCPServer.h
+1
-0
ModbusTCPSession.h
include/modbus/ModbusTCPSession.h
+2
-0
ModbusTCPServer.cc
src/Communications/Modbus/ModbusTCPServer.cc
+30
-1
ModbusTCPServerSlot.cc
src/Communications/Modbus/ModbusTCPServerSlot.cc
+0
-0
ModbusTCPSession.cc
src/Communications/Modbus/ModbusTCPSession.cc
+35
-2
UniSetActivator.cc
src/ObjectRepository/UniSetActivator.cc
+5
-2
UniSetManager.cc
src/ObjectRepository/UniSetManager.cc
+19
-4
UniSetObject.cc
src/ObjectRepository/UniSetObject.cc
+25
-16
Mutex.cc
src/Various/Mutex.cc
+7
-4
umutex.cc
tests/umutex.cc
+19
-0
No files found.
extensions/ModbusSlave/MBSlave.cc
View file @
465d626e
...
...
@@ -22,6 +22,7 @@ respond_id(DefaultObjectId),
respond_invert
(
false
),
askCount
(
0
),
activated
(
false
),
cancelled
(
false
),
activateTimeout
(
500
),
pingOK
(
true
),
force
(
false
),
...
...
@@ -120,6 +121,9 @@ prefix(prefix)
mbslot
=
mbtcp
;
thr
=
new
ThreadCreator
<
MBSlave
>
(
this
,
&
MBSlave
::
execute_tcp
);
dinfo
<<
myname
<<
"(init): init TCP connection ok. "
<<
" inet="
<<
iaddr
<<
" port="
<<
port
<<
endl
;
if
(
dlog
.
debugging
(
Debug
::
LEVEL9
)
)
mbtcp
->
setLog
(
dlog
);
}
else
throw
UniSetTypes
::
SystemError
(
myname
+
"(MBSlave): Unknown slave type. Use: --mbs-type [RTU|TCP]"
);
...
...
@@ -357,9 +361,17 @@ prefix(prefix)
// -----------------------------------------------------------------------------
MBSlave
::~
MBSlave
()
{
cancelled
=
true
;
if
(
thr
&&
thr
->
isRunning
()
)
{
thr
->
stop
();
thr
->
join
();
}
delete
thr
;
delete
mbslot
;
delete
shm
;
delete
thr
;
}
// -----------------------------------------------------------------------------
void
MBSlave
::
waitSMReady
()
...
...
@@ -386,7 +398,7 @@ void MBSlave::execute_rtu()
ModbusRTU
::
mbErrCode
prev
=
erNoError
;
while
(
1
)
while
(
!
cancelled
)
{
try
{
...
...
@@ -467,7 +479,9 @@ void MBSlave::execute_tcp()
ModbusRTU
::
mbErrCode
prev
=
erNoError
;
while
(
1
)
dinfo
<<
myname
<<
"(execute_tcp): thread running.."
<<
endl
;
while
(
!
cancelled
)
{
try
{
...
...
@@ -540,6 +554,8 @@ void MBSlave::execute_tcp()
}
catch
(...){}
}
dinfo
<<
myname
<<
"(execute_tcp): thread stopped.."
<<
endl
;
}
// -------------------------------------------------------------------------
void
MBSlave
::
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
...
...
@@ -721,10 +737,27 @@ bool MBSlave::activateObject()
return
true
;
}
// ------------------------------------------------------------------------------------------
bool
MBSlave
::
disactivateObject
()
{
dinfo
<<
myname
<<
"(disactivateObject): ..."
<<
endl
;
activated
=
false
;
cancelled
=
true
;
try
{
if
(
mbslot
)
mbslot
->
sigterm
(
SIGTERM
);
}
catch
(...){}
return
UniSetObject_LT
::
disactivateObject
();
}
// ------------------------------------------------------------------------------------------
void
MBSlave
::
sigterm
(
int
signo
)
{
dinfo
<<
myname
<<
": ********* SIGTERM("
<<
signo
<<
") ********"
<<
endl
;
activated
=
false
;
cancelled
=
true
;
try
{
if
(
mbslot
)
...
...
extensions/ModbusSlave/MBSlave.h
View file @
465d626e
...
...
@@ -144,6 +144,7 @@ class MBSlave:
virtual
void
execute_tcp
();
virtual
bool
activateObject
()
override
;
virtual
bool
disactivateObject
()
override
;
// действия при завершении работы
virtual
void
sigterm
(
int
signo
)
override
;
...
...
@@ -187,6 +188,7 @@ class MBSlave:
ExchangeErrorMap
errmap
;
/*!< статистика обмена */
std
::
atomic_bool
activated
;
std
::
atomic_bool
cancelled
;
int
activateTimeout
;
bool
pingOK
;
timeout_t
wait_msec
;
...
...
extensions/ModbusSlave/MBTCPMultiSlave.cc
View file @
465d626e
...
...
@@ -150,7 +150,9 @@ void MBTCPMultiSlave::execute_tcp()
sslot
->
setMaxSessions
(
sessMaxNum
);
while
(
1
)
dinfo
<<
myname
<<
"(execute_tcp): thread running.."
<<
endl
;
while
(
!
cancelled
)
{
try
{
...
...
@@ -286,6 +288,8 @@ void MBTCPMultiSlave::execute_tcp()
}
catch
(...){}
}
dinfo
<<
myname
<<
"(execute_tcp): thread stopped.."
<<
endl
;
}
// -----------------------------------------------------------------------------
void
MBTCPMultiSlave
::
initIterators
()
...
...
@@ -298,3 +302,27 @@ void MBTCPMultiSlave::initIterators()
i
.
second
.
initIterators
(
shm
);
}
// -----------------------------------------------------------------------------
bool
MBTCPMultiSlave
::
disactivateObject
()
{
if
(
mbslot
)
{
ModbusTCPServerSlot
*
sslot
=
dynamic_cast
<
ModbusTCPServerSlot
*>
(
mbslot
);
if
(
sslot
)
sslot
->
sigterm
(
SIGTERM
);
}
return
MBSlave
::
disactivateObject
();
}
// -----------------------------------------------------------------------------
void
MBTCPMultiSlave
::
sigterm
(
int
signo
)
{
if
(
mbslot
)
{
ModbusTCPServerSlot
*
sslot
=
dynamic_cast
<
ModbusTCPServerSlot
*>
(
mbslot
);
if
(
sslot
)
sslot
->
sigterm
(
signo
);
}
MBSlave
::
sigterm
(
signo
);
}
// -----------------------------------------------------------------------------
extensions/ModbusSlave/MBTCPMultiSlave.h
View file @
465d626e
...
...
@@ -35,6 +35,8 @@ class MBTCPMultiSlave:
protected
:
virtual
void
execute_tcp
()
override
;
virtual
void
initIterators
()
override
;
virtual
bool
disactivateObject
()
override
;
virtual
void
sigterm
(
int
signo
)
override
;
timeout_t
sessTimeout
;
/*!< таймаут на сессию */
timeout_t
waitTimeout
;
...
...
extensions/ModbusSlave/start_tcp_multi_fg.sh
View file @
465d626e
...
...
@@ -3,6 +3,7 @@
uniset2-start.sh
-f
./uniset2-mbtcp-multislave
--confile
test.xml
--dlog-add-levels
level3,level4
\
--smemory-id
SharedMemory
\
--mbs-name
MBMultiSlave1
--mbs-type
TCP
--mbs-inet-addr
127.0.0.1
--mbs-inet-port
2048
--mbs-reg-from-id
1
--mbs-my-addr
0x01
\
$*
# --mbs-force 1
#--mbs-reg-from-id 1 \
#--mbs-filter-field CAN2sender --mbs-filter-value SYSTSNode \
\ No newline at end of file
extensions/SharedMemory/SharedMemory.cc
View file @
465d626e
...
...
@@ -240,9 +240,7 @@ bool SharedMemory::activateObject()
// инициализируем указатели
for
(
auto
&
it
:
hlist
)
{
it
.
ioit
=
myioEnd
();
}
itPulsar
=
myioEnd
();
...
...
@@ -261,7 +259,6 @@ bool SharedMemory::activateObject()
// ------------------------------------------------------------------------------------------
CORBA
::
Boolean
SharedMemory
::
exist
()
{
// return activated;
return
workready
;
}
// ------------------------------------------------------------------------------------------
...
...
@@ -270,6 +267,7 @@ void SharedMemory::sigterm( int signo )
if
(
signo
==
SIGTERM
)
wdt
->
stop
();
// raise(SIGKILL);
IONotifyController_LT
::
sigterm
(
signo
);
}
// ------------------------------------------------------------------------------------------
void
SharedMemory
::
checkHeartBeat
()
...
...
extensions/include/Extensions.h
View file @
465d626e
...
...
@@ -32,20 +32,20 @@ namespace UniSetExtensions
}
// -------------------------------------------------------------------------
// "синтаксический сахар"..для логов
#define dinfo if( UniSetExtensions::dlog.debugging(Debug::INFO) ) UniSetExtensions::dlog
#define dwarn if( UniSetExtensions::dlog.debugging(Debug::WARN) ) UniSetExtensions::dlog
#define dcrit if( UniSetExtensions::dlog.debugging(Debug::CRIT) ) UniSetExtensions::dlog
#define dlog1 if( UniSetExtensions::dlog.debugging(Debug::LEVEL1) ) UniSetExtensions::dlog
#define dlog2 if( UniSetExtensions::dlog.debugging(Debug::LEVEL2) ) UniSetExtensions::dlog
#define dlog3 if( UniSetExtensions::dlog.debugging(Debug::LEVEL3) ) UniSetExtensions::dlog
#define dlog4 if( UniSetExtensions::dlog.debugging(Debug::LEVEL4) ) UniSetExtensions::dlog
#define dlog5 if( UniSetExtensions::dlog.debugging(Debug::LEVEL5) ) UniSetExtensions::dlog
#define dlog6 if( UniSetExtensions::dlog.debugging(Debug::LEVEL6) ) UniSetExtensions::dlog
#define dlog7 if( UniSetExtensions::dlog.debugging(Debug::LEVEL7) ) UniSetExtensions::dlog
#define dlog8 if( UniSetExtensions::dlog.debugging(Debug::LEVEL8) ) UniSetExtensions::dlog
#define dlog9 if( UniSetExtensions::dlog.debugging(Debug::LEVEL9) ) UniSetExtensions::dlog
#define dlogsys if( UniSetExtensions::dlog.debugging(Debug::SYSTEM) ) UniSetExtensions::dlog
#define dlogrep if( UniSetExtensions::dlog.debugging(Debug::REPOSITORY) ) UniSetExtensions::dlog
#define dinfo if( UniSetExtensions::dlog.debugging(Debug::INFO) ) UniSetExtensions::dlog
[Debug::INFO]
#define dwarn if( UniSetExtensions::dlog.debugging(Debug::WARN) ) UniSetExtensions::dlog
[Debug::WARN]
#define dcrit if( UniSetExtensions::dlog.debugging(Debug::CRIT) ) UniSetExtensions::dlog
[Debug::CRIT]
#define dlog1 if( UniSetExtensions::dlog.debugging(Debug::LEVEL1) ) UniSetExtensions::dlog
[Debug::LEVEL1]
#define dlog2 if( UniSetExtensions::dlog.debugging(Debug::LEVEL2) ) UniSetExtensions::dlog
[Debug::LEVEL2]
#define dlog3 if( UniSetExtensions::dlog.debugging(Debug::LEVEL3) ) UniSetExtensions::dlog
[Debug::LEVEL3]
#define dlog4 if( UniSetExtensions::dlog.debugging(Debug::LEVEL4) ) UniSetExtensions::dlog
[Debug::LEVEL4]
#define dlog5 if( UniSetExtensions::dlog.debugging(Debug::LEVEL5) ) UniSetExtensions::dlog
[Debug::LEVEL5]
#define dlog6 if( UniSetExtensions::dlog.debugging(Debug::LEVEL6) ) UniSetExtensions::dlog
[Debug::LEVEL6]
#define dlog7 if( UniSetExtensions::dlog.debugging(Debug::LEVEL7) ) UniSetExtensions::dlog
[Debug::LEVEL7]
#define dlog8 if( UniSetExtensions::dlog.debugging(Debug::LEVEL8) ) UniSetExtensions::dlog
[Debug::LEVEL8]
#define dlog9 if( UniSetExtensions::dlog.debugging(Debug::LEVEL9) ) UniSetExtensions::dlog
[Debug::LEVEL9]
#define dlogsys if( UniSetExtensions::dlog.debugging(Debug::SYSTEM) ) UniSetExtensions::dlog
[Debug::SYSTEM]
#define dlogrep if( UniSetExtensions::dlog.debugging(Debug::REPOSITORY) ) UniSetExtensions::dlog
[Debug::REPOSITORY]
// -------------------------------------------------------------------------
#endif // Extensions_H_
// -------------------------------------------------------------------------
include/Configuration.h
View file @
465d626e
...
...
@@ -249,19 +249,19 @@ namespace UniSetTypes
}
// end of UniSetTypes namespace
// --------------------------------------------------------------------------
// "синтаксический сахар"..для логов
#define uinfo if( UniSetTypes::ulog.debugging(Debug::INFO) ) UniSetTypes::ulog
#define uwarn if( UniSetTypes::ulog.debugging(Debug::WARN) ) UniSetTypes::ulog
#define ucrit if( UniSetTypes::ulog.debugging(Debug::CRIT) ) UniSetTypes::ulog
#define ulog1 if( UniSetTypes::ulog.debugging(Debug::LEVEL1) ) UniSetTypes::ulog
#define ulog2 if( UniSetTypes::ulog.debugging(Debug::LEVEL2) ) UniSetTypes::ulog
#define ulog3 if( UniSetTypes::ulog.debugging(Debug::LEVEL3) ) UniSetTypes::ulog
#define ulog4 if( UniSetTypes::ulog.debugging(Debug::LEVEL4) ) UniSetTypes::ulog
#define ulog5 if( UniSetTypes::ulog.debugging(Debug::LEVEL5) ) UniSetTypes::ulog
#define ulog6 if( UniSetTypes::ulog.debugging(Debug::LEVEL6) ) UniSetTypes::ulog
#define ulog7 if( UniSetTypes::ulog.debugging(Debug::LEVEL7) ) UniSetTypes::ulog
#define ulog8 if( UniSetTypes::ulog.debugging(Debug::LEVEL8) ) UniSetTypes::ulog
#define ulog9 if( UniSetTypes::ulog.debugging(Debug::LEVEL9) ) UniSetTypes::ulog
#define ulogsys if( UniSetTypes::ulog.debugging(Debug::SYSTEM) ) UniSetTypes::ulog
#define ulogrep if( UniSetTypes::ulog.debugging(Debug::REPOSITORY) ) UniSetTypes::ulog
#define uinfo if( UniSetTypes::ulog.debugging(Debug::INFO) ) UniSetTypes::ulog
[Debug::INFO]
#define uwarn if( UniSetTypes::ulog.debugging(Debug::WARN) ) UniSetTypes::ulog
[Debug::WARN]
#define ucrit if( UniSetTypes::ulog.debugging(Debug::CRIT) ) UniSetTypes::ulog
[Debug::CRIT]
#define ulog1 if( UniSetTypes::ulog.debugging(Debug::LEVEL1) ) UniSetTypes::ulog
[Debug::LEVEL1]
#define ulog2 if( UniSetTypes::ulog.debugging(Debug::LEVEL2) ) UniSetTypes::ulog
[Debug::LEVEL2]
#define ulog3 if( UniSetTypes::ulog.debugging(Debug::LEVEL3) ) UniSetTypes::ulog
[Debug::LEVEL3]
#define ulog4 if( UniSetTypes::ulog.debugging(Debug::LEVEL4) ) UniSetTypes::ulog
[Debug::LEVEL4]
#define ulog5 if( UniSetTypes::ulog.debugging(Debug::LEVEL5) ) UniSetTypes::ulog
[Debug::LEVEL5]
#define ulog6 if( UniSetTypes::ulog.debugging(Debug::LEVEL6) ) UniSetTypes::ulog
[Debug::LEVEL6]
#define ulog7 if( UniSetTypes::ulog.debugging(Debug::LEVEL7) ) UniSetTypes::ulog
[Debug::LEVEL7]
#define ulog8 if( UniSetTypes::ulog.debugging(Debug::LEVEL8) ) UniSetTypes::ulog
[Debug::LEVEL8]
#define ulog9 if( UniSetTypes::ulog.debugging(Debug::LEVEL9) ) UniSetTypes::ulog
[Debug::LEVEL9]
#define ulogsys if( UniSetTypes::ulog.debugging(Debug::SYSTEM) ) UniSetTypes::ulog
[Debug::SYSTEM]
#define ulogrep if( UniSetTypes::ulog.debugging(Debug::REPOSITORY) ) UniSetTypes::ulog
[Debug::REPOSITORY]
// --------------------------------------------------------------------------
#endif // Configuration_H_
include/Mutex.h
View file @
465d626e
...
...
@@ -63,8 +63,6 @@ namespace UniSetTypes
*
* Предназначен для блокирования совместного доступа. Как пользоваться см. \ref MutexHowToPage
* \note Если ресурс уже занят, то lock ждет его освобождения...
* \warning Насколько ожидание защищено от зависания надо еще проверять!
* \todo Может на откуп пользователям оставить проверку занятости ресурса перед захватом? может не ждать?
*/
class
uniset_mutex_lock
{
...
...
@@ -76,7 +74,7 @@ namespace UniSetTypes
private
:
uniset_mutex
*
mutex
;
std
::
atomic
<
int
>
locked
;
std
::
atomic
_bool
locked
;
uniset_mutex_lock
(
const
uniset_mutex_lock
&
)
=
delete
;
uniset_mutex_lock
&
operator
=
(
const
uniset_mutex_lock
&
)
=
delete
;
...
...
include/UniSetManager.h
View file @
465d626e
...
...
@@ -120,7 +120,8 @@ class UniSetManager:
UniSetManager
();
enum
OManagerCommand
{
deactiv
,
activ
,
initial
,
term
};
enum
OManagerCommand
{
deactiv
,
activ
,
initial
,
term
};
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
OManagerCommand
&
cmd
);
// работа со списком объектов
void
objects
(
OManagerCommand
cmd
);
...
...
include/UniSetObject.h
View file @
465d626e
...
...
@@ -186,7 +186,7 @@ class UniSetObject:
virtual
void
cleanMsgQueue
(
MessagesQueue
&
q
);
inline
bool
isActive
(){
return
active
;
}
inline
void
setActive
(
bool
set
){
active
=
set
?
1
:
0
;
}
inline
void
setActive
(
bool
set
){
active
=
set
;
}
UniSetTypes
::
VoidMessage
msg
;
UniSetManager
*
mymngr
;
...
...
include/modbus/ModbusTCPServer.h
View file @
465d626e
...
...
@@ -95,6 +95,7 @@ class ModbusTCPServer:
private
:
std
::
atomic_bool
cancelled
;
};
// -------------------------------------------------------------------------
#endif // ModbusTCPServer_H_
...
...
include/modbus/ModbusTCPSession.h
View file @
465d626e
...
...
@@ -103,6 +103,8 @@ class ModbusTCPSession:
FinalSlot
slFin
;
std
::
atomic_bool
cancelled
;
// статистика
UniSetTypes
::
uniset_rwmutex
mAsk
;
unsigned
int
askCount
;
...
...
src/Communications/Modbus/ModbusTCPServer.cc
View file @
465d626e
...
...
@@ -14,7 +14,8 @@ ModbusTCPServer::ModbusTCPServer( ost::InetAddress &ia, int port ):
ignoreAddr
(
false
),
maxSessions
(
10
),
sessCount
(
0
),
sessTimeout
(
10000
)
sessTimeout
(
10000
),
cancelled
(
false
)
{
setCRCNoCheckit
(
true
);
}
...
...
@@ -23,6 +24,16 @@ ModbusTCPServer::ModbusTCPServer( ost::InetAddress &ia, int port ):
ModbusTCPServer
::~
ModbusTCPServer
()
{
terminate
();
/*
{
uniset_mutex_lock l(sMutex);
for( auto& s: slist )
{
if( s->isRunning() )
s->ost::Thread::join();
}
}
*/
}
// -------------------------------------------------------------------------
void
ModbusTCPServer
::
setMaxSessions
(
unsigned
int
num
)
...
...
@@ -61,10 +72,16 @@ bool ModbusTCPServer::waitQuery( ModbusRTU::ModbusAddr mbaddr, timeout_t msec )
if
(
sessCount
>=
maxSessions
)
return
false
;
if
(
cancelled
)
return
false
;
try
{
if
(
isPendingConnection
(
msec
)
)
{
if
(
cancelled
)
return
false
;
ModbusTCPSession
*
s
=
new
ModbusTCPSession
(
*
this
,
mbaddr
,
sessTimeout
);
s
->
connectReadCoil
(
sigc
::
mem_fun
(
this
,
&
ModbusTCPServer
::
readCoilStatus
)
);
...
...
@@ -340,11 +357,23 @@ void ModbusTCPServer::cleanInputStream()
// -------------------------------------------------------------------------
void
ModbusTCPServer
::
terminate
()
{
cancelled
=
true
;
if
(
dlog
.
is_info
()
)
dlog
.
info
()
<<
"(ModbusTCPServer): terminate..."
<<
endl
;
if
(
tcp
&&
tcp
.
isConnected
()
)
tcp
.
disconnect
();
uniset_mutex_lock
l
(
sMutex
);
for
(
auto
&
s
:
slist
)
{
try
{
s
->
terminate
();
}
catch
(...){}
}
}
// -------------------------------------------------------------------------
void
ModbusTCPServer
::
sessionFinished
(
ModbusTCPSession
*
s
)
...
...
src/Communications/Modbus/ModbusTCPServerSlot.cc
View file @
465d626e
src/Communications/Modbus/ModbusTCPSession.cc
View file @
465d626e
...
...
@@ -14,6 +14,9 @@ using namespace UniSetTypes;
// -------------------------------------------------------------------------
ModbusTCPSession
::~
ModbusTCPSession
()
{
cancelled
=
true
;
if
(
isRunning
()
)
ost
::
Thread
::
join
();
}
// -------------------------------------------------------------------------
ModbusTCPSession
::
ModbusTCPSession
(
ost
::
TCPSocket
&
server
,
ModbusRTU
::
ModbusAddr
a
,
timeout_t
timeout
)
:
...
...
@@ -22,6 +25,7 @@ addr(a),
timeout
(
timeout
),
peername
(
""
),
caddr
(
""
),
cancelled
(
false
),
askCount
(
0
)
{
setCRCNoCheckit
(
true
);
...
...
@@ -35,6 +39,9 @@ unsigned int ModbusTCPSession::getAskCount()
// -------------------------------------------------------------------------
void
ModbusTCPSession
::
run
()
{
if
(
cancelled
)
return
;
{
ost
::
tpport_t
p
;
ost
::
InetAddress
iaddr
=
getIPV4Peer
(
&
p
);
...
...
@@ -50,8 +57,12 @@ void ModbusTCPSession::run()
// cerr << "**************** CREATE SESS FOR " << string( inet_ntoa(a) ) << endl;
}
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
peername
<<
"(run): run thread of sessions.."
<<
endl
;
ModbusRTU
::
mbErrCode
res
=
erTimeOut
;
while
(
isPending
(
Socket
::
pendingInput
,
timeout
)
)
cancelled
=
false
;
while
(
!
cancelled
&&
isPending
(
Socket
::
pendingInput
,
timeout
)
)
{
res
=
receive
(
addr
,
timeout
);
...
...
@@ -68,7 +79,13 @@ void ModbusTCPSession::run()
}
}
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
peername
<<
"(run): stop thread of sessions..disconnect.."
<<
endl
;
disconnect
();
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
peername
<<
"(run): thread stopping..."
<<
endl
;
}
// -------------------------------------------------------------------------
ModbusRTU
::
mbErrCode
ModbusTCPSession
::
receive
(
ModbusRTU
::
ModbusAddr
addr
,
timeout_t
msec
)
...
...
@@ -106,9 +123,15 @@ ModbusRTU::mbErrCode ModbusTCPSession::receive( ModbusRTU::ModbusAddr addr, time
}
}
if
(
cancelled
)
return
erSessionClosed
;
memset
(
&
buf
,
0
,
sizeof
(
buf
));
res
=
recv
(
addr
,
buf
,
msec
);
if
(
cancelled
)
return
erSessionClosed
;
if
(
res
!=
erNoError
)
// && res!=erBadReplyNodeAddress )
{
if
(
res
<
erInternalErrorCode
)
...
...
@@ -134,6 +157,9 @@ ModbusRTU::mbErrCode ModbusTCPSession::receive( ModbusRTU::ModbusAddr addr, time
if
(
res
!=
erNoError
)
return
res
;
if
(
cancelled
)
return
erSessionClosed
;
// processing message...
res
=
processing
(
buf
);
}
...
...
@@ -246,11 +272,18 @@ void ModbusTCPSession::cleanInputStream()
// -------------------------------------------------------------------------
void
ModbusTCPSession
::
terminate
()
{
ModbusServer
::
terminate
();
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
peername
<<
"(ModbusTCPSession): terminate..."
<<
endl
;
dlog
[
Debug
::
INFO
]
<<
peername
<<
"(terminate)..."
<<
endl
;
cancelled
=
true
;
if
(
isConnected
()
)
disconnect
();
// if( isRunning() )
// ost::Thread::join();
}
// -------------------------------------------------------------------------
mbErrCode
ModbusTCPSession
::
readCoilStatus
(
ReadCoilMessage
&
query
,
...
...
src/ObjectRepository/UniSetActivator.cc
View file @
465d626e
...
...
@@ -69,7 +69,7 @@ static UniSetActivator* gActivator=0;
//static ThreadCreator<UniSetActivator>* termthread=0;
static
int
SIGNO
;
static
int
MYPID
;
static
const
int
TERMINATE_TIMEOUT
=
2
;
// время отведенное на завершение процесса [сек]
static
const
int
TERMINATE_TIMEOUT
=
10
;
// время отведенное на завершение процесса [сек]
ost
::
AtomicCounter
procterm
=
0
;
ost
::
AtomicCounter
doneterm
=
0
;
...
...
@@ -118,6 +118,9 @@ sig(false)
// ------------------------------------------------------------------------------------------
void
UniSetActivator
::
init
()
{
if
(
getId
()
==
DefaultObjectId
)
myname
=
"UniSetActivator"
;
orb
=
conf
->
getORB
();
CORBA
::
Object_var
obj
=
orb
->
resolve_initial_references
(
"RootPOA"
);
PortableServer
::
POA_var
root_poa
=
PortableServer
::
POA
::
_narrow
(
obj
);
...
...
@@ -283,7 +286,7 @@ void UniSetActivator::work()
ulogsys
<<
myname
<<
"(work): запускаем orb на обработку запросов..."
<<
endl
;
try
{
if
(
orbthr
)
if
(
orbthr
)
thpid
=
orbthr
->
getTID
();
else
thpid
=
getpid
();
...
...
src/ObjectRepository/UniSetManager.cc
View file @
465d626e
...
...
@@ -160,7 +160,7 @@ bool UniSetManager::addObject( UniSetObject *obj )
}
// ------------------------------------------------------------------------------------------
bool
UniSetManager
::
removeObject
(
UniSetObject
*
obj
)
bool
UniSetManager
::
removeObject
(
UniSetObject
*
obj
)
{
{
//lock
uniset_rwmutex_wrlock
lock
(
olistMutex
);
...
...
@@ -204,10 +204,9 @@ bool UniSetManager::removeObject(UniSetObject* obj)
/*!
* Функция работы со списком менеджеров
*/
void
UniSetManager
::
managers
(
OManagerCommand
cmd
)
void
UniSetManager
::
managers
(
OManagerCommand
cmd
)
{
uinfo
<<
myname
<<
"(managers): mlist.size="
<<
mlist
.
size
()
<<
" cmd="
<<
cmd
<<
endl
;
uinfo
<<
myname
<<
"(managers): mlist.size="
<<
mlist
.
size
()
<<
" cmd="
<<
cmd
<<
endl
;
{
//lock
uniset_rwmutex_rlock
lock
(
mlistMutex
);
for
(
auto
&
li
:
mlist
)
...
...
@@ -522,3 +521,18 @@ SimpleInfoSeq* UniSetManager::getObjectsInfo( CORBA::Long maxlength )
}
// ------------------------------------------------------------------------------------------
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
UniSetManager
::
OManagerCommand
&
cmd
)
{
// { deactiv, activ, initial, term };
if
(
cmd
==
UniSetManager
::
deactiv
)
return
os
<<
"deactivate"
;
if
(
cmd
==
UniSetManager
::
activ
)
return
os
<<
"activate"
;
if
(
cmd
==
UniSetManager
::
initial
)
return
os
<<
"init"
;
if
(
cmd
==
UniSetManager
::
term
)
return
os
<<
"terminate"
;
return
os
<<
"unkwnown"
;
}
// ------------------------------------------------------------------------------------------
\ No newline at end of file
src/ObjectRepository/UniSetObject.cc
View file @
465d626e
...
...
@@ -93,8 +93,8 @@ stCountOfQueueFull(0)
{
threadcreate
=
false
;
myid
=
UniSetTypes
::
DefaultObjectId
;
myname
=
"
noname
"
;
section
=
"
noname
Section"
;
myname
=
"
UnknownUniSetObject
"
;
section
=
"
Unknown
Section"
;
}
init_object
();
...
...
@@ -135,12 +135,20 @@ stCountOfQueueFull(0)
UniSetObject
::~
UniSetObject
()
{
disactivate
();
delete
tmr
;
if
(
thr
)
tmr
->
terminate
();
if
(
thr
)
{
thr
->
stop
();
if
(
thr
->
isRunning
()
)
thr
->
join
();
delete
thr
;
}
delete
tmr
;
}
// ------------------------------------------------------------------------------------------
void
UniSetObject
::
init_object
()
...
...
@@ -624,7 +632,7 @@ bool UniSetObject::disactivate()
try
{
uinfo
<<
"disactivateObject
..."
<<
endl
;
uinfo
<<
myname
<<
"(disactivate):
..."
<<
endl
;
PortableServer
::
POA_var
poamngr
=
mymngr
->
getPOA
();
if
(
!
PortableServer
::
POA_Helper
::
is_nil
(
poamngr
)
)
...
...
@@ -634,33 +642,34 @@ bool UniSetObject::disactivate()
disactivateObject
();
}
catch
(...){}
unregister
();
PortableServer
::
ObjectId_var
oid
=
poamngr
->
servant_to_id
(
static_cast
<
PortableServer
::
ServantBase
*>
(
this
));
poamngr
->
deactivate_object
(
oid
);
uinfo
<<
"ok
..."
<<
endl
;
uinfo
<<
myname
<<
"(disacivate): finished
..."
<<
endl
;
return
true
;
}
uwarn
<<
"
manager already destroyed.."
<<
endl
;
uwarn
<<
myname
<<
"(disactivate):
manager already destroyed.."
<<
endl
;
}
catch
(
CORBA
::
TRANSIENT
)
{
uwarn
<<
"
isExist: нет связи..."
<<
endl
;
uwarn
<<
myname
<<
"(disactivate):
isExist: нет связи..."
<<
endl
;
}
catch
(
CORBA
::
SystemException
&
ex
)
{
uwarn
<<
"UniSetObject: "
<<
"поймали CORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
uwarn
<<
myname
<<
"(disactivate): "
<<
"поймали CORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
}
catch
(
CORBA
::
Exception
&
ex
)
{
uwarn
<<
"UniSetObject: "
<<
"поймали CORBA::Exception."
<<
endl
;
uwarn
<<
myname
<<
"(disactivate): "
<<
"поймали CORBA::Exception."
<<
endl
;
}
catch
(
Exception
&
ex
)
{
uwarn
<<
"UniSetObject: "
<<
ex
<<
endl
;
uwarn
<<
myname
<<
"(disactivate): "
<<
ex
<<
endl
;
}
catch
(...)
{
uwarn
<<
"UniSetObject: "
<<
" catch ..."
<<
endl
;
uwarn
<<
myname
<<
"(disactivate): "
<<
" catch ..."
<<
endl
;
}
return
false
;
...
...
@@ -742,15 +751,15 @@ bool UniSetObject::activate()
// ------------------------------------------------------------------------------------------
void
UniSetObject
::
work
()
{
uinfo
<<
myname
<<
": thread processing messages run..."
<<
endl
;
uinfo
<<
myname
<<
": thread processing messages running..."
<<
endl
;
if
(
thr
)
msgpid
=
thr
->
getTID
();
while
(
isActive
()
)
{
callback
();
}
uinfo
<<
myname
<<
": thread processing messages stop..."
<<
endl
;
uinfo
<<
myname
<<
": thread processing messages stop
ped
..."
<<
endl
;
}
// ------------------------------------------------------------------------------------------
void
UniSetObject
::
callback
()
...
...
src/Various/Mutex.cc
View file @
465d626e
...
...
@@ -73,7 +73,7 @@ bool uniset_mutex::try_lock_for( const time_t& msec )
// -----------------------------------------------------------------------------
uniset_mutex_lock
::
uniset_mutex_lock
(
uniset_mutex
&
m
,
const
time_t
timeMS
)
:
mutex
(
&
m
),
locked
(
0
)
locked
(
false
)
{
if
(
timeMS
==
0
)
...
...
@@ -93,18 +93,21 @@ uniset_mutex_lock::uniset_mutex_lock( uniset_mutex& m, const time_t timeMS ):
return
;
}
locked
=
1
;
locked
=
true
;
}
// -----------------------------------------------------------------------------
bool
uniset_mutex_lock
::
lock_ok
()
{
return
(
locked
==
1
)
;
return
locked
;
}
// -----------------------------------------------------------------------------
uniset_mutex_lock
::~
uniset_mutex_lock
()
{
if
(
locked
)
{
mutex
->
unlock
();
locked
=
0
;
locked
=
false
;
}
}
// -----------------------------------------------------------------------------
uniset_rwmutex
::
uniset_rwmutex
(
const
std
::
string
&
name
)
:
...
...
tests/umutex.cc
View file @
465d626e
...
...
@@ -140,6 +140,25 @@ int main( int argc, const char **argv )
try
{
{
cout
<<
"check timed_mutex..."
<<
endl
;
std
::
timed_mutex
m
;
cout
<<
" 'unlock' without 'lock'.."
;
m
.
unlock
();
cout
<<
" ok."
<<
endl
;
cout
<<
"try lock (lock): "
<<
(
m
.
try_lock
()
?
"OK"
:
"FAIL"
)
<<
endl
;
m
.
unlock
();
m
.
lock
();
cout
<<
"try lock (fail): "
<<
(
m
.
try_lock
()
?
"FAIL"
:
"OK"
)
<<
endl
;
m
.
unlock
();
}
{
uniset_mutex
m
(
"testmutex"
);
{
uniset_mutex_lock
l
(
m
);
...
...
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