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

Revision 1498, 8.2 kB (checked in by ppalmers, 15 years ago)

Merge all changes from 2.0 branch into trunk (since r1361). This _should_ contain all forward merges done in the mean time. At this moment in time both branches should be in sync.

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; // required to have container access other slave elements
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     bool isLocked();
125     Util::Mutex* getLock();
126
127     Element *           m_Parent;
128     Control::Element &  m_Slave;
129 private:
130     Util::Mutex*        m_UpdateLock;
131 protected:
132     DECLARE_DEBUG_MODULE;
133 };
134 typedef std::vector<Element *> ElementVector;
135 typedef std::vector<Element *>::iterator ElementVectorIterator;
136 typedef std::vector<Element *>::const_iterator ConstElementVectorIterator;
137
138 class Container
139 : public org::ffado::Control::Element::Container
140 , public DBusControl::Element
141 {
142 public:
143     Container( DBus::Connection& connection,
144                   std::string p, Element *,
145                   Control::Container &slave );
146     virtual ~Container();
147
148     DBus::Int32 getNbElements( );
149     DBus::String getElementName( const DBus::Int32& );
150
151     void updated(int new_nb_elements);
152     void destroyed();
153
154     void setVerboseLevel( const DBus::Int32 &);
155 private:
156     Element *createHandler(Element *, Control::Element& e);
157     void updateTree();
158     Element * findElementForControl(Control::Element *e);
159     void removeElement(Element *e);
160
161     Control::Container &        m_Slave;
162     ElementVector               m_Children;
163     Control::SignalFunctor *    m_updateFunctor;
164 };
165
166 class Continuous
167 : public org::ffado::Control::Element::Continuous
168 , public Element
169 {
170 public:
171     Continuous( DBus::Connection& connection,
172                   std::string p, Element *,
173                   Control::Continuous &slave );
174    
175     DBus::Double setValue( const DBus::Double & value );
176     DBus::Double getValue( );
177     DBus::Double getMinimum( );
178     DBus::Double getMaximum( );
179     DBus::Double setValueIdx( const DBus::Int32 & idx,
180                               const DBus::Double & value );
181     DBus::Double getValueIdx( const DBus::Int32 & idx );
182
183 private:
184     Control::Continuous &m_Slave;
185 };
186
187 class Discrete
188 : public org::ffado::Control::Element::Discrete
189 , public Element
190 {
191 public:
192     Discrete( DBus::Connection& connection,
193               std::string p, Element *,
194               Control::Discrete &slave );
195    
196     DBus::Int32 setValue( const DBus::Int32 & value );
197     DBus::Int32 getValue( );
198     DBus::Int32 setValueIdx( const DBus::Int32 & idx,
199                              const DBus::Int32 & value );
200     DBus::Int32 getValueIdx( const DBus::Int32 & idx );
201
202 private:
203     Control::Discrete &m_Slave;
204 };
205
206 class Text
207 : public org::ffado::Control::Element::Text
208 , public Element
209 {
210 public:
211     Text( DBus::Connection& connection,
212           std::string p, Element *,
213           Control::Text &slave );
214
215     DBus::String setValue( const DBus::String & value );
216     DBus::String getValue( );
217
218 private:
219     Control::Text &m_Slave;
220 };
221
222 class Register
223 : public org::ffado::Control::Element::Register
224 , public Element
225 {
226 public:
227     Register( DBus::Connection& connection,
228               std::string p, Element *,
229               Control::Register &slave );
230    
231     DBus::UInt64 setValue( const DBus::UInt64 & addr, const DBus::UInt64 & value );
232     DBus::UInt64 getValue( const DBus::UInt64 & addr );
233
234 private:
235     Control::Register &m_Slave;
236 };
237
238 class Enum
239 : public org::ffado::Control::Element::Enum
240 , public Element
241 {
242 public:
243     Enum( DBus::Connection& connection,
244           std::string p, Element *,
245           Control::Enum &slave );
246    
247     DBus::Int32 select( const DBus::Int32 & idx );
248     DBus::Int32 selected( );
249     DBus::Int32 count( );
250     DBus::String getEnumLabel( const DBus::Int32 & idx );
251
252 private:
253     Control::Enum &m_Slave;
254 };
255
256 class AttributeEnum
257 : public org::ffado::Control::Element::AttributeEnum
258 , public Element
259 {
260 public:
261     AttributeEnum( DBus::Connection& connection,
262                    std::string p, Element *,
263                    Control::AttributeEnum &slave );
264    
265     DBus::Int32 select( const DBus::Int32 & idx );
266     DBus::Int32 selected( );
267     DBus::Int32 count( );
268     DBus::Int32 attributeCount();
269     DBus::String getEnumLabel( const DBus::Int32 & idx );
270     DBus::String getAttributeValue( const DBus::Int32 & idx );
271     DBus::String getAttributeName( const DBus::Int32 & idx );
272
273 private:
274     Control::AttributeEnum &m_Slave;
275 };
276
277 // FIXME: to change this to a normal ConfigRom class name we have to
278 // put the 1394 config rom class into a separate namespace.
279 class ConfigRomX
280 : public org::ffado::Control::Element::ConfigRomX
281 , public Element
282 {
283 public:
284     ConfigRomX( DBus::Connection& connection,
285                   std::string p, Element *,
286                   ConfigRom &slave );
287
288     DBus::String getGUID( );
289     DBus::String getVendorName( );
290     DBus::String getModelName( );
291     DBus::Int32 getVendorId( );
292     DBus::Int32 getModelId( );
293     DBus::Int32 getUnitVersion( );
294
295 private:
296     ConfigRom &m_Slave;
297 };
298
299 class MatrixMixer
300 : public org::ffado::Control::Element::MatrixMixer
301 , public Element
302 {
303 public:
304     MatrixMixer(  DBus::Connection& connection,
305                   std::string p, Element *,
306                   Control::MatrixMixer &slave );
307
308     DBus::String getRowName( const DBus::Int32& );
309     DBus::String getColName( const DBus::Int32& );
310     DBus::Int32 canWrite( const DBus::Int32&, const DBus::Int32& );
311     DBus::Double setValue( const DBus::Int32&, const DBus::Int32&, const DBus::Double& );
312     DBus::Double getValue( const DBus::Int32&, const DBus::Int32& );
313     DBus::Int32 getRowCount( );
314     DBus::Int32 getColCount( );
315
316 private:
317     Control::MatrixMixer &m_Slave;
318 };
319
320 }
321
322 #endif // CONTROLSERVER_H
Note: See TracBrowser for help on using the browser.