src/3rdparty/phonon/mmf/utils.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /*  This file is part of the KDE project.
       
     2 
       
     3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 
       
     5 This library 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, either version 2.1 or 3 of the License.
       
     8 
       
     9 This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
       
    16 
       
    17 */
       
    18 
       
    19 #ifndef PHONON_MMF_UTILS_H
       
    20 #define PHONON_MMF_UTILS_H
       
    21 
       
    22 #include <private/qcore_symbian_p.h>
       
    23 #include <e32debug.h>   // for RDebug
       
    24 
       
    25 #include <QColor>
       
    26 
       
    27 #include "defs.h"
       
    28 
       
    29 QT_BEGIN_NAMESPACE
       
    30 
       
    31 namespace Phonon
       
    32 {
       
    33 namespace MMF
       
    34 {
       
    35 /**
       
    36  * Panic codes for fatal errors
       
    37  */
       
    38 enum PanicCode {
       
    39     InvalidStatePanic               = 1,
       
    40     InvalidMediaTypePanic           = 2,
       
    41     InvalidBackendInterfaceClass    = 3
       
    42 };
       
    43 
       
    44 namespace Utils
       
    45 {
       
    46 /**
       
    47  * Raise a fatal exception
       
    48  */
       
    49 void panic(PanicCode code);
       
    50 
       
    51 /**
       
    52  * Determines whether the provided MIME type is an audio or video
       
    53  * type.  If it is neither, the function returns MediaTypeUnknown.
       
    54  */
       
    55 MediaType mimeTypeToMediaType(const TDesC& mimeType);
       
    56 
       
    57 #ifndef QT_NO_DEBUG
       
    58 /**
       
    59  * Retrieve color of specified pixel from the screen.
       
    60  */
       
    61 QColor getScreenPixel(const QPoint& pos);
       
    62 
       
    63 /**
       
    64  * Samples a small number of pixels from the screen, and dumps their
       
    65  * colors to the debug log.
       
    66  */
       
    67 void dumpScreenPixelSample();
       
    68 #endif
       
    69 }
       
    70 
       
    71 /**
       
    72  * Available trace categories;
       
    73  */
       
    74 enum TTraceCategory {
       
    75     /**
       
    76      * Backend
       
    77      */
       
    78     EBackend             = 0x00000001,
       
    79 
       
    80     /**
       
    81      * Functions which map directly to the public Phonon audio API
       
    82      */
       
    83     EAudioApi            = 0x00000010,
       
    84 
       
    85     /**
       
    86      * Internal functions in the audio implementation
       
    87      */
       
    88     EAudioInternal       = 0x00000020,
       
    89 
       
    90     /**
       
    91      * Functions which map directly to the public Phonon video API
       
    92      */
       
    93     EVideoApi            = 0x00010000,
       
    94 
       
    95     /**
       
    96      * Internal functions in the video implementation
       
    97      */
       
    98     EVideoInternal       = 0x00020000
       
    99 };
       
   100 
       
   101 /**
       
   102  * Mask indicating which trace categories are enabled
       
   103  *
       
   104  * Note that, at the moment, this is a compiled static constant.  For
       
   105  * runtime control over enabled trace categories, this could be replaced
       
   106  * by a per-thread singleton object which owns the trace mask, and which
       
   107  * exposes an API allowing it to be modified.
       
   108  */
       
   109 static const TUint KTraceMask = 0xffffffff;
       
   110 
       
   111 /**
       
   112  * Data structure used by tracing macros
       
   113  */
       
   114 class TTraceContext
       
   115 {
       
   116 public:
       
   117     TTraceContext(const TText* aFunction, const TUint aAddr,
       
   118                   const TUint aCategory = 0)
       
   119             :    iFunction(aFunction),
       
   120             iAddr(aAddr),
       
   121             iCategory(aCategory) { }
       
   122 
       
   123     /**
       
   124      * Check whether iCategory appears in the trace mask
       
   125      */
       
   126     TBool Enabled() const {
       
   127         return (iCategory == 0) or(iCategory & KTraceMask);
       
   128     }
       
   129 
       
   130     const TText*    iFunction;    // Name of function
       
   131     const TUint        iAddr;        // 'this' pointer
       
   132     const TUint        iCategory;
       
   133 };
       
   134 
       
   135 // Macros used internally by the trace system
       
   136 #define _TRACE_PRINT RDebug::Print
       
   137 #define _TRACE_TEXT(x) (TPtrC((const TText *)(x)))
       
   138 #define _TRACE_MODULE Phonon::MMF
       
   139 
       
   140 // Macros available for use by implementation code
       
   141 #ifndef QT_NO_DEBUG
       
   142 #define TRACE_CONTEXT(_fn, _cat) const ::Phonon::MMF::TTraceContext _tc((TText*)L ## #_fn, (TUint)this, _cat);
       
   143 #define TRACE_ENTRY_0() { if (_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "+ Phonon::MMF::%s [0x%08x]"), _tc.iFunction, _tc.iAddr); }
       
   144 #define TRACE_ENTRY(string, args...) { if (_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "+ Phonon::MMF::%s [0x%08x] " L ## string), _tc.iFunction, _tc.iAddr, args); }
       
   145 #define TRACE_EXIT_0() { if (_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "- Phonon::MMF::%s [0x%08x]"), _tc.iFunction, _tc.iAddr); }
       
   146 #define TRACE_EXIT(string, args...) { if (_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "- Phonon::MMF::%s [0x%08x] " L ## string), _tc.iFunction, _tc.iAddr, args); }
       
   147 #define TRACE_RETURN(string, result) { if (_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "r Phonon::MMF::%s [0x%08x] " L ## string), _tc.iFunction, _tc.iAddr, result); } return result;
       
   148 #define TRACE_PANIC(code) { _TRACE_PRINT(_TRACE_TEXT(L ## "! Phonon::MMF::%s [0x%08x] panic %d"), _tc.iFunction, _tc.iAddr, code); } Utils::panic(code);
       
   149 #define TRACE_0(string) { if (_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "  Phonon::MMF::%s [0x%08x] " L ## string), _tc.iFunction, _tc.iAddr); }
       
   150 #define TRACE(string, args...) { if (_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "  Phonon::MMF::%s [0x%08x] " L ## string), _tc.iFunction, _tc.iAddr, args); }
       
   151 #else
       
   152 #define TRACE_CONTEXT(_fn, _cat)
       
   153 #define TRACE_ENTRY_0()
       
   154 #define TRACE_ENTRY(string, args...)
       
   155 #define TRACE_EXIT_0()
       
   156 #define TRACE_EXIT(string, args...)
       
   157 #define TRACE_RETURN(string, result) return result;
       
   158 #define TRACE_PANIC(code) Utils::panic(code);
       
   159 #define TRACE_0(string)
       
   160 #define TRACE(string, args...)
       
   161 #endif
       
   162 }
       
   163 }
       
   164 
       
   165 QT_END_NAMESPACE
       
   166 
       
   167 #endif