qtmobileextensions/examples/keycaptureex/txlogger.h
branchRCL_3
changeset 9 5d007b20cfd0
equal deleted inserted replaced
8:885c2596c964 9:5d007b20cfd0
       
     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("[KeyCaptureTestApp] %s", msg);\
       
    58             }
       
    59     #endif // TRACE_FILE
       
    60 
       
    61     #define _TX_INSTALL qInstallMsgHandler(__tx_myMessageOutput);
       
    62     #define TX_MAIN(a, b) _TX_INIT \
       
    63             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))
       
    64 
       
    65     #define TX_UNUSED(name);
       
    66     #define TX_STATIC_ENTRY qDebug() << __PRETTY_FUNCTION__ << "entry";
       
    67     #define TX_STATIC_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "entry," << args;
       
    68     #define TX_STATIC_EXIT qDebug() << __PRETTY_FUNCTION__ << "exit";
       
    69     #define TX_STATIC_EXIT_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "exit," << args; 
       
    70     #define TX_ENTRY qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry";
       
    71     #define TX_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry," << args;
       
    72     #define TX_EXIT qDebug() << __PRETTY_FUNCTION__ << "exit";
       
    73     #define TX_EXIT_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "exit," << args;
       
    74     #define TX_LOG qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this;
       
    75     #define TX_LOG_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << args;
       
    76 #else
       
    77     #define TX_MAIN(a,b) int main(int (a), char **(b))
       
    78     #define TX_UNUSED(name) Q_UNUSED(name);
       
    79     #define TX_STATIC_ENTRY ;
       
    80     #define TX_STATIC_ENTRY_ARGS(args) ;
       
    81     #define TX_STATIC_EXIT ;
       
    82     #define TX_STATIC_EXIT_ARGS(args) ;
       
    83     #define TX_ENTRY ;
       
    84     #define TX_ENTRY_ARGS(args) ;
       
    85     #define TX_EXIT ;
       
    86     #define TX_EXIT_ARGS(args) ;
       
    87     #define TX_LOG ;
       
    88     #define TX_LOG_ARGS(args) ;
       
    89 #endif // ENABLETRACE
       
    90 
       
    91 
       
    92 #endif /* __TXLOGGER_H */