root/trunk/libffado/src/ffadodevice.cpp

Revision 1789, 6.9 kB (checked in by arnonym, 11 years ago)

Use the GUID as the id and get rid of setId(). This is part of making the port names unique and persistent per device.

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",m_pConfigRom->getGuidString()));
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         // add a generic control for the streaming status
77         if(!m_genericContainer->addElement(new Control::StreamingStatus(*this))) {
78             debugWarning("failed to add StreamingStatus control to container\n");
79         }
80     }
81 }
82
83 FFADODevice::~FFADODevice()
84 {
85     if (!deleteElement(&getConfigRom())) {
86         debugWarning("failed to remove ConfigRom from Control::Container\n");
87     }
88
89     // remove generic controls if present
90     if(m_genericContainer) {
91         if (!deleteElement(m_genericContainer)) {
92             debugError("Generic controls present but not registered to the avdevice\n");
93         }
94         // remove and delete (as in free) child control elements
95         m_genericContainer->clearElements(true);
96         delete m_genericContainer;
97     }
98 }
99
100 FFADODevice *
101 FFADODevice::createDevice(std::auto_ptr<ConfigRom>( x ))
102 {
103     // re-implement this!!
104     assert(0);
105     return NULL;
106 }
107
108 std::string
109 FFADODevice::getName()
110 {
111     return getConfigRom().getGuidString();
112 }
113
114 int
115 FFADODevice::getNodeId()
116 {
117     return getConfigRom().getNodeId();
118 }
119
120 bool FFADODevice::compareGUID( FFADODevice *a, FFADODevice *b ) {
121     assert(a);
122     assert(b);
123     return ConfigRom::compareGUID(a->getConfigRom(), b->getConfigRom());
124 }
125
126 ConfigRom&
127 FFADODevice::getConfigRom() const
128 {
129     return *m_pConfigRom;
130 }
131
132 Ieee1394Service&
133 FFADODevice::get1394Service()
134 {
135     return getConfigRom().get1394Service();
136 }
137
138 bool
139 FFADODevice::loadFromCache()
140 {
141     return false;
142 }
143
144 bool
145 FFADODevice::saveCache()
146 {
147     return false;
148 }
149
150 bool
151 FFADODevice::needsRediscovery()
152 {
153     // require rediscovery by default
154     return true;
155 }
156
157 enum FFADODevice::eSyncState
158 FFADODevice::getSyncState( ) {
159     return eSS_Unknown;
160 }
161
162 enum FFADODevice::eStreamingState
163 FFADODevice::getStreamingState()
164 {
165     return eSS_Idle;
166 }
167
168 bool
169 FFADODevice::setNickname( std::string name)
170 {
171     return false;
172 }
173
174 std::string
175 FFADODevice::getNickname()
176 {
177     return "Unsupported";
178 }
179
180 bool
181 FFADODevice::canChangeNickname()
182 {
183     return false;
184 }
185
186 void
187 FFADODevice::handleBusReset()
188 {
189     debugOutput( DEBUG_LEVEL_VERBOSE, "Handle bus reset...\n");
190
191     // update the config rom node id
192     sleep(1);
193
194     Util::MutexLockHelper lock(m_DeviceMutex);
195     getConfigRom().setVerboseLevel(getDebugLevel());
196     getConfigRom().updatedNodeId();
197 }
198
199 void
200 FFADODevice::setVerboseLevel(int l)
201 {
202     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
203     setDebugLevel(l);
204     m_DeviceMutex.setVerboseLevel(l);
205     getConfigRom().setVerboseLevel(l);
206 }
207
208 void
209 FFADODevice::showDevice()
210 {
211     #ifdef DEBUG
212     Ieee1394Service& s = getConfigRom().get1394Service();
213     debugOutput(DEBUG_LEVEL_NORMAL, "Attached to port.......: %d (%s)\n",
214                                     s.getPort(), s.getPortName().c_str());
215     debugOutput(DEBUG_LEVEL_NORMAL, "Node...................: %d\n", getNodeId());
216     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor name............: %s\n",
217                                     getConfigRom().getVendorName().c_str());
218     debugOutput(DEBUG_LEVEL_NORMAL, "Model name.............: %s\n",
219                                     getConfigRom().getModelName().c_str());
220     debugOutput(DEBUG_LEVEL_NORMAL, "GUID...................: %s\n",
221                                     getConfigRom().getGuidString().c_str());
222
223     std::string id=std::string("dev? [none]");
224     getOption("id", id);
225
226     debugOutput(DEBUG_LEVEL_NORMAL, "Assigned ID....: %s\n", id.c_str());
227
228     flushDebugOutput();
229     #endif
230 }
231
232
233 bool
234 FFADODevice::enableStreaming() {
235     return true;
236 }
237
238 bool
239 FFADODevice::disableStreaming() {
240     return true;
241 }
242
243 const char *
244 FFADODevice::ClockSourceTypeToString(enum eClockSourceType t)
245 {
246     switch(t) {
247         default:            return "Erratic type      ";
248         case eCT_Invalid:   return "Invalid           ";
249         case eCT_Internal:  return "Internal          ";
250         case eCT_1394Bus:   return "1394 Bus          ";
251         case eCT_SytMatch:  return "Compound Syt Match";
252         case eCT_SytStream: return "Sync Syt Match    ";
253         case eCT_WordClock: return "WordClock         ";
254         case eCT_SPDIF:     return "SPDIF             ";
255         case eCT_ADAT:      return "ADAT              ";
256         case eCT_TDIF:      return "TDIF              ";
257         case eCT_AES:       return "AES               ";
258     }
259 }
Note: See TracBrowser for help on using the browser.