root/trunk/libffado/src/ffadodevice.cpp

Revision 967, 6.1 kB (checked in by ppalmers, 14 years ago)

- first attempt at not causing total havoc when devices are removed from the bus.

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
27 #include "libieee1394/configrom.h"
28 #include "libieee1394/ieee1394service.h"
29
30 #include "libcontrol/Element.h"
31 #include "libcontrol/ClockSelect.h"
32
33 #include <iostream>
34 #include <sstream>
35
36 #include <assert.h>
37
38 IMPL_DEBUG_MODULE( FFADODevice, FFADODevice, DEBUG_LEVEL_NORMAL );
39
40 FFADODevice::FFADODevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) )
41     : Control::Container()
42     , m_pConfigRom( configRom )
43     , m_pDeviceManager( d )
44 {
45     addOption(Util::OptionContainer::Option("id",std::string("dev?")));
46
47     std::ostringstream nodestr;
48     nodestr << "node" << getConfigRom().getNodeId();
49
50     if (!addElement(&getConfigRom())) {
51         debugWarning("failed to add ConfigRom to Control::Container\n");
52     }
53
54     m_genericContainer = new Control::Container("Generic");
55     if(m_genericContainer == NULL) {
56         debugError("Could not create Control::Container for generic controls\n");
57     } else {
58
59         if (!addElement(m_genericContainer)) {
60             debugWarning("failed to add generic container to Control::Container\n");
61         }
62         // add a generic control for the clock source selection
63         if(!m_genericContainer->addElement(new Control::ClockSelect(*this))) {
64             debugWarning("failed to add clock source control to container\n");
65         }
66     }
67 }
68
69 FFADODevice::~FFADODevice()
70 {
71     if (!deleteElement(&getConfigRom())) {
72         debugWarning("failed to remove ConfigRom from Control::Container\n");
73     }
74
75     // remove generic controls if present
76     if(m_genericContainer) {
77         if (!deleteElement(m_genericContainer)) {
78             debugError("Generic controls present but not registered to the avdevice\n");
79         }
80         // remove and delete (as in free) child control elements
81         m_genericContainer->clearElements(true);
82         delete m_genericContainer;
83     }
84 }
85
86 FFADODevice *
87 FFADODevice::createDevice(std::auto_ptr<ConfigRom>( x ))
88 {
89     // re-implement this!!
90     assert(0);
91     return NULL;
92 }
93
94 std::string
95 FFADODevice::getName()
96 {
97     return getConfigRom().getGuidString();
98 }
99
100 int
101 FFADODevice::getNodeId()
102 {
103     return getConfigRom().getNodeId();
104 }
105
106 bool FFADODevice::compareGUID( FFADODevice *a, FFADODevice *b ) {
107     assert(a);
108     assert(b);
109     return ConfigRom::compareGUID(a->getConfigRom(), b->getConfigRom());
110 }
111
112 ConfigRom&
113 FFADODevice::getConfigRom() const
114 {
115     return *m_pConfigRom;
116 }
117
118 Ieee1394Service&
119 FFADODevice::get1394Service()
120 {
121     return getConfigRom().get1394Service();
122 }
123
124 bool
125 FFADODevice::loadFromCache()
126 {
127     return false;
128 }
129
130 bool
131 FFADODevice::saveCache()
132 {
133     return false;
134 }
135
136 enum FFADODevice::eSyncState
137 FFADODevice::getSyncState( ) {
138     return eSS_Unknown;
139 }
140
141 bool
142 FFADODevice::setId( unsigned int id)
143 {
144     m_DeviceMutex.Lock();
145     bool retval;
146     // FIXME: decent ID system nescessary
147     std::ostringstream idstr;
148     idstr << "dev" << id;
149     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %s...\n", idstr.str().c_str());
150
151     retval=setOption("id",idstr.str());
152     m_DeviceMutex.Unlock();
153     return retval;
154 }
155
156 void
157 FFADODevice::handleBusReset()
158 {
159     debugOutput( DEBUG_LEVEL_VERBOSE, "Handle bus reset...\n");
160
161     // update the config rom node id
162     sleep(1);
163
164     m_DeviceMutex.Lock();
165     getConfigRom().setVerboseLevel(getDebugLevel());
166     getConfigRom().updatedNodeId();
167     m_DeviceMutex.Unlock();
168 }
169
170 void
171 FFADODevice::setVerboseLevel(int l)
172 {
173     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
174     setDebugLevel(l);
175     m_DeviceMutex.setVerboseLevel(l);
176     getConfigRom().setVerboseLevel(l);
177 }
178
179 void
180 FFADODevice::showDevice()
181 {
182     #ifdef DEBUG
183     Ieee1394Service& s = getConfigRom().get1394Service();
184     debugOutput(DEBUG_LEVEL_NORMAL, "Attached to port.......: %d (%s)\n",
185                                     s.getPort(), s.getPortName().c_str());
186     debugOutput(DEBUG_LEVEL_NORMAL, "Node...................: %d\n", getNodeId());
187     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor name............: %s\n",
188                                     getConfigRom().getVendorName().c_str());
189     debugOutput(DEBUG_LEVEL_NORMAL, "Model name.............: %s\n",
190                                     getConfigRom().getModelName().c_str());
191     debugOutput(DEBUG_LEVEL_NORMAL, "GUID...................: %s\n",
192                                     getConfigRom().getGuidString().c_str());
193
194     std::string id=std::string("dev? [none]");
195     getOption("id", id);
196
197     debugOutput(DEBUG_LEVEL_NORMAL, "Assigned ID....: %s\n", id.c_str());
198
199     flushDebugOutput();
200     #endif
201 }
202
203
204 bool
205 FFADODevice::enableStreaming() {
206     return true;
207 }
208
209 bool
210 FFADODevice::disableStreaming() {
211     return true;
212 }
213
214 const char *
215 FFADODevice::ClockSourceTypeToString(enum eClockSourceType t)
216 {
217     switch(t) {
218         default:            return "Erratic type      ";
219         case eCT_Invalid:   return "Invalid           ";
220         case eCT_Internal:  return "Internal          ";
221         case eCT_1394Bus:   return "1394 Bus          ";
222         case eCT_SytMatch:  return "Compound Syt Match";
223         case eCT_SytStream: return "Sync Syt Match    ";
224         case eCT_WordClock: return "WordClock         ";
225         case eCT_SPDIF:     return "SPDIF             ";
226         case eCT_ADAT:      return "ADAT              ";
227         case eCT_TDIF:      return "TDIF              ";
228         case eCT_AES:       return "AES               ";
229     }
230 }
Note: See TracBrowser for help on using the browser.