root/branches/libffado-2.0/support/dbus/controlserver.h

Revision 1385, 8.2 kB (checked in by ppalmers, 12 years ago)

Implement a mechanism to disable the samplerate and clock source controls while the device is streaming in order to avoid changes that could mess up jack. The saffire pro controls that cause a device reset to
happen are also disabled while streaming is active.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program 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
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef CONTROLSERVER_H
25 #define CONTROLSERVER_H
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <dbus-c++/dbus.h>
30
31 #include "controlserver-glue.h"
32
33 #include "libcontrol/BasicElements.h"
34 #include "libieee1394/configrom.h"
35 #include "libutil/Mutex.h"
36
37 namespace Control {
38     class MatrixMixer;
39 };
40
41 namespace DBusControl {
42
43 class Element;
44 class Container;
45
46 template< typename CalleePtr, typename MemFunPtr >
47 class MemberSignalFunctor0
48     : public Control::SignalFunctor
49 {
50 public:
51     MemberSignalFunctor0( const CalleePtr& pCallee,
52             MemFunPtr pMemFun,
53             int pSignalId)
54         : Control::SignalFunctor( pSignalId )
55         , m_pCallee( pCallee )
56         , m_pMemFun( pMemFun )
57         {}
58
59     virtual ~MemberSignalFunctor0()
60         {}
61
62     virtual void operator() ()
63         {
64             ( ( *m_pCallee ).*m_pMemFun )();
65         }
66     virtual void operator() (int) {}
67 private:
68     CalleePtr  m_pCallee;
69     MemFunPtr  m_pMemFun;
70 };
71
72 template< typename CalleePtr, typename MemFunPtr >
73 class MemberSignalFunctor1
74     : public Control::SignalFunctor
75 {
76 public:
77     MemberSignalFunctor1( const CalleePtr& pCallee,
78             MemFunPtr pMemFun,
79             int pSignalId)
80         : Control::SignalFunctor( pSignalId )
81         , m_pCallee( pCallee )
82         , m_pMemFun( pMemFun )
83         {}
84
85     virtual ~MemberSignalFunctor1()
86         {}
87
88     virtual void operator() () {}
89
90     virtual void operator() (int value)
91         {
92             ( ( *m_pCallee ).*m_pMemFun )(value);
93         }
94 private:
95     CalleePtr  m_pCallee;
96     MemFunPtr  m_pMemFun;
97 };
98
99 class Element
100 : public org::ffado::Control::Element::Element
101 , public DBus::IntrospectableAdaptor
102 , public DBus::ObjectAdaptor
103 {
104 friend class Container; // This should not be necessary since Container derives from Element
105 public:
106
107     Element( DBus::Connection& connection,
108              std::string p, Element *,
109              Control::Element &slave );
110
111     DBus::UInt64 getId( );
112     DBus::String getName( );
113     DBus::String getLabel( );
114     DBus::String getDescription( );
115
116     DBus::Bool canChangeValue( );
117
118     void setVerboseLevel( const DBus::Int32 &);
119     DBus::Int32 getVerboseLevel();
120
121 protected:
122     void Lock();
123     void Unlock();
124     Util::Mutex* getLock();
125
126     Element *           m_Parent;
127     Control::Element &  m_Slave;
128 private:
129     Util::Mutex*        m_UpdateLock;
130 protected:
131     DECLARE_DEBUG_MODULE;
132 };
133 typedef std::vector<Element *> ElementVector;
134 typedef std::vector<Element *>::iterator ElementVectorIterator;
135 typedef std::vector<Element *>::const_iterator ConstElementVectorIterator;
136
137 class Container
138 : public org::ffado::Control::Element::Container
139 , public Element
140 {
141 public:
142     Container( DBus::Connection& connection,
143                   std::string p, Element *,
144                   Control::Container &slave );
145     virtual ~Container();
146
147     DBus::Int32 getNbElements( );
148     DBus::String getElementName( const DBus::Int32& );
149
150     void updated(int new_nb_elements);
151     void destroyed();
152
153     void setVerboseLevel( const DBus::Int32 &);
154 private:
155     Element *createHandler(Element *, Control::Element& e);
156     void updateTree();
157     Element * findElementForControl(Control::Element *e);
158     void removeElement(Element *e);
159
160     Control::Container &        m_Slave;
161     ElementVector               m_Children;
162     Control::SignalFunctor *    m_updateFunctor;
163 };
164
165 class Continuous
166 : public org::ffado::Control::Element::Continuous
167 , public Element
168 {
169 public:
170     Continuous( DBus::Connection& connection,
171                   std::string p, Element *,
172                   Control::Continuous &slave );
173    
174     DBus::Double setValue( const DBus::Double & value );
175     DBus::Double getValue( );
176     DBus::Double getMinimum( );
177     DBus::Double getMaximum( );
178     DBus::Double setValueIdx( const DBus::Int32 & idx,
179                               const DBus::Double & value );
180     DBus::Double getValueIdx( const DBus::Int32 & idx );
181
182 private:
183     Control::Continuous &m_Slave;
184 };
185
186 class Discrete
187 : public org::ffado::Control::Element::Discrete
188 , public Element
189 {
190 public:
191     Discrete( DBus::Connection& connection,
192               std::string p, Element *,
193               Control::Discrete &slave );
194    
195     DBus::Int32 setValue( const DBus::Int32 & value );
196     DBus::Int32 getValue( );
197     DBus::Int32 setValueIdx( const DBus::Int32 & idx,
198                              const DBus::Int32 & value );
199     DBus::Int32 getValueIdx( const DBus::Int32 & idx );
200
201 private:
202     Control::Discrete &m_Slave;
203 };
204
205 class Text
206 : public org::ffado::Control::Element::Text
207 , public Element
208 {
209 public:
210     Text( DBus::Connection& connection,
211           std::string p, Element *,
212           Control::Text &slave );
213
214     DBus::String setValue( const DBus::String & value );
215     DBus::String getValue( );
216
217 private:
218     Control::Text &m_Slave;
219 };
220
221 class Register
222 : public org::ffado::Control::Element::Register
223 , public Element
224 {
225 public:
226     Register( DBus::Connection& connection,
227               std::string p, Element *,
228               Control::Register &slave );
229    
230     DBus::UInt64 setValue( const DBus::UInt64 & addr, const DBus::UInt64 & value );
231     DBus::UInt64 getValue( const DBus::UInt64 & addr );
232
233 private:
234     Control::Register &m_Slave;
235 };
236
237 class Enum
238 : public org::ffado::Control::Element::Enum
239 , public Element
240 {
241 public:
242     Enum( DBus::Connection& connection,
243           std::string p, Element *,
244           Control::Enum &slave );
245    
246     DBus::Int32 select( const DBus::Int32 & idx );
247     DBus::Int32 selected( );
248     DBus::Int32 count( );
249     DBus::String getEnumLabel( const DBus::Int32 & idx );
250
251 private:
252     Control::Enum &m_Slave;
253 };
254
255 class AttributeEnum
256 : public org::ffado::Control::Element::AttributeEnum
257 , public Element
258 {
259 public:
260     AttributeEnum( DBus::Connection& connection,
261                    std::string p, Element *,
262                    Control::AttributeEnum &slave );
263    
264     DBus::Int32 select( const DBus::Int32 & idx );
265     DBus::Int32 selected( );
266     DBus::Int32 count( );
267     DBus::Int32 attributeCount();
268     DBus::String getEnumLabel( const DBus::Int32 & idx );
269     DBus::String getAttributeValue( const DBus::Int32 & idx );
270     DBus::String getAttributeName( const DBus::Int32 & idx );
271
272 private:
273     Control::AttributeEnum &m_Slave;
274 };
275
276 // FIXME: to change this to a normal ConfigRom class name we have to
277 // put the 1394 config rom class into a separate namespace.
278 class ConfigRomX
279 : public org::ffado::Control::Element::ConfigRomX
280 , public Element
281 {
282 public:
283     ConfigRomX( DBus::Connection& connection,
284                   std::string p, Element *,
285                   ConfigRom &slave );
286
287     DBus::String getGUID( );
288     DBus::String getVendorName( );
289     DBus::String getModelName( );
290     DBus::Int32 getVendorId( );
291     DBus::Int32 getModelId( );
292     DBus::Int32 getUnitVersion( );
293
294 private:
295     ConfigRom &m_Slave;
296 };
297
298 class MatrixMixer
299 : public org::ffado::Control::Element::MatrixMixer
300 , public Element
301 {
302 public:
303     MatrixMixer(  DBus::Connection& connection,
304                   std::string p, Element *,
305                   Control::MatrixMixer &slave );
306
307     DBus::String getRowName( const DBus::Int32& );
308     DBus::String getColName( const DBus::Int32& );
309     DBus::Int32 canWrite( const DBus::Int32&, const DBus::Int32& );
310     DBus::Double setValue( const DBus::Int32&, const DBus::Int32&, const DBus::Double& );
311     DBus::Double getValue( const DBus::Int32&, const DBus::Int32& );
312     DBus::Int32 getRowCount( );
313     DBus::Int32 getColCount( );
314
315 private:
316     Control::MatrixMixer &m_Slave;
317 };
318
319 }
320
321 #endif // CONTROLSERVER_H
Note: See TracBrowser for help on using the browser.