Subversion Repositories tpanel

Rev

Rev 305 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 305 Rev 306
Line 20... Line 20...
20
#include <sstream>
20
#include <sstream>
21
#include <ios>
21
#include <ios>
22
#include <time.h>
22
#include <time.h>
23
#include <mutex>
23
#include <mutex>
24
#include <thread>
24
#include <thread>
-
 
25
//#ifdef __APPLE__
-
 
26
//#include <unistd.h>
-
 
27
//#include <sys/syscall.h>
-
 
28
//#endif
25
 
29
 
26
#include "terror.h"
30
#include "terror.h"
27
#include "tconfig.h"
31
#include "tconfig.h"
28
 
32
 
29
#include <QMessageBox>
33
#include <QMessageBox>
Line 47... Line 51...
47
 
51
 
48
bool TError::mHaveError{false};
52
bool TError::mHaveError{false};
49
terrtype_t TError::mErrType{TERRNONE};
53
terrtype_t TError::mErrType{TERRNONE};
50
TStreamError *TError::mCurrent{nullptr};
54
TStreamError *TError::mCurrent{nullptr};
51
std::string TError::msError;
55
std::string TError::msError;
52
std::thread::id TError::mThreadID{0};
56
threadID_t TError::mThreadID{0};
53
 
57
 
54
int TStreamError::mIndent{1};
58
int TStreamError::mIndent{1};
55
std::ostream *TStreamError::mStream{nullptr};
59
std::ostream *TStreamError::mStream{nullptr};
56
std::filebuf TStreamError::mOfStream;
60
std::filebuf TStreamError::mOfStream;
57
char *TStreamError::mBuffer{nullptr};
61
char *TStreamError::mBuffer{nullptr};
Line 59... Line 63...
59
bool TStreamError::mInitialized{false};
63
bool TStreamError::mInitialized{false};
60
unsigned int TStreamError::mLogLevel{HLOG_PROTOCOL};
64
unsigned int TStreamError::mLogLevel{HLOG_PROTOCOL};
61
unsigned int TStreamError::mLogLevelOld{HLOG_NONE};
65
unsigned int TStreamError::mLogLevelOld{HLOG_NONE};
62
bool TStreamError::haveTemporaryLogLevel{false};
66
bool TStreamError::haveTemporaryLogLevel{false};
63
 
67
 
64
string _threadIDtoStr(std::thread::id tid)
68
string _threadIDtoStr(threadID_t tid)
65
{
69
{
66
    std::stringstream s;
70
    std::stringstream s;
67
    s << std::hex << std::setw(8) << std::setfill('0') << tid;
71
    s << std::hex << std::setw(8) << std::setfill('0') << tid;
68
    return s.str();
72
    return s.str();
69
}
73
}
70
 
74
 
-
 
75
threadID_t _getThreadID()
-
 
76
{
-
 
77
#ifdef __APPLE__
-
 
78
//    threadID_t tid;
-
 
79
//    return pthread_threadid_np(NULL, &tid);
-
 
80
    return pthread_mach_thread_np(pthread_self());
-
 
81
//    return syscall(SYS_thread_selfid);
-
 
82
#else
-
 
83
    return std::this_thread::get_id();
-
 
84
#endif
-
 
85
}
-
 
86
 
71
void _lock()
87
void _lock()
72
{
88
{
73
    _macro_mutex.lock();
89
    _macro_mutex.lock();
74
}
90
}
75
 
91
 
Line 374... Line 390...
374
    {
390
    {
375
#ifdef __ANDROID__
391
#ifdef __ANDROID__
376
        std::cout.rdbuf(new androidbuf);
392
        std::cout.rdbuf(new androidbuf);
377
#endif  // __ANDROID__
393
#endif  // __ANDROID__
378
        mStream = &std::cout;
394
        mStream = &std::cout;
-
 
395
#if defined(QT_DEBUG) || defined(DEBUG)
379
#ifdef __ANDROID__
396
#ifdef __ANDROID__
380
        __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "TStreamError::_init: Stream wurde auf std::cout gesetzt.");
397
        __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "TStreamError::_init: Stream wurde auf std::cout gesetzt.");
381
#else
398
#else
382
        std::cout << "DEBUG: Stream wurde auf std::cout gesetzt." << std::endl;
399
        std::cout << "DEBUG: Stream wurde auf std::cout gesetzt." << std::endl;
-
 
400
#endif  // __ANDROID__
383
#endif
401
#endif
384
    }
402
    }
385
#else  // LOGPATH == LPATH_FILE
403
#else  // LOGPATH == LPATH_FILE
386
    if (!mStream)
404
    if (!mStream)
387
    {
405
    {
Line 575... Line 593...
575
 
593
 
576
/********************************************************************/
594
/********************************************************************/
577
 
595
 
578
std::mutex tracer_mutex;
596
std::mutex tracer_mutex;
579
 
597
 
580
TTracer::TTracer(const std::string msg, int line, char *file, std::thread::id tid)
598
TTracer::TTracer(const std::string msg, int line, char *file, threadID_t tid)
-
 
599
    : mThreadID(tid)
581
{
600
{
582
    if (!TConfig::isInitialized() || !TStreamError::checkFilter(HLOG_TRACE))
601
    if (!TConfig::isInitialized() || !TStreamError::checkFilter(HLOG_TRACE))
583
        return;
602
        return;
584
 
603
 
585
    std::lock_guard<mutex> guard(tracer_mutex);
604
    std::lock_guard<mutex> guard(tracer_mutex);
586
 
605
 
587
    mFile = file;
606
    mFile = file;
588
    mThreadID = tid;
-
 
589
    size_t pos = mFile.find_last_of("/");
607
    size_t pos = mFile.find_last_of("/");
590
 
608
 
591
    if (pos != string::npos)
609
    if (pos != string::npos)
592
        mFile = mFile.substr(pos + 1);
610
        mFile = mFile.substr(pos + 1);
593
 
611
 
Line 689... Line 707...
689
        mCurrent = new TStreamError(TConfig::getLogFile(), TConfig::getLogLevel());
707
        mCurrent = new TStreamError(TConfig::getLogFile(), TConfig::getLogLevel());
690
 
708
 
691
    return mCurrent;
709
    return mCurrent;
692
}
710
}
693
 
711
 
694
TStreamError *TError::Current(std::thread::id tid)
712
TStreamError *TError::Current(threadID_t tid)
695
{
713
{
696
    mThreadID = tid;
714
    mThreadID = tid;
697
    return Current();
715
    return Current();
698
}
716
}
699
 
717