root/trunk/libffado/support/dbus/controlserver.h

Revision 1776, 10.1 kB (checked in by arnonym, 11 years ago)

Reduce the LOC:

  • Use only strings as identifiers for the Dice::EAP::Router. Updating the router doesn't happen that often, using strings only is acceptable. And it eases handling so much.
  • Adapt the control interface.
  • Adapt the dbus interface.
  • Adapt the routers gui.
  • The peak-space is not yet working (I didn't actually test it), the peak-functions of EAP::Router return nothing.
  • And the test for the dice has to be adopted when the peaks are working again.

TODO:

  • Re-activate the peaks.
  • Adopt the mixer interface.
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     class CrossbarRouter;
40 };
41
42 namespace DBusControl {
43
44 class Element;
45 class Container;
46
47 template< typename CalleePtr, typename MemFunPtr >
48 class MemberSignalFunctor0
49     : public Control::SignalFunctor
50 {
51 public:
52     MemberSignalFunctor0( const CalleePtr& pCallee,
53             MemFunPtr pMemFun,
54             int pSignalId)
55         : Control::SignalFunctor( pSignalId )
56         , m_pCallee( pCallee )
57         , m_pMemFun( pMemFun )
58         {}
59
60     virtual ~MemberSignalFunctor0()
61         {}
62
63     virtual void operator() ()
64         {
65             ( ( *m_pCallee ).*m_pMemFun )();
66         }
67     virtual void operator() (int) {}
68 private:
69     CalleePtr  m_pCallee;
70     MemFunPtr  m_pMemFun;
71 };
72
73 template< typename CalleePtr, typename MemFunPtr >
74 class MemberSignalFunctor1
75     : public Control::SignalFunctor
76 {
77 public:
78     MemberSignalFunctor1( const CalleePtr& pCallee,
79             MemFunPtr pMemFun,
80             int pSignalId)
81         : Control::SignalFunctor( pSignalId )
82         , m_pCallee( pCallee )
83         , m_pMemFun( pMemFun )
84         {}
85
86     virtual ~MemberSignalFunctor1()
87         {}
88
89     virtual void operator() () {}
90
91     virtual void operator() (int value)
92         {
93             ( ( *m_pCallee ).*m_pMemFun )(value);
94         }
95 private:
96     CalleePtr  m_pCallee;
97     MemFunPtr  m_pMemFun;
98 };
99
100 class Element
101 : public org::ffado::Control::Element::Element
102 , public DBus::IntrospectableAdaptor
103 , public DBus::ObjectAdaptor
104 {
105 friend class Container; // required to have container access other slave elements
106 public:
107
108     Element( DBus::Connection& connection,
109              std::string p, Element *,
110              Control::Element &slave );
111
112     DBus::UInt64 getId( );
113     DBus::String getName( );
114     DBus::String getLabel( );
115     DBus::String getDescription( );
116
117     DBus::Bool canChangeValue( );
118
119     void setVerboseLevel( const DBus::Int32 &);
120     DBus::Int32 getVerboseLevel();
121
122 protected:
123     void Lock();
124     void Unlock();
125     bool isLocked();
126     Util::Mutex* getLock();
127
128     Element *           m_Parent;
129     Control::Element &  m_Slave;
130 private:
131     Util::Mutex*        m_UpdateLock;
132 protected:
133     DECLARE_DEBUG_MODULE;
134 };
135 typedef std::vector<Element *> ElementVector;
136 typedef std::vector<Element *>::iterator ElementVectorIterator;
137 typedef std::vector<Element *>::const_iterator ConstElementVectorIterator;
138
139 class Container
140 : public org::ffado::Control::Element::Container
141 , public DBusControl::Element
142 {
143 public:
144     Container( DBus::Connection& connection,
145                   std::string p, Element *,
146                   Control::Container &slave );
147     virtual ~Container();
148
149     DBus::Int32 getNbElements( );
150     DBus::String getElementName( const DBus::Int32& );
151
152     void updated(int new_nb_elements);
153     void destroyed();
154
155     void setVerboseLevel( const DBus::Int32 &);
156 private:
157     Element *createHandler(Element *, Control::Element& e);
158     void updateTree();
159     Element * findElementForControl(Control::Element *e);
160     void removeElement(Element *e);
161
162     Control::Container &        m_Slave;
163     ElementVector               m_Children;
164     Control::SignalFunctor *    m_updateFunctor;
165 };
166
167 class Continuous
168 : public org::ffado::Control::Element::Continuous
169 , public Element
170 {
171 public:
172     Continuous( DBus::Connection& connection,
173                   std::string p, Element *,
174                   Control::Continuous &slave );
175    
176     DBus::Double setValue( const DBus::Double & value );
177     DBus::Double getValue( );
178     DBus::Double getMinimum( );
179     DBus::Double getMaximum( );
180     DBus::Double setValueIdx( const DBus::Int32 & idx,
181                               const DBus::Double & value );
182     DBus::Double getValueIdx( const DBus::Int32 & idx );
183
184 private:
185     Control::Continuous &m_Slave;
186 };
187
188 class Discrete
189 : public org::ffado::Control::Element::Discrete
190 , public Element
191 {
192 public:
193     Discrete( DBus::Connection& connection,
194               std::string p, Element *,
195               Control::Discrete &slave );
196    
197     DBus::Int32 setValue( const DBus::Int32 & value );
198     DBus::Int32 getValue( );
199     DBus::Int32 setValueIdx( const DBus::Int32 & idx,
200                              const DBus::Int32 & value );
201     DBus::Int32 getValueIdx( const DBus::Int32 & idx );
202
203 private:
204     Control::Discrete &m_Slave;
205 };
206
207 class Text
208 : public org::ffado::Control::Element::Text
209 , public Element
210 {
211 public:
212     Text( DBus::Connection& connection,
213           std::string p, Element *,
214           Control::Text &slave );
215
216     DBus::String setValue( const DBus::String & value );
217     DBus::String getValue( );
218
219 private:
220     Control::Text &m_Slave;
221 };
222
223 class Register
224 : public org::ffado::Control::Element::Register
225 , public Element
226 {
227 public:
228     Register( DBus::Connection& connection,
229               std::string p, Element *,
230               Control::Register &slave );
231    
232     DBus::UInt64 setValue( const DBus::UInt64 & addr, const DBus::UInt64 & value );
233     DBus::UInt64 getValue( const DBus::UInt64 & addr );
234
235 private:
236     Control::Register &m_Slave;
237 };
238
239 class Enum
240 : public org::ffado::Control::Element::Enum
241 , public Element
242 {
243 public:
244     Enum( DBus::Connection& connection,
245           std::string p, Element *,
246           Control::Enum &slave );
247    
248     DBus::Int32 select( const DBus::Int32 & idx );
249     DBus::Int32 selected( );
250     DBus::Int32 count( );
251     DBus::String getEnumLabel( const DBus::Int32 & idx );
252
253 private:
254     Control::Enum &m_Slave;
255 };
256
257 class AttributeEnum
258 : public org::ffado::Control::Element::AttributeEnum
259 , public Element
260 {
261 public:
262     AttributeEnum( DBus::Connection& connection,
263                    std::string p, Element *,
264                    Control::AttributeEnum &slave );
265    
266     DBus::Int32 select( const DBus::Int32 & idx );
267     DBus::Int32 selected( );
268     DBus::Int32 count( );
269     DBus::Int32 attributeCount();
270     DBus::String getEnumLabel( const DBus::Int32 & idx );
271     DBus::String getAttributeValue( const DBus::Int32 & idx );
272     DBus::String getAttributeName( const DBus::Int32 & idx );
273
274 private:
275     Control::AttributeEnum &m_Slave;
276 };
277
278 // FIXME: to change this to a normal ConfigRom class name we have to
279 // put the 1394 config rom class into a separate namespace.
280 class ConfigRomX
281 : public org::ffado::Control::Element::ConfigRomX
282 , public Element
283 {
284 public:
285     ConfigRomX( DBus::Connection& connection,
286                   std::string p, Element *,
287                   ConfigRom &slave );
288
289     DBus::String getGUID( );
290     DBus::String getVendorName( );
291     DBus::String getModelName( );
292     DBus::Int32 getVendorId( );
293     DBus::Int32 getModelId( );
294     DBus::Int32 getUnitVersion( );
295
296 private:
297     ConfigRom &m_Slave;
298 };
299
300 class MatrixMixer
301 : public org::ffado::Control::Element::MatrixMixer
302 , public Element
303 {
304 public:
305     MatrixMixer(  DBus::Connection& connection,
306                   std::string p, Element *,
307                   Control::MatrixMixer &slave );
308
309     DBus::Int32 getRowCount( );
310     DBus::Int32 getColCount( );
311
312     DBus::Int32 canWrite( const DBus::Int32&, const DBus::Int32& );
313     DBus::Double setValue( const DBus::Int32&, const DBus::Int32&, const DBus::Double& );
314     DBus::Double getValue( const DBus::Int32&, const DBus::Int32& );
315
316     DBus::Bool hasNames();
317     DBus::String getRowName( const DBus::Int32& );
318     DBus::String getColName( const DBus::Int32& );
319     DBus::Bool setRowName( const DBus::Int32&, const DBus::String& );
320     DBus::Bool setColName( const DBus::Int32&, const DBus::String& );
321
322     DBus::Bool canConnect();
323     std::vector<DBus::String> availableConnectionsForRow( const DBus::Int32& );
324     std::vector<DBus::String> availableConnectionsForCol( const DBus::Int32& );
325     DBus::Bool connectRowTo( const DBus::Int32&, const DBus::String& );
326     DBus::Bool connectColTo( const DBus::Int32&, const DBus::String& );
327
328 private:
329     Control::MatrixMixer &m_Slave;
330 };
331
332 class CrossbarRouter
333 : public org::ffado::Control::Element::CrossbarRouter
334 , public Element
335 {
336 public:
337     CrossbarRouter(  DBus::Connection& connection,
338                   std::string p, Element *,
339                   Control::CrossbarRouter &slave );
340
341     std::vector< DBus::String > getSourceNames();
342     std::vector< DBus::String > getDestinationNames();
343
344     std::vector< DBus::String > getDestinationsForSource(const DBus::String &);
345     DBus::String getSourceForDestination(const DBus::String &);
346
347     DBus::Bool  canConnect(const DBus::String &source, const DBus::String &dest);
348     DBus::Bool  setConnectionState(const DBus::String &source, const DBus::String &dest, const DBus::Bool &enable);
349     DBus::Bool  getConnectionState(const DBus::String &source, const DBus::String &dest);
350
351     DBus::Bool  clearAllConnections();
352
353     DBus::Bool  hasPeakMetering();
354     DBus::Double getPeakValue(const DBus::String &dest);
355     std::vector< DBus::Struct<DBus::String, double> > getPeakValues();
356
357 private:
358     Control::CrossbarRouter &m_Slave;
359 };
360
361 class Boolean
362 : public org::ffado::Control::Element::Boolean
363 , public Element
364 {
365 public:
366     Boolean( DBus::Connection& connection,
367           std::string p, Element *,
368           Control::Boolean &slave );
369    
370     DBus::Bool select( const DBus::Bool& value );
371     DBus::Bool selected();
372     DBus::String getBooleanLabel( const DBus::Bool& value );
373
374 private:
375     Control::Boolean &m_Slave;
376 };
377 }
378
379 #endif // CONTROLSERVER_H
Note: See TracBrowser for help on using the browser.