root/trunk/libffado/src/debugmodule/debugmodule.h

Revision 575, 8.6 kB (checked in by ppalmers, 17 years ago)

- Fixed bug in dbus c++ bindings
- First attempt at a decoupled control interface. [WIP]


The src/libcontrol/* elements are the ones that should be
subclassed to implement control elements on the FFADODevice
side.

The tests/controlserver.* files contain some code that
interfaces the DBus calls to these libcontrol elements. The
DBus classes allow for introspection and path discovery,
such that we don't have to care about that anymore.

In the end it should be fairly easy to write another 'backend'
to replace the current DBus one, e.g. to implement OSC support
or MIDI support. (Should we ever want that)

Note that there is no connection between ffado and dbus yet,
this code is merely to experiment with the Control/DBus infra-
structure. Once that is sort-of working, connecting ffado to
this infrastructure is a matter of subclassing the Control::*
classes, creating them on discovery and putting them into one
Container::* that is passed on to the DBus handlers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  * Copyright (C) 2005-2007 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software Foundation;
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  */
24
25 #ifndef DEBUGMODULE_H
26 #define DEBUGMODULE_H
27
28 #include "../fbtypes.h"
29 #include <assert.h>
30
31 #include <vector>
32 #include <iostream>
33
34 typedef short debug_level_t;
35
36 #define DEBUG_MAX_MESSAGE_LENGTH 1024
37
38 /* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
39 #define MB_BUFFERS    (1<<16)
40
41 #define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
42 #define MB_BUFFERSIZE    DEBUG_MAX_MESSAGE_LENGTH        /* message length limit */
43
44 #define debugFatal( format, args... )                               \
45                 m_debugModule.print( DebugModule::eDL_Fatal,        \
46                                      __FILE__,                      \
47                                      __FUNCTION__,                  \
48                                      __LINE__,                      \
49                                      format,                        \
50                                      ##args )
51 #define debugError( format, args... )                               \
52                 m_debugModule.print( DebugModule::eDL_Error,        \
53                                      __FILE__,                      \
54                                      __FUNCTION__,                  \
55                                      __LINE__,                      \
56                                      format,                        \
57                                      ##args )
58 #define debugWarning( format, args... )                             \
59                 m_debugModule.print( DebugModule::eDL_Warning,      \
60                                      __FILE__,                      \
61                                      __FUNCTION__,                  \
62                                      __LINE__,                      \
63                                     format,                         \
64                                     ##args )
65
66 #define debugFatalShort( format, args... )                          \
67                 m_debugModule.printShort( DebugModule::eDL_Fatal,   \
68                                      format,                        \
69                                      ##args )
70 #define debugErrorShort( format, args... )                          \
71                 m_debugModule.printShort( DebugModule::eDL_Error,   \
72                                      format,                        \
73                                      ##args )
74 #define debugWarningShort( format, args... )                        \
75                 m_debugModule.printShort( DebugModule::eDL_Warning, \
76                                      format,                        \
77                                      ##args )
78
79 #define DECLARE_DEBUG_MODULE static DebugModule m_debugModule
80 #define IMPL_DEBUG_MODULE( ClassName, RegisterName, Level )        \
81                 DebugModule ClassName::m_debugModule =             \
82                     DebugModule( #RegisterName, Level )
83
84 #define DECLARE_GLOBAL_DEBUG_MODULE extern DebugModule m_debugModule
85 #define IMPL_GLOBAL_DEBUG_MODULE( RegisterName, Level )            \
86                 DebugModule m_debugModule =                        \
87             DebugModule( #RegisterName, Level )
88
89 #define setDebugLevel( Level ) {                                    \
90                 m_debugModule.setLevel( Level ); \
91                 }
92
93 /*                m_debugModule.print( eDL_Normal,                        \
94                                      __FILE__,                     \
95                                      __FUNCTION__,                 \
96                                      __LINE__,                     \
97                                      "Setting debug level to %d\n",  \
98                                      Level ); \
99                 }*/
100
101 #define getDebugLevel(  )                                     \
102                 m_debugModule.getLevel( )
103
104 #define flushDebugOutput()      DebugModuleManager::instance()->flush()
105
106 #ifdef DEBUG
107
108     #define debugOutput( level, format, args... )                  \
109                 m_debugModule.print( level,                        \
110                                      __FILE__,                     \
111                                      __FUNCTION__,                 \
112                                      __LINE__,                     \
113                                      format,                       \
114                                      ##args )
115
116     #define debugOutputShort( level, format, args... )             \
117                 m_debugModule.printShort( level,                   \
118                                      format,                       \
119                                      ##args )
120
121 #else
122
123     #define debugOutput( level, format, args... )
124     #define debugOutputShort( level, format, args... )
125
126 #endif
127
128 /* Enable preemption checking for Linux Realtime Preemption kernels.
129  *
130  * This checks if any RT-safe code section does anything to cause CPU
131  * preemption.  Examples are sleep() or other system calls that block.
132  * If a problem is detected, the kernel writes a syslog entry, and
133  * sends SIGUSR2 to the client.
134  */
135
136 // #define DO_PREEMPTION_CHECKING
137
138 #include <sys/time.h>
139
140 #ifdef DO_PREEMPTION_CHECKING
141 #define CHECK_PREEMPTION(onoff) \
142     gettimeofday((struct timeval *)1, (struct timezone *)onoff)
143 #else
144 #define CHECK_PREEMPTION(onoff)
145 #endif
146
147 unsigned char toAscii( unsigned char c );
148 void quadlet2char( fb_quadlet_t quadlet, unsigned char* buff );
149 void hexDump( unsigned char *data_start, unsigned int length );
150 void hexDumpQuadlets( quadlet_t *data_start, unsigned int length );
151
152 class DebugModule {
153 public:
154     enum {
155         eDL_Fatal       = 0,
156         eDL_Error       = 1,
157         eDL_Warning     = 2,
158         eDL_Normal      = 3,
159         eDL_Info        = 4,
160         eDL_Verbose     = 5,
161         eDL_VeryVerbose = 6,
162     } EDebugLevel;
163
164     DebugModule( std::string name, debug_level_t level );
165     virtual ~DebugModule();
166
167     void printShort( debug_level_t level,
168                      const char* format,
169                      ... ) const;
170
171     void print( debug_level_t level,
172                 const char*   file,
173                 const char*   function,
174                 unsigned int  line,
175                 const char*   format,
176                 ... ) const;
177
178     bool setLevel( debug_level_t level )
179         { m_level = level; return true; }
180     debug_level_t getLevel()
181         { return m_level; }
182     std::string getName()
183         { return m_name; }
184
185 protected:
186     const char* getPreSequence( debug_level_t level ) const;
187     const char* getPostSequence( debug_level_t level ) const;
188
189 private:
190     std::string   m_name;
191     debug_level_t m_level;
192 };
193
194 #define DEBUG_LEVEL_NORMAL          DebugModule::eDL_Normal
195 #define DEBUG_LEVEL_INFO            DebugModule::eDL_Info
196 #define DEBUG_LEVEL_VERBOSE         DebugModule::eDL_Verbose
197 #define DEBUG_LEVEL_VERY_VERBOSE    DebugModule::eDL_VeryVerbose
198
199
200 class DebugModuleManager {
201 public:
202     friend class DebugModule;
203
204     static DebugModuleManager* instance();
205     ~DebugModuleManager();
206
207     bool setMgrDebugLevel( std::string name, debug_level_t level );
208
209     void flush();
210
211 protected:
212     bool registerModule( DebugModule& debugModule );
213     bool unregisterModule( DebugModule& debugModule );
214
215     bool init();
216
217     void print(const char *fmt, ...);
218     void va_print(const char *fmt, va_list);
219
220 private:
221     DebugModuleManager();
222
223     typedef std::vector< DebugModule* > DebugModuleVector;
224     typedef std::vector< DebugModule* >::iterator DebugModuleVectorIterator;
225
226     char mb_buffers[MB_BUFFERS][MB_BUFFERSIZE];
227     unsigned int mb_initialized;
228     unsigned int mb_inbuffer;
229     unsigned int mb_outbuffer;
230     unsigned int mb_overruns;
231     pthread_t mb_writer_thread;
232     pthread_mutex_t mb_write_lock;
233     pthread_mutex_t mb_flush_lock;
234     pthread_cond_t mb_ready_cond;
235
236     static void *mb_thread_func(void *arg);
237     void mb_flush();
238
239     static DebugModuleManager* m_instance;
240     DebugModuleVector          m_debugModules;
241 };
242
243 #endif
Note: See TracBrowser for help on using the browser.