Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
VACore
Commits
2b88a692
Commit
2b88a692
authored
Feb 01, 2017
by
Jonas Stienen
Browse files
Refactoring for linux compat
parent
5347c24d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Utils/VAUtils.h
View file @
2b88a692
...
...
@@ -234,8 +234,9 @@ public:
if
(
!
pValue
)
ErrorMissKey
(
sKey
);
// Allows implicit type conversions
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
||
pValue
->
IsString
()
)
{
sValue
=
*
pValue
;
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
||
pValue
->
IsString
()
)
{
sValue
=
std
::
string
(
*
pValue
);
return
;
}
...
...
@@ -253,8 +254,9 @@ public:
}
// Allows implicit type conversions
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
||
pValue
->
IsString
()
)
{
sValue
=
*
pValue
;
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
||
pValue
->
IsString
()
)
{
sValue
=
std
::
string
(
*
pValue
);
return
true
;
}
...
...
@@ -409,18 +411,20 @@ public:
{
const
CVAStructValue
*
pValue
=
m_oStruct
.
GetValue
(
sKey
);
if
(
!
pValue
)
ErrorMissKey
(
sKey
);
if
(
!
pValue
)
ErrorMissKey
(
sKey
);
// Default case
if
(
pValue
->
IsString
()
)
{
std
::
string
sValue
=
*
pValue
;
std
::
string
sValue
=
std
::
string
(
*
pValue
)
;
vList
=
splitString
(
sValue
,
sSeparator
);
return
;
}
// Allows implicit type conversions
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
)
{
std
::
string
sValue
=
*
pValue
;
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
)
{
std
::
string
sValue
=
std
::
string
(
*
pValue
);
vList
.
clear
();
vList
.
push_back
(
sValue
);
return
;
...
...
@@ -437,15 +441,17 @@ public:
if
(
!
pValue
)
ErrorMissKey
(
sKey
);
// Default case
if
(
pValue
->
IsString
()
)
{
std
::
string
sValue
=
*
pValue
;
if
(
pValue
->
IsString
()
)
{
std
::
string
sValue
=
std
::
string
(
*
pValue
);
regexSplitString
(
sValue
,
vList
,
sRegex
);
return
;
}
// Allows implicit type conversions
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
)
{
std
::
string
sValue
=
*
pValue
;
if
(
pValue
->
IsBool
()
||
pValue
->
IsNumeric
()
)
{
std
::
string
sValue
=
std
::
string
(
*
pValue
);
vList
.
clear
();
vList
.
push_back
(
sValue
);
return
;
...
...
src/VALog.cpp
View file @
2b88a692
...
...
@@ -5,18 +5,18 @@
std
::
ostream
*
VA_STDOUT
=
&
std
::
cout
;
std
::
ostream
*
VA_STDERR
=
&
std
::
cerr
;
void
VALog_setOutputStream
(
std
::
ostream
*
os
)
{
VA_STDOUT
=
os
;
}
void
VALog_setErrorStream
(
std
::
ostream
*
os
)
{
VA_STDERR
=
os
;
}
std
::
ostream
*
VA_STDERR
=
&
std
::
cerr
;
void
VALog_setErrorStream
(
std
::
ostream
*
os
)
{
VA_STDERR
=
os
;
}
static
int
g_iVALogLevel
=
VACORE_DEFAULT_LOG_LEVEL
;
int
VALog_GetLogLevel
()
{
return
g_iVALogLevel
;
...
...
@@ -31,24 +31,25 @@ void VALog_SetLogLevel( int iLevel )
VistaMutex
g_mxOutputStream
;
VistaMutex
&
VALog_getOutputStreamMutex
()
{
return
g_mxOutputStream
;
}
VistaMutex
&
VALog_getOutputStreamMutex
()
{
return
g_mxOutputStream
;
}
static
CVARealtimeLogger
g_oInstance
;
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
CVALogItem
&
item
)
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
CVALogItem
&
item
)
{
out
<<
"["
<<
item
.
dTimestamp
<<
"] "
;
if
(
!
item
.
sLogger
.
empty
())
out
<<
"<"
<<
item
.
sLogger
<<
"> "
;
if
(
!
item
.
sLogger
.
empty
()
)
out
<<
"<"
<<
item
.
sLogger
<<
"> "
;
out
<<
item
.
sMsg
<<
std
::
endl
;
return
out
;
}
CVARealtimeLogger
::
CVARealtimeLogger
()
:
m_evTrigger
(
VistaThreadEvent
::
WAITABLE_EVENT
)
,
m_bStop
(
false
)
,
m_iTriggerCnt
(
0
)
,
m_bStop
(
false
)
,
m_iTriggerCnt
(
0
)
{
SetThreadName
(
"VACore::RealtimeLogger"
);
SetThreadName
(
"VACore::RealtimeLogger"
);
// Low thread priority
int
iPriority
=
VistaPriority
::
VISTA_MIN_PRIORITY
;
...
...
@@ -57,60 +58,68 @@ CVARealtimeLogger::CVARealtimeLogger()
Run
();
}
CVARealtimeLogger
*
CVARealtimeLogger
::
GetInstance
()
{
static
CVARealtimeLogger
g_oInstance
;
CVARealtimeLogger
*
CVARealtimeLogger
::
GetInstance
()
{
return
&
g_oInstance
;
}
void
CVARealtimeLogger
::
Register
(
CVARealtimeLogStream
*
pStream
)
{
void
CVARealtimeLogger
::
Register
(
CVARealtimeLogStream
*
pStream
)
{
m_mxRegistration
.
Lock
();
m_lpStreams
.
push_back
(
pStream
);
m_lpStreams
.
push_back
(
pStream
);
m_mxRegistration
.
Unlock
();
Trigger
();
}
void
CVARealtimeLogger
::
Unregister
(
CVARealtimeLogStream
*
pStream
)
{
void
CVARealtimeLogger
::
Unregister
(
CVARealtimeLogStream
*
pStream
)
{
m_mxRegistration
.
Lock
();
m_lpStreams
.
remove
(
pStream
);
m_lpStreams
.
remove
(
pStream
);
m_mxRegistration
.
Unlock
();
Trigger
();
}
CVARealtimeLogger
::~
CVARealtimeLogger
()
{
CVARealtimeLogger
::~
CVARealtimeLogger
()
{
m_bStop
=
true
;
m_evTrigger
.
SignalEvent
();
// TODO: Problematisch mit Matlab
// StopGently(false);
StopGently
(
false
);
StopGently
(
false
);
}
void
CVARealtimeLogger
::
Trigger
()
{
void
CVARealtimeLogger
::
Trigger
()
{
++
m_iTriggerCnt
;
m_evTrigger
.
SignalEvent
();
}
bool
CVARealtimeLogger
::
LoopBody
()
{
if
((
m_iTriggerCnt
==
0
)
&&
!
m_bStop
)
{
bool
CVARealtimeLogger
::
LoopBody
()
{
if
(
(
m_iTriggerCnt
==
0
)
&&
!
m_bStop
)
{
// Blockierend warten
m_evTrigger
.
WaitForEvent
(
true
);
m_evTrigger
.
WaitForEvent
(
true
);
// Daten greifen
std
::
vector
<
CVALogItem
>
vLogItems
;
m_mxRegistration
.
Lock
();
std
::
list
<
CVARealtimeLogStream
*>::
const_iterator
it
;
for
(
it
=
m_lpStreams
.
begin
();
it
!=
m_lpStreams
.
end
();
++
it
)
{
for
(
it
=
m_lpStreams
.
begin
();
it
!=
m_lpStreams
.
end
();
++
it
)
{
CVARealtimeLogStream
*
pStream
=
*
it
;
CVALogItem
oLogItem
;
while
(
pStream
->
m_qLog
.
try_pop
(
oLogItem
)
)
vLogItems
.
push_back
(
oLogItem
);
while
(
pStream
->
m_qLog
.
try_pop
(
oLogItem
)
)
vLogItems
.
push_back
(
oLogItem
);
}
m_mxRegistration
.
Unlock
();
// Daten sortieren (mittels berlademen Vergleichsoperator
if
(
vLogItems
.
size
()
>
1
)
std
::
sort
(
vLogItems
.
begin
(),
vLogItems
.
end
());
if
(
vLogItems
.
size
()
>
1
)
std
::
sort
(
vLogItems
.
begin
(),
vLogItems
.
end
()
);
// Daten ausgeben
...
...
@@ -119,7 +128,7 @@ bool CVARealtimeLogger::LoopBody() {
}
// Stop-Flag berprfen, ggf. selbst beenden
if
(
m_bStop
)
{
if
(
m_bStop
)
{
IndicateLoopEnd
();
return
false
;
}
...
...
@@ -131,15 +140,17 @@ bool CVARealtimeLogger::LoopBody() {
}
//! Kleiner-Operator
bool
CVALogItem
::
operator
<
(
CVALogItem
const
&
rhs
)
{
if
(
this
->
dTimestamp
<
rhs
.
dTimestamp
)
bool
CVALogItem
::
operator
<
(
CVALogItem
const
&
rhs
)
{
if
(
this
->
dTimestamp
<
rhs
.
dTimestamp
)
return
true
;
return
false
;
}
;
}
//! Grer-Operator
bool
CVALogItem
::
operator
>
(
CVALogItem
const
&
rhs
)
{
if
(
this
->
dTimestamp
>
rhs
.
dTimestamp
)
bool
CVALogItem
::
operator
>
(
CVALogItem
const
&
rhs
)
{
if
(
this
->
dTimestamp
>
rhs
.
dTimestamp
)
return
true
;
return
false
;
};
\ No newline at end of file
}
src/VALog.h
View file @
2b88a692
...
...
@@ -22,8 +22,8 @@
extern
VACORE_API
std
::
ostream
*
VA_STDOUT
;
extern
VACORE_API
std
::
ostream
*
VA_STDERR
;
void
VACORE_API
VALog_setOutputStream
(
std
::
ostream
*
os
);
void
VACORE_API
VALog_setErrorStream
(
std
::
ostream
*
os
);
void
VACORE_API
VALog_setOutputStream
(
std
::
ostream
*
os
);
void
VACORE_API
VALog_setErrorStream
(
std
::
ostream
*
os
);
int
VACORE_API
VALog_GetLogLevel
();
void
VACORE_API
VALog_SetLogLevel
(
int
);
...
...
@@ -43,23 +43,31 @@ public:
std
::
string
sLogger
;
std
::
string
sMsg
;
CVALogItem
()
:
dTimestamp
(
0
)
{};
inline
CVALogItem
()
:
dTimestamp
(
0
)
{
};
inline
CVALogItem
(
double
dTheTimestamp
,
const
std
::
string
sTheLogger
,
const
std
::
string
sTheMsg
)
:
dTimestamp
(
dTheTimestamp
)
,
sLogger
(
sTheLogger
)
,
sMsg
(
sTheMsg
)
{
};
CVALogItem
(
double
dTheTimestamp
,
const
std
::
string
sTheLogger
,
const
std
::
string
sTheMsg
)
:
dTimestamp
(
dTheTimestamp
),
sLogger
(
sTheLogger
),
sMsg
(
sTheMsg
)
{};
//! Grer-Operator zur Verwendung der sort() Funktion
bool
CVALogItem
::
operator
>
(
CVALogItem
const
&
rhs
);
bool
operator
>
(
CVALogItem
const
&
rhs
);
//! Kleiner-Operation
bool
CVALogItem
::
operator
<
(
CVALogItem
const
&
rhs
);
bool
operator
<
(
CVALogItem
const
&
rhs
);
};
class
CVARealtimeLogStream
;
//! Realtime Logger entkoppelt die Ausgabe von Logger-Streams auf einem niederpriorisierten Thread
class
CVARealtimeLogger
:
public
VistaThreadLoop
{
class
CVARealtimeLogger
:
public
VistaThreadLoop
{
public:
CVARealtimeLogger
();
~
CVARealtimeLogger
();
...
...
@@ -67,10 +75,10 @@ public:
static
CVARealtimeLogger
*
GetInstance
();
//! Streams registrieren
void
Register
(
CVARealtimeLogStream
*
pStream
);
void
Register
(
CVARealtimeLogStream
*
pStream
);
//! Streams deregistrieren
void
Unregister
(
CVARealtimeLogStream
*
pStream
);
void
Unregister
(
CVARealtimeLogStream
*
pStream
);
//! Thread anschubsen (nach Aktion)
void
Trigger
();
...
...
@@ -97,34 +105,34 @@ private:
*/
class
CVARealtimeLogStream
{
public:
CVARealtimeLogStream
(
ITAClock
*
pClock
=
ITAClock
::
getDefaultClock
())
:
m_pClock
(
pClock
)
{
CVARealtimeLogStream
(
ITAClock
*
pClock
=
ITAClock
::
getDefaultClock
()
)
:
m_pClock
(
pClock
)
{
// Bei Ausgabe-Thread registrieren (Singleton)
CVARealtimeLogger
::
GetInstance
()
->
Register
(
this
);
CVARealtimeLogger
::
GetInstance
()
->
Register
(
this
);
}
virtual
~
CVARealtimeLogStream
()
{
// Bei Thread deregistieren
CVARealtimeLogger
::
GetInstance
()
->
Unregister
(
this
);
CVARealtimeLogger
::
GetInstance
()
->
Unregister
(
this
);
}
std
::
string
GetName
()
const
{
return
m_sName
;
}
void
SetName
(
const
std
::
string
&
sName
)
{
void
SetName
(
const
std
::
string
&
sName
)
{
m_sName
=
sName
;
}
// Ausgabe
void
Printf
(
const
char
*
format
,
...)
{
char
buf
[
16384
];
void
Printf
(
const
char
*
format
,
...
)
{
char
buf
[
16384
];
va_list
args
;
va_start
(
args
,
format
);
vsprintf_s
(
buf
,
format
,
args
);
va_end
(
args
);
va_start
(
args
,
format
);
vsprintf_s
(
buf
,
format
,
args
);
va_end
(
args
);
m_qLog
.
push
(
CVALogItem
(
m_pClock
->
getTime
(),
m_sName
,
buf
)
);
m_qLog
.
push
(
CVALogItem
(
m_pClock
->
getTime
(),
m_sName
,
buf
)
);
// TODO: Thread zur Ausgabe anwerfen ggf.
}
...
...
Write
Preview
Supports
Markdown
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