Subversion Repositories tpanel

Rev

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

Rev 398 Rev 406
Line 31... Line 31...
31
#include <QTimer>
31
#include <QTimer>
32
 
32
 
33
#include "terror.h"
33
#include "terror.h"
34
#include "tconfig.h"
34
#include "tconfig.h"
35
 
35
 
-
 
36
#if __cplusplus < 201402L
-
 
37
#   error "This module requires at least C++ 14 standard!"
-
 
38
#else
-
 
39
#   if __cplusplus < 201703L
-
 
40
#       include <experimental/filesystem>
-
 
41
namespace fs = std::experimental::filesystem;
-
 
42
#       warning "Support for C++14 and experimental filesystem will be removed in a future version!"
-
 
43
#   else
-
 
44
#       include <filesystem>
-
 
45
#       ifdef __ANDROID__
-
 
46
namespace fs = std::__fs::filesystem;
-
 
47
#       else
-
 
48
namespace fs = std::filesystem;
-
 
49
#       endif
-
 
50
#   endif
-
 
51
#endif
36
 
52
 
37
#if LOGPATH == LPATH_SYSLOG || defined(__ANDROID__)
53
#if LOGPATH == LPATH_SYSLOG || defined(__ANDROID__)
38
#   ifdef __ANDROID__
54
#   ifdef __ANDROID__
39
#       include <android/log.h>
55
#       include <android/log.h>
40
#   else
56
#   else
Line 330... Line 346...
330
        return;
346
        return;
331
 
347
 
332
    mInitialized = true;
348
    mInitialized = true;
333
 
349
 
334
#ifdef __ANDROID__
350
#ifdef __ANDROID__
335
//    mLogFileEnabled = TConfig::getLogFileEnabled();
-
 
336
    __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "TStreamError::_init: Logfile is %s", (mLogFileEnabled ? "ENABLED" : "DISABLED"));
351
    __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "TStreamError::_init: Logfile is %s", (mLogFileEnabled ? "ENABLED" : "DISABLED"));
337
#endif
352
#endif
338
 
353
 
339
#if LOGPATH == LPATH_FILE
354
#if LOGPATH == LPATH_FILE
340
    if (mLogFileEnabled && !mLogfile.empty())
355
    if (mLogFileEnabled && !mLogfile.empty())
Line 381... Line 396...
381
                    mOfStream.close();
396
                    mOfStream.close();
382
 
397
 
383
                if (mStream && mStream != &std::cout)
398
                if (mStream && mStream != &std::cout)
384
                    delete mStream;
399
                    delete mStream;
385
 
400
 
386
#if __cplusplus < 201402L
-
 
387
                mOfStream.open(mLogfile.c_str(), std::ios::out | std::ios::ate);
401
                __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "TStreamError::_init: Opening logfile: \"%s\"", mLogfile.c_str());
388
#else   // __cplusplus < 201402L
-
 
389
                mOfStream.open(mLogfile, std::ios::out | std::ios::ate);
-
 
390
#endif  //__cplusplus < 201402L
-
 
391
                mStream = new std::ostream(&mOfStream);
-
 
392
 
402
 
393
                if (!isStreamValid())
403
                if (!mOfStream.open(mLogfile, std::ios::out | std::ios::trunc))
394
                {
404
                {
395
                    if (mOfStream.is_open())
405
                    __android_log_print(ANDROID_LOG_ERROR, "tpanel", "TStreamError::_init: Could not open logfile!");
396
                        mOfStream.close();
406
                    std::cout.rdbuf(new androidbuf);
397
 
-
 
398
                    mStream = &std::cout;
407
                    mStream = &std::cout;
-
 
408
                    mLogFileEnabled = false;
-
 
409
                }
-
 
410
                else
-
 
411
                {
-
 
412
                    mStream = new std::ostream(&mOfStream);
-
 
413
 
-
 
414
                    if (!isStreamValid())
-
 
415
                    {
-
 
416
                        delete mStream;
-
 
417
 
-
 
418
                        if (mOfStream.is_open())
-
 
419
                            mOfStream.close();
-
 
420
 
-
 
421
                        std::cout.rdbuf(new androidbuf);
-
 
422
                        mStream = &std::cout;
-
 
423
                        mLogFileEnabled = false;
-
 
424
                    }
399
                }
425
                }
400
            }
426
            }
401
            else
427
            else
402
            {
428
            {
403
                std::cout.rdbuf(new androidbuf);
429
                std::cout.rdbuf(new androidbuf);
Line 577... Line 603...
577
}
603
}
578
 
604
 
579
bool TStreamError::isStreamValid()
605
bool TStreamError::isStreamValid()
580
{
606
{
581
    if (!mStream)
607
    if (!mStream)
-
 
608
    {
-
 
609
#ifdef __ANDROID__
-
 
610
        __android_log_print(ANDROID_LOG_ERROR, "tpanel", "TStreamError::isStreamValid: Stream is nullptr!");
-
 
611
#else
-
 
612
        std::cerr << "ERROR: TStreamError::isStreamValid: Stream is nullptr!" << std::endl;
-
 
613
#endif
582
        return false;
614
        return false;
-
 
615
    }
583
 
616
 
584
    if (mStream->rdstate() & std::ostream::failbit)
617
    if (mStream->rdstate() & std::ostream::failbit)
-
 
618
    {
-
 
619
#ifdef __ANDROID__
-
 
620
        __android_log_print(ANDROID_LOG_ERROR, "tpanel", "TStreamError::isStreamValid: Stream has failbit set!");
-
 
621
#else
-
 
622
        std::cerr << "ERROR: TStreamError::isStreamValid: Stream has failbit set!" << std::endl;
-
 
623
#endif
585
        return false;
624
        return false;
-
 
625
    }
586
 
626
 
587
    if (mStream->rdstate() & std::ostream::badbit)
627
    if (mStream->rdstate() & std::ostream::badbit)
-
 
628
    {
-
 
629
#ifdef __ANDROID__
-
 
630
        __android_log_print(ANDROID_LOG_ERROR, "tpanel", "TStreamError::isStreamValid: Stream has badbit set!");
-
 
631
#else
-
 
632
        std::cerr << "ERROR: TStreamError::isStreamValid: Stream has badbit set!" << std::endl;
-
 
633
#endif
588
        return false;
634
        return false;
-
 
635
    }
589
 
636
 
590
    return true;
637
    return true;
591
}
638
}
592
 
639
 
593
bool TStreamError::isStreamValid(std::ostream& os)
640
bool TStreamError::isStreamValid(std::ostream& os)