root/trunk/libffado/src/ffadodevice.cpp

Revision 1158, 6.5 kB (checked in by ppalmers, 13 years ago)

make control more thread safe (unfinished)

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