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

Revision 1297, 8.1 kB (checked in by ppalmers, 13 years ago)

improve signals

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