Commit 2b88a692 authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Refactoring for linux compat

parent 5347c24d
...@@ -234,8 +234,9 @@ public: ...@@ -234,8 +234,9 @@ public:
if( !pValue ) ErrorMissKey( sKey ); if( !pValue ) ErrorMissKey( sKey );
// Allows implicit type conversions // Allows implicit type conversions
if( pValue->IsBool() || pValue->IsNumeric() || pValue->IsString() ) { if( pValue->IsBool() || pValue->IsNumeric() || pValue->IsString() )
sValue = *pValue; {
sValue = std::string( *pValue );
return; return;
} }
...@@ -253,8 +254,9 @@ public: ...@@ -253,8 +254,9 @@ public:
} }
// Allows implicit type conversions // Allows implicit type conversions
if( pValue->IsBool() || pValue->IsNumeric() || pValue->IsString() ) { if( pValue->IsBool() || pValue->IsNumeric() || pValue->IsString() )
sValue = *pValue; {
sValue = std::string( *pValue );
return true; return true;
} }
...@@ -409,18 +411,20 @@ public: ...@@ -409,18 +411,20 @@ public:
{ {
const CVAStructValue* pValue = m_oStruct.GetValue( sKey ); const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if( !pValue ) ErrorMissKey( sKey ); if( !pValue )
ErrorMissKey( sKey );
// Default case // Default case
if( pValue->IsString() ) { if( pValue->IsString() ) {
std::string sValue = *pValue; std::string sValue = std::string( *pValue );
vList = splitString( sValue, sSeparator ); vList = splitString( sValue, sSeparator );
return; return;
} }
// Allows implicit type conversions // Allows implicit type conversions
if( pValue->IsBool() || pValue->IsNumeric() ) { if( pValue->IsBool() || pValue->IsNumeric() )
std::string sValue = *pValue; {
std::string sValue = std::string( *pValue );
vList.clear(); vList.clear();
vList.push_back( sValue ); vList.push_back( sValue );
return; return;
...@@ -437,15 +441,17 @@ public: ...@@ -437,15 +441,17 @@ public:
if( !pValue ) ErrorMissKey( sKey ); if( !pValue ) ErrorMissKey( sKey );
// Default case // Default case
if( pValue->IsString() ) { if( pValue->IsString() )
std::string sValue = *pValue; {
std::string sValue = std::string( *pValue );
regexSplitString( sValue, vList, sRegex ); regexSplitString( sValue, vList, sRegex );
return; return;
} }
// Allows implicit type conversions // Allows implicit type conversions
if( pValue->IsBool() || pValue->IsNumeric() ) { if( pValue->IsBool() || pValue->IsNumeric() )
std::string sValue = *pValue; {
std::string sValue = std::string( *pValue );
vList.clear(); vList.clear();
vList.push_back( sValue ); vList.push_back( sValue );
return; return;
......
...@@ -5,18 +5,18 @@ ...@@ -5,18 +5,18 @@
std::ostream* VA_STDOUT = &std::cout; std::ostream* VA_STDOUT = &std::cout;
std::ostream* VA_STDERR = &std::cerr;
void VALog_setOutputStream( std::ostream* os ) void VALog_setOutputStream( std::ostream* os )
{ {
VA_STDOUT = 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; static int g_iVALogLevel = VACORE_DEFAULT_LOG_LEVEL;
int VALog_GetLogLevel() int VALog_GetLogLevel()
{ {
return g_iVALogLevel; return g_iVALogLevel;
...@@ -31,24 +31,25 @@ void VALog_SetLogLevel( int iLevel ) ...@@ -31,24 +31,25 @@ void VALog_SetLogLevel( int iLevel )
VistaMutex g_mxOutputStream; VistaMutex g_mxOutputStream;
VistaMutex& VALog_getOutputStreamMutex()
{
return g_mxOutputStream;
}
VistaMutex& VALog_getOutputStreamMutex() { return g_mxOutputStream; } std::ostream& operator<<( std::ostream& out, const CVALogItem& item )
{
static CVARealtimeLogger g_oInstance;
std::ostream& operator<<(std::ostream& out, const CVALogItem& item) {
out << "[" << item.dTimestamp << "] "; out << "[" << item.dTimestamp << "] ";
if (!item.sLogger.empty()) out << "<" << item.sLogger << "> "; if( !item.sLogger.empty() ) out << "<" << item.sLogger << "> ";
out << item.sMsg << std::endl; out << item.sMsg << std::endl;
return out; return out;
} }
CVARealtimeLogger::CVARealtimeLogger() CVARealtimeLogger::CVARealtimeLogger()
: m_evTrigger( VistaThreadEvent::WAITABLE_EVENT ) : m_evTrigger( VistaThreadEvent::WAITABLE_EVENT )
, m_bStop(false) , m_bStop( false )
, m_iTriggerCnt(0) , m_iTriggerCnt( 0 )
{ {
SetThreadName("VACore::RealtimeLogger"); SetThreadName( "VACore::RealtimeLogger" );
// Low thread priority // Low thread priority
int iPriority = VistaPriority::VISTA_MIN_PRIORITY; int iPriority = VistaPriority::VISTA_MIN_PRIORITY;
...@@ -57,60 +58,68 @@ CVARealtimeLogger::CVARealtimeLogger() ...@@ -57,60 +58,68 @@ CVARealtimeLogger::CVARealtimeLogger()
Run(); Run();
} }
CVARealtimeLogger* CVARealtimeLogger::GetInstance() { static CVARealtimeLogger g_oInstance;
CVARealtimeLogger* CVARealtimeLogger::GetInstance()
{
return &g_oInstance; return &g_oInstance;
} }
void CVARealtimeLogger::Register(CVARealtimeLogStream* pStream) { void CVARealtimeLogger::Register( CVARealtimeLogStream* pStream )
{
m_mxRegistration.Lock(); m_mxRegistration.Lock();
m_lpStreams.push_back(pStream); m_lpStreams.push_back( pStream );
m_mxRegistration.Unlock(); m_mxRegistration.Unlock();
Trigger(); Trigger();
} }
void CVARealtimeLogger::Unregister(CVARealtimeLogStream* pStream) { void CVARealtimeLogger::Unregister( CVARealtimeLogStream* pStream )
{
m_mxRegistration.Lock(); m_mxRegistration.Lock();
m_lpStreams.remove(pStream); m_lpStreams.remove( pStream );
m_mxRegistration.Unlock(); m_mxRegistration.Unlock();
Trigger(); Trigger();
} }
CVARealtimeLogger::~CVARealtimeLogger() { CVARealtimeLogger::~CVARealtimeLogger()
{
m_bStop = true; m_bStop = true;
m_evTrigger.SignalEvent(); m_evTrigger.SignalEvent();
// TODO: Problematisch mit Matlab // TODO: Problematisch mit Matlab
// StopGently(false); // StopGently(false);
StopGently(false); StopGently( false );
} }
void CVARealtimeLogger::Trigger() { void CVARealtimeLogger::Trigger()
{
++m_iTriggerCnt; ++m_iTriggerCnt;
m_evTrigger.SignalEvent(); m_evTrigger.SignalEvent();
} }
bool CVARealtimeLogger::LoopBody() { bool CVARealtimeLogger::LoopBody()
{
if ((m_iTriggerCnt == 0) && !m_bStop) {
if( ( m_iTriggerCnt == 0 ) && !m_bStop ) {
// Blockierend warten // Blockierend warten
m_evTrigger.WaitForEvent(true); m_evTrigger.WaitForEvent( true );
// Daten greifen // Daten greifen
std::vector<CVALogItem> vLogItems; std::vector<CVALogItem> vLogItems;
m_mxRegistration.Lock(); m_mxRegistration.Lock();
std::list<CVARealtimeLogStream*>::const_iterator it; 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; CVARealtimeLogStream* pStream = *it;
CVALogItem oLogItem; CVALogItem oLogItem;
while(pStream->m_qLog.try_pop(oLogItem)) while( pStream->m_qLog.try_pop( oLogItem ) )
vLogItems.push_back(oLogItem); vLogItems.push_back( oLogItem );
} }
m_mxRegistration.Unlock(); m_mxRegistration.Unlock();
// Daten sortieren (mittels berlademen Vergleichsoperator // Daten sortieren (mittels berlademen Vergleichsoperator
if (vLogItems.size() > 1) if( vLogItems.size() > 1 )
std::sort(vLogItems.begin(), vLogItems.end()); std::sort( vLogItems.begin(), vLogItems.end() );
// Daten ausgeben // Daten ausgeben
...@@ -119,7 +128,7 @@ bool CVARealtimeLogger::LoopBody() { ...@@ -119,7 +128,7 @@ bool CVARealtimeLogger::LoopBody() {
} }
// Stop-Flag berprfen, ggf. selbst beenden // Stop-Flag berprfen, ggf. selbst beenden
if (m_bStop) { if( m_bStop ) {
IndicateLoopEnd(); IndicateLoopEnd();
return false; return false;
} }
...@@ -131,15 +140,17 @@ bool CVARealtimeLogger::LoopBody() { ...@@ -131,15 +140,17 @@ bool CVARealtimeLogger::LoopBody() {
} }
//! Kleiner-Operator //! Kleiner-Operator
bool CVALogItem::operator< (CVALogItem const& rhs) { bool CVALogItem::operator< ( CVALogItem const& rhs )
if(this->dTimestamp < rhs.dTimestamp) {
if( this->dTimestamp < rhs.dTimestamp )
return true; return true;
return false; return false;
}; }
//! Grer-Operator //! Grer-Operator
bool CVALogItem::operator> (CVALogItem const& rhs) { bool CVALogItem::operator>( CVALogItem const& rhs )
if(this->dTimestamp > rhs.dTimestamp) {
if( this->dTimestamp > rhs.dTimestamp )
return true; return true;
return false; return false;
}; }
\ No newline at end of file
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
extern VACORE_API std::ostream* VA_STDOUT; extern VACORE_API std::ostream* VA_STDOUT;
extern VACORE_API std::ostream* VA_STDERR; extern VACORE_API std::ostream* VA_STDERR;
void VACORE_API VALog_setOutputStream(std::ostream* os); void VACORE_API VALog_setOutputStream( std::ostream* os );
void VACORE_API VALog_setErrorStream(std::ostream* os); void VACORE_API VALog_setErrorStream( std::ostream* os );
int VACORE_API VALog_GetLogLevel(); int VACORE_API VALog_GetLogLevel();
void VACORE_API VALog_SetLogLevel( int ); void VACORE_API VALog_SetLogLevel( int );
...@@ -43,23 +43,31 @@ public: ...@@ -43,23 +43,31 @@ public:
std::string sLogger; std::string sLogger;
std::string sMsg; 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 //! Grer-Operator zur Verwendung der sort() Funktion
bool CVALogItem::operator> (CVALogItem const& rhs); bool operator> ( CVALogItem const& rhs );
//! Kleiner-Operation //! Kleiner-Operation
bool CVALogItem::operator< (CVALogItem const& rhs); bool operator< ( CVALogItem const& rhs );
}; };
class CVARealtimeLogStream; class CVARealtimeLogStream;
//! Realtime Logger entkoppelt die Ausgabe von Logger-Streams auf einem niederpriorisierten Thread //! Realtime Logger entkoppelt die Ausgabe von Logger-Streams auf einem niederpriorisierten Thread
class CVARealtimeLogger : public VistaThreadLoop { class CVARealtimeLogger : public VistaThreadLoop
{
public: public:
CVARealtimeLogger(); CVARealtimeLogger();
~CVARealtimeLogger(); ~CVARealtimeLogger();
...@@ -67,10 +75,10 @@ public: ...@@ -67,10 +75,10 @@ public:
static CVARealtimeLogger* GetInstance(); static CVARealtimeLogger* GetInstance();
//! Streams registrieren //! Streams registrieren
void Register(CVARealtimeLogStream* pStream); void Register( CVARealtimeLogStream* pStream );
//! Streams deregistrieren //! Streams deregistrieren
void Unregister(CVARealtimeLogStream* pStream); void Unregister( CVARealtimeLogStream* pStream );
//! Thread anschubsen (nach Aktion) //! Thread anschubsen (nach Aktion)
void Trigger(); void Trigger();
...@@ -97,34 +105,34 @@ private: ...@@ -97,34 +105,34 @@ private:
*/ */
class CVARealtimeLogStream { class CVARealtimeLogStream {
public: public:
CVARealtimeLogStream(ITAClock* pClock=ITAClock::getDefaultClock()) CVARealtimeLogStream( ITAClock* pClock = ITAClock::getDefaultClock() )
: m_pClock(pClock) { : m_pClock( pClock ) {
// Bei Ausgabe-Thread registrieren (Singleton) // Bei Ausgabe-Thread registrieren (Singleton)
CVARealtimeLogger::GetInstance()->Register(this); CVARealtimeLogger::GetInstance()->Register( this );
} }
virtual ~CVARealtimeLogStream() { virtual ~CVARealtimeLogStream() {
// Bei Thread deregistieren // Bei Thread deregistieren
CVARealtimeLogger::GetInstance()->Unregister(this); CVARealtimeLogger::GetInstance()->Unregister( this );
} }
std::string GetName() const { std::string GetName() const {
return m_sName; return m_sName;
} }
void SetName(const std::string& sName) { void SetName( const std::string& sName ) {
m_sName = sName; m_sName = sName;
} }
// Ausgabe // Ausgabe
void Printf(const char * format, ...) { void Printf( const char * format, ... ) {
char buf[16384]; char buf[ 16384 ];
va_list args; va_list args;
va_start(args, format); va_start( args, format );
vsprintf_s(buf, format, args); vsprintf_s( buf, format, args );
va_end(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. // TODO: Thread zur Ausgabe anwerfen ggf.
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment