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

Revision 965, 12.8 kB (checked in by ppalmers, 15 years ago)

add generic register read for focusrite devices

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 #include "controlserver.h"
25 #include "libcontrol/Element.h"
26 #include "libcontrol/BasicElements.h"
27 #include "libcontrol/MatrixMixer.h"
28 #include "libutil/Time.h"
29
30 namespace DBusControl {
31
32 IMPL_DEBUG_MODULE( Element, Element, DEBUG_LEVEL_VERBOSE );
33
34 // --- Element
35 Element::Element( DBus::Connection& connection, std::string p, Control::Element &slave)
36 : DBus::ObjectAdaptor(connection, p)
37 , m_Slave(slave)
38 {
39     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Element on '%s'\n",
40                  path().c_str() );
41 }
42
43 DBus::UInt64
44 Element::getId( )
45 {
46     return m_Slave.getId();
47 }
48
49 DBus::String
50 Element::getName( )
51 {
52     return DBus::String(m_Slave.getName());
53 }
54
55 DBus::String
56 Element::getLabel( )
57 {
58     return DBus::String(m_Slave.getLabel());
59 }
60
61 DBus::String
62 Element::getDescription( )
63 {
64     return DBus::String(m_Slave.getDescription());
65 }
66
67 // --- Container
68 Container::Container( DBus::Connection& connection, std::string p, Control::Container &slave)
69 : Element(connection, p, slave)
70 , m_Slave(slave)
71 {
72     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Container on '%s'\n",
73                  path().c_str() );
74
75     // add children for the slave container
76     for ( Control::ConstElementVectorIterator it = slave.getElements().begin();
77       it != slave.getElements().end();
78       ++it )
79     {
80         Element *e=createHandler(*(*it));
81         if (e) {
82             m_Children.push_back(e);
83         } else {
84             debugWarning("Failed to create handler for Control::Element %s\n",
85                 (*it)->getName().c_str());
86         }
87     }
88 }
89
90 Container::~Container() {
91     for ( ElementVectorIterator it = m_Children.begin();
92       it != m_Children.end();
93       ++it )
94     {
95         delete (*it);
96     }
97 }
98
99 DBus::Int32
100 Container::getNbElements( ) {
101     return m_Slave.countElements();
102 }
103
104 DBus::String
105 Container::getElementName( const DBus::Int32& i ) {
106     int nbElements=m_Slave.countElements();
107     if (i<nbElements) {
108         return m_Slave.getElements().at(i)->getName();
109     } else return "";
110 }
111
112
113 /**
114  * \brief create a correct DBusControl counterpart for a given Control::Element
115  */
116 Element *
117 Container::createHandler(Control::Element& e) {
118     debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handler for '%s'\n",
119                  e.getName().c_str() );
120                  
121     if (dynamic_cast<Control::Container *>(&e) != NULL) {
122         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Container\n");
123        
124         return new Container(conn(), std::string(path()+"/"+e.getName()),
125             *dynamic_cast<Control::Container *>(&e));
126     }
127    
128     if (dynamic_cast<Control::Continuous *>(&e) != NULL) {
129         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Continuous\n");
130        
131         return new Continuous(conn(), std::string(path()+"/"+e.getName()),
132             *dynamic_cast<Control::Continuous *>(&e));
133     }
134    
135     if (dynamic_cast<Control::Discrete *>(&e) != NULL) {
136         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Discrete\n");
137        
138         return new Discrete(conn(), std::string(path()+"/"+e.getName()),
139             *dynamic_cast<Control::Discrete *>(&e));
140     }
141    
142     if (dynamic_cast<Control::Text *>(&e) != NULL) {
143         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Text\n");
144        
145         return new Text(conn(), std::string(path()+"/"+e.getName()),
146             *dynamic_cast<Control::Text *>(&e));
147     }
148
149     if (dynamic_cast<Control::Register *>(&e) != NULL) {
150         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Register\n");
151        
152         return new Register(conn(), std::string(path()+"/"+e.getName()),
153             *dynamic_cast<Control::Register *>(&e));
154     }
155
156     // note that we have to check this before checking the Enum,
157     // since Enum is a base class
158     if (dynamic_cast<Control::AttributeEnum *>(&e) != NULL) {
159         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::AttributeEnum\n");
160        
161         return new AttributeEnum(conn(), std::string(path()+"/"+e.getName()),
162             *dynamic_cast<Control::AttributeEnum *>(&e));
163     }
164    
165     if (dynamic_cast<Control::Enum *>(&e) != NULL) {
166         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Enum\n");
167        
168         return new Enum(conn(), std::string(path()+"/"+e.getName()),
169             *dynamic_cast<Control::Enum *>(&e));
170     }
171    
172     if (dynamic_cast<ConfigRom *>(&e) != NULL) {
173         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a ConfigRom\n");
174        
175         return new ConfigRomX(conn(), std::string(path()+"/"+e.getName()),
176             *dynamic_cast<ConfigRom *>(&e));
177     }
178    
179     if (dynamic_cast<Control::MatrixMixer *>(&e) != NULL) {
180         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::MatrixMixer\n");
181        
182         return new MatrixMixer(conn(), std::string(path()+"/"+e.getName()),
183             *dynamic_cast<Control::MatrixMixer *>(&e));
184     }
185    
186     debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Element\n");
187     return new Element(conn(), std::string(path()+"/"+e.getName()), e);
188 }
189
190 // --- Continuous
191
192 Continuous::Continuous( DBus::Connection& connection, std::string p, Control::Continuous &slave)
193 : Element(connection, p, slave)
194 , m_Slave(slave)
195 {
196     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Continuous on '%s'\n",
197                  path().c_str() );
198 }
199
200 DBus::Double
201 Continuous::setValue( const DBus::Double& value )
202 {
203     m_Slave.setValue(value);
204 /*   
205     SleepRelativeUsec(1000*500);
206    
207     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() );
208    
209     return m_Slave.getValue();*/
210     return value;
211 }
212
213 DBus::Double
214 Continuous::getValue(  )
215 {
216     double val = m_Slave.getValue();
217     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %lf\n", val );
218     return val;
219 }
220
221 // --- Discrete
222
223 Discrete::Discrete( DBus::Connection& connection, std::string p, Control::Discrete &slave)
224 : Element(connection, p, slave)
225 , m_Slave(slave)
226 {
227     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Discrete on '%s'\n",
228                  path().c_str() );
229 }
230
231 DBus::Int32
232 Discrete::setValue( const DBus::Int32& value )
233 {
234     m_Slave.setValue(value);
235    
236 /*    SleepRelativeUsec(1000*500);
237     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
238    
239     return m_Slave.getValue();*/
240     return value;
241 }
242
243 DBus::Int32
244 Discrete::getValue()
245 {
246     int32_t val = m_Slave.getValue();
247     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %d\n", val );
248     return val;
249 }
250
251 // --- Text
252
253 Text::Text( DBus::Connection& connection, std::string p, Control::Text &slave)
254 : Element(connection, p, slave)
255 , m_Slave(slave)
256 {
257     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Text on '%s'\n",
258                  path().c_str() );
259 }
260
261 DBus::String
262 Text::setValue( const DBus::String& value )
263 {
264     m_Slave.setValue(value);
265    
266 /*    SleepRelativeUsec(1000*500);
267     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
268    
269     return m_Slave.getValue();*/
270     return value;
271 }
272
273 DBus::String
274 Text::getValue()
275 {
276     std::string val = m_Slave.getValue();
277     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %s\n", val.c_str() );
278     return val;
279 }
280
281 // --- Register
282
283 Register::Register( DBus::Connection& connection, std::string p, Control::Register &slave)
284 : Element(connection, p, slave)
285 , m_Slave(slave)
286 {
287     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Register on '%s'\n",
288                  path().c_str() );
289 }
290
291 DBus::UInt64
292 Register::setValue( const DBus::UInt64& addr, const DBus::UInt64& value )
293 {
294     m_Slave.setValue(addr, value);
295    
296 /*    SleepRelativeUsec(1000*500);
297     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
298    
299     return m_Slave.getValue();*/
300     return value;
301 }
302
303 DBus::UInt64
304 Register::getValue( const DBus::UInt64& addr )
305 {
306     DBus::UInt64 val = m_Slave.getValue(addr);
307     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue(%lld) => %lld\n", addr, val );
308     return val;
309 }
310
311 // --- Enum
312
313 Enum::Enum( DBus::Connection& connection, std::string p, Control::Enum &slave)
314 : Element(connection, p, slave)
315 , m_Slave(slave)
316 {
317     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Enum on '%s'\n",
318                  path().c_str() );
319 }
320
321 DBus::Int32
322 Enum::select( const DBus::Int32& idx )
323 {
324     debugOutput( DEBUG_LEVEL_VERBOSE, "select(%d)\n", idx );
325     return  m_Slave.select(idx);
326 }
327
328 DBus::Int32
329 Enum::selected()
330 {
331     int retval = m_Slave.selected();
332     debugOutput( DEBUG_LEVEL_VERBOSE, "selected() => %d\n", retval );
333     return retval;
334 }
335
336 DBus::Int32
337 Enum::count()
338 {
339     int retval = m_Slave.count();
340     debugOutput( DEBUG_LEVEL_VERBOSE, "count() => %d\n", retval );
341     return retval;
342 }
343
344 DBus::String
345 Enum::getEnumLabel( const DBus::Int32 & idx )
346 {
347     std::string retval = m_Slave.getEnumLabel(idx);
348     debugOutput( DEBUG_LEVEL_VERBOSE, "getEnumLabel(%d) => %s\n", idx, retval.c_str() );
349     return retval;
350 }
351
352 // --- AttributeEnum
353 AttributeEnum::AttributeEnum( DBus::Connection& connection, std::string p, Control::AttributeEnum &slave)
354 : Element(connection, p, slave)
355 , m_Slave(slave)
356 {
357     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Enum on '%s'\n",
358                  path().c_str() );
359 }
360
361 DBus::Int32
362 AttributeEnum::select( const DBus::Int32& idx )
363 {
364     debugOutput( DEBUG_LEVEL_VERBOSE, "select(%d)\n", idx );
365     return  m_Slave.select(idx);
366 }
367
368 DBus::Int32
369 AttributeEnum::selected()
370 {
371     int retval = m_Slave.selected();
372     debugOutput( DEBUG_LEVEL_VERBOSE, "selected() => %d\n", retval );
373     return retval;
374 }
375
376 DBus::Int32
377 AttributeEnum::count()
378 {
379     int retval = m_Slave.count();
380     debugOutput( DEBUG_LEVEL_VERBOSE, "count() => %d\n", retval );
381     return retval;
382 }
383
384 DBus::Int32
385 AttributeEnum::attributeCount()
386 {
387     int retval = m_Slave.attributeCount();
388     debugOutput( DEBUG_LEVEL_VERBOSE, "attributeCount() => %d\n", retval );
389     return retval;
390 }
391
392 DBus::String
393 AttributeEnum::getEnumLabel( const DBus::Int32 & idx )
394 {
395     std::string retval = m_Slave.getEnumLabel(idx);
396     debugOutput( DEBUG_LEVEL_VERBOSE, "getEnumLabel(%d) => %s\n", idx, retval.c_str() );
397     return retval;
398 }
399
400 DBus::String
401 AttributeEnum::getAttributeValue( const DBus::Int32 & idx )
402 {
403     std::string retval = m_Slave.getAttributeValue(idx);
404     debugOutput( DEBUG_LEVEL_VERBOSE, "getAttributeValue(%d) => %s\n", idx, retval.c_str() );
405     return retval;
406 }
407
408 DBus::String
409 AttributeEnum::getAttributeName( const DBus::Int32 & idx )
410 {
411     std::string retval = m_Slave.getAttributeName(idx);
412     debugOutput( DEBUG_LEVEL_VERBOSE, "getAttributeName(%d) => %s\n", idx, retval.c_str() );
413     return retval;
414 }
415
416 // --- ConfigRom
417
418 ConfigRomX::ConfigRomX( DBus::Connection& connection, std::string p, ConfigRom &slave)
419 : Element(connection, p, slave)
420 , m_Slave(slave)
421 {
422     debugOutput( DEBUG_LEVEL_VERBOSE, "Created ConfigRomX on '%s'\n",
423                  path().c_str() );
424 }
425
426 DBus::String
427 ConfigRomX::getGUID( )
428 {
429     return m_Slave.getGuidString();
430 }
431
432 DBus::String
433 ConfigRomX::getVendorName( )
434 {
435     return m_Slave.getVendorName();
436 }
437
438 DBus::String
439 ConfigRomX::getModelName( )
440 {
441     return m_Slave.getModelName();
442 }
443
444 DBus::Int32
445 ConfigRomX::getVendorId( )
446 {
447     return m_Slave.getNodeVendorId();
448 }
449
450 DBus::Int32
451 ConfigRomX::getModelId( )
452 {
453     return m_Slave.getModelId();
454 }
455
456 // --- MatrixMixer
457
458 MatrixMixer::MatrixMixer( DBus::Connection& connection, std::string p, Control::MatrixMixer &slave)
459 : Element(connection, p, slave)
460 , m_Slave(slave)
461 {
462     debugOutput( DEBUG_LEVEL_VERBOSE, "Created MatrixMixer on '%s'\n",
463                  path().c_str() );
464 }
465
466 DBus::String
467 MatrixMixer::getRowName( const DBus::Int32& row) {
468     return m_Slave.getRowName(row);
469 }
470
471 DBus::String
472 MatrixMixer::getColName( const DBus::Int32& col) {
473     return m_Slave.getColName(col);
474 }
475
476 DBus::Int32
477 MatrixMixer::canWrite( const DBus::Int32& row, const DBus::Int32& col) {
478     return m_Slave.canWrite(row,col);
479 }
480
481 DBus::Double
482 MatrixMixer::setValue( const DBus::Int32& row, const DBus::Int32& col, const DBus::Double& val ) {
483     return m_Slave.setValue(row,col,val);
484 }
485
486 DBus::Double
487 MatrixMixer::getValue( const DBus::Int32& row, const DBus::Int32& col) {
488     return m_Slave.getValue(row,col);
489 }
490
491 DBus::Int32
492 MatrixMixer::getRowCount( ) {
493     return m_Slave.getRowCount();
494 }
495
496 DBus::Int32
497 MatrixMixer::getColCount( ) {
498     return m_Slave.getColCount();
499 }
500
501 } // end of namespace Control
Note: See TracBrowser for help on using the browser.