videocollection/tsrc/simplevideoplayback/inc/trace.h
author hgs
Fri, 03 Sep 2010 12:37:43 +0300
changeset 58 d2b028fd1f7d
parent 50 21fe8338c6bf
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Tracing macros, 2nd generation
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#ifndef TRACE_H
hgs
parents:
diff changeset
    19
#define TRACE_H
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include <QDebug>
hgs
parents:
diff changeset
    22
hgs
parents:
diff changeset
    23
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    24
// Trace definitions
hgs
parents:
diff changeset
    25
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    26
//
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
/**
hgs
parents:
diff changeset
    29
* Error trace enabled
hgs
parents:
diff changeset
    30
*/
hgs
parents:
diff changeset
    31
#ifdef _DEBUG
hgs
parents:
diff changeset
    32
    #define ERROR_TRACE
hgs
parents:
diff changeset
    33
    #define INFO_TRACE
hgs
parents:
diff changeset
    34
    #define TIMESTAMP_TRACE
hgs
parents:
diff changeset
    35
    #define FUNC_TRACE
hgs
parents:
diff changeset
    36
#else
hgs
parents:
diff changeset
    37
    #define ERROR_TRACE
hgs
parents:
diff changeset
    38
    #define INFO_TRACE
hgs
parents:
diff changeset
    39
    #define TIMESTAMP_TRACE
hgs
parents:
diff changeset
    40
    #define FUNC_TRACE
hgs
parents:
diff changeset
    41
#endif
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    44
// Constants
hgs
parents:
diff changeset
    45
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    46
//
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
/**
hgs
parents:
diff changeset
    49
* Trace prefixes for macros with component name.
hgs
parents:
diff changeset
    50
*/
hgs
parents:
diff changeset
    51
#define _TRACE_PREFIX "[SVPB]:"
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
/**
hgs
parents:
diff changeset
    54
* Prefix error trace
hgs
parents:
diff changeset
    55
*/
hgs
parents:
diff changeset
    56
#define _ERROR_PREFIX _TRACE_PREFIX " [ERROR]:"
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
/**
hgs
parents:
diff changeset
    59
* Prefix info trace.
hgs
parents:
diff changeset
    60
*/
hgs
parents:
diff changeset
    61
#define _INFO_PREFIX _TRACE_PREFIX " [INFO]:"
hgs
parents:
diff changeset
    62
hgs
parents:
diff changeset
    63
/**
hgs
parents:
diff changeset
    64
* Prefix timestamp trace.
hgs
parents:
diff changeset
    65
*/
hgs
parents:
diff changeset
    66
#define _TIMESTAMP_PREFIX _TRACE_PREFIX " [TIMESTAMP]:"
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
// Error trace macros
hgs
parents:
diff changeset
    70
// Usage: wrap traces in ERROR() macro to allow disabling them in release builds.
hgs
parents:
diff changeset
    71
// Use normal stream object operations.
hgs
parents:
diff changeset
    72
// Examples:
hgs
parents:
diff changeset
    73
// ERROR( "xxx failed" );
hgs
parents:
diff changeset
    74
// ERROR( "Test trace arg =" << 999 << "arg2 =" << title() );
hgs
parents:
diff changeset
    75
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    76
//
hgs
parents:
diff changeset
    77
#ifdef ERROR_TRACE
hgs
parents:
diff changeset
    78
    #define ERROR(trace) {qDebug() << _ERROR_PREFIX << trace;}
hgs
parents:
diff changeset
    79
    #define ERROR_PARAM(param) param
hgs
parents:
diff changeset
    80
    #define HANDLE_ERROR(trace) {ERROR(trace); __BREAKPOINT();}
hgs
parents:
diff changeset
    81
    #define HANDLE_ERROR_BOOL(x) {if (!x) {ERROR(#x << "is false"); __BREAKPOINT();}}
hgs
parents:
diff changeset
    82
    #define HANDLE_ERROR_NULL(x) {if (!x) {ERROR(#x << "is NULL"); __BREAKPOINT();}}
hgs
parents:
diff changeset
    83
    #define HANDLE_ERROR_NEG(x) {if (x < 0) {ERROR(#x << "=" << x << "File:" << __FILE__ << ", line:" << __LINE__); __BREAKPOINT();}}
