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

Revision 864, 7.6 kB (checked in by ppalmers, 15 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

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<ConfigRom *>(&e) != NULL) {
143         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a ConfigRom\n");
144        
145         return new ConfigRomX(conn(), std::string(path()+"/"+e.getName()),
146             *dynamic_cast<ConfigRom *>(&e));
147     }
148    
149     if (dynamic_cast<Control::MatrixMixer *>(&e) != NULL) {
150         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::MatrixMixer\n");
151        
152         return new MatrixMixer(conn(), std::string(path()+"/"+e.getName()),
153             *dynamic_cast<Control::MatrixMixer *>(&e));
154     }
155    
156     debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Element\n");
157     return new Element(conn(), std::string(path()+"/"+e.getName()), e);
158 }
159
160 // --- Continuous
161
162 Continuous::Continuous( DBus::Connection& connection, std::string p, Control::Continuous &slave)
163 : Element(connection, p, slave)
164 , m_Slave(slave)
165 {
166     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Continuous on '%s'\n",
167                  path().c_str() );
168 }
169
170 DBus::Double
171 Continuous::setValue( const DBus::Double& value )
172 {
173     m_Slave.setValue(value);
174 /*   
175     SleepRelativeUsec(1000*500);
176    
177     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() );
178    
179     return m_Slave.getValue();*/
180     return value;
181 }
182
183 DBus::Double
184 Continuous::getValue(  )
185 {
186     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %lf\n", m_Slave.getValue() );
187     return m_Slave.getValue();
188 }
189
190 // --- Discrete
191
192 Discrete::Discrete( DBus::Connection& connection, std::string p, Control::Discrete &slave)
193 : Element(connection, p, slave)
194 , m_Slave(slave)
195 {
196     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Discrete on '%s'\n",
197                  path().c_str() );
198 }
199
200 DBus::Int32
201 Discrete::setValue( const DBus::Int32& value )
202 {
203     m_Slave.setValue(value);
204    
205 /*    SleepRelativeUsec(1000*500);
206     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
207    
208     return m_Slave.getValue();*/
209     return value;
210 }
211
212 DBus::Int32
213 Discrete::getValue(  )
214 {
215     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %d\n", m_Slave.getValue() );
216     return m_Slave.getValue();
217 }
218
219 // --- ConfigRom
220
221 ConfigRomX::ConfigRomX( DBus::Connection& connection, std::string p, ConfigRom &slave)
222 : Element(connection, p, slave)
223 , m_Slave(slave)
224 {
225     debugOutput( DEBUG_LEVEL_VERBOSE, "Created ConfigRomX on '%s'\n",
226                  path().c_str() );
227 }
228
229 DBus::String
230 ConfigRomX::getGUID( )
231 {
232     return m_Slave.getGuidString();
233 }
234
235 DBus::String
236 ConfigRomX::getVendorName( )
237 {
238     return m_Slave.getVendorName();
239 }
240
241 DBus::String
242 ConfigRomX::getModelName( )
243 {
244     return m_Slave.getModelName();
245 }
246
247 DBus::Int32
248 ConfigRomX::getVendorId( )
249 {
250     return m_Slave.getNodeVendorId();
251 }
252
253 DBus::Int32
254 ConfigRomX::getModelId( )
255 {
256     return m_Slave.getModelId();
257 }
258
259 // --- MatrixMixer
260
261 MatrixMixer::MatrixMixer( DBus::Connection& connection, std::string p, Control::MatrixMixer &slave)
262 : Element(connection, p, slave)
263 , m_Slave(slave)
264 {
265     debugOutput( DEBUG_LEVEL_VERBOSE, "Created MatrixMixer on '%s'\n",
266                  path().c_str() );
267 }
268
269 DBus::String
270 MatrixMixer::getRowName( const DBus::Int32& row) {
271     return m_Slave.getRowName(row);
272 }
273
274 DBus::String
275 MatrixMixer::getColName( const DBus::Int32& col) {
276     return m_Slave.getColName(col);
277 }
278
279 DBus::Int32
280 MatrixMixer::canWrite( const DBus::Int32& row, const DBus::Int32& col) {
281     return m_Slave.canWrite(row,col);
282 }
283
284 DBus::Double
285 MatrixMixer::setValue( const DBus::Int32& row, const DBus::Int32& col, const DBus::Double& val ) {
286     return m_Slave.setValue(row,col,val);
287 }
288
289 DBus::Double
290 MatrixMixer::getValue( const DBus::Int32& row, const DBus::Int32& col) {
291     return m_Slave.getValue(row,col);
292 }
293
294 DBus::Int32
295 MatrixMixer::getRowCount( ) {
296     return m_Slave.getRowCount();
297 }
298
299 DBus::Int32
300 MatrixMixer::getColCount( ) {
301     return m_Slave.getColCount();
302 }
303
304 } // end of namespace Control
Note: See TracBrowser for help on using the browser.