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
13719a7b
Commit
13719a7b
authored
Sep 30, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogServer): ушёл от использования переменной scount (перевёл на vector)
parent
1ff72a00
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
187 additions
and
193 deletions
+187
-193
UObject_SK.h
extensions/include/UObject_SK.h
+65
-82
UObject_SK.cc
extensions/lib/UObject_SK.cc
+115
-100
LogServer.h
include/LogServer.h
+2
-3
LogServer.cc
src/Log/LogServer.cc
+5
-8
No files found.
extensions/include/UObject_SK.h
View file @
13719a7b
...
...
@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2016-0
8-25
+03:00
// generate timestamp: 2016-0
9-30
+03:00
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#define UObject_SK_H_
...
...
@@ -29,7 +29,7 @@ class UObject_SK:
public
UniSetObject
{
public
:
UObject_SK
(
UniSetTypes
::
ObjectId
id
,
xmlNode
*
node
=
UniSetTypes
::
uniset_conf
()
->
getNode
(
"UObject"
),
const
std
::
string
&
argprefix
=
""
);
UObject_SK
(
UniSetTypes
::
ObjectId
id
,
xmlNode
*
node
=
UniSetTypes
::
uniset_conf
()
->
getNode
(
"UObject"
),
const
std
::
string
&
argprefix
=
""
);
UObject_SK
();
virtual
~
UObject_SK
();
...
...
@@ -41,62 +41,56 @@ class UObject_SK:
virtual
UniSetTypes
::
SimpleInfo
*
getInfo
(
CORBA
::
Long
userparam
=
0
)
override
;
virtual
bool
setMsg
(
UniSetTypes
::
ObjectId
code
,
bool
state
=
true
);
virtual
bool
setMsg
(
UniSetTypes
::
ObjectId
code
,
bool
state
=
true
)
noexcept
;
inline
std
::
shared_ptr
<
DebugStream
>
log
()
{
return
mylog
;
}
inline
std
::
shared_ptr
<
LogAgregator
>
logAgregator
()
{
return
loga
;
}
inline
std
::
shared_ptr
<
DebugStream
>
log
()
noexcept
{
return
mylog
;
}
inline
std
::
shared_ptr
<
LogAgregator
>
logAgregator
()
noexcept
{
return
loga
;
}
void
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
);
void
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
)
noexcept
;
// "синтаксический сахар"..для логов
#ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif
#ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif
#ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif
#ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif
#ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif
#ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif
#ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif
#ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif
#ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif
#ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif
#ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif
#ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif
#ifndef mylogany
#define mylogany log()->any()
#endif
#ifndef vmonit
#define vmonit( var ) vmon.add( #var, var )
#endif
#ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif
#ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif
#ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif
#ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif
#ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif
#ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif
#ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif
#ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif
#ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif
#ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif
#ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif
#ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif
#ifndef mylogany
#define mylogany log()->any()
#endif
#ifndef vmonit
#define vmonit( var ) vmon.add( #var, var )
#endif
// Вспомогательные функции для удобства логирования
// ------------------------------------------------------------
...
...
@@ -113,21 +107,18 @@ class UObject_SK:
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std
::
string
str
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
=
true
)
const
;
std
::
string
str
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
=
true
)
const
;
/*! Вывод значения входа/выхода в формате: in_xxx(SensorName)=val
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std
::
string
strval
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
=
true
)
const
;
std
::
string
strval
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
=
true
)
const
;
/*! Вывод состояния внутренних переменных */
inline
std
::
string
dumpVars
()
{
return
std
::
move
(
vmon
.
pretty_str
());
}
inline
std
::
string
dumpVars
(){
return
std
::
move
(
vmon
.
pretty_str
());
}
// ------------------------------------------------------------
std
::
string
help
()
;
std
::
string
help
()
noexcept
;
...
...
@@ -152,21 +143,21 @@ class UObject_SK:
// ---- end of protected variables ----
virtual
void
callback
()
override
;
virtual
void
callback
()
noexcept
override
;
virtual
void
processingMessage
(
const
UniSetTypes
::
VoidMessage
*
msg
)
override
;
virtual
void
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
{};
virtual
void
askSensors
(
UniversalIO
::
UIOCommand
cmd
)
{}
virtual
void
sensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
)
override
{}
virtual
void
timerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
)
override
{}
virtual
void
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
){};
virtual
void
askSensors
(
UniversalIO
::
UIOCommand
cmd
){}
virtual
void
sensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
)
override
{}
virtual
void
timerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
)
override
{}
virtual
void
sigterm
(
int
signo
)
override
;
virtual
bool
activateObject
()
override
;
virtual
std
::
string
getMonitInfo
()
{
return
""
;
/*!< пользовательская информация выводимая в getInfo() */
}
virtual
std
::
string
getMonitInfo
(){
return
""
;
}
/*!< пользовательская информация выводимая в getInfo() */
// Выполнение очередного шага программы
virtual
void
step
()
{}
virtual
void
step
(){}
void
preAskSensors
(
UniversalIO
::
UIOCommand
cmd
);
void
preSysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
);
virtual
void
testMode
(
bool
state
);
void
updateOutputs
(
bool
force
);
...
...
@@ -192,15 +183,9 @@ class UObject_SK:
xmlNode
*
confnode
;
/*! получить числовое свойство из конф. файла по привязанной confnode */
int
getIntProp
(
const
std
::
string
&
name
)
{
return
UniSetTypes
::
uniset_conf
()
->
getIntProp
(
confnode
,
name
);
}
int
getIntProp
(
const
std
::
string
&
name
)
{
return
UniSetTypes
::
uniset_conf
()
->
getIntProp
(
confnode
,
name
);
}
/*! получить текстовое свойство из конф. файла по привязанной confnode */
inline
const
std
::
string
getProp
(
const
std
::
string
&
name
)
{
return
UniSetTypes
::
uniset_conf
()
->
getProp
(
confnode
,
name
);
}
inline
const
std
::
string
getProp
(
const
std
::
string
&
name
)
{
return
UniSetTypes
::
uniset_conf
()
->
getProp
(
confnode
,
name
);
}
timeout_t
smReadyTimeout
;
/*!< время ожидания готовности SM */
std
::
atomic_bool
activated
;
...
...
@@ -235,11 +220,9 @@ class UObject_SK:
// Используемые идентификаторы сообщений
// ------------ private функции ---------------
void
updatePreviousValues
();
void
preAskSensors
(
UniversalIO
::
UIOCommand
cmd
);
void
updatePreviousValues
()
noexcept
;
void
preSensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
);
void
preTimerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
);
void
preSysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
);
void
initFromSM
();
void
checkSensors
();
// --------------------------------------------
...
...
extensions/lib/UObject_SK.cc
View file @
13719a7b
...
...
@@ -11,7 +11,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2016-0
8-25
+03:00
// generate timestamp: 2016-0
9-30
+03:00
// -----------------------------------------------------------------------------
#include <memory>
#include <iomanip>
...
...
@@ -32,28 +32,28 @@ using namespace UniSetTypes;
// -----------------------------------------------------------------------------
UObject_SK
::
UObject_SK
()
:
// Инициализация идентификаторов (имена берутся из конф. файла)
// Инициализация идентификаторов (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла)
// variables (public and proteced)
// variables (public and proteced)
// ------------------
active
(
false
),
// ------------------
active
(
false
),
idHeartBeat
(
DefaultObjectId
),
maxHeartBeat
(
10
),
confnode
(
0
),
smReadyTimeout
(
0
),
activated
(
false
),
askPause
(
2000
),
forceOut
(
false
),
// private variables
idHeartBeat
(
DefaultObjectId
),
maxHeartBeat
(
10
),
confnode
(
0
),
smReadyTimeout
(
0
),
activated
(
false
),
askPause
(
2000
),
forceOut
(
false
),
// private variables
end_private
(
false
)
end_private
(
false
)
{
mycrit
<<
"UObject: init failed!!!!!!!!!!!!!!!"
<<
endl
;
throw
Exception
(
string
(
myname
+
": init failed!!!"
)
);
throw
Exception
(
string
(
myname
+
": init failed!!!"
)
);
}
// -----------------------------------------------------------------------------
// ( val, confval, default val )
...
...
@@ -61,7 +61,6 @@ static const std::string init3_str( const std::string& s1, const std::string& s2
{
if
(
!
s1
.
empty
()
)
return
s1
;
if
(
!
s2
.
empty
()
)
return
s2
;
...
...
@@ -75,41 +74,41 @@ static UniSetTypes::ObjectId init_node( xmlNode* cnode, const std::string& prop
auto
conf
=
uniset_conf
();
if
(
conf
->
getProp
(
cnode
,
prop
).
empty
()
)
if
(
conf
->
getProp
(
cnode
,
prop
).
empty
()
)
return
conf
->
getLocalNode
();
return
conf
->
getNodeID
(
conf
->
getProp
(
cnode
,
prop
));
return
conf
->
getNodeID
(
conf
->
getProp
(
cnode
,
prop
));
}
// -----------------------------------------------------------------------------
UObject_SK
::
UObject_SK
(
ObjectId
id
,
xmlNode
*
cnode
,
const
std
::
string
&
_argprefix
)
:
UniSetObject
(
id
),
// Инициализация идентификаторов (имена берутся из конф. файла)
UniSetObject
(
id
),
// Инициализация идентификаторов (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла)
// variables
// variables
sleep_msec
(
150
),
active
(
true
),
argprefix
(
(
_argprefix
.
empty
()
?
myname
+
"-"
:
_argprefix
)
),
sleep_msec
(
150
),
active
(
true
),
argprefix
(
(
_argprefix
.
empty
()
?
myname
+
"-"
:
_argprefix
)
),
idHeartBeat
(
DefaultObjectId
),
maxHeartBeat
(
10
),
confnode
(
cnode
),
smReadyTimeout
(
0
),
activated
(
false
),
askPause
(
uniset_conf
()
->
getPIntProp
(
cnode
,
"askPause"
,
2000
)),
forceOut
(
false
),
idHeartBeat
(
DefaultObjectId
),
maxHeartBeat
(
10
),
confnode
(
cnode
),
smReadyTimeout
(
0
),
activated
(
false
),
askPause
(
uniset_conf
()
->
getPIntProp
(
cnode
,
"askPause"
,
2000
)),
forceOut
(
false
),
end_private
(
false
)
end_private
(
false
)
{
auto
conf
=
uniset_conf
();
if
(
UniSetTypes
::
findArgParam
(
"--print-id-list"
,
uniset_conf
()
->
getArgc
(),
uniset_conf
()
->
getArgv
())
!=
-
1
)
if
(
UniSetTypes
::
findArgParam
(
"--print-id-list"
,
uniset_conf
()
->
getArgc
(),
uniset_conf
()
->
getArgv
())
!=
-
1
)
{
// abort();
// abort();
}
...
...
@@ -125,10 +124,10 @@ UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argpref
{
ostringstream
s
;
s
<<
argprefix
<<
"log"
;
conf
->
initLogStream
(
mylog
,
s
.
str
());
conf
->
initLogStream
(
mylog
,
s
.
str
());
}
loga
=
make_shared
<
LogAgregator
>
(
myname
+
"-loga"
);
loga
=
make_shared
<
LogAgregator
>
(
myname
+
"-loga"
);
loga
->
add
(
mylog
);
loga
->
add
(
ulog
());
...
...
@@ -146,14 +145,12 @@ UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argpref
logserv_port
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"logserver-port"
,
it
.
getProp
(
"logserverPort"
),
getId
());
}
forceOut
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"force-out"
,
it
.
getProp
(
"forceOut"
),
false
);
string
heart
=
conf
->
getArgParam
(
"--"
+
argprefix
+
"heartbeat-id"
,
it
.
getProp
(
"heartbeat_id"
));
forceOut
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"force-out"
,
it
.
getProp
(
"forceOut"
),
false
);
string
heart
=
conf
->
getArgParam
(
"--"
+
argprefix
+
"heartbeat-id"
,
it
.
getProp
(
"heartbeat_id"
));
if
(
!
heart
.
empty
()
)
{
idHeartBeat
=
conf
->
getSensorID
(
heart
);
if
(
idHeartBeat
==
DefaultObjectId
)
{
ostringstream
err
;
...
...
@@ -161,14 +158,13 @@ UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argpref
throw
SystemError
(
err
.
str
());
}
int
heartbeatTime
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"heartbeat-time"
,
it
.
getProp
(
"heartbeatTime"
),
conf
->
getHeartBeatTime
());
if
(
heartbeatTime
>
0
)
int
heartbeatTime
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"heartbeat-time"
,
it
.
getProp
(
"heartbeatTime"
),
conf
->
getHeartBeatTime
());
if
(
heartbeatTime
>
0
)
ptHeartBeat
.
setTiming
(
heartbeatTime
);
else
ptHeartBeat
.
setTiming
(
UniSetTimer
::
WaitUpTime
);
maxHeartBeat
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"heartbeat-max"
,
it
.
getProp
(
"heartbeat_max"
),
10
);
maxHeartBeat
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"heartbeat-max"
,
it
.
getProp
(
"heartbeat_max"
),
10
);
}
// Инициализация значений
...
...
@@ -177,18 +173,16 @@ UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argpref
si
.
id
=
UniSetTypes
::
DefaultObjectId
;
si
.
node
=
conf
->
getLocalNode
();
sleep_msec
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"sleep-msec"
,
"150"
,
150
);
sleep_msec
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"sleep-msec"
,
"150"
,
150
);
string
s_resetTime
(
""
);
if
(
s_resetTime
.
empty
()
)
s_resetTime
=
"500"
;
resetMsgTime
=
uni_atoi
(
init3_str
(
conf
->
getArgParam
(
"--"
+
argprefix
+
"resetMsgTime"
),
conf
->
getProp
(
cnode
,
"resetMsgTime"
),
s_resetTime
));
resetMsgTime
=
uni_atoi
(
init3_str
(
conf
->
getArgParam
(
"--"
+
argprefix
+
"resetMsgTime"
),
conf
->
getProp
(
cnode
,
"resetMsgTime"
),
s_resetTime
));
ptResetMsg
.
setTiming
(
resetMsgTime
);
int
sm_tout
=
conf
->
getArgInt
(
"--"
+
argprefix
+
"sm-ready-timeout"
,
""
);
int
sm_tout
=
conf
->
getArgInt
(
"--"
+
argprefix
+
"sm-ready-timeout"
,
""
);
if
(
sm_tout
==
0
)
smReadyTimeout
=
60000
;
else
if
(
sm_tout
<
0
)
...
...
@@ -196,7 +190,7 @@ UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argpref
else
smReadyTimeout
=
sm_tout
;
smTestID
=
conf
->
getSensorID
(
init3_str
(
conf
->
getArgParam
(
"--"
+
argprefix
+
"sm-test-id"
),
conf
->
getProp
(
cnode
,
"smTestID"
),
""
));
smTestID
=
conf
->
getSensorID
(
init3_str
(
conf
->
getArgParam
(
"--"
+
argprefix
+
"sm-test-id"
),
conf
->
getProp
(
cnode
,
"smTestID"
),
""
));
if
(
smTestID
==
DefaultObjectId
)
...
...
@@ -219,6 +213,11 @@ UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argpref
vmonit
(
maxHeartBeat
);
vmonit
(
activateTimeout
);
vmonit
(
smReadyTimeout
);
// help надо выводить в конце, когда уже все переменные инициализированы по умолчанию
if
(
UniSetTypes
::
findArgParam
(
"--"
+
argprefix
+
"help"
,
uniset_conf
()
->
getArgc
(),
uniset_conf
()
->
getArgv
())
!=
-
1
)
cout
<<
help
()
<<
endl
;
}
// -----------------------------------------------------------------------------
...
...
@@ -233,7 +232,7 @@ void UObject_SK::updateValues()
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
updatePreviousValues
()
void
UObject_SK
::
updatePreviousValues
()
noexcept
{
}
...
...
@@ -243,7 +242,7 @@ void UObject_SK::checkSensors()
}
// -----------------------------------------------------------------------------
bool
UObject_SK
::
setMsg
(
UniSetTypes
::
ObjectId
_code
,
bool
_state
)
bool
UObject_SK
::
setMsg
(
UniSetTypes
::
ObjectId
_code
,
bool
_state
)
noexcept
{
if
(
_code
==
UniSetTypes
::
DefaultObjectId
)
{
...
...
@@ -269,7 +268,7 @@ bool UObject_SK::setMsg( UniSetTypes::ObjectId _code, bool _state )
void
UObject_SK
::
resetMsg
()
{
mylog8
<<
myname
<<
"(resetMsg): reset messages.."
<<
endl
;
// reset messages
// reset messages
}
// -----------------------------------------------------------------------------
...
...
@@ -307,23 +306,19 @@ std::string UObject_SK::dumpIO()
s
<<
endl
;
int
n
=
0
;
for
(
const
auto
&
e
:
v_in
)
for
(
const
auto
&
e
:
v_in
)
{
s
<<
e
;
if
(
(
n
++
)
%
2
)
if
(
(
n
++
)
%
2
)
s
<<
std
::
endl
;
}
s
<<
endl
;
n
=
0
;
for
(
const
auto
&
e
:
v_out
)
for
(
const
auto
&
e
:
v_out
)
{
s
<<
e
;
if
(
(
n
++
)
%
2
)
if
(
(
n
++
)
%
2
)
s
<<
std
::
endl
;
}
...
...
@@ -348,7 +343,7 @@ std::string UObject_SK::strval( UniSetTypes::ObjectId id, bool showLinkName ) c
// --------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
void
UObject_SK
::
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
)
void
UObject_SK
::
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
)
noexcept
{
UObject_SK
::
mylog
=
d
;
}
...
...
@@ -375,9 +370,9 @@ void UObject_SK::processingMessage( const UniSetTypes::VoidMessage* _msg )
break
;
}
}
catch
(
const
E
xception
&
ex
)
catch
(
const
std
::
e
xception
&
ex
)
{
mycrit
<<
myname
<<
"(processingMessage): "
<<
ex
<<
endl
;
mycrit
<<
myname
<<
"(processingMessage): "
<<
ex
.
what
()
<<
endl
;
}
}
// -----------------------------------------------------------------------------
...
...
@@ -387,13 +382,11 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
{
case
SystemMessage
:
:
WatchDog
:
myinfo
<<
myname
<<
"(preSysCommand): WatchDog"
<<
endl
;
if
(
!
active
||
!
ptStartUpTimeout
.
checkTime
()
)
{
mywarn
<<
myname
<<
"(preSysCommand): игнорируем WatchDog, потому-что только-что стартанули"
<<
endl
;
break
;
}
case
SystemMessage
:
:
StartUp
:
{
if
(
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
&&
!
logserv
->
isRunning
()
)
...
...
@@ -426,12 +419,14 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
// переоткрываем логи
mylogany
<<
myname
<<
"(preSysCommand): logRotate"
<<
endl
;
string
fname
(
log
()
->
getLogFile
()
);
if
(
!
fname
.
empty
()
)
{
mylog
->
logFile
(
fname
.
c_str
(),
true
);
mylog
->
logFile
(
fname
.
c_str
(),
true
);
mylogany
<<
myname
<<
"(preSysCommand): ***************** mylog LOG ROTATE *****************"
<<
endl
;
}
if
(
logserv
&&
!
logserv_host
.
empty
()
&&
logserv_port
!=
0
)
logserv
->
check
(
true
);
}
break
;
...
...
@@ -450,21 +445,28 @@ UniSetTypes::SimpleInfo* UObject_SK::getInfo( CORBA::Long userparam )
ostringstream
inf
;
inf
<<
i
->
info
<<
endl
;
inf
<<
"LogServer: "
<<
logserv_host
<<
":"
<<
logserv_port
<<
endl
;
if
(
logserv
/* && userparam < 0 */
)
{
inf
<<
"LogServer: "
<<
logserv_host
<<
":"
<<
logserv_port
<<
(
logserv
->
isRunning
()
?
" [RUNNIG]"
:
" [FAILED]"
)
<<
endl
;
inf
<<
" "
<<
logserv
->
getShortInfo
()
<<
endl
;
}
else
inf
<<
"LogServer: NONE"
<<
endl
;
inf
<<
dumpIO
()
<<
endl
;
inf
<<
endl
;
auto
timers
=
getTimersList
();
inf
<<
"Timers["
<<
timers
.
size
()
<<
"]:"
<<
endl
;
for
(
const
auto
&
t
:
timers
)
for
(
const
auto
&
t
:
timers
)
{
inf
<<
" "
<<
setw
(
15
)
<<
getTimerName
(
t
.
id
)
<<
"["
<<
t
.
id
<<
"]: msec="
<<
setw
(
6
)
<<
t
.
tmr
.
getInterval
()
<<
" timeleft="
<<
setw
(
6
)
<<
t
.
curTimeMS
<<
" tick="
<<
setw
(
3
)
<<
(
t
.
curTick
>=
0
?
t
.
curTick
:
-
1
)
<<
" tick="
<<
setw
(
3
)
<<
(
t
.
curTick
>=
0
?
t
.
curTick
:
-
1
)
<<
endl
;
}
inf
<<
endl
;
inf
<<
vmon
.
pretty_str
()
<<
endl
;
inf
<<
endl
;
...
...
@@ -518,7 +520,7 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<<
" testID="
<<
_testID
<<
endl
;
// waitReady можно использовать т.к. датчик это по сути IONotifyController
if
(
!
ui
->
waitReady
(
_testID
,
wait_msec
)
)
if
(
!
ui
->
waitReady
(
_testID
,
wait_msec
)
)
{
ostringstream
err
;
err
<<
myname
...
...
@@ -526,14 +528,14 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<<
wait_msec
<<
" мсек"
;
mycrit
<<
err
.
str
()
<<
endl
;
// terminate();
// abort();
// terminate();
// abort();
raise
(
SIGTERM
);
terminate
();
// throw SystemError(err.str());
// throw SystemError(err.str());
}
if
(
!
ui
->
waitWorking
(
_testID
,
wait_msec
)
)
if
(
!
ui
->
waitWorking
(
_testID
,
wait_msec
)
)
{
ostringstream
err
;
err
<<
myname
...
...
@@ -541,16 +543,34 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<<
wait_msec
<<
" мсек"
;
mycrit
<<
err
.
str
()
<<
endl
;
// terminate();
// abort();
// terminate();
// abort();
raise
(
SIGTERM
);
// throw SystemError(err.str());
// throw SystemError(err.str());
}
}
// ----------------------------------------------------------------------------
std
::
string
UObject_SK
::
help
()
std
::
string
UObject_SK
::
help
()
noexcept
{
ostringstream
s
;
s
<<
" ************* "
<<
myname
<<
" HELP:"
<<
" ************* "
<<
endl
;
s
<<
"Init default values: "
<<
endl
;
s
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"sm-ready-timeout msec - wait SM ready for ask sensors. Now: "
<<
smReadyTimeout
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"sm-test-id msec sensor - sensor for test SM ready. Now: "
<<
smTestID
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"sleep-msec msec - step period. Now: "
<<
sleep_msec
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"activate-timeout msec - activate process timeout. Now: "
<<
activateTimeout
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"startup-timeout msec - wait startup timeout. Now: "
<<
ptStartUpTimeout
.
getInterval
()
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"force-out [0|1] - 1 - save out-values in SM at each step. Now: "
<<
forceOut
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"heartbeat-max num - max value for heartbeat counter. Now: "
<<
maxHeartBeat
<<
endl
;
s
<<
"--"
<<
argprefix
<<
"heartbeat-time msec - heartbeat periond. Now: "
<<
ptHeartBeat
.
getInterval
()
<<
endl
;
s
<<
endl
;
s
<<
"--print-id-list - print ID list"
<<
endl
;
s
<<
endl
;
s
<<
" ****************************************************************************************** "
<<
endl
;
return
std
::
move
(
s
.
str
());
...
...
@@ -558,46 +578,43 @@ std::string UObject_SK::help()
// ----------------------------------------------------------------------------
// --------------------------------------------------------------------------
void
UObject_SK
::
callback
()
void
UObject_SK
::
callback
()
noexcept
{
if
(
!
active
)
return
;
try
{
// проверка таймеров
checkTimers
(
this
);
if
(
resetMsgTime
>
0
&&
trResetMsg
.
hi
(
ptResetMsg
.
checkTime
())
)
if
(
resetMsgTime
>
0
&&
trResetMsg
.
hi
(
ptResetMsg
.
checkTime
())
)
{
// cout << myname << ": ********* reset messages *********" << endl;
// cout << myname << ": ********* reset messages *********" << endl;
resetMsg
();
}
// обработка сообщений (таймеров и т.п.)
for
(
unsigned
int
i
=
0
;
i
<
20
;
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
20
;
i
++
)
{
auto
m
=
receiveMessage
();
if
(
!
m
)
break
;
processingMessage
(
m
.
get
());
updateOutputs
(
forceOut
);
// updatePreviousValues();
// updatePreviousValues();
}
// Выполнение шага программы
step
();
// "сердцебиение"
if
(
idHeartBeat
!=
DefaultObjectId
&&
ptHeartBeat
.
checkTime
()
)
if
(
idHeartBeat
!=
DefaultObjectId
&&
ptHeartBeat
.
checkTime
()
)
{
try
{
ui
->
setValue
(
idHeartBeat
,
maxHeartBeat
);
ui
->
setValue
(
idHeartBeat
,
maxHeartBeat
);
ptHeartBeat
.
reset
();
}
catch
(
const
Exception
&
ex
)
...
...
@@ -619,7 +636,7 @@ void UObject_SK::callback()
mycrit
<<
myname
<<
"(execute): СORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
}
catch
(
const
std
::
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
mycrit
<<
myname
<<
"(execute): catch "
<<
ex
.
what
()
<<
endl
;
}
...
...
@@ -637,7 +654,7 @@ void UObject_SK::setValue( UniSetTypes::ObjectId _sid, long _val )
ui
->
setValue
(
_sid
,
_val
);
ui
->
setValue
(
_sid
,
_val
);
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
updateOutputs
(
bool
_force
)
...
...
@@ -659,7 +676,7 @@ void UObject_SK::initFromSM()
// -----------------------------------------------------------------------------
void
UObject_SK
::
askSensor
(
UniSetTypes
::
ObjectId
_sid
,
UniversalIO
::
UIOCommand
_cmd
,
UniSetTypes
::
ObjectId
_node
)
{
ui
->
askRemoteSensor
(
_sid
,
_cmd
,
_node
,
getId
());
ui
->
askRemoteSensor
(
_sid
,
_cmd
,
_node
,
getId
());
}
// -----------------------------------------------------------------------------
long
UObject_SK
::
getValue
(
UniSetTypes
::
ObjectId
_sid
)
...
...
@@ -681,12 +698,10 @@ long UObject_SK::getValue( UniSetTypes::ObjectId _sid )
void
UObject_SK
::
preAskSensors
(
UniversalIO
::
UIOCommand
_cmd
)
{
PassiveTimer
ptAct
(
activateTimeout
);
while
(
!
activated
&&
!
ptAct
.
checkTime
()
)
{
cout
<<
myname
<<
"(preAskSensors): wait activate..."
<<
endl
;
msleep
(
300
);
if
(
activated
)
break
;
}
...
...
@@ -706,7 +721,7 @@ void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd )
{
mycrit
<<
myname
<<
"(preAskSensors): "
<<
ex
<<
endl
;
}
catch
(
const
std
::
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
mycrit
<<
myname
<<
"(execute): catch "
<<
ex
.
what
()
<<
endl
;
}
...
...
include/LogServer.h
View file @
13719a7b
...
...
@@ -17,7 +17,7 @@
#ifndef LogServer_H_
#define LogServer_H_
// -------------------------------------------------------------------------
#include <
list
>
#include <
vector
>
#include <string>
#include <memory>
#include <unordered_map>
...
...
@@ -138,9 +138,8 @@ class LogServer:
std
::
string
onCommand
(
LogSession
*
s
,
LogServerTypes
::
Command
cmd
,
const
std
::
string
&
logname
);
private
:
typedef
std
::
list
<
std
::
shared_ptr
<
LogSession
>
>
SessionList
;
typedef
std
::
vector
<
std
::
shared_ptr
<
LogSession
>
>
SessionList
;
SessionList
slist
;
size_t
scount
=
{
0
};
UniSetTypes
::
uniset_rwmutex
mutSList
;
timeout_t
timeout
=
{
UniSetTimer
::
WaitUpTime
};
...
...
src/Log/LogServer.cc
View file @
13719a7b
...
...
@@ -46,6 +46,7 @@ LogServer::LogServer( std::shared_ptr<LogAgregator> log ) noexcept:
}
// -------------------------------------------------------------------------
LogServer
::
LogServer
(
std
::
shared_ptr
<
DebugStream
>
log
)
noexcept
:
slist
(
sessMaxCount
),
timeout
(
UniSetTimer
::
WaitUpTime
),
cmdTimeout
(
2000
),
sessLogLevel
(
Debug
::
NONE
),
...
...
@@ -55,6 +56,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept:
}
// -------------------------------------------------------------------------
LogServer
::
LogServer
()
noexcept
:
slist
(
sessMaxCount
),
timeout
(
UniSetTimer
::
WaitUpTime
),
cmdTimeout
(
2000
),
sessLogLevel
(
Debug
::
NONE
),
...
...
@@ -213,7 +215,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
{
uniset_rwmutex_wrlock
l
(
mutSList
);
if
(
s
count
>=
sessMaxCount
)
if
(
s
list
.
size
()
>=
sessMaxCount
)
{
if
(
mylog
.
is_crit
()
)
mylog
.
crit
()
<<
myname
<<
"(LogServer::ioAccept): session limit("
<<
sessMaxCount
<<
")"
<<
endl
;
...
...
@@ -233,13 +235,10 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
s
->
signal_logsession_command
().
connect
(
sigc
::
mem_fun
(
this
,
&
LogServer
::
onCommand
)
);
{
uniset_rwmutex_wrlock
l
(
mutSList
);
scount
++
;
slist
.
push_back
(
s
);
// на первой сессии запоминаем состояние логов
if
(
s
count
==
1
)
if
(
s
list
.
size
()
==
1
)
saveDefaultLogLevels
(
"ALL"
);
slist
.
push_back
(
s
);
}
s
->
run
(
watcher
.
loop
);
...
...
@@ -259,14 +258,12 @@ void LogServer::sessionFinished( LogSession* s )
if
(
i
->
get
()
==
s
)
{
slist
.
erase
(
i
);
scount
--
;
break
;
}
}
if
(
slist
.
empty
()
)
{
scount
=
0
;
// восстанавливаем уровни логов по умолчанию
restoreDefaultLogLevels
(
"ALL"
);
}
...
...
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