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
90a08483
Commit
90a08483
authored
Jan 25, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Log): перевёл LogServer и LogAgregator на использование (только)
shared_ptr.
parent
3bf24d0d
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
492 additions
and
463 deletions
+492
-463
log-stdin.cc
Utilities/ULog/log-stdin.cc
+2
-2
log-wrap.cc
Utilities/ULog/log-wrap.cc
+3
-3
log.cc
Utilities/ULog/log.cc
+24
-8
logserver.cc
Utilities/ULog/logserver.cc
+19
-5
libuniset2.spec
conf/libuniset2.spec
+1
-0
smemory-plus.cc
extensions/SharedMemoryPlus/smemory-plus.cc
+11
-38
UObject_SK.h
extensions/include/UObject_SK.h
+102
-102
UObject_SK.cc
extensions/lib/UObject_SK.cc
+288
-288
LogReader.h
include/LogReader.h
+8
-0
LogServer.h
include/LogServer.h
+5
-2
LogSession.h
include/LogSession.h
+4
-0
LogReader.cc
src/Log/LogReader.cc
+9
-3
LogServer.cc
src/Log/LogServer.cc
+8
-11
LogSession.cc
src/Log/LogSession.cc
+8
-1
No files found.
Utilities/ULog/log-stdin.cc
View file @
90a08483
...
...
@@ -65,7 +65,7 @@ int main( int argc, char* argv[], char* envp[] )
if
(
verb
)
cout
<<
"(init): listen "
<<
addr
<<
":"
<<
port
<<
endl
;
DebugStream
log
;
auto
log
=
make_shared
<
DebugStream
>
()
;
LogServer
ls
(
log
);
ls
.
run
(
addr
,
port
,
true
);
...
...
@@ -78,7 +78,7 @@ int main( int argc, char* argv[], char* envp[] )
if
(
r
>
0
)
{
buf
[
r
]
=
'\0'
;
log
<<
buf
;
(
*
(
log
.
get
()))
<<
buf
;
}
}
}
...
...
Utilities/ULog/log-wrap.cc
View file @
90a08483
...
...
@@ -74,8 +74,8 @@ int main( int argc, char* argv[], char* envp[] )
/* Parent. */
close
(
cp
[
1
]);
DebugStream
zlog
;
zlog
.
addLevel
(
Debug
::
ANY
);
auto
zlog
=
make_shared
<
DebugStream
>
()
;
zlog
->
addLevel
(
Debug
::
ANY
);
LogServer
ls
(
zlog
);
...
...
@@ -90,7 +90,7 @@ int main( int argc, char* argv[], char* envp[] )
if
(
r
>
0
)
{
buf
[
r
]
=
'\0'
;
zlog
<<
buf
;
(
*
(
zlog
.
get
()))
<<
buf
;
}
}
...
...
Utilities/ULog/log.cc
View file @
90a08483
...
...
@@ -23,24 +23,28 @@ static struct option longopts[] = {
{
"rotate"
,
required_argument
,
0
,
'r'
},
{
"logname"
,
required_argument
,
0
,
'l'
},
{
"command-only"
,
no_argument
,
0
,
'b'
},
{
"timeout"
,
required_argument
,
0
,
'w'
},
{
"reconnect-delay"
,
required_argument
,
0
,
'x'
},
{
NULL
,
0
,
0
,
0
}
};
// --------------------------------------------------------------------------
static
void
print_help
()
{
printf
(
"-h, --help - this message
\n
"
);
printf
(
"-v, --verbose - Print all messages to stdout
\n
"
);
printf
(
"[-i|--iaddr] addr - LogServer ip or hostname.
\n
"
);
printf
(
"[-p|--port] port - LogServer port.
\n
"
);
printf
(
"[-l|--logname] name - Send command only for 'logname'.
\n
"
);
printf
(
"[-b|--command-only] - Send command and break. (No read logs).
\n
"
);
printf
(
"-h, --help - this message
\n
"
);
printf
(
"-v, --verbose - Print all messages to stdout
\n
"
);
printf
(
"[-i|--iaddr] addr - LogServer ip or hostname.
\n
"
);
printf
(
"[-p|--port] port - LogServer port.
\n
"
);
printf
(
"[-l|--logname] name - Send command only for 'logname'.
\n
"
);
printf
(
"[-b|--command-only] - Send command and break. (No read logs).
\n
"
);
printf
(
"[-w|--timeout] msec - Timeout for wait data. Default: 0 - endless waiting
\n
"
);
printf
(
"[-x|--reconnect-delay] msec - Pause for repeat connect to LogServer. Default: 5000 msec.
\n
"
);
printf
(
"
\n
"
);
printf
(
"Commands:
\n
"
);
printf
(
"[--add | -a] info,warn,crit,... - Add log levels.
\n
"
);
printf
(
"[--del | -d] info,warn,crit,... - Delete log levels.
\n
"
);
printf
(
"[--set | -s] info,wa
nr
,crit,... - Set log levels.
\n
"
);
printf
(
"[--set | -s] info,wa
rn
,crit,... - Set log levels.
\n
"
);
printf
(
"--off, -o - Off the write log file (if enabled).
\n
"
);
printf
(
"--on, -n - On the write log file (if before disabled).
\n
"
);
printf
(
"--rotate, -r - rotate log file.
\n
"
);
...
...
@@ -59,10 +63,12 @@ int main( int argc, char **argv )
string
sdata
(
""
);
int
cmdonly
=
0
;
string
logname
(
""
);
timeout_t
tout
=
0
;
timeout_t
rdelay
=
5000
;
try
{
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hva:p:i:d:s:l:onrb"
,
longopts
,
&
optindex
))
!=
-
1
)
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hva:p:i:d:s:l:onrb
x:w:
"
,
longopts
,
&
optindex
))
!=
-
1
)
{
switch
(
opt
)
{
...
...
@@ -114,6 +120,14 @@ int main( int argc, char **argv )
port
=
uni_atoi
(
optarg
);
break
;
case
'x'
:
rdelay
=
uni_atoi
(
optarg
);
break
;
case
'w'
:
tout
=
uni_atoi
(
optarg
);
break
;
case
'v'
:
verb
=
1
;
break
;
...
...
@@ -134,6 +148,8 @@ int main( int argc, char **argv )
LogReader
lr
;
lr
.
setCommandOnlyMode
(
cmdonly
);
lr
.
setinTimeout
(
tout
);
lr
.
setReconnectDelay
(
rdelay
);
if
(
!
sdata
.
empty
()
)
{
...
...
Utilities/ULog/logserver.cc
View file @
90a08483
...
...
@@ -81,14 +81,29 @@ int main( int argc, char **argv )
// dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
}
LogAgregator
la
;
auto
la
=
make_shared
<
LogAgregator
>
()
;
auto
dlog
=
make_shared
<
DebugStream
>
();
dlog
->
setLogName
(
"dlog"
);
la
.
add
(
dlog
);
la
->
add
(
dlog
);
auto
dlog2
=
la
.
create
(
"dlog2"
);
auto
dlog2
=
la
->
create
(
"dlog2"
);
if
(
la
->
getLog
(
"dlog"
)
==
nullptr
)
{
cerr
<<
"Not found 'dlog'"
<<
endl
;
return
1
;
}
if
(
la
->
getLog
(
"dlog2"
)
==
nullptr
)
{
cerr
<<
"Not found 'dlog2'"
<<
endl
;
return
1
;
}
LogServer
ls
(
la
);
// LogServer ls(cout);
...
...
@@ -96,7 +111,7 @@ int main( int argc, char **argv )
dlog2
->
addLevel
(
Debug
::
ANY
);
ls
.
run
(
addr
,
port
,
true
);
#if 0
ls
.
setSessionLog
(
Debug
::
ANY
);
unsigned
int
i
=
0
;
while
(
true
)
...
...
@@ -112,7 +127,6 @@ int main( int argc, char **argv )
msleep
(
delay
);
}
#endif
}
catch
(
SystemError
&
err
)
{
...
...
conf/libuniset2.spec
View file @
90a08483
...
...
@@ -409,6 +409,7 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
* Fri Jan 23 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt13
- refactoring ulog and dlog: Objects converted to shared_ptr<DebugStream>
for subsequent use LogAgregator.
- modify interface for LogReader,LogSession,LogServer
* Fri Jan 23 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt12
- refactoring LogAgregator,LogServer,LogSesson --> use shared_ptr
...
...
extensions/SharedMemoryPlus/smemory-plus.cc
View file @
90a08483
...
...
@@ -2,6 +2,7 @@
#include <string>
#include <error.h>
#include <errno.h>
#include <memory>
#include <Debug.h>
#include <UniSetActivator.h>
#include <ThreadCreator.h>
...
...
@@ -26,37 +27,11 @@ using namespace UniSetExtensions;
const
unsigned
int
MaxAddNum
=
10
;
// --------------------------------------------------------------------------
static
void
help_print
(
int
argc
,
const
char
*
argv
[]
);
static
LogServer
*
run_logserver
(
const
std
::
string
&
cnamem
,
DebugStream
&
log
);
static
LogServer
*
logserver
=
0
;
static
std
::
shared_ptr
<
LogServer
>
run_logserver
(
const
std
::
string
&
cnamem
,
std
::
shared_ptr
<
LogAgregator
>&
log
);
#ifdef UNISET_ENABLE_IO
std
::
list
<
ThreadCreator
<
IOControl
>*
>
lst_iothr
;
#endif
// --------------------------------------------------------------------------
void
activator_terminate
(
int
signo
)
{
if
(
logserver
)
{
try
{
delete
logserver
;
logserver
=
0
;
}
catch
(...){}
}
#ifdef UNISET_IO_ENABLE
for
(
auto
&
i
:
lst_iothr
)
{
try
{
i
->
stop
();
}
catch
(...){}
}
#endif
}
// --------------------------------------------------------------------------
int
main
(
int
argc
,
const
char
**
argv
)
{
std
::
ios
::
sync_with_stdio
(
false
);
...
...
@@ -77,7 +52,7 @@ int main( int argc, const char **argv )
dlog
()
->
logFile
(
logname
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
signal_terminate_event
().
connect
(
&
activator_terminate
);
//
act->signal_terminate_event().connect( &activator_terminate );
// ------------ SharedMemory ----------------
auto
shm
=
SharedMemory
::
init_smemory
(
argc
,
argv
);
if
(
!
shm
)
...
...
@@ -212,11 +187,11 @@ int main( int argc, const char **argv )
i
->
start
();
#endif
LogAgregator
la
;
la
.
add
(
ulog
());
la
.
add
(
dlog
());
auto
la
=
make_shared
<
LogAgregator
>
()
;
la
->
add
(
ulog
());
la
->
add
(
dlog
());
logserver
=
run_logserver
(
"smplus"
,
la
);
auto
logserver
=
run_logserver
(
"smplus"
,
la
);
if
(
logserver
==
0
)
{
cerr
<<
"(smemory-plus): run logserver for 'smplus' FAILED"
<<
endl
;
...
...
@@ -280,7 +255,7 @@ void help_print( int argc, const char* argv[] )
cout
<<
"--logfile - Use logfile. Default: smemory-plus.log"
<<
endl
;
}
// -----------------------------------------------------------------------------
LogServer
*
run_logserver
(
const
std
::
string
&
cname
,
DebugStream
&
log
)
std
::
shared_ptr
<
LogServer
>
run_logserver
(
const
std
::
string
&
cname
,
std
::
shared_ptr
<
LogAgregator
>
&
log
)
{
auto
conf
=
uniset_conf
();
auto
xml
=
conf
->
getConfXML
();
...
...
@@ -294,7 +269,7 @@ LogServer* run_logserver( const std::string& cname, DebugStream& log )
UniXML
::
iterator
it
(
cnode
);
LogServer
*
ls
=
new
LogServer
(
log
);
auto
ls
=
make_shared
<
LogServer
>
(
log
);
timeout_t
sessTimeout
=
conf
->
getArgPInt
(
"--"
+
cname
+
"-session-timeout"
,
it
.
getProp
(
"sessTimeout"
),
3600000
);
timeout_t
cmdTimeout
=
conf
->
getArgPInt
(
"--"
+
cname
+
"-cmd-timeout"
,
it
.
getProp
(
"cmdTimeout"
),
2000
);
...
...
@@ -308,16 +283,14 @@ LogServer* run_logserver( const std::string& cname, DebugStream& log )
if
(
host
.
empty
()
)
{
cerr
<<
"(init_ulogserver): "
<<
cname
<<
": unknown host.."
<<
endl
;
delete
ls
;
return
0
;
return
nullptr
;
}
ost
::
tpport_t
port
=
conf
->
getArgPInt
(
"--"
+
cname
+
"-port"
,
it
.
getProp
(
"port"
),
0
);
if
(
port
==
0
)
{
cerr
<<
"(init_ulogserver): "
<<
cname
<<
": unknown port.."
<<
endl
;
delete
ls
;
return
0
;
return
nullptr
;
}
cout
<<
"logserver: "
<<
host
<<
":"
<<
port
<<
endl
;
...
...
extensions/include/UObject_SK.h
View file @
90a08483
...
...
@@ -22,24 +22,24 @@
#include "DebugStream.h"
// -----------------------------------------------------------------------------
class
UObject_SK
:
public
UniSetObject
,
public
LT_Object
public
UniSetObject
,
public
LT_Object
{
public
:
UObject_SK
(
UniSetTypes
::
ObjectId
id
,
xmlNode
*
node
=
UniSetTypes
::
uniset_conf
()
->
getNode
(
"UObject"
),
const
std
::
string
&
argprefix
=
""
);
UObject_SK
();
virtual
~
UObject_SK
();
bool
alarm
(
UniSetTypes
::
ObjectId
sid
,
bool
state
);
long
getValue
(
UniSetTypes
::
ObjectId
sid
);
void
setValue
(
UniSetTypes
::
ObjectId
sid
,
long
value
);
void
askSensor
(
UniSetTypes
::
ObjectId
sid
,
UniversalIO
::
UIOCommand
,
UniSetTypes
::
ObjectId
node
=
UniSetTypes
::
uniset_conf
()
->
getLocalNode
()
);
void
updateValues
();
void
setMsg
(
UniSetTypes
::
ObjectId
code
,
bool
state
);
std
::
shared_ptr
<
DebugStream
>
mylog
;
void
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
);
public
:
UObject_SK
(
UniSetTypes
::
ObjectId
id
,
xmlNode
*
node
=
UniSetTypes
::
uniset_conf
()
->
getNode
(
"UObject"
),
const
std
::
string
&
argprefix
=
""
);
UObject_SK
();
virtual
~
UObject_SK
();
bool
alarm
(
UniSetTypes
::
ObjectId
sid
,
bool
state
);
long
getValue
(
UniSetTypes
::
ObjectId
sid
);
void
setValue
(
UniSetTypes
::
ObjectId
sid
,
long
value
);
void
askSensor
(
UniSetTypes
::
ObjectId
sid
,
UniversalIO
::
UIOCommand
,
UniSetTypes
::
ObjectId
node
=
UniSetTypes
::
uniset_conf
()
->
getLocalNode
()
);
void
updateValues
();
void
setMsg
(
UniSetTypes
::
ObjectId
code
,
bool
state
);
std
::
shared_ptr
<
DebugStream
>
mylog
;
void
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
);
// "синтаксический сахар"..для логов
#define myinfo if( mylog->debugging(Debug::INFO) ) mylog->any()
...
...
@@ -57,91 +57,91 @@ class UObject_SK:
#define mylogany mylog->any()
// Используемые идентификаторы
// Используемые идентификаторы сообщений
// Текущее значение
// --- public variables ---
// --- end of public variables ---
protected
:
// --- protected variables ---
// ---- end of protected variables ----
virtual
void
callback
()
override
;
virtual
void
processingMessage
(
UniSetTypes
::
VoidMessage
*
msg
)
override
;
virtual
void
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
override
;
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
void
testMode
(
bool
state
);
void
updatePreviousValues
();
void
checkSensors
();
void
updateOutputs
(
bool
force
);
void
preAskSensors
(
UniversalIO
::
UIOCommand
cmd
);
void
preSensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
);
void
preTimerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
);
void
waitSM
(
int
wait_msec
,
UniSetTypes
::
ObjectId
testID
=
UniSetTypes
::
DefaultObjectId
);
void
resetMsg
();
Trigger
trResetMsg
;
PassiveTimer
ptResetMsg
;
int
resetMsgTime
;
// Выполнение очередного шага программы
virtual
void
step
(){}
int
sleep_msec
;
/*!< пауза между итерациями */
bool
active
;
UniSetTypes
::
ObjectId
smTestID
;
/*!< идентификатор датчика для тестирования готовности SM */
// управление датчиком "сердцебиения"
PassiveTimer
ptHeartBeat
;
/*! < период "сердцебиения" */
UniSetTypes
::
ObjectId
idHeartBeat
;
/*! < идентификатор датчика (AI) "сердцебиения" */
int
maxHeartBeat
;
/*! < сохраняемое значение */
xmlNode
*
confnode
;
/*! получить числовое свойство из конф. файла по привязанной confnode */
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
);
}
int
smReadyTimeout
;
/*!< время ожидания готовности SM */
std
::
atomic_bool
activated
;
int
activateTimeout
;
/*!< время ожидания готовности UniSetObject к работе */
PassiveTimer
ptStartUpTimeout
;
/*!< время на блокировку обработки WatchDog, если недавно был StartUp */
int
askPause
;
/*!< пауза между неудачными попытками заказать датчики */
IOController_i
::
SensorInfo
si
;
bool
forceOut
;
/*!< флаг принудительного обноления "выходов" */
private
:
// --- private variables ---
// --- end of private variables ---
// предыдущее значение (для работы UpdateValue())
// Используемые идентификаторы сообщений
bool
end_private
;
// вспомогательное поле (для внутреннего использования при генерировании кода)
// Используемые идентификаторы
// Используемые идентификаторы сообщений
// Текущее значение
// --- public variables ---
// --- end of public variables ---
protected
:
// --- protected variables ---
// ---- end of protected variables ----
virtual
void
callback
()
override
;
virtual
void
processingMessage
(
UniSetTypes
::
VoidMessage
*
msg
)
override
;
virtual
void
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
override
;
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
void
testMode
(
bool
state
);
void
updatePreviousValues
();
void
checkSensors
();
void
updateOutputs
(
bool
force
);
void
preAskSensors
(
UniversalIO
::
UIOCommand
cmd
);
void
preSensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
);
void
preTimerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
);
void
waitSM
(
int
wait_msec
,
UniSetTypes
::
ObjectId
testID
=
UniSetTypes
::
DefaultObjectId
);
void
resetMsg
();
Trigger
trResetMsg
;
PassiveTimer
ptResetMsg
;
int
resetMsgTime
;
// Выполнение очередного шага программы
virtual
void
step
(){}
int
sleep_msec
;
/*!< пауза между итерациями */
bool
active
;
UniSetTypes
::
ObjectId
smTestID
;
/*!< идентификатор датчика для тестирования готовности SM */
// управление датчиком "сердцебиения"
PassiveTimer
ptHeartBeat
;
/*! < период "сердцебиения" */
UniSetTypes
::
ObjectId
idHeartBeat
;
/*! < идентификатор датчика (AI) "сердцебиения" */
int
maxHeartBeat
;
/*! < сохраняемое значение */
xmlNode
*
confnode
;
/*! получить числовое свойство из конф. файла по привязанной confnode */
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
);
}
int
smReadyTimeout
;
/*!< время ожидания готовности SM */
std
::
atomic_bool
activated
;
int
activateTimeout
;
/*!< время ожидания готовности UniSetObject к работе */
PassiveTimer
ptStartUpTimeout
;
/*!< время на блокировку обработки WatchDog, если недавно был StartUp */
int
askPause
;
/*!< пауза между неудачными попытками заказать датчики */
IOController_i
::
SensorInfo
si
;
bool
forceOut
;
/*!< флаг принудительного обноления "выходов" */
private
:
// --- private variables ---
// --- end of private variables ---
// предыдущее значение (для работы UpdateValue())
// Используемые идентификаторы сообщений
bool
end_private
;
// вспомогательное поле (для внутреннего использования при генерировании кода)
};
// -----------------------------------------------------------------------------
...
...
extensions/lib/UObject_SK.cc
View file @
90a08483
...
...
@@ -45,19 +45,19 @@ forceOut(false),
end_private
(
false
)
{
ucrit
<<
"UObject: init failed!!!!!!!!!!!!!!!"
<<
endl
;
throw
Exception
(
string
(
myname
+
": init failed!!!"
)
);
ucrit
<<
"UObject: init failed!!!!!!!!!!!!!!!"
<<
endl
;
throw
Exception
(
string
(
myname
+
": init failed!!!"
)
);
}
// -----------------------------------------------------------------------------
// ( val, confval, default val )
static
const
std
::
string
init3_str
(
const
std
::
string
&
s1
,
const
std
::
string
&
s2
,
const
std
::
string
&
s3
)
{
if
(
!
s1
.
empty
()
)
return
s1
;
if
(
!
s2
.
empty
()
)
return
s2
;
return
s3
;
if
(
!
s1
.
empty
()
)
return
s1
;
if
(
!
s2
.
empty
()
)
return
s2
;
return
s3
;
}
// -----------------------------------------------------------------------------
UObject_SK
::
UObject_SK
(
ObjectId
id
,
xmlNode
*
cnode
,
const
std
::
string
&
argprefix
)
:
...
...
@@ -81,77 +81,77 @@ forceOut(false),
end_private
(
false
)
{
auto
conf
=
uniset_conf
();
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();
}
if
(
getId
()
==
DefaultObjectId
)
{
ostringstream
err
;
err
<<
"(UObject::init): Unknown ObjectID!"
;
throw
SystemError
(
err
.
str
()
);
}
if
(
getId
()
==
DefaultObjectId
)
{
ostringstream
err
;
err
<<
"(UObject::init): Unknown ObjectID!"
;
throw
SystemError
(
err
.
str
()
);
}
mylog
=
make_shared
<
DebugStream
>
();
mylog
->
setLogName
(
myname
);
mylog
->
setLogName
(
myname
);
UniXML
::
iterator
it
(
cnode
);
forceOut
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"force-out"
,
it
.
getProp
(
"forceOut"
),
fals
e
);
UniXML
::
iterator
it
(
cnod
e
);
string
heart
=
conf
->
getArgParam
(
"--"
+
argprefix
+
"heartbeat-id"
,
it
.
getProp
(
"heartbeat_id"
));
if
(
!
heart
.
empty
()
)
{
idHeartBeat
=
conf
->
getSensorID
(
heart
);
if
(
idHeartBeat
==
DefaultObjectId
)
{
ostringstream
err
;
err
<<
myname
<<
": не найден идентификатор для датчика 'HeartBeat' "
<<
heart
;
throw
SystemError
(
err
.
str
());
}
forceOut
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"force-out"
,
it
.
getProp
(
"forceOut"
),
false
);
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
);
}
string
heart
=
conf
->
getArgParam
(
"--"
+
argprefix
+
"heartbeat-id"
,
it
.
getProp
(
"heartbeat_id"
));
if
(
!
heart
.
empty
()
)
{
idHeartBeat
=
conf
->
getSensorID
(
heart
);
if
(
idHeartBeat
==
DefaultObjectId
)
{
ostringstream
err
;
err
<<
myname
<<
": не найден идентификатор для датчика 'HeartBeat' "
<<
heart
;
throw
SystemError
(
err
.
str
());
}
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
);
}
// Инициализация значений
sleep_msec
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"sleep-msec"
,
"150"
,
150
);
// Инициализация значений
sleep_msec
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"sleep-msec"
,
"150"
,
150
);
resetMsgTime
=
conf
->
getPIntProp
(
cnode
,
"resetMsgTime"
,
2000
);
ptResetMsg
.
setTiming
(
resetMsgTime
);
resetMsgTime
=
conf
->
getPIntProp
(
cnode
,
"resetMsgTime"
,
2000
);
ptResetMsg
.
setTiming
(
resetMsgTime
);
smReadyTimeout
=
conf
->
getArgInt
(
"--"
+
argprefix
+
"sm-ready-timeout"
,
""
);
if
(
smReadyTimeout
==
0
)
smReadyTimeout
=
60000
;
else
if
(
smReadyTimeout
<
0
)
smReadyTimeout
=
UniSetTimer
::
WaitUpTime
;
smReadyTimeout
=
conf
->
getArgInt
(
"--"
+
argprefix
+
"sm-ready-timeout"
,
""
);
if
(
smReadyTimeout
==
0
)
smReadyTimeout
=
60000
;
else
if
(
smReadyTimeout
<
0
)
smReadyTimeout
=
UniSetTimer
::
WaitUpTime
;
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"
),
""
));
activateTimeout
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"activate-timeout"
,
20000
);
activateTimeout
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"activate-timeout"
,
20000
);
int
msec
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"startup-timeout"
,
10000
);
ptStartUpTimeout
.
setTiming
(
msec
);
int
msec
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"startup-timeout"
,
10000
);
ptStartUpTimeout
.
setTiming
(
msec
);
// ===================== <variables> =====================
// ===================== end of <variables> =====================
// ===================== <variables> =====================
// ===================== end of <variables> =====================
}
// -----------------------------------------------------------------------------
...
...
@@ -162,36 +162,36 @@ UObject_SK::~UObject_SK()
// -----------------------------------------------------------------------------
void
UObject_SK
::
updateValues
()
{
// Опрашиваем все входы...
// Опрашиваем все входы...
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
updatePreviousValues
()
{
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
checkSensors
()
{
}
// -----------------------------------------------------------------------------
bool
UObject_SK
::
alarm
(
UniSetTypes
::
ObjectId
_code
,
bool
_state
)
{
if
(
_code
==
UniSetTypes
::
DefaultObjectId
)
{
if
(
_code
==
UniSetTypes
::
DefaultObjectId
)
{
ucrit
<<
getName
()
<<
"(alarm): попытка послать сообщение с DefaultObjectId"
<<
endl
;
return
false
;
}
<<
"(alarm): попытка послать сообщение с DefaultObjectId"
<<
endl
;
return
false
;
}
ulog1
<<
getName
()
<<
"(alarm): "
<<
(
_state
?
"SEND "
:
"RESET "
)
<<
endl
;
ulog1
<<
" not found MessgeOID?!!"
<<
endl
;
return
false
;
return
false
;
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
resetMsg
()
...
...
@@ -202,11 +202,11 @@ void UObject_SK::resetMsg()
// -----------------------------------------------------------------------------
void
UObject_SK
::
testMode
(
bool
_state
)
{
if
(
!
_state
)
return
;
if
(
!
_state
)
return
;
// отключаем все выходы
// отключаем все выходы
}
// -----------------------------------------------------------------------------
...
...
@@ -215,140 +215,140 @@ void UObject_SK::testMode( bool _state )
// ------------------------------------------------------------------------------------------
void
UObject_SK
::
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
)
{
UObject_SK
::
mylog
=
d
;
UObject_SK
::
mylog
=
d
;
}
// ------------------------------------------------------------------------------------------
void
UObject_SK
::
processingMessage
(
UniSetTypes
::
VoidMessage
*
_msg
)
{
try
{
switch
(
_msg
->
type
)
{
case
Message
:
:
SensorInfo
:
preSensorInfo
(
reinterpret_cast
<
SensorMessage
*>
(
_msg
)
);
break
;
case
Message
:
:
Timer
:
preTimerInfo
(
reinterpret_cast
<
TimerMessage
*>
(
_msg
)
);
break
;
case
Message
:
:
SysCommand
:
sysCommand
(
reinterpret_cast
<
SystemMessage
*>
(
_msg
)
);
break
;
default
:
break
;
}
}
catch
(
Exception
&
ex
)
{
ucrit
<<
myname
<<
"(processingMessage): "
<<
ex
<<
endl
;
}
try
{
switch
(
_msg
->
type
)
{
case
Message
:
:
SensorInfo
:
preSensorInfo
(
reinterpret_cast
<
SensorMessage
*>
(
_msg
)
);
break
;
case
Message
:
:
Timer
:
preTimerInfo
(
reinterpret_cast
<
TimerMessage
*>
(
_msg
)
);
break
;
case
Message
:
:
SysCommand
:
sysCommand
(
reinterpret_cast
<
SystemMessage
*>
(
_msg
)
);
break
;
default
:
break
;
}
}
catch
(
Exception
&
ex
)
{
ucrit
<<
myname
<<
"(processingMessage): "
<<
ex
<<
endl
;
}
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
sysCommand
(
const
SystemMessage
*
_sm
)
{
switch
(
_sm
->
command
)
{
case
SystemMessage
:
:
WatchDog
:
ulogany
<<
myname
<<
"(sysCommand): WatchDog"
<<
endl
;
if
(
!
active
||
!
ptStartUpTimeout
.
checkTime
()
)
{
switch
(
_sm
->
command
)
{
case
SystemMessage
:
:
WatchDog
:
ulogany
<<
myname
<<
"(sysCommand): WatchDog"
<<
endl
;
if
(
!
active
||
!
ptStartUpTimeout
.
checkTime
()
)
{
uwarn
<<
myname
<<
"(sysCommand): игнорируем WatchDog, потому-что только-что стартанули"
<<
endl
;
break
;
}
case
SystemMessage
:
:
StartUp
:
{
waitSM
(
smReadyTimeout
);
ptStartUpTimeout
.
reset
();
// т.к. для io-переменных важно соблюдать последовательность!
// сперва обновить входы.. а потом уже выходы
updateValues
();
updateOutputs
(
true
);
// принудительное обновление выходов
preAskSensors
(
UniversalIO
::
UIONotify
);
askSensors
(
UniversalIO
::
UIONotify
);
active
=
true
;
break
;
}
case
SystemMessage
:
:
FoldUp
:
case
SystemMessage
:
:
Finish
:
preAskSensors
(
UniversalIO
::
UIODontNotify
);
askSensors
(
UniversalIO
::
UIODontNotify
);
break
;
case
SystemMessage
:
:
LogRotate
:
{
// переоткрываем логи
mylogany
<<
myname
<<
"(sysCommand): logRotate"
<<
endl
;
string
fname
(
mylog
->
getLogFile
()
);
if
(
!
fname
.
empty
()
)
{
mylog
->
logFile
(
fname
.
c_str
(),
true
);
mylogany
<<
myname
<<
"(sysCommand): ***************** mylog LOG ROTATE *****************"
<<
endl
;
}
}
break
;
default
:
break
;
}
break
;
}
case
SystemMessage
:
:
StartUp
:
{
waitSM
(
smReadyTimeout
);
ptStartUpTimeout
.
reset
();
// т.к. для io-переменных важно соблюдать последовательность!
// сперва обновить входы.. а потом уже выходы
updateValues
();
updateOutputs
(
true
);
// принудительное обновление выходов
preAskSensors
(
UniversalIO
::
UIONotify
);
askSensors
(
UniversalIO
::
UIONotify
);
active
=
true
;
break
;
}
case
SystemMessage
:
:
FoldUp
:
case
SystemMessage
:
:
Finish
:
preAskSensors
(
UniversalIO
::
UIODontNotify
);
askSensors
(
UniversalIO
::
UIODontNotify
);
break
;
case
SystemMessage
:
:
LogRotate
:
{
// переоткрываем логи
mylogany
<<
myname
<<
"(sysCommand): logRotate"
<<
endl
;
string
fname
(
mylog
->
getLogFile
()
);
if
(
!
fname
.
empty
()
)
{
mylog
->
logFile
(
fname
.
c_str
(),
true
);
mylogany
<<
myname
<<
"(sysCommand): ***************** mylog LOG ROTATE *****************"
<<
endl
;
}
}
break
;
default
:
break
;
}
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
sigterm
(
int
signo
)
{
UniSetObject
::
sigterm
(
signo
);
active
=
false
;
UniSetObject
::
sigterm
(
signo
);
active
=
false
;
}
// -----------------------------------------------------------------------------
bool
UObject_SK
::
activateObject
()
{
// блокирование обработки Startup
// пока не пройдёт инициализация датчиков
// см. sysCommand()
{
activated
=
false
;
UniSetObject
::
activateObject
();
activated
=
true
;
}
return
true
;
// блокирование обработки Startup
// пока не пройдёт инициализация датчиков
// см. sysCommand()
{
activated
=
false
;
UniSetObject
::
activateObject
();
activated
=
true
;
}
return
true
;
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
preTimerInfo
(
const
UniSetTypes
::
TimerMessage
*
_tm
)
{
timerInfo
(
_tm
);
timerInfo
(
_tm
);
}
// ----------------------------------------------------------------------------
void
UObject_SK
::
waitSM
(
int
wait_msec
,
ObjectId
_testID
)
{
if
(
_testID
==
DefaultObjectId
)
_testID
=
smTestID
;
if
(
_testID
==
DefaultObjectId
)
_testID
=
smTestID
;
if
(
_testID
==
DefaultObjectId
)
return
;
uinfo
<<
myname
<<
"(waitSM): waiting SM ready "
<<
wait_msec
<<
" msec"
<<
" testID="
<<
_testID
<<
endl
;
if
(
!
ui
->
waitReady
(
_testID
,
wait_msec
)
)
{
ostringstream
err
;
err
<<
myname
<<
"(waitSM): Не дождались готовности(exist) SharedMemory к работе в течение "
<<
wait_msec
<<
" мсек"
;
if
(
_testID
==
DefaultObjectId
)
return
;
uinfo
<<
myname
<<
"(waitSM): waiting SM ready "
<<
wait_msec
<<
" msec"
<<
" testID="
<<
_testID
<<
endl
;
if
(
!
ui
->
waitReady
(
_testID
,
wait_msec
)
)
{
ostringstream
err
;
err
<<
myname
<<
"(waitSM): Не дождались готовности(exist) SharedMemory к работе в течение "
<<
wait_msec
<<
" мсек"
;
ucrit
<<
err
.
str
()
<<
endl
;
//
terminate();
//
abort();
raise
(
SIGTERM
);
terminate
();
//
throw SystemError(err.str());
}
//
terminate();
//
abort();
raise
(
SIGTERM
);
terminate
();
//
throw SystemError(err.str());
}
}
...
...
@@ -357,153 +357,153 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
// --------------------------------------------------------------------------
void
UObject_SK
::
callback
()
{
if
(
!
active
)
return
;
try
{
// проверка таймеров
checkTimers
(
this
);
if
(
resetMsgTime
>
0
&&
trResetMsg
.
hi
(
ptResetMsg
.
checkTime
())
)
{
//
cout << myname << ": ********* reset messages *********" << endl;
resetMsg
();
}
// обработка сообщений (таймеров и т.п.)
for
(
unsigned
int
i
=
0
;
i
<
20
;
i
++
)
{
if
(
!
receiveMessage
(
msg
)
)
break
;
processingMessage
(
&
msg
);
updateOutputs
(
forceOut
);
//
updatePreviousValues();
}
// Выполнение шага программы
step
();
// "сердцебиение"
if
(
idHeartBeat
!=
DefaultObjectId
&&
ptHeartBeat
.
checkTime
()
)
{
ui
->
setValue
(
idHeartBeat
,
maxHeartBeat
,
UniversalIO
::
AI
);
ptHeartBeat
.
reset
();
}
// обновление выходов
updateOutputs
(
forceOut
);
updatePreviousValues
();
}
catch
(
Exception
&
ex
)
{
if
(
!
active
)
return
;
try
{
// проверка таймеров
checkTimers
(
this
);
if
(
resetMsgTime
>
0
&&
trResetMsg
.
hi
(
ptResetMsg
.
checkTime
())
)
{
//
cout << myname << ": ********* reset messages *********" << endl;
resetMsg
();
}
// обработка сообщений (таймеров и т.п.)
for
(
unsigned
int
i
=
0
;
i
<
20
;
i
++
)
{
if
(
!
receiveMessage
(
msg
)
)
break
;
processingMessage
(
&
msg
);
updateOutputs
(
forceOut
);
//
updatePreviousValues();
}
// Выполнение шага программы
step
();
// "сердцебиение"
if
(
idHeartBeat
!=
DefaultObjectId
&&
ptHeartBeat
.
checkTime
()
)
{
ui
->
setValue
(
idHeartBeat
,
maxHeartBeat
,
UniversalIO
::
AI
);
ptHeartBeat
.
reset
();
}
// обновление выходов
updateOutputs
(
forceOut
);
updatePreviousValues
();
}
catch
(
Exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): "
<<
ex
<<
endl
;
}
catch
(
CORBA
::
SystemException
&
ex
)
{
}
catch
(
CORBA
::
SystemException
&
ex
)
{
ucrit
<<
myname
<<
"(execute): СORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
}
}
catch
(
std
::
exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch "
<<
ex
.
what
()
<<
endl
;
}
if
(
!
active
)
return
;
msleep
(
sleep_msec
);
if
(
!
active
)
return
;
msleep
(
sleep_msec
);
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
setValue
(
UniSetTypes
::
ObjectId
_sid
,
long
_val
)
{
ui
->
setValue
(
_sid
,
_val
);
ui
->
setValue
(
_sid
,
_val
);
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
updateOutputs
(
bool
_force
)
{
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
preSensorInfo
(
const
UniSetTypes
::
SensorMessage
*
_sm
)
{
sensorInfo
(
_sm
);
sensorInfo
(
_sm
);
}
// -----------------------------------------------------------------------------
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
)
{
try
{
try
{
return
ui
->
getValue
(
_sid
);
}
catch
(
Exception
&
ex
)
{
return
ui
->
getValue
(
_sid
);
}
catch
(
Exception
&
ex
)
{
ucrit
<<
myname
<<
"(getValue): "
<<
ex
<<
endl
;
throw
;
}
throw
;
}
}
// -----------------------------------------------------------------------------
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
;
}
if
(
!
activated
)
ucrit
<<
myname
<<
"(preAskSensors): ************* don`t activated?! ************"
<<
endl
;
for
(
;;
)
{
try
{
return
;
}
catch
(
SystemError
&
err
)
{
PassiveTimer
ptAct
(
activateTimeout
);
while
(
!
activated
&&
!
ptAct
.
checkTime
()
)
{
cout
<<
myname
<<
"(preAskSensors): wait activate..."
<<
endl
;
msleep
(
300
);
if
(
activated
)
break
;
}
if
(
!
activated
)
ucrit
<<
myname
<<
"(preAskSensors): ************* don`t activated?! ************"
<<
endl
;
for
(
;;
)
{
try
{
return
;
}
catch
(
SystemError
&
err
)
{
ucrit
<<
myname
<<
"(preAskSensors): "
<<
err
<<
endl
;
}
catch
(
Exception
&
ex
)
{
}
catch
(
Exception
&
ex
)
{
ucrit
<<
myname
<<
"(preAskSensors): "
<<
ex
<<
endl
;
}
catch
(
std
::
exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch "
<<
ex
.
what
()
<<
endl
;
}
msleep
(
askPause
);
}
}
catch
(
std
::
exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch "
<<
ex
.
what
()
<<
endl
;
}
msleep
(
askPause
);
}
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
setMsg
(
UniSetTypes
::
ObjectId
_code
,
bool
_state
)
{
// блокируем сброс (т.к. он автоматически по таймеру)
if
(
!
_state
)
{
ptResetMsg
.
reset
();
return
;
}
alarm
(
_code
,
_state
);
ptResetMsg
.
reset
();
}
// блокируем сброс (т.к. он автоматически по таймеру)
if
(
!
_state
)
{
ptResetMsg
.
reset
();
return
;
}
alarm
(
_code
,
_state
);
ptResetMsg
.
reset
();
}
// ----------------------------------------------------------------------------
include/LogReader.h
View file @
90a08483
...
...
@@ -27,12 +27,20 @@ class LogReader
inline
void
setCommandOnlyMode
(
bool
s
){
cmdonly
=
s
;
}
inline
void
setinTimeout
(
timeout_t
msec
){
inTimeout
=
msec
;
}
inline
void
setoutTimeout
(
timeout_t
msec
){
outTimeout
=
msec
;
}
inline
void
setReconnectDelay
(
timeout_t
msec
){
reconDelay
=
msec
;
}
protected
:
void
connect
(
const
std
::
string
&
addr
,
ost
::
tpport_t
port
,
timeout_t
tout
=
TIMEOUT_INF
);
void
connect
(
ost
::
InetAddress
addr
,
ost
::
tpport_t
port
,
timeout_t
tout
=
TIMEOUT_INF
);
void
disconnect
();
timeout_t
inTimeout
;
timeout_t
outTimeout
;
timeout_t
reconDelay
;
private
:
UTCPStream
*
tcp
;
std
::
string
iaddr
;
...
...
include/LogServer.h
View file @
90a08483
...
...
@@ -10,6 +10,7 @@
#include "DebugStream.h"
#include "ThreadCreator.h"
class
LogSession
;
class
LogAgregator
;
// -------------------------------------------------------------------------
/*! \page pgLogServer Лог сервер
Лог сервер предназначен для возможности удалённого чтения логов (DebugStream).
...
...
@@ -49,13 +50,14 @@ class LogServer
{
public
:
LogServer
(
std
::
shared_ptr
<
DebugStream
>
&
log
);
LogServer
(
std
::
ostream
&
os
);
LogServer
(
std
::
shared_ptr
<
DebugStream
>
log
);
LogServer
(
std
::
shared_ptr
<
LogAgregator
>
log
);
~
LogServer
();
inline
void
setSessionTimeout
(
timeout_t
msec
){
sessTimeout
=
msec
;
}
inline
void
setCmdTimeout
(
timeout_t
msec
){
cmdTimeout
=
msec
;
}
inline
void
setOutTimeout
(
timeout_t
msec
){
outTimeout
=
msec
;
}
inline
void
setSessionLog
(
Debug
::
type
t
){
sessLogLevel
=
t
;
}
void
run
(
const
std
::
string
&
addr
,
ost
::
tpport_t
port
,
bool
thread
=
true
);
...
...
@@ -74,6 +76,7 @@ class LogServer
timeout_t
sessTimeout
;
timeout_t
cmdTimeout
;
timeout_t
outTimeout
;
Debug
::
type
sessLogLevel
;
std
::
atomic_bool
cancelled
;
DebugStream
mylog
;
...
...
include/LogSession.h
View file @
90a08483
...
...
@@ -25,6 +25,10 @@ class LogSession:
inline
std
::
string
getClientAddress
(){
return
caddr
;
}
inline
void
setSessionLogLevel
(
Debug
::
type
t
){
slog
.
level
(
t
);
}
inline
void
addSessionLogLevel
(
Debug
::
type
t
){
slog
.
addLevel
(
t
);
}
inline
void
delSessionLogLevel
(
Debug
::
type
t
){
slog
.
delLevel
(
t
);
}
protected
:
virtual
void
run
();
virtual
void
final
();
...
...
src/Log/LogReader.cc
View file @
90a08483
...
...
@@ -10,6 +10,9 @@ using namespace std;
using
namespace
UniSetTypes
;
// -------------------------------------------------------------------------
LogReader
::
LogReader
()
:
inTimeout
(
10000
),
outTimeout
(
6000
),
reconDelay
(
5000
),
tcp
(
0
),
iaddr
(
""
),
cmdonly
(
false
)
...
...
@@ -111,9 +114,6 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
// -------------------------------------------------------------------------
void
LogReader
::
readlogs
(
const
std
::
string
&
_addr
,
ost
::
tpport_t
_port
,
LogServerTypes
::
lsMessage
&
msg
,
bool
verbose
)
{
timeout_t
inTimeout
=
10000
;
timeout_t
outTimeout
=
6000
;
timeout_t
reconDelay
=
5000
;
char
buf
[
100001
];
if
(
verbose
)
...
...
@@ -121,6 +121,12 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
bool
send_ok
=
false
;
if
(
inTimeout
==
0
)
inTimeout
=
TIMEOUT_INF
;
if
(
outTimeout
==
0
)
outTimeout
=
TIMEOUT_INF
;
while
(
true
)
{
if
(
!
isConnection
()
)
...
...
src/Log/LogServer.cc
View file @
90a08483
...
...
@@ -3,6 +3,7 @@
#include "UniSetTypes.h"
#include "Exceptions.h"
#include "LogSession.h"
#include "LogAgregator.h"
// -------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
...
...
@@ -30,24 +31,18 @@ LogServer::~LogServer()
delete
tcp
;
}
// -------------------------------------------------------------------------
LogServer
::
LogServer
(
std
::
ostream
&
os
)
:
timeout
(
TIMEOUT_INF
),
sessTimeout
(
3600000
),
cmdTimeout
(
2000
),
outTimeout
(
2000
),
cancelled
(
false
),
thr
(
0
),
tcp
(
0
),
elog
(
nullptr
),
oslog
(
&
os
)
LogServer
::
LogServer
(
std
::
shared_ptr
<
LogAgregator
>
log
)
:
LogServer
(
static_pointer_cast
<
DebugStream
>
(
log
))
{
}
// -------------------------------------------------------------------------
LogServer
::
LogServer
(
std
::
shared_ptr
<
DebugStream
>
&
log
)
:
LogServer
::
LogServer
(
std
::
shared_ptr
<
DebugStream
>
log
)
:
timeout
(
TIMEOUT_INF
),
sessTimeout
(
3600000
),
cmdTimeout
(
2000
),
outTimeout
(
2000
),
sessLogLevel
(
Debug
::
NONE
),
cancelled
(
false
),
thr
(
0
),
tcp
(
0
),
...
...
@@ -61,6 +56,7 @@ timeout(TIMEOUT_INF),
sessTimeout
(
3600000
),
cmdTimeout
(
2000
),
outTimeout
(
2000
),
sessLogLevel
(
Debug
::
NONE
),
cancelled
(
false
),
thr
(
0
),
tcp
(
0
),
...
...
@@ -111,6 +107,7 @@ void LogServer::work()
while
(
!
cancelled
&&
tcp
->
isPendingConnection
(
timeout
)
)
{
auto
s
=
make_shared
<
LogSession
>
(
*
tcp
,
elog
,
sessTimeout
,
cmdTimeout
,
outTimeout
);
s
->
setSessionLogLevel
(
sessLogLevel
);
{
uniset_rwmutex_wrlock
l
(
mutSList
);
slist
.
push_back
(
s
);
...
...
src/Log/LogSession.cc
View file @
90a08483
...
...
@@ -36,7 +36,10 @@ delayTime(_delay),
cancelled
(
false
)
{
//slog.addLevel(Debug::ANY);
log
->
signal_stream_event
().
connect
(
sigc
::
mem_fun
(
this
,
&
LogSession
::
logOnEvent
)
);
if
(
log
)
log
->
signal_stream_event
().
connect
(
sigc
::
mem_fun
(
this
,
&
LogSession
::
logOnEvent
)
);
else
slog
.
crit
()
<<
"LOG NULL!!"
<<
endl
;
}
// -------------------------------------------------------------------------
void
LogSession
::
logOnEvent
(
const
std
::
string
&
s
)
...
...
@@ -65,6 +68,10 @@ void LogSession::run()
if
(
slog
.
debugging
(
Debug
::
INFO
)
)
slog
[
Debug
::
INFO
]
<<
peername
<<
"(run): run thread of sessions.."
<<
endl
;
if
(
!
log
)
slog
.
crit
()
<<
peername
<<
"(run): LOG NULL!!"
<<
endl
;
ptSessionTimeout
.
setTiming
(
sessTimeout
);
setKeepAlive
(
true
);
...
...
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