hgs
parents:
diff changeset
    84
    #define CHECK_ERROR(err, trace) {if (err < 0) ERROR(trace << err);}
hgs
parents:
diff changeset
    85
#else //ERROR_TRACE not defined
hgs
parents:
diff changeset
    86
    #define ERROR(trace)
hgs
parents:
diff changeset
    87
    #define ERROR_PARAM(param)
hgs
parents:
diff changeset
    88
    #define HANDLE_ERROR(trace)
hgs
parents:
diff changeset
    89
    #define HANDLE_ERROR_BOOL(x)
hgs
parents:
diff changeset
    90
    #define HANDLE_ERROR_NULL(x)
hgs
parents:
diff changeset
    91
    #define HANDLE_ERROR_NEG(x)
hgs
parents:
diff changeset
    92
    #define CHECK_ERROR(err,trace)
hgs
parents:
diff changeset
    93
#endif //ERROR_TRACE
hgs
parents:
diff changeset
    94
hgs
parents:
diff changeset
    95
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    96
// Info trace macros
hgs
parents:
diff changeset
    97
// Usage: wrap traces in INFO() macro to allow disabling them in release builds.
hgs
parents:
diff changeset
    98
// Use normal stream object operations.
hgs
parents:
diff changeset
    99
// Examples:
hgs
parents:
diff changeset
   100
// INFO( "Test trace" );
hgs
parents:
diff changeset
   101
// INFO( "Test trace arg =" << 999 << "arg2 =" << title() );
hgs
parents:
diff changeset
   102
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   103
//
hgs
parents:
diff changeset
   104
#ifdef INFO_TRACE
hgs
parents:
diff changeset
   105
    #define INFO(trace) {qDebug() << _INFO_PREFIX << trace;}
hgs
parents:
diff changeset
   106
    #define INFO_PARAM(param) param
hgs
parents:
diff changeset
   107
#else //INFO_TRACE not defined
hgs
parents:
diff changeset
   108
    #define INFO(trace)
hgs
parents:
diff changeset
   109
    #define INFO_PARAM(param)
hgs
parents:
diff changeset
   110
#endif //INFO_TRACE
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   113
// Function trace macros
hgs
parents:
diff changeset
   114
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   115
//
hgs
parents:
diff changeset
   116
#ifdef FUNC_TRACE
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118
    class FuncLog
hgs
parents:
diff changeset
   119
    {
hgs
parents:
diff changeset
   120
    public:
hgs
parents:
diff changeset
   121
    inline FuncLog( const char* func ) : m_func( func )
hgs
parents:
diff changeset
   122
        { qDebug() << _TRACE_PREFIX << m_func << "-START"; }
hgs
parents:
diff changeset
   123
    inline ~FuncLog() { qDebug() << _TRACE_PREFIX << m_func << "-END"; }
hgs
parents:
diff changeset
   124
    private: // Data
hgs
parents:
diff changeset
   125
        QString m_func;
hgs
parents:
diff changeset
   126
    };
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
    #define FUNC_LOG FuncLog _fl( __PRETTY_FUNCTION__ );
hgs
parents:
diff changeset
   129
#else //FUNC_TRACE not defined
hgs
parents:
diff changeset
   130
    #define FUNC_LOG
hgs
parents:
diff changeset
   131
#endif //FUNC_TRACE
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   134
// Timestamp trace macros
hgs
parents:
diff changeset
   135
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   136
//
hgs
parents:
diff changeset
   137
#ifdef TIMESTAMP_TRACE
hgs
parents:
diff changeset
   138
    #include <QTime>
hgs
parents:
diff changeset
   139
    #define TIMESTAMP(trace)\
hgs
parents:
diff changeset
   140
        {qDebug() << _TIMESTAMP_PREFIX << "(" << \
hgs
parents:
diff changeset
   141
            QTime::currentTime().toString("HH:mm:ss:zzz") << ")" << trace;}
hgs
parents:
diff changeset
   142
#else //TIMESTAMP_TRACE not defined
hgs
parents:
diff changeset
   143
    #define TIMESTAMP(trace)
hgs
parents:
diff changeset
   144
#endif //TIMESTAMP_TRACE
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
#endif // TRACE_H