root/trunk/libffado/tests/controlserver.cpp

Revision 582, 5.0 kB (checked in by ppalmers, 15 years ago)

see prev commit

Line 
1 /*
2  * Copyright (C) 2007 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  * FFADO 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) any later version.
13  * FFADO is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with FFADO; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA.
22  *
23  */
24
25 #include "controlserver.h"
26 #include "libcontrol/Element.h"
27 #include "libcontrol/BasicElements.h"
28
29 namespace DBusControl {
30
31 IMPL_DEBUG_MODULE( Element, Element, DEBUG_LEVEL_VERBOSE );
32
33 // --- Element
34 Element::Element( DBus::Connection& connection, std::string p, Control::Element &slave)
35 : DBus::ObjectAdaptor(connection, p)
36 , m_Slave(slave)
37 {
38     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Element on '%s'\n",
39                  path().c_str() );
40 }
41
42 DBus::UInt64
43 Element::getId( )
44 {
45     return m_Slave.getId();
46 }
47
48 DBus::String
49 Element::getName( )
50 {
51     return DBus::String(m_Slave.getName());
52 }
53
54 DBus::String
55 Element::getLabel( )
56 {
57     return DBus::String(m_Slave.getLabel());
58 }
59
60 DBus::String
61 Element::getDescription( )
62 {
63     return DBus::String(m_Slave.getDescription());
64 }
65
66 // --- Container
67 Container::Container( DBus::Connection& connection, std::string p, Control::Container &slave)
68 : Element(connection, p, slave)
69 , m_Slave(slave)
70 {
71     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Container on '%s'\n",
72                  path().c_str() );
73
74     // add children for the slave container
75     for ( Control::ConstElementVectorIterator it = slave.getElements().begin();
76       it != slave.getElements().end();
77       ++it )
78     {
79         Element *e=createHandler(*(*it));
80         if (e) {
81             m_Children.push_back(e);
82         } else {
83             debugWarning("Failed to create handler for Control::Element %s\n",
84                 (*it)->getName().c_str());
85         }
86     }
87 }
88
89 Container::~Container() {
90     for ( ElementVectorIterator it = m_Children.begin();
91       it != m_Children.end();
92       ++it )
93     {
94         delete (*it);
95     }
96 }
97
98 /**
99  * \brief create a correct DBusControl counterpart for a given Control::Element
100  */
101 Element *
102 Container::createHandler(Control::Element& e) {
103     debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handler for '%s'\n",
104                  e.getName().c_str() );
105                  
106     if (dynamic_cast<Control::Container *>(&e) != NULL) {
107         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Container\n");
108        
109         return new Container(conn(), std::string(path()+"/"+e.getName()),
110             *dynamic_cast<Control::Container *>(&e));
111     }
112    
113     if (dynamic_cast<Control::Continuous *>(&e) != NULL) {
114         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Continuous\n");
115        
116         return new Continuous(conn(), std::string(path()+"/"+e.getName()),
117             *dynamic_cast<Control::Continuous *>(&e));
118     }
119    
120     if (dynamic_cast<Control::Discrete *>(&e) != NULL) {
121         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Discrete\n");
122        
123         return new Discrete(conn(), std::string(path()+"/"+e.getName()),
124             *dynamic_cast<Control::Discrete *>(&e));
125     }
126    
127     debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Element\n");
128     return new Element(conn(), std::string(path()+"/"+e.getName()), e);
129 }
130
131 // --- Continuous
132
133 Continuous::Continuous( DBus::Connection& connection, std::string p, Control::Continuous &slave)
134 : Element(connection, p, slave)
135 , m_Slave(slave)
136 {
137     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Continuous on '%s'\n",
138                  path().c_str() );
139 }
140
141 DBus::Double
142 Continuous::setValue( const DBus::Double& value )
143 {
144     m_Slave.setValue(value);
145     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() );
146    
147     return m_Slave.getValue();
148 }
149
150 DBus::Double
151 Continuous::getValue(  )
152 {
153     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %lf\n", m_Slave.getValue() );
154     return m_Slave.getValue();
155 }
156
157 // --- Discrete
158
159 Discrete::Discrete( DBus::Connection& connection, std::string p, Control::Discrete &slave)
160 : Element(connection, p, slave)
161 , m_Slave(slave)
162 {
163     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Discrete on '%s'\n",
164                  path().c_str() );
165 }
166
167 DBus::Int32
168 Discrete::setValue( const DBus::Int32& value )
169 {
170     m_Slave.setValue(value);
171     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
172    
173     return m_Slave.getValue();
174 }
175
176 DBus::Int32
177 Discrete::getValue(  )
178 {
179     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %d\n", m_Slave.getValue() );
180     return m_Slave.getValue();
181 }
182
183 } // end of namespace Control
Note: See TracBrowser for help on using the browser.