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

Revision 998, 14.2 kB (checked in by arnonym, 16 years ago)

Try to improve the generic mixer.

Moving the sliders now sends values to the ffado-dbus-server.

And the interface of Continuous is extended by getMinimum() and getMaximum() which should return the range of values this value can have. For now its just [-100,10]. The generic mixer gui adopts to the values returned by these functions...

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 DBus::Double
222 Continuous::setValueIdx( const DBus::Int32 & idx, const DBus::Double& value )
223 {
224     m_Slave.setValue(idx, value);
225 /*   
226     SleepRelativeUsec(1000*500);
227    
228     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() );
229    
230     return m_Slave.getValue();*/
231     return value;
232 }
233
234 DBus::Double
235 Continuous::getValueIdx( const DBus::Int32 & idx )
236 {
237     double val = m_Slave.getValue(idx);
238     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue(%d) => %lf\n", idx, val );
239     return val;
240 }
241
242 DBus::Double
243 Continuous::getMinimum()
244 {
245     debugOutput( DEBUG_LEVEL_VERBOSE, "getMinimum() TODO: Return a real device-value...\n" );
246     return -100.0;
247 }
248
249 DBus::Double
250 Continuous::getMaximum()
251 {
252     debugOutput( DEBUG_LEVEL_VERBOSE, "getMaximum() TODO: Return a real device-value...\n" );
253     return 10.0;
254 }
255
256 // --- Discrete
257
258 Discrete::Discrete( DBus::Connection& connection, std::string p, Control::Discrete &slave)
259 : Element(connection, p, slave)
260 , m_Slave(slave)
261 {
262     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Discrete on '%s'\n",
263                  path().c_str() );
264 }
265
266 DBus::Int32
267 Discrete::setValue( const DBus::Int32& value )
268 {
269     m_Slave.setValue(value);
270    
271 /*    SleepRelativeUsec(1000*500);
272     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
273    
274     return m_Slave.getValue();*/
275     return value;
276 }
277
278 DBus::Int32
279 Discrete::getValue()
280 {
281     int32_t val = m_Slave.getValue();
282     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %d\n", val );
283     return val;
284 }
285
286 DBus::Int32
287 Discrete::setValueIdx( const DBus::Int32& idx, const DBus::Int32& value )
288 {
289     m_Slave.setValue(idx, value);
290    
291 /*    SleepRelativeUsec(1000*500);
292     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
293    
294     return m_Slave.getValue();*/
295     return value;
296 }
297
298 DBus::Int32
299 Discrete::getValueIdx( const DBus::Int32& idx )
300 {
301     int32_t val = m_Slave.getValue(idx);
302     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue(%d) => %d\n", idx, val );
303     return val;
304 }
305
306 // --- Text
307
308 Text::Text( DBus::Connection& connection, std::string p, Control::Text &slave)
309 : Element(connection, p, slave)
310 , m_Slave(slave)
311 {
312     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Text on '%s'\n",
313                  path().c_str() );
314 }
315
316 DBus::String
317 Text::setValue( const DBus::String& value )
318 {
319     m_Slave.setValue(value);
320    
321 /*    SleepRelativeUsec(1000*500);
322     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
323    
324     return m_Slave.getValue();*/
325     return value;
326 }
327
328 DBus::String
329 Text::getValue()
330 {
331     std::string val = m_Slave.getValue();
332     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %s\n", val.c_str() );
333     return val;
334 }
335
336 // --- Register
337
338 Register::Register( DBus::Connection& connection, std::string p, Control::Register &slave)
339 : Element(connection, p, slave)
340 , m_Slave(slave)
341 {
342     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Register on '%s'\n",
343                  path().c_str() );
344 }
345
346 DBus::UInt64
347 Register::setValue( const DBus::UInt64& addr, const DBus::UInt64& value )
348 {
349     m_Slave.setValue(addr, value);
350    
351 /*    SleepRelativeUsec(1000*500);
352     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
353    
354     return m_Slave.getValue();*/
355     return value;
356 }
357
358 DBus::UInt64
359 Register::getValue( const DBus::UInt64& addr )
360 {
361     DBus::UInt64 val = m_Slave.getValue(addr);
362     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue(%lld) => %lld\n", addr, val );
363     return val;
364 }
365
366 // --- Enum
367
368 Enum::Enum( DBus::Connection& connection, std::string p, Control::Enum &slave)
369 : Element(connection, p, slave)
370 , m_Slave(slave)
371 {
372     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Enum on '%s'\n",
373                  path().c_str() );
374 }
375
376 DBus::Int32
377 Enum::select( const DBus::Int32& idx )
378 {
379     debugOutput( DEBUG_LEVEL_VERBOSE, "select(%d)\n", idx );
380     return  m_Slave.select(idx);
381 }
382
383 DBus::Int32
384 Enum::selected()
385 {
386     int retval = m_Slave.selected();
387     debugOutput( DEBUG_LEVEL_VERBOSE, "selected() => %d\n", retval );
388     return retval;
389 }
390
391 DBus::Int32
392 Enum::count()
393 {
394     int retval = m_Slave.count();
395     debugOutput( DEBUG_LEVEL_VERBOSE, "count() => %d\n", retval );
396     return retval;
397 }
398
399 DBus::String
400 Enum::getEnumLabel( const DBus::Int32 & idx )
401 {
402     std::string retval = m_Slave.getEnumLabel(idx);
403     debugOutput( DEBUG_LEVEL_VERBOSE, "getEnumLabel(%d) => %s\n", idx, retval.c_str() );
404     return retval;
405 }
406
407 // --- AttributeEnum
408 AttributeEnum::AttributeEnum( DBus::Connection& connection, std::string p, Control::AttributeEnum &slave)
409 : Element(connection, p, slave)
410 , m_Slave(slave)
411 {
412     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Enum on '%s'\n",
413                  path().c_str() );
414 }
415
416 DBus::Int32
417 AttributeEnum::select( const DBus::Int32& idx )
418 {
419     debugOutput( DEBUG_LEVEL_VERBOSE, "select(%d)\n", idx );
420     return  m_Slave.select(idx);
421 }
422
423 DBus::Int32
424 AttributeEnum::selected()
425 {
426     int retval = m_Slave.selected();
427     debugOutput( DEBUG_LEVEL_VERBOSE, "selected() => %d\n", retval );
428     return retval;
429 }
430
431 DBus::Int32
432 AttributeEnum::count()
433 {
434     int retval = m_Slave.count();
435     debugOutput( DEBUG_LEVEL_VERBOSE, "count() => %d\n", retval );
436     return retval;
437 }
438
439 DBus::Int32
440 AttributeEnum::attributeCount()
441 {
442     int retval = m_Slave.attributeCount();
443     debugOutput( DEBUG_LEVEL_VERBOSE, "attributeCount() => %d\n", retval );
444     return retval;
445 }
446
447 DBus::String
448 AttributeEnum::getEnumLabel( const DBus::Int32 & idx )
449 {
450     std::string retval = m_Slave.getEnumLabel(idx);
451     debugOutput( DEBUG_LEVEL_VERBOSE, "getEnumLabel(%d) => %s\n", idx, retval.c_str() );
452     return retval;
453 }
454
455 DBus::String
456 AttributeEnum::getAttributeValue( const DBus::Int32 & idx )
457 {
458     std::string retval = m_Slave.getAttributeValue(idx);
459     debugOutput( DEBUG_LEVEL_VERBOSE, "getAttributeValue(%d) => %s\n", idx, retval.c_str() );
460     return retval;
461 }
462
463 DBus::String
464 AttributeEnum::getAttributeName( const DBus::Int32 & idx )
465 {
466     std::string retval = m_Slave.getAttributeName(idx);
467     debugOutput( DEBUG_LEVEL_VERBOSE, "getAttributeName(%d) => %s\n", idx, retval.c_str() );
468     return retval;
469 }
470
471 // --- ConfigRom
472
473 ConfigRomX::ConfigRomX( DBus::Connection& connection, std::string p, ConfigRom &slave)
474 : Element(connection, p, slave)
475 , m_Slave(slave)
476 {
477     debugOutput( DEBUG_LEVEL_VERBOSE, "Created ConfigRomX on '%s'\n",
478                  path().c_str() );
479 }
480
481 DBus::String
482 ConfigRomX::getGUID( )
483 {
484     return m_Slave.getGuidString();
485 }
486
487 DBus::String
488 ConfigRomX::getVendorName( )
489 {
490     return m_Slave.getVendorName();
491 }
492
493 DBus::String
494 ConfigRomX::getModelName( )
495 {
496     return m_Slave.getModelName();
497 }
498
499 DBus::Int32
500 ConfigRomX::getVendorId( )
501 {
502     return m_Slave.getNodeVendorId();
503 }
504
505 DBus::Int32
506 ConfigRomX::getModelId( )
507 {
508     return m_Slave.getModelId();
509 }
510
511 DBus::Int32
512 ConfigRomX::getUnitVersion( )
513 {
514     return m_Slave.getUnitVersion();
515 }
516
517 // --- MatrixMixer
518
519 MatrixMixer::MatrixMixer( DBus::Connection& connection, std::string p, Control::MatrixMixer &slave)
520 : Element(connection, p, slave)
521 , m_Slave(slave)
522 {
523     debugOutput( DEBUG_LEVEL_VERBOSE, "Created MatrixMixer on '%s'\n",
524                  path().c_str() );
525 }
526
527 DBus::String
528 MatrixMixer::getRowName( const DBus::Int32& row) {
529     return m_Slave.getRowName(row);
530 }
531
532 DBus::String
533 MatrixMixer::getColName( const DBus::Int32& col) {
534     return m_Slave.getColName(col);
535 }
536
537 DBus::Int32
538 MatrixMixer::canWrite( const DBus::Int32& row, const DBus::Int32& col) {
539     return m_Slave.canWrite(row,col);
540 }
541
542 DBus::Double
543 MatrixMixer::setValue( const DBus::Int32& row, const DBus::Int32& col, const DBus::Double& val ) {
544     return m_Slave.setValue(row,col,val);
545 }
546
547 DBus::Double
548 MatrixMixer::getValue( const DBus::Int32& row, const DBus::Int32& col) {
549     return m_Slave.getValue(row,col);
550 }
551
552 DBus::Int32
553 MatrixMixer::getRowCount( ) {
554     return m_Slave.getRowCount();
555 }
556
557 DBus::Int32
558 MatrixMixer::getColCount( ) {
559     return m_Slave.getColCount();
560 }
561
562 } // end of namespace Control
Note: See TracBrowser for help on using the browser.