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

Revision 1888, 9.8 kB (checked in by arnonym, 11 years ago)

Drop the libs in external/ and use the system-libs for that. Easier on administration, easier on compilation time, easier for packagers.

This is basically the patches provided by packagers in #290.

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_adaptor
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     uint64_t getId( );
113     std::string getName( );
114     std::string getLabel( );
115     std::string getDescription( );
116
117     bool canChangeValue( );
118
119     void setVerboseLevel( const int32_t &);
120     int32_t 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_adaptor
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     int32_t getNbElements( );
150     std::string getElementName( const int32_t& );
151
152     void updated(int new_nb_elements);
153     void destroyed();
154
155     void setVerboseLevel( const int32_t &);
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_adaptor
169 , public Element
170 {
171 public:
172     Continuous( DBus::Connection& connection,
173                   std::string p, Element *,
174                   Control::Continuous &slave );
175    
176     double setValue( const double & value );
177     double getValue( );
178     double getMinimum( );
179     double getMaximum( );
180     double setValueIdx( const int32_t & idx,
181                               const double & value );
182     double getValueIdx( const int32_t & idx );
183
184 private:
185     Control::Continuous &m_Slave;
186 };
187
188 class Discrete
189 : public org::ffado::Control::Element::Discrete_adaptor
190 , public Element
191 {
192 public:
193     Discrete( DBus::Connection& connection,
194               std::string p, Element *,
195               Control::Discrete &slave );
196    
197     int32_t setValue( const int32_t & value );
198     int32_t getValue( );
199     int32_t setValueIdx( const int32_t & idx,
200                              const int32_t & value );
201     int32_t getValueIdx( const int32_t & idx );
202
203 private:
204     Control::Discrete &m_Slave;
205 };
206
207 class Text
208 : public org::ffado::Control::Element::Text_adaptor
209 , public Element
210 {
211 public:
212     Text( DBus::Connection& connection,
213           std::string p, Element *,
214           Control::Text &slave );
215
216     std::string setValue( const std::string & value );
217     std::string getValue( );
218
219 private:
220     Control::Text &m_Slave;
221 };
222
223 class Register
224 : public org::ffado::Control::Element::Register_adaptor
225 , public Element
226 {
227 public:
228     Register( DBus::Connection& connection,
229               std::string p, Element *,
230               Control::Register &slave );
231    
232     uint64_t setValue( const uint64_t & addr, const uint64_t & value );
233     uint64_t getValue( const uint64_t & addr );
234
235 private:
236     Control::Register &m_Slave;
237 };
238
239 class Enum
240 : public org::ffado::Control::Element::Enum_adaptor
241 , public Element
242 {
243 public:
244     Enum( DBus::Connection& connection,
245           std::string p, Element *,
246           Control::Enum &slave );
247    
248     int32_t select( const int32_t & idx );
249     int32_t selected( );
250     int32_t count( );
251     std::string getEnumLabel( const int32_t & idx );
252
253 private:
254     Control::Enum &m_Slave;
255 };
256
257 class AttributeEnum
258 : public org::ffado::Control::Element::AttributeEnum_adaptor
259 , public Element
260 {
261 public:
262     AttributeEnum( DBus::Connection& connection,
263                    std::string p, Element *,
264                    Control::AttributeEnum &slave );
265    
266     int32_t select( const int32_t & idx );
267     int32_t selected( );
268     int32_t count( );
269     int32_t attributeCount();
270     std::string getEnumLabel( const int32_t & idx );
271     std::string getAttributeValue( const int32_t & idx );
272     std::string getAttributeName( const int32_t & 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_adaptor
282 , public Element
283 {
284 public:
285     ConfigRomX( DBus::Connection& connection,
286                   std::string p, Element *,
287                   ConfigRom &slave );
288
289     std::string getGUID( );
290     std::string getVendorName( );
291     std::string getModelName( );
292     int32_t getVendorId( );
293     int32_t getModelId( );
294     int32_t getUnitVersion( );
295
296 private:
297     ConfigRom &m_Slave;
298 };
299
300 class MatrixMixer
301 : public org::ffado::Control::Element::MatrixMixer_adaptor
302 , public Element
303 {
304 public:
305     MatrixMixer(  DBus::Connection& connection,
306                   std::string p, Element *,
307                   Control::MatrixMixer &slave );
308
309     int32_t getRowCount( );
310     int32_t getColCount( );
311
312     int32_t canWrite( const int32_t&, const int32_t& );
313     double setValue( const int32_t&, const int32_t&, const double& );
314     double getValue( const int32_t&, const int32_t& );
315
316     bool hasNames();
317     std::string getRowName( const int32_t& );
318     std::string getColName( const int32_t& );
319     bool setRowName( const int32_t&, const std::string& );
320     bool setColName( const int32_t&, const std::string& );
321
322     bool canConnect();
323     std::vector<std::string> availableConnectionsForRow( const int32_t& );
324     std::vector<std::string> availableConnectionsForCol( const int32_t& );
325     bool connectRowTo( const int32_t&, const std::string& );
326     bool connectColTo( const int32_t&, const std::string& );
327
328 private:
329     Control::MatrixMixer &m_Slave;
330 };
331
332 class CrossbarRouter
333 : public org::ffado::Control::Element::CrossbarRouter_adaptor
334 , public Element
335 {
336 public:
337     CrossbarRouter(  DBus::Connection& connection,
338                   std::string p, Element *,
339                   Control::CrossbarRouter &slave );
340
341     std::vector< std::string > getSourceNames();
342     std::vector< std::string > getDestinationNames();
343
344     std::vector< std::string > getDestinationsForSource(const std::string &);
345     std::string getSourceForDestination(const std::string &);
346
347     bool  canConnect(const std::string &source, const std::string &dest);
348     bool  setConnectionState(const std::string &source, const std::string &dest, const bool &enable);
349     bool  getConnectionState(const std::string &source, const std::string &dest);
350
351     bool  clearAllConnections();
352
353     bool  hasPeakMetering();
354     double getPeakValue(const std::string &dest);
355     std::vector< DBus::Struct<std::string, double> > getPeakValues();
356
357 private:
358     Control::CrossbarRouter &m_Slave;
359 };
360
361 class Boolean
362 : public org::ffado::Control::Element::Boolean_adaptor
363 , public Element
364 {
365 public:
366     Boolean( DBus::Connection& connection,
367           std::string p, Element *,
368           Control::Boolean &slave );
369    
370     bool select( const bool& value );
371     bool selected();
372     std::string getBooleanLabel( const 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.