root/branches/libffado-2.0/src/ffadodevice.cpp

Revision 1366, 6.8 kB (checked in by ppalmers, 12 years ago)

sometimes a busreset is issued to indicate a config change of a device. This requires a device to be rediscovered.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include "ffadodevice.h"
26 #include "devicemanager.h"
27
28 #include "libieee1394/configrom.h"
29 #include "libieee1394/ieee1394service.h"
30
31 #include "libcontrol/Element.h"
32 #include "libcontrol/ClockSelect.h"
33 #include "libcontrol/Nickname.h"
34
35 #include <iostream>
36 #include <sstream>
37
38 #include <assert.h>
39
40 IMPL_DEBUG_MODULE( FFADODevice, FFADODevice, DEBUG_LEVEL_NORMAL );
41
42 FFADODevice::FFADODevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) )
43     : Control::Container(&d)
44     , m_pConfigRom( configRom )
45     , m_pDeviceManager( d )
46 {
47     addOption(Util::OptionContainer::Option("id",std::string("dev?")));
48
49     std::ostringstream nodestr;
50     nodestr << "node" << getConfigRom().getNodeId();
51
52     if (!addElement(&getConfigRom())) {
53         debugWarning("failed to add ConfigRom to Control::Container\n");
54     }
55
56     m_genericContainer = new Control::Container(this, "Generic");
57     if(m_genericContainer == NULL) {
58         debugError("Could not create Control::Container for generic controls\n");
59     } else {
60
61         if (!addElement(m_genericContainer)) {
62             debugWarning("failed to add generic container to Control::Container\n");
63         }
64         // add a generic control for the clock source selection
65         if(!m_genericContainer->addElement(new Control::ClockSelect(*this))) {
66             debugWarning("failed to add clock source control to container\n");
67         }
68         // add a generic control for the sample rate selection
69         if(!m_genericContainer->addElement(new Control::SamplerateSelect(*this))) {
70             debugWarning("failed to add sample rate control to container\n");
71         }
72         // add a generic control for the nickname
73         if(!m_genericContainer->addElement(new Control::Nickname(*this))) {
74             debugWarning("failed to add Nickname control to container\n");
75         }
76     }
77 }
78
79 FFADODevice::~FFADODevice()
80 {
81     if (!deleteElement(&getConfigRom())) {
82         debugWarning("failed to remove ConfigRom from Control::Container\n");
83     }
84
85     // remove generic controls if present
86     if(m_genericContainer) {
87         if (!deleteElement(m_genericContainer)) {
88             debugError("Generic controls present but not registered to the avdevice\n");
89         }
90         // remove and delete (as in free) child control elements
91         m_genericContainer->clearElements(true);
92         delete m_genericContainer;
93     }
94 }
95
96 FFADODevice *
97 FFADODevice::createDevice(std::auto_ptr<ConfigRom>( x ))
98 {
99     // re-implement this!!
100     assert(0);
101     return NULL;
102 }
103
104 std::string
105 FFADODevice::getName()
106 {
107     return getConfigRom().getGuidString();
108 }
109
110 int
111 FFADODevice::getNodeId()
112 {
113     return getConfigRom().getNodeId();
114 }
115
116 bool FFADODevice::compareGUID( FFADODevice *a, FFADODevice *b ) {
117     assert(a);
118     assert(b);
119     return ConfigRom::compareGUID(a->getConfigRom(), b->getConfigRom());
120 }
121
122 ConfigRom&
123 FFADODevice::getConfigRom() const
124 {
125     return *m_pConfigRom;
126 }
127
128 Ieee1394Service&
129 FFADODevice::get1394Service()
130 {
131     return getConfigRom().get1394Service();
132 }
133
134 bool
135 FFADODevice::loadFromCache()
136 {
137     return false;
138 }
139
140 bool
141 FFADODevice::saveCache()
142 {
143     return false;
144 }
145
146 bool
147 FFADODevice::needsRediscovery()
148 {
149     // require rediscovery by default
150     return true;
151 }
152
153 enum FFADODevice::eSyncState
154 FFADODevice::getSyncState( ) {
155     return eSS_Unknown;
156 }
157
158 bool
159 FFADODevice::setId( unsigned int id)
160 {
161     Util::MutexLockHelper lock(m_DeviceMutex);
162     bool retval;
163     // FIXME: decent ID system nescessary
164     std::ostringstream idstr;
165     idstr << "dev" << id;
166     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %s...\n", idstr.str().c_str());
167
168     retval=setOption("id",idstr.str());
169     return retval;
170 }
171
172 bool
173 FFADODevice::setNickname( std::string name)
174 {
175     return false;
176 }
177
178 std::string
179 FFADODevice::getNickname()
180 {
181     return "Unknown";
182 }
183
184 void
185 FFADODevice::handleBusReset()
186 {
187     debugOutput( DEBUG_LEVEL_VERBOSE, "Handle bus reset...\n");
188
189     // update the config rom node id
190     sleep(1);
191
192     Util::MutexLockHelper lock(m_DeviceMutex);
193     getConfigRom().setVerboseLevel(getDebugLevel());
194     getConfigRom().updatedNodeId();
195 }
196
197 void
198 FFADODevice::setVerboseLevel(int l)
199 {
200     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
201     setDebugLevel(l);
202     m_DeviceMutex.setVerboseLevel(l);
203     getConfigRom().setVerboseLevel(l);
204 }
205
206 void
207 FFADODevice::showDevice()
208 {
209     #ifdef DEBUG
210     Ieee1394Service& s = getConfigRom().get1394Service();
211     debugOutput(DEBUG_LEVEL_NORMAL, "Attached to port.......: %d (%s)\n",
212                                     s.getPort(), s.getPortName().c_str());
213     debugOutput(DEBUG_LEVEL_NORMAL, "Node...................: %d\n", getNodeId());
214     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor name............: %s\n",
215                                     getConfigRom().getVendorName().c_str());
216     debugOutput(DEBUG_LEVEL_NORMAL, "Model name.............: %s\n",
217                                     getConfigRom().getModelName().c_str());
218     debugOutput(DEBUG_LEVEL_NORMAL, "GUID...................: %s\n",
219                                     getConfigRom().getGuidString().c_str());
220
221     std::string id=std::string("dev? [none]");
222     getOption("id", id);
223
224     debugOutput(DEBUG_LEVEL_NORMAL, "Assigned ID....: %s\n", id.c_str());
225
226     flushDebugOutput();
227     #endif
228 }
229
230
231 bool
232 FFADODevice::enableStreaming() {
233     return true;
234 }
235
236 bool
237 FFADODevice::disableStreaming() {
238     return true;
239 }
240
241 const char *
242 FFADODevice::ClockSourceTypeToString(enum eClockSourceType t)
243 {
244     switch(t) {
245         default:            return "Erratic type      ";
246         case eCT_Invalid:   return "Invalid           ";
247         case eCT_Internal:  return "Internal          ";
248         case eCT_1394Bus:   return "1394 Bus          ";
249         case eCT_SytMatch:  return "Compound Syt Match";
250         case eCT_SytStream: return "Sync Syt Match    ";
251         case eCT_WordClock: return "WordClock         ";
252         case eCT_SPDIF:     return "SPDIF             ";
253         case eCT_ADAT:      return "ADAT              ";
254         case eCT_TDIF:      return "TDIF              ";
255         case eCT_AES:       return "AES               ";
256     }
257 }
Note: See TracBrowser for help on using the browser.