qtmobileextensions/src/keycapture/txlogger.h
changeset 1 2b40d63a9c3d
child 27 6bfad47013df
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU Lesser General Public License as published by
       
     7  * the Free Software Foundation, version 2.1 of the License.
       
     8  * 
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU Lesser General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Lesser General Public License
       
    15  * along with this program.  If not, 
       
    16  * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17  *
       
    18  * Description:
       
    19  *
       
    20  */
       
    21 
       
    22 #ifndef __TXLOGGER_H
       
    23 #define __TXLOGGER_H
       
    24 
       
    25 //To enable tracking define ENABLETRACE
       
    26 //if TRACE_FILENAME is set then trace will go to file, otherwise to RDebug
       
    27 
       
    28 #include <QObject>
       
    29 #include <qglobal.h>
       
    30 
       
    31 #define XQCONNECT_ASSERT(a, b, c, d) if (!(QObject::connect((a),(b), (c), (d)))) { qFatal("Connection failed: connect(%s, %s, %s, %s)", #a, #b, #c, #d); }
       
    32 
       
    33 // stolen from qt-music :)
       
    34 #ifdef ENABLETRACE
       
    35 #include <QString>
       
    36 #include <QDebug>
       
    37 #include <QTime>
       
    38 #include <stdio.h>
       
    39 #include <stdlib.h>
       
    40 #include <e32debug.h>
       
    41 
       
    42 #ifdef TRACE_FILE
       
    43 #define _TRACE_FILENAME "c:/trace.txt"
       
    44 #define _TX_INIT void __tx_myMessageOutput(QtMsgType type, const char *msg) {\
       
    45              static const QString timeFmt("hh:mm:ss.zzz");\
       
    46              FILE *f = fopen(_TRACE_FILENAME, "a");\
       
    47              fprintf(f, "%s ", QTime::currentTime().toString(timeFmt).toLatin1().data() );\
       
    48              switch (type) {\
       
    49              case QtDebugMsg: fprintf(f, "[DEB] %s\n", msg); break;\
       
    50              case QtWarningMsg: fprintf(f, "[WRN] %s\n", msg); break;\
       
    51              case QtCriticalMsg: fprintf(f, "[CRT] %s\n", msg); break;\
       
    52              case QtFatalMsg: fprintf(f, "[FTL] %s\n", msg); fclose(f); abort();\
       
    53              } fclose(f);\
       
    54         }
       
    55 #else
       
    56 #define _TX_INIT void __tx_myMessageOutput(QtMsgType /*type*/, const char *msg) {\
       
    57             RDebug::Printf("[TX] %s", msg);\
       
    58             }
       
    59 #endif // TRACE_FILE
       
    60 #define _TX_INSTALL qInstallMsgHandler(__tx_myMessageOutput);
       
    61 #define TX_MAIN(a, b) _TX_INIT \
       
    62             int __tx__main(int, char**); int main(int (a), char **(b)) { _TX_INSTALL return __tx__main(a, b); } int __tx__main(int (a), char **(b))
       
    63 
       
    64 #define TX_UNUSED(name);
       
    65 #define TX_STATIC_ENTRY qDebug() << __PRETTY_FUNCTION__ << "entry";
       
    66 #define TX_STATIC_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "entry," << args;
       
    67 #define TX_STATIC_EXIT qDebug() << __PRETTY_FUNCTION__ << "exit";
       
    68 #define TX_STATIC_EXIT_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "exit," << args; 
       
    69 #define TX_ENTRY qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry";
       
    70 #define TX_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry," << args;
       
    71 #define TX_EXIT qDebug() << __PRETTY_FUNCTION__ << "exit";
       
    72 #define TX_EXIT_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "exit," << args;
       
    73 #define TX_LOG qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this;
       
    74 #define TX_LOG_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << args;
       
    75 #else
       
    76 #define TX_MAIN(a,b) int main(int (a), char **(b))
       
    77 #define TX_UNUSED(name) Q_UNUSED(name);
       
    78 #define TX_STATIC_ENTRY ;
       
    79 #define TX_STATIC_ENTRY_ARGS(args) ;
       
    80 #define TX_STATIC_EXIT ;
       
    81 #define TX_STATIC_EXIT_ARGS(args) ;
       
    82 #define TX_ENTRY ;
       
    83 #define TX_ENTRY_ARGS(args) ;
       
    84 #define TX_EXIT ;
       
    85 #define TX_EXIT_ARGS(args) ;
       
    86 #define TX_LOG ;
       
    87 #define TX_LOG_ARGS(args) ;
       
    88 #endif // ENABLETRACE
       
    89 
       
    90 #endif /* __TXLOGGER_H */