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

Revision 742, 7.6 kB (checked in by ppalmers, 16 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-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  * 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 3 of the License, or
12  * (at your option) any later version.
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
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 DBus::Int32
99 Container::getNbElements( ) {
100     return m_Slave.countElements();
101 }
102
103 DBus::String
104 Container::getElementName( const DBus::Int32& i ) {
105     int nbElements=m_Slave.countElements();
106     if (i<nbElements) {
107         return m_Slave.getElements().at(i)->getName();
108     } else return "";
109 }
110
111
112 /**
113  * \brief create a correct DBusControl counterpart for a given Control::Element
114  */
115 Element *
116 Container::createHandler(Control::Element& e) {
117     debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handler for '%s'\n",
118                  e.getName().c_str() );
119                  
120     if (dynamic_cast<Control::Container *>(&e) != NULL) {
121         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Container\n");
122        
123         return new Container(conn(), std::string(path()+"/"+e.getName()),
124             *dynamic_cast<Control::Container *>(&e));
125     }
126    
127     if (dynamic_cast<Control::Continuous *>(&e) != NULL) {
128         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Continuous\n");
129        
130         return new Continuous(conn(), std::string(path()+"/"+e.getName()),
131             *dynamic_cast<Control::Continuous *>(&e));
132     }
133    
134     if (dynamic_cast<Control::Discrete *>(&e) != NULL) {
135         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Discrete\n");
136        
137         return new Discrete(conn(), std::string(path()+"/"+e.getName()),
138             *dynamic_cast<Control::Discrete *>(&e));
139     }
140    
141     if (dynamic_cast<ConfigRom *>(&e) != NULL) {
142         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a ConfigRom\n");
143        
144         return new ConfigRomX(conn(), std::string(path()+"/"+e.getName()),
145             *dynamic_cast<ConfigRom *>(&e));
146     }
147    
148     if (dynamic_cast<Control::MatrixMixer *>(&e) != NULL) {
149         debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::MatrixMixer\n");
150        
151         return new MatrixMixer(conn(), std::string(path()+"/"+e.getName()),
152             *dynamic_cast<Control::MatrixMixer *>(&e));
153     }
154    
155     debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Element\n");
156     return new Element(conn(), std::string(path()+"/"+e.getName()), e);
157 }
158
159 // --- Continuous
160
161 Continuous::Continuous( DBus::Connection& connection, std::string p, Control::Continuous &slave)
162 : Element(connection, p, slave)
163 , m_Slave(slave)
164 {
165     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Continuous on '%s'\n",
166                  path().c_str() );
167 }
168
169 DBus::Double
170 Continuous::setValue( const DBus::Double& value )
171 {
172     m_Slave.setValue(value);
173 /*   
174     usleep(1000*500);
175    
176     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() );
177    
178     return m_Slave.getValue();*/
179     return value;
180 }
181
182 DBus::Double
183 Continuous::getValue(  )
184 {
185     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %lf\n", m_Slave.getValue() );
186     return m_Slave.getValue();
187 }
188
189 // --- Discrete
190
191 Discrete::Discrete( DBus::Connection& connection, std::string p, Control::Discrete &slave)
192 : Element(connection, p, slave)
193 , m_Slave(slave)
194 {
195     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Discrete on '%s'\n",
196                  path().c_str() );
197 }
198
199 DBus::Int32
200 Discrete::setValue( const DBus::Int32& value )
201 {
202     m_Slave.setValue(value);
203    
204 /*    usleep(1000*500);
205     debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() );
206    
207     return m_Slave.getValue();*/
208     return value;
209 }
210
211 DBus::Int32
212 Discrete::getValue(  )
213 {
214     debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %d\n", m_Slave.getValue() );
215     return m_Slave.getValue();
216 }
217
218 // --- ConfigRom
219
220 ConfigRomX::ConfigRomX( DBus::Connection& connection, std::string p, ConfigRom &slave)
221 : Element(connection, p, slave)
222 , m_Slave(slave)
223 {
224     debugOutput( DEBUG_LEVEL_VERBOSE, "Created ConfigRomX on '%s'\n",
225                  path().c_str() );
226 }
227
228 DBus::String
229 ConfigRomX::getGUID( )
230 {
231     return m_Slave.getGuidString();
232 }
233
234 DBus::String
235 ConfigRomX::getVendorName( )
236 {
237     return m_Slave.getVendorName();
238 }
239
240 DBus::String
241 ConfigRomX::getModelName( )
242 {
243     return m_Slave.getModelName();
244 }
245
246 DBus::Int32
247 ConfigRomX::getVendorId( )
248 {
249     return m_Slave.getNodeVendorId();
250 }
251
252 DBus::Int32
253 ConfigRomX::getModelId( )
254 {
255     return m_Slave.getModelId();
256 }
257
258 // --- MatrixMixer
259
260 MatrixMixer::MatrixMixer( DBus::Connection& connection, std::string p, Control::MatrixMixer &slave)
261 : Element(connection, p, slave)
262 , m_Slave(slave)
263 {
264     debugOutput( DEBUG_LEVEL_VERBOSE, "Created MatrixMixer on '%s'\n",
265                  path().c_str() );
266 }
267
268 DBus::String
269 MatrixMixer::getRowName( const DBus::Int32& row) {
270     return m_Slave.getRowName(row);
271 }
272
273 DBus::String
274 MatrixMixer::getColName( const DBus::Int32& col) {
275     return m_Slave.getColName(col);
276 }
277
278 DBus::Int32
279 MatrixMixer::canWrite( const DBus::Int32& row, const DBus::Int32& col) {
280     return m_Slave.canWrite(row,col);
281 }
282
283 DBus::Double
284 MatrixMixer::setValue( const DBus::Int32& row, const DBus::Int32& col, const DBus::Double& val ) {
285     return m_Slave.setValue(row,col,val);
286 }
287
288 DBus::Double
289 MatrixMixer::getValue( const DBus::Int32& row, const DBus::Int32& col) {
290     return m_Slave.getValue(row,col);
291 }
292
293 DBus::Int32
294 MatrixMixer::getRowCount( ) {
295     return m_Slave.getRowCount();
296 }
297
298 DBus::Int32
299 MatrixMixer::getColCount( ) {
300     return m_Slave.getColCount();
301 }
302
303 } // end of namespace Control
Note: See TracBrowser for help on using the browser.