root/trunk/libffado/src/ffadodevice.cpp

Revision 674, 4.5 kB (checked in by ppalmers, 16 years ago)

Introduce bus reset handling

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  * Copyright (C) 2005-2007 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 library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software Foundation;
13  *
14  * This library 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 GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  */
24
25 #include "ffadodevice.h"
26
27 #include "libieee1394/configrom.h"
28 #include "libieee1394/ieee1394service.h"
29
30 #include <iostream>
31 #include <sstream>
32
33 #include <assert.h>
34
35 IMPL_DEBUG_MODULE( FFADODevice, FFADODevice, DEBUG_LEVEL_VERBOSE );
36
37 FFADODevice::FFADODevice( Ieee1394Service& ieee1394Service,
38                           std::auto_ptr<ConfigRom>( configRom ))
39     : Control::Container()
40     , m_pConfigRom( configRom )
41     , m_p1394Service( &ieee1394Service )
42 {
43     addOption(Util::OptionContainer::Option("id",std::string("dev?")));
44
45     std::ostringstream nodestr;
46     nodestr << "node" << getConfigRom().getNodeId();
47
48     if (!addElement(&getConfigRom())) {
49         debugWarning("failed to add ConfigRom to Control::Container\n");
50     }
51 }
52
53 FFADODevice::~FFADODevice()
54 {
55     if (!deleteElement(&getConfigRom())) {
56         debugWarning("failed to remove ConfigRom from Control::Container\n");
57     }
58 }
59
60 FFADODevice *
61 FFADODevice::createDevice( Ieee1394Service& ,
62                            std::auto_ptr<ConfigRom>( x ))
63 {
64     // re-implement this!!
65     assert(0);
66     return NULL;
67 }
68
69 std::string
70 FFADODevice::getName()
71 {
72     return getConfigRom().getGuidString();
73 }
74
75 int
76 FFADODevice::getNodeId()
77 {
78     return getConfigRom().getNodeId();
79 }
80
81 bool FFADODevice::compareGUID( FFADODevice *a, FFADODevice *b ) {
82     assert(a);
83     assert(b);
84     return ConfigRom::compareGUID(a->getConfigRom(), b->getConfigRom());
85 }
86
87 ConfigRom&
88 FFADODevice::getConfigRom() const
89 {
90     return *m_pConfigRom;
91 }
92
93 bool
94 FFADODevice::loadFromCache()
95 {
96     return false;
97 }
98
99 bool
100 FFADODevice::saveCache()
101 {
102     return false;
103 }
104
105 enum FFADODevice::eSyncState
106 FFADODevice::getSyncState( ) {
107     return eSS_Unknown;
108 }
109
110 bool
111 FFADODevice::setId( unsigned int id)
112 {
113     bool retval;
114     // FIXME: decent ID system nescessary
115     std::ostringstream idstr;
116     idstr << "dev" << id;
117     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %s...\n", idstr.str().c_str());
118
119     retval=setOption("id",idstr.str());
120 /*    if (retval) {
121         setOscBase(idstr.str());
122     }*/
123     return retval;
124 }
125
126 void
127 FFADODevice::handleBusReset()
128 {
129     debugOutput( DEBUG_LEVEL_VERBOSE, "Handle bus reset...\n");
130    
131     // update the config rom node id
132     sleep(1);
133     getConfigRom().setVerboseLevel(getDebugLevel());
134     getConfigRom().updatedNodeId();
135
136 }
137
138 void
139 FFADODevice::setVerboseLevel(int l)
140 {
141     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
142     setDebugLevel(l);
143     getConfigRom().setVerboseLevel(l);
144 }
145
146 void
147 FFADODevice::showDevice()
148 {
149     debugOutput(DEBUG_LEVEL_NORMAL, "Node...........: %d\n", getNodeId());
150     debugOutput(DEBUG_LEVEL_NORMAL, "GUID...........: %s\n", getConfigRom().getGuidString().c_str());
151    
152     std::string id=std::string("dev? [none]");
153     getOption("id", id);
154      
155     debugOutput(DEBUG_LEVEL_NORMAL, "Assigned ID....: %s\n", id.c_str());
156
157     flushDebugOutput();
158 }
159
160
161 bool
162 FFADODevice::enableStreaming() {
163     return true;
164 }
165
166 bool
167 FFADODevice::disableStreaming() {
168     return true;
169 }
170
171 const char *
172 FFADODevice::ClockSourceTypeToString(enum eClockSourceType t)
173 {
174     switch(t) {
175         default:            return "Erratic type      ";
176         case eCT_Invalid:   return "Invalid           ";
177         case eCT_Internal:  return "Internal          ";
178         case eCT_1394Bus:   return "1394 Bus          ";
179         case eCT_SytMatch:  return "Compound Syt Match";
180         case eCT_SytStream: return "Sync Syt Match    ";
181         case eCT_WordClock: return "WordClock         ";
182         case eCT_SPDIF:     return "SPDIF             ";
183         case eCT_ADAT:      return "ADAT              ";
184         case eCT_TDIF:      return "TDIF              ";
185         case eCT_AES:       return "AES               ";
186     }
187 }
Note: See TracBrowser for help on using the browser.