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

Revision 1724, 27.4 kB (checked in by arnonym, 14 years ago)

Introduce a Control::Boolean for simple switches. To be used in the SaffirePro?24 first, but maybe others will follow? Using this instead of Control::Enum saves code.

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 "libcontrol/CrossbarRouter.h"
29 #include "libutil/Time.h"
30 #include "libutil/PosixMutex.h"
31
32 namespace DBusControl {
33
34 IMPL_DEBUG_MODULE( Element, Element, DEBUG_LEVEL_NORMAL );
35
36 // --- Element
37 Element::Element( DBus::Connection& connection, std::string p, Element* parent, Control::Element &slave)
38 : DBus::ObjectAdaptor(connection, p)
39 , m_Parent(parent)
40 , m_Slave(slave)
41 , m_UpdateLock( NULL )
42 {
43     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Element on '%s'\n",
44                  path().c_str() );
45     // allocate a lock
46     if(parent == NULL) {
47         m_UpdateLock = new Util::PosixMutex("CTLSVEL");
48     } else {
49         m_UpdateLock = NULL;
50     }
51     // set verbose level AFTER allocating the lock
52     setVerboseLevel(m_Slave.getVerboseLevel());
53 }
54
55 void Element::setVerboseLevel( const DBus::Int32 &i)
56 {
57     setDebugLevel(i);
58     m_Slave.setVerboseLevel(i);
59     if(m_UpdateLock) m_UpdateLock->setVerboseLevel(i);
60 }
61
62 DBus::Int32 Element::getVerboseLevel()
63 {
64     return getDebugLevel();
65 }
66
67 DBus::Bool
68 Element::canChangeValue()
69 {
70     return m_Slave.canChangeValue();
71 }
72
73 void
74 Element::Lock()
75 {
76     if(m_Parent) {
77         m_Parent->Lock();
78     } else {
79         m_UpdateLock->Lock();
80     }
81 }
82
83 void
84 Element::Unlock()
85 {
86     if(m_Parent) {
87         m_Parent->Unlock();
88     } else {
89         m_UpdateLock->Unlock();
90     }
91 }
92
93 bool
94 Element::isLocked()
95 {
96     if(m_Parent) {
97         return m_Parent->isLocked();
98     } else {
99         return m_UpdateLock->isLocked();
100     }
101 }
102
103 Util::Mutex*
104 Element::getLock()
105 {
106     if(m_Parent) {
107         return m_Parent->getLock();
108     } else {
109         return m_UpdateLock;
110     }
111 }
112
113 DBus::UInt64
114 Element::getId( )
115 {
116     return m_Slave.getId();
117 }
118
119 DBus::String
120 Element::getName( )
121 {
122     return DBus::String(m_Slave.getName());
123 }
124
125 DBus::String
126 Element::getLabel( )
127 {
128     return DBus::String(m_Slave.getLabel());
129 }
130
131 DBus::String
132 Element::getDescription( )
133 {
134     return DBus::String(m_Slave.getDescription());
135 }
136
137 // --- Container
138 Container::Container( DBus::Connection& connection, std::string p, Element* parent, Control::Container &slave)
139 : Element(connection, p, parent, slave)
140 , m_Slave(slave)
141 {
142     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Container on '%s'\n",
143                  path().c_str() );
144
145     setDebugLevel(slave.getVerboseLevel());
146
147     // register an update signal handler
148     m_updateFunctor = new MemberSignalFunctor1< Container*,
149                       void (Container::*)(int) >
150                       ( this, &Container::updated, (int)Control::Container::eS_Updated );
151     if(m_updateFunctor) {
152         if(!slave.addSignalHandler(m_updateFunctor)) {
153             debugWarning("Could not add update signal functor\n");
154         }
155     } else {
156         debugWarning("Could not create update signal functor\n");
157     }
158
159     // build the initial tree
160     m_Slave = slave;
161     updateTree();
162 }
163
164 Container::~Container() {
165     debugOutput( DEBUG_LEVEL_VERBOSE, "Deleting Container on '%s'\n",
166                  path().c_str() );
167
168     Destroyed(); //send dbus signal
169
170     if(m_updateFunctor) {
171         if(!m_Slave.remSignalHandler(m_updateFunctor)) {
172             debugWarning("Could not remove update signal functor\n");
173         }
174     }
175     delete m_updateFunctor;
176
177     for ( ElementVectorIterator it = m_Children.begin();
178       it != m_Children.end();
179       ++it )
180     {
181         delete (*it);
182     }
183 }
184
185 void
186 Container::setVerboseLevel( const DBus::Int32 & i)
187 {
188     Element::setVerboseLevel(i);
189     for ( ElementVectorIterator it = m_Children.begin();
190       it != m_Children.end();
191       ++it )
192     {
193         (*it)->setVerboseLevel(i);
194     }
195 }
196
197 DBus::Int32
198 Container::getNbElements( ) {
199     return m_Slave.countElements();
200 }
201
202 DBus::String
203 Container::getElementName( const DBus::Int32& i ) {
204     int nbElements=m_Slave.countElements();
205     if (i<nbElements) {
206         m_Slave.lockControl();
207         const Control::ElementVector elements = m_Slave.getElementVector();
208         Control::Element *e = elements.at(i);
209         std::string name;
210         if(e) name = e->getName();
211         m_Slave.unlockControl();
212         return name;
213     } else return "";
214 }
215 //     Util::MutexLockHelper lock(*m_access_lock);
216
217 // NOTE: call with tree locked
218 void
219 Container::updateTree()
220 {
221     bool something_changed = false;
222     debugOutput( DEBUG_LEVEL_VERBOSE, "Updating tree...\n");
223     // send a pre update signal
224     PreUpdate();
225     debugOutput( DEBUG_LEVEL_VERBOSE, "Add handlers for elements...\n");
226     // add handlers for the slaves that don't have one yet
227     const Control::ElementVector elements = m_Slave.getElementVector();
228     for ( Control::ConstElementVectorIterator it = elements.begin();
229       it != elements.end();
230       ++it )
231     {
232         Element *e = findElementForControl((*it));
233         if(e == NULL) { // element not in tree
234             e = createHandler(this, *(*it));
235             if (e) {
236                 e->setVerboseLevel(getDebugLevel());
237                 m_Children.push_back(e);
238                 debugOutput( DEBUG_LEVEL_VERBOSE, "Created handler %p for Control::Element %s...\n",
239                             e, (*it)->getName().c_str());
240                 something_changed = true;
241             } else {
242                 debugWarning("Failed to create handler for Control::Element %s\n",
243                     (*it)->getName().c_str());
244             }
245         } else {
246             // element already present
247             debugOutput( DEBUG_LEVEL_VERBOSE, "Already have handler (%p) for Control::Element %s...\n",
248                          e, (*it)->getName().c_str());
249         }
250     }
251
252     debugOutput( DEBUG_LEVEL_VERBOSE, "Remove handlers without element...\n");
253     std::vector<Element *> to_remove;
254     // remove handlers that don't have a slave anymore
255     for ( ElementVectorIterator it = m_Children.begin();
256       it != m_Children.end();
257       ++it )
258     {
259         Element *e = *it;
260         bool found = false;
261         for ( Control::ConstElementVectorIterator it2 = elements.begin();
262               it2 != elements.end();
263               ++it2 )
264         {
265             if(&(e)->m_Slave == *it2) {
266                 found = true;
267                 debugOutput( DEBUG_LEVEL_VERBOSE, "Slave for handler %p at %s is present: Control::Element %s...\n",
268                             e, e->path().c_str(), (*it)->getName().c_str());
269                 break;
270             }
271         }
272
273         if (!found) {
274             debugOutput(DEBUG_LEVEL_VERBOSE,
275                         "going to remove handler %p on path %s since slave is gone\n",
276                         e, e->path().c_str());
277             // can't remove while iterating
278             to_remove.push_back(e);
279             something_changed = true;
280         }
281     }
282     // do the actual remove
283     while(to_remove.size()) {
284         Element * e = *(to_remove.begin());
285         removeElement(e);
286         to_remove.erase(to_remove.begin());
287     }
288
289     if(something_changed) {
290         debugOutput(DEBUG_LEVEL_VERBOSE,
291                     "send dbus signal for path %s since something changed\n",
292                     path().c_str());
293         // send a dbus signal
294         Updated();
295     }
296     // send a post update signal
297     PostUpdate();
298 }
299
300 void
301 Container::removeElement(Element *e)
302 {
303     debugOutput(DEBUG_LEVEL_VERBOSE,
304                 "removing handler %p on path %s\n",
305                 e, path().c_str());
306     for ( ElementVectorIterator it = m_Children.begin();
307       it != m_Children.end();
308       ++it )
309     {
310         if(*it == e) {
311             m_Children.erase(it);
312             delete e;
313             return;
314         }
315     }
316     debugError("BUG: Element %p not found!\n", e);
317 }
318
319 // NOTE: call with access lock held!
320 Element *
321 Container::findElementForControl(Control::Element *e)
322 {
323     for ( ElementVectorIterator it = m_Children.begin();
324       it != m_Children.end();
325       ++it )
326     {
327         if(&(*it)->m_Slave == e) return (*it);
328     }
329     return NULL;
330 }
331
332 void
333 Container::updated(int new_nb_elements)
334 {
335     debugOutput( DEBUG_LEVEL_VERBOSE, "Got updated signal, new count='%d'\n",
336                  new_nb_elements );
337     // we lock the tree first
338     Lock();
339
340     // also lock the slave tree
341     m_Slave.lockControl();
342
343     // update our tree
344     updateTree();
345
346     // now unlock the slave tree
347     m_Slave.unlockControl();
348
349     // and unlock the access
350     Unlock();
351 }
352
353 /**
354  * \brief create a correct DBusControl counterpart for a given Control::Element
355  */
356 Element *
357 Container::createHandler(Element *parent, Control::Element& e) {
358     debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handler for '%s'\n",
359                  e.getName().c_str() );
360     try {
361         if (dynamic_cast<Control::Container *>(&e) != NULL) {
362             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Container\n");
363            
364             return new Container(conn(), std::string(path()+"/"+e.getName()),
365                 parent, *dynamic_cast<Control::Container *>(&e));
366         }
367        
368         if (dynamic_cast<Control::Continuous *>(&e) != NULL) {
369             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Continuous\n");
370            
371             return new Continuous(conn(), std::string(path()+"/"+e.getName()),
372                 parent, *dynamic_cast<Control::Continuous *>(&e));
373         }
374        
375         if (dynamic_cast<Control::Discrete *>(&e) != NULL) {
376             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Discrete\n");
377            
378             return new Discrete(conn(), std::string(path()+"/"+e.getName()),
379                 parent, *dynamic_cast<Control::Discrete *>(&e));
380         }
381        
382         if (dynamic_cast<Control::Text *>(&e) != NULL) {
383             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Text\n");
384            
385             return new Text(conn(), std::string(path()+"/"+e.getName()),
386                 parent, *dynamic_cast<Control::Text *>(&e));
387         }
388    
389         if (dynamic_cast<Control::Register *>(&e) != NULL) {
390             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Register\n");
391            
392             return new Register(conn(), std::string(path()+"/"+e.getName()),
393                 parent, *dynamic_cast<Control::Register *>(&e));
394         }
395    
396         // note that we have to check this before checking the Enum,
397         // since Enum is a base class
398         if (dynamic_cast<Control::AttributeEnum *>(&e) != NULL) {
399             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::AttributeEnum\n");
400            
401             return new AttributeEnum(conn(), std::string(path()+"/"+e.getName()),
402                 parent, *dynamic_cast<Control::AttributeEnum *>(&e));
403         }
404        
405         if (dynamic_cast<Control::Enum *>(&e) != NULL) {
406             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Enum\n");
407            
408             return new Enum(conn(), std::string(path()+"/"+e.getName()),
409                 parent, *dynamic_cast<Control::Enum *>(&e));
410         }
411        
412         if (dynamic_cast<Control::Boolean *>(&e) != NULL) {
413             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Boolean\n");
414            
415             return new Boolean(conn(), std::string(path()+"/"+e.getName()),
416                 parent, *dynamic_cast<Control::Boolean *>(&e));
417         }
418        
419         if (dynamic_cast<ConfigRom *>(&e) != NULL) {
420             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a ConfigRom\n");
421            
422             return new ConfigRomX(conn(), std::string(path()+"/"+e.getName()),
423                 parent, *dynamic_cast<ConfigRom *>(&e));
424         }
425        
426         if (dynamic_cast<Control::MatrixMixer *>(&e) != NULL) {
427             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::MatrixMixer\n");
428            
429             return new MatrixMixer(conn(), std::string(path()+"/"+e.getName()),
430                 parent, *dynamic_cast<Control::MatrixMixer *>(&e));
431         }
432        
433         if (dynamic_cast<Control::CrossbarRouter *>(&e) != NULL) {
434             debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::CrossbarRouter\n");
435            
436             return new CrossbarRouter(conn(), std::string(path()+"/"+e.getName()),
437                 parent, *dynamic_cast<Control::CrossbarRouter *>(&e));
438         }
439        
440         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Element\n");
441         return new Element(conn(), std::string(path()+"/"+e.getName()), parent, e);
442     } catch (...) {
443         debugWarning("Could not register %s\n", std::string(path()+"/"+e.getName()).c_str());
444         if(e.isControlLocked()) {
445             e.unlockControl();
446         }
447         if(isLocked()) {
448             Unlock();
449         }
450         return NULL;
451     };
452 }
453
454 // --- Continuous
455
456 Continuous::Continuous( DBus::Connection& connection, std::string p, Element* parent, Control::Continuous &slave)
457 : Element(connection, p, parent, slave)
458 , m_Slave(slave)
459 {
460     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Continuous on '%s'\n",
461                  path().c_str() );
462 }
463
464 DBus::Double
465 Continuous::setValue( const DBus::Double& value )
466 {
467     m_Slave.setValue(value);
468 /*   
469     SleepRelativeUsec(1000*500);
470    
471     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() );
472    
473     return m_Slave.getValue();*/
474     return value;
475 }
476
477 DBus::Double
478 Continuous::getValue(  )
479 {
480     double val = m_Slave.getValue();
481     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %lf\n", val );
482     return val;
483 }
484
485 DBus::Double
486 Continuous::setValueIdx( const DBus::Int32 & idx, const DBus::Double& value )
487 {
488     m_Slave.setValue(idx, value);
489 /*   
490     SleepRelativeUsec(1000*500);
491    
492     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() );
493    
494     return m_Slave.getValue();*/
495     return value;
496 }
497
498 DBus::Double
499 Continuous::getValueIdx( const DBus::Int32 & idx )
500 {
501     double val = m_Slave.getValue(idx);
502     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue(%d) => %lf\n", idx, val );
503     return val;
504 }
505
506 DBus::Double
507 Continuous::getMinimum()
508 {
509     double val = m_Slave.getMinimum();
510     debugOutput( DEBUG_LEVEL_VERBOSE, "getMinimum() => %lf\n", val );
511     return val;
512 }
513
514 DBus::Double
515 Continuous::getMaximum()
516 {
517     double val = m_Slave.getMaximum();
518     debugOutput( DEBUG_LEVEL_VERBOSE, "getMaximum() => %lf\n", val );
519     return val;
520 }
521
522 // --- Discrete
523
524 Discrete::Discrete( DBus::Connection& connection, std::string p, Element* parent, Control::Discrete &slave)
525 : Element(connection, p, parent, slave)
526 , m_Slave(slave)
527 {
528     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Discrete on '%s'\n",
529                  path().c_str() );
530 }
531
532 DBus::Int32
533 Discrete::setValue( const DBus::Int32& value )
534 {
535     m_Slave.setValue(value);
536    
537 /*    SleepRelativeUsec(1000*500);
538     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
539    
540     return m_Slave.getValue();*/
541     return value;
542 }
543
544 DBus::Int32
545 Discrete::getValue()
546 {
547     int32_t val = m_Slave.getValue();
548     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %d\n", val );
549     return val;
550 }
551
552 DBus::Int32
553 Discrete::setValueIdx( const DBus::Int32& idx, const DBus::Int32& value )
554 {
555     m_Slave.setValue(idx, value);
556    
557 /*    SleepRelativeUsec(1000*500);
558     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
559    
560     return m_Slave.getValue();*/
561     return value;
562 }
563
564 DBus::Int32
565 Discrete::getValueIdx( const DBus::Int32& idx )
566 {
567     int32_t val = m_Slave.getValue(idx);
568     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue(%d) => %d\n", idx, val );
569     return val;
570 }
571
572 // --- Text
573
574 Text::Text( DBus::Connection& connection, std::string p, Element* parent, Control::Text &slave)
575 : Element(connection, p, parent, slave)
576 , m_Slave(slave)
577 {
578     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Text on '%s'\n",
579                  path().c_str() );
580 }
581
582 DBus::String
583 Text::setValue( const DBus::String& value )
584 {
585     m_Slave.setValue(value);
586    
587 /*    SleepRelativeUsec(1000*500);
588     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
589    
590     return m_Slave.getValue();*/
591     return value;
592 }
593
594 DBus::String
595 Text::getValue()
596 {
597     std::string val = m_Slave.getValue();
598     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %s\n", val.c_str() );
599     return val;
600 }
601
602 // --- Register
603
604 Register::Register( DBus::Connection& connection, std::string p, Element* parent, Control::Register &slave)
605 : Element(connection, p, parent, slave)
606 , m_Slave(slave)
607 {
608     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Register on '%s'\n",
609                  path().c_str() );
610 }
611
612 DBus::UInt64
613 Register::setValue( const DBus::UInt64& addr, const DBus::UInt64& value )
614 {
615     m_Slave.setValue(addr, value);
616    
617 /*    SleepRelativeUsec(1000*500);
618     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
619    
620     return m_Slave.getValue();*/
621     return value;
622 }
623
624 DBus::UInt64
625 Register::getValue( const DBus::UInt64& addr )
626 {
627     DBus::UInt64 val = m_Slave.getValue(addr);
628     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue(%lld) => %lld\n", addr, val );
629     return val;
630 }
631
632 // --- Enum
633
634 Enum::Enum( DBus::Connection& connection, std::string p, Element* parent, Control::Enum &slave)
635 : Element(connection, p, parent, slave)
636 , m_Slave(slave)
637 {
638     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Enum on '%s'\n",
639                  path().c_str() );
640 }
641
642 DBus::Int32
643 Enum::select( const DBus::Int32& idx )
644 {
645     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "select(%d)\n", idx );
646     return  m_Slave.select(idx);
647 }
648
649 DBus::Int32
650 Enum::selected()
651 {
652     int retval = m_Slave.selected();
653     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "selected() => %d\n", retval );
654     return retval;
655 }
656
657 DBus::Int32
658 Enum::count()
659 {
660     int retval = m_Slave.count();
661     debugOutput( DEBUG_LEVEL_VERBOSE, "count() => %d\n", retval );
662     return retval;
663 }
664
665 DBus::String
666 Enum::getEnumLabel( const DBus::Int32 & idx )
667 {
668     std::string retval = m_Slave.getEnumLabel(idx);
669     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "getEnumLabel(%d) => %s\n", idx, retval.c_str() );
670     return retval;
671 }
672
673 // --- AttributeEnum
674 AttributeEnum::AttributeEnum( DBus::Connection& connection, std::string p, Element* parent, Control::AttributeEnum &slave)
675 : Element(connection, p, parent, slave)
676 , m_Slave(slave)
677 {
678     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Enum on '%s'\n",
679                  path().c_str() );
680 }
681
682 DBus::Int32
683 AttributeEnum::select( const DBus::Int32& idx )
684 {
685     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "select(%d)\n", idx );
686     return  m_Slave.select(idx);
687 }
688
689 DBus::Int32
690 AttributeEnum::selected()
691 {
692     int retval = m_Slave.selected();
693     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "selected() => %d\n", retval );
694     return retval;
695 }
696
697 DBus::Int32
698 AttributeEnum::count()
699 {
700     int retval = m_Slave.count();
701     debugOutput( DEBUG_LEVEL_VERBOSE, "count() => %d\n", retval );
702     return retval;
703 }
704
705 DBus::Int32
706 AttributeEnum::attributeCount()
707 {
708     int retval = m_Slave.attributeCount();
709     debugOutput( DEBUG_LEVEL_VERBOSE, "attributeCount() => %d\n", retval );
710     return retval;
711 }
712
713 DBus::String
714 AttributeEnum::getEnumLabel( const DBus::Int32 & idx )
715 {
716     std::string retval = m_Slave.getEnumLabel(idx);
717     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "getEnumLabel(%d) => %s\n", idx, retval.c_str() );
718     return retval;
719 }
720
721 DBus::String
722 AttributeEnum::getAttributeValue( const DBus::Int32 & idx )
723 {
724     std::string retval = m_Slave.getAttributeValue(idx);
725     debugOutput( DEBUG_LEVEL_VERBOSE, "getAttributeValue(%d) => %s\n", idx, retval.c_str() );
726     return retval;
727 }
728
729 DBus::String
730 AttributeEnum::getAttributeName( const DBus::Int32 & idx )
731 {
732     std::string retval = m_Slave.getAttributeName(idx);
733     debugOutput( DEBUG_LEVEL_VERBOSE, "getAttributeName(%d) => %s\n", idx, retval.c_str() );
734     return retval;
735 }
736
737 // --- ConfigRom
738
739 ConfigRomX::ConfigRomX( DBus::Connection& connection, std::string p, Element* parent, ConfigRom &slave)
740 : Element(connection, p, parent, slave)
741 , m_Slave(slave)
742 {
743     debugOutput( DEBUG_LEVEL_VERBOSE, "Created ConfigRomX on '%s'\n",
744                  path().c_str() );
745 }
746
747 DBus::String
748 ConfigRomX::getGUID( )
749 {
750     return m_Slave.getGuidString();
751 }
752
753 DBus::String
754 ConfigRomX::getVendorName( )
755 {
756     return m_Slave.getVendorName();
757 }
758
759 DBus::String
760 ConfigRomX::getModelName( )
761 {
762     return m_Slave.getModelName();
763 }
764
765 DBus::Int32
766 ConfigRomX::getVendorId( )
767 {
768     return m_Slave.getNodeVendorId();
769 }
770
771 DBus::Int32
772 ConfigRomX::getModelId( )
773 {
774     return m_Slave.getModelId();
775 }
776
777 DBus::Int32
778 ConfigRomX::getUnitVersion( )
779 {
780     return m_Slave.getUnitVersion();
781 }
782
783 // --- MatrixMixer
784
785 MatrixMixer::MatrixMixer( DBus::Connection& connection, std::string p, Element* parent, Control::MatrixMixer &slave)
786 : Element(connection, p, parent, slave)
787 , m_Slave(slave)
788 {
789     debugOutput( DEBUG_LEVEL_VERBOSE, "Created MatrixMixer on '%s'\n",
790                  path().c_str() );
791 }
792
793 DBus::String
794 MatrixMixer::getRowName( const DBus::Int32& row) {
795     return m_Slave.getRowName(row);
796 }
797
798 DBus::String
799 MatrixMixer::getColName( const DBus::Int32& col) {
800     return m_Slave.getColName(col);
801 }
802
803 DBus::Int32
804 MatrixMixer::canWrite( const DBus::Int32& row, const DBus::Int32& col) {
805     return m_Slave.canWrite(row,col);
806 }
807
808 DBus::Double
809 MatrixMixer::setValue( const DBus::Int32& row, const DBus::Int32& col, const DBus::Double& val ) {
810     return m_Slave.setValue(row,col,val);
811 }
812
813 DBus::Double
814 MatrixMixer::getValue( const DBus::Int32& row, const DBus::Int32& col) {
815     return m_Slave.getValue(row,col);
816 }
817
818 DBus::Int32
819 MatrixMixer::getRowCount( ) {
820     return m_Slave.getRowCount();
821 }
822
823 DBus::Int32
824 MatrixMixer::getColCount( ) {
825     return m_Slave.getColCount();
826 }
827
828 // --- CrossbarRouter
829
830 CrossbarRouter::CrossbarRouter( DBus::Connection& connection, std::string p, Element* parent, Control::CrossbarRouter &slave)
831 : Element(connection, p, parent, slave)
832 , m_Slave(slave)
833 {
834     debugOutput( DEBUG_LEVEL_VERBOSE, "Created CrossbarRouter on '%s'\n",
835                  path().c_str() );
836 }
837
838 DBus::String
839 CrossbarRouter::getSourceName(const DBus::Int32 &idx)
840 {
841     return m_Slave.getSourceName(idx);
842 }
843
844 DBus::String
845 CrossbarRouter::getDestinationName(const DBus::Int32 &idx)
846 {
847     return m_Slave.getDestinationName(idx);
848 }
849
850 DBus::Int32
851 CrossbarRouter::getSourceIndex(const DBus::String &name)
852 {
853     return m_Slave.getSourceIndex(name);
854 }
855
856 DBus::Int32
857 CrossbarRouter::getDestinationIndex(const DBus::String &name)
858 {
859     return m_Slave.getDestinationIndex(name);
860 }
861
862 std::vector< DBus::String >
863 CrossbarRouter::getSourceNames()
864 {
865     return m_Slave.getSourceNames();
866 }
867
868 std::vector< DBus::String >
869 CrossbarRouter::getDestinationNames()
870 {
871     return m_Slave.getDestinationNames();
872 }
873
874 std::vector< DBus::Struct<DBus::String, int> >
875 CrossbarRouter::getSources()
876 {
877     return std::vector< DBus::Struct<DBus::String, int> >();
878 }
879
880 std::vector< DBus::Struct<DBus::String, int> >
881 CrossbarRouter::getDestinations()
882 {
883     return std::vector< DBus::Struct<DBus::String, int> >();
884 }
885
886 std::vector< DBus::Int32 >
887 CrossbarRouter::getDestinationsForSource(const DBus::Int32 &idx)
888 {
889     return m_Slave.getDestinationsForSource(idx);
890 }
891
892 DBus::Int32
893 CrossbarRouter::getSourceForDestination(const DBus::Int32 &idx)
894 {
895     return m_Slave.getSourceForDestination(idx);
896 }
897
898 DBus::Bool
899 CrossbarRouter::canConnect(const DBus::Int32 &source, const DBus::Int32 &dest)
900 {
901     return m_Slave.canConnect(source, dest);
902 }
903
904 DBus::Bool
905 CrossbarRouter::setConnectionState(const DBus::Int32 &source, const DBus::Int32 &dest, const DBus::Bool &enable)
906 {
907     return m_Slave.setConnectionState(source, dest, enable);
908 }
909
910 DBus::Bool
911 CrossbarRouter::getConnectionState(const DBus::Int32 &source, const DBus::Int32 &dest)
912 {
913     return m_Slave.getConnectionState(source, dest);
914 }
915
916 DBus::Bool
917 CrossbarRouter::canConnectNamed(const DBus::String& source, const DBus::String& dest)
918 {
919     return m_Slave.canConnect(source, dest);
920 }
921
922 DBus::Bool
923 CrossbarRouter::setConnectionStateNamed(const DBus::String &source, const DBus::String &dest, const DBus::Bool &enable)
924 {
925     return m_Slave.setConnectionState(source, dest, enable);
926 }
927
928 DBus::Bool
929 CrossbarRouter::getConnectionStateNamed(const DBus::String &source, const DBus::String &dest)
930 {
931     return m_Slave.getConnectionState(source, dest);
932 }
933
934 DBus::Bool
935 CrossbarRouter::clearAllConnections()
936 {
937     return m_Slave.clearAllConnections();
938 }
939
940 DBus::Int32
941 CrossbarRouter::getNbSources()
942 {
943     return m_Slave.getNbSources();
944 }
945
946 DBus::Int32
947 CrossbarRouter::getNbDestinations()
948 {
949     return m_Slave.getNbDestinations();
950 }
951
952 DBus::Bool
953 CrossbarRouter::hasPeakMetering()
954 {
955     return m_Slave.hasPeakMetering();
956 }
957
958 DBus::Double
959 CrossbarRouter::getPeakValue(const DBus::Int32 &source, const DBus::Int32 &dest)
960 {
961     return m_Slave.getPeakValue(source, dest);
962 }
963 std::vector< DBus::Struct<int, double> >
964 CrossbarRouter::getPeakValues()
965 {
966     //return std::vector< DBus::Struct<int, int, double> >();
967     std::vector< DBus::Struct<int, double> > out;
968     Control::CrossbarRouter::PeakValues values = m_Slave.getPeakValues();
969     for ( unsigned int i=0; i<values.size(); ++i ) {
970         DBus::Struct<int, double> tmp;
971         tmp._1 = values[i].destination;
972         tmp._2 = values[i].peakvalue;
973         out.push_back(tmp);
974     }
975     return out;
976 }
977
978 std::vector< DBus::Int32 >
979 CrossbarRouter::getConnectionMap()
980 {
981     std::vector< DBus::Int32 >connmap;
982     unsigned int nb_sources = m_Slave.getNbSources();
983     unsigned int nb_destinations = m_Slave.getNbDestinations();
984     unsigned int nb_entries = nb_sources * nb_destinations;
985
986     int map_data[nb_entries];
987
988     if(!m_Slave.getConnectionMap(map_data)) {
989         debugError("Could not fetch connection map\n");
990         return connmap;
991     }
992
993     for(unsigned int i=0; i<nb_entries; i++) {
994         connmap.push_back(map_data[i]);
995     }
996     return connmap;
997 }
998
999 DBus::Int32
1000 CrossbarRouter::setConnectionMap(const std::vector< DBus::Int32 >&connmap)
1001 {
1002     unsigned int nb_sources = m_Slave.getNbSources();
1003     unsigned int nb_destinations = m_Slave.getNbDestinations();
1004     unsigned int nb_entries = nb_sources * nb_destinations;
1005
1006     if(connmap.size() != nb_entries) {
1007         debugError("bogus map size\n");
1008         return false;
1009     }
1010
1011     int map_data[nb_entries];
1012     for (unsigned int i=0; i<nb_entries; i++) {
1013         map_data[i] = connmap.at(i);
1014     }
1015     return m_Slave.setConnectionMap(map_data);
1016 }
1017
1018 // --- Boolean
1019
1020 Boolean::Boolean( DBus::Connection& connection, std::string p, Element* parent, Control::Boolean &slave)
1021 : Element(connection, p, parent, slave)
1022 , m_Slave(slave)
1023 {
1024     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Boolean on '%s'\n",
1025                  path().c_str() );
1026 }
1027
1028 DBus::Bool
1029 Boolean::select( const DBus::Bool& value )
1030 {
1031     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "select(%d)\n", value );
1032     return  m_Slave.select(value);
1033 }
1034
1035 DBus::Bool
1036 Boolean::selected()
1037 {
1038     bool retval = m_Slave.selected();
1039     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "selected() => %d\n", retval );
1040     return retval;
1041 }
1042
1043 DBus::String
1044 Boolean::getBooleanLabel( const DBus::Bool& value )
1045 {
1046     std::string retval = m_Slave.getBooleanLabel(value);
1047     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "getBooleanLabel(%d) => %s\n", value, retval.c_str() );
1048     return retval;
1049 }
1050
1051
1052 } // end of namespace Control
Note: See TracBrowser for help on using the browser.