summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon/mmf/utils.h
blob: 4b967fc73bdf14cdeed242cb4ccc77d3a45a66a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*  This file is part of the KDE project.

Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).

This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 or 3 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef PHONON_MMF_UTILS_H
#define PHONON_MMF_UTILS_H

#include <private/qcore_symbian_p.h>

namespace Phonon
{
    namespace MMF
    {
        /**
         * Panic codes for fatal errors
         */
        enum PanicCode
            {
            InvalidStatePanic,
            InvalidMediaTypePanic
            };

        namespace Utils
        {
            /**
             * Raise a fatal exception
             */
            void panic(PanicCode code);

            /**
             * Translate forward slashes to backslashes
             *
             * \note    This function is a temporary measure, for use until the
             *             responsibility for constructing valid file paths is
             *             determined.
             */
            QHBufC symbianFilename(const QString& qtFilename);
        }

        /**
         * Available trace categories;
         */
        enum TTraceCategory
            {
            /**
             * Functions which map directly to the public Phonon audio API
             */
            EAudioApi            = 0x00000001,

            /**
             * Internal functions in the audio implementation
             */
            EAudioInternal        = 0x00000002
            };

        /**
         * Mask indicating which trace categories are enabled
         *
         * Note that, at the moment, this is a compiled static constant.  For
         * runtime control over enabled trace categories, this could be replaced
         * by a per-thread singleton object which owns the trace mask, and which
         * exposes an API allowing it to be modified.
         */
        static const TUint KTraceMask = 0xffffffff;

        /**
         * Data structure used by tracing macros
         */
        class TTraceContext
            {
        public:
            TTraceContext(const TText* aFunction, const TUint aAddr,
                    const TUint aCategory=0)
            :    iFunction(aFunction),
                iAddr(aAddr),
                iCategory(aCategory)
            { }

            /**
             * Check whether iCategory appears in the trace mask
             */
            TBool Enabled() const
                {
                return (iCategory == 0) or (iCategory & KTraceMask);
                }

            const TText*    iFunction;    // Name of function
            const TUint        iAddr;        // 'this' pointer
            const TUint        iCategory;
            };

        // Macros used internally by the trace system
        #define _TRACE_PRINT RDebug::Print
        #define _TRACE_TEXT(x) (TPtrC((const TText *)(x)))
        #define _TRACE_MODULE Phonon::MMF

        // Macros available for use by implementation code
#ifdef _DEBUG
        #define TRACE_CONTEXT(_fn, _cat) const ::Phonon::MMF::TTraceContext _tc((TText*)L ## #_fn, (TUint)this, _cat);
        #define TRACE_ENTRY_0() { if(_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "+ Phonon::MMF::%s [0x%08x]"), _tc.iFunction, _tc.iAddr); }
        #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); }
        #define TRACE_EXIT_0() { if(_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "- Phonon::MMF::%s [0x%08x]"), _tc.iFunction, _tc.iAddr); }
        #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); }
        #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;
        #define TRACE_PANIC(code) { _TRACE_PRINT(_TRACE_TEXT(L ## "! Phonon::MMF::%s [0x%08x] panic %d"), _tc.iFunction, _tc.iAddr, code); } Utils::panic(code);
        #define TRACE(string, args...) { if(_tc.Enabled()) _TRACE_PRINT(_TRACE_TEXT(L ## "Phonon::MMF::%s [0x%08x] " L ## string), _tc.iFunction, _tc.iAddr, args); }
#else
        #define TRACE_CONTEXT(_fn, _cat)
        #define TRACE_ENTRY_0()
        #define TRACE_ENTRY(string, args...)
        #define TRACE_EXIT_0()
        #define TRACE_EXIT(string, args...)
        #define TRACE_RETURN(string, result) return result;
        #define TRACE_PANIC(code) Utils::panic(code);
        #define TRACE(string, args...)
#endif
    }
}

#endif