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 |
#ifndef FFADODEVICEMANAGER_H |
---|
26 |
#define FFADODEVICEMANAGER_H |
---|
27 |
|
---|
28 |
#include "debugmodule/debugmodule.h" |
---|
29 |
|
---|
30 |
#include "libieee1394/configrom.h" |
---|
31 |
#include "libieee1394/ieee1394service.h" |
---|
32 |
|
---|
33 |
#include "libstreaming/StreamProcessorManager.h" |
---|
34 |
|
---|
35 |
#include "libutil/OptionContainer.h" |
---|
36 |
#include "libcontrol/BasicElements.h" |
---|
37 |
|
---|
38 |
#include "libutil/Functors.h" |
---|
39 |
#include "libutil/Mutex.h" |
---|
40 |
#include "libutil/Configuration.h" |
---|
41 |
|
---|
42 |
#include <vector> |
---|
43 |
#include <string> |
---|
44 |
|
---|
45 |
class Ieee1394Service; |
---|
46 |
class FFADODevice; |
---|
47 |
class DeviceStringParser; |
---|
48 |
|
---|
49 |
namespace Streaming { |
---|
50 |
class StreamProcessor; |
---|
51 |
} |
---|
52 |
|
---|
53 |
typedef std::vector< FFADODevice* > FFADODeviceVector; |
---|
54 |
typedef std::vector< FFADODevice* >::iterator FFADODeviceVectorIterator; |
---|
55 |
|
---|
56 |
typedef std::vector< Ieee1394Service* > Ieee1394ServiceVector; |
---|
57 |
typedef std::vector< Ieee1394Service* >::iterator Ieee1394ServiceVectorIterator; |
---|
58 |
|
---|
59 |
typedef std::vector< Util::Functor* > FunctorVector; |
---|
60 |
typedef std::vector< Util::Functor* >::iterator FunctorVectorIterator; |
---|
61 |
|
---|
62 |
typedef std::vector< ConfigRom* > ConfigRomVector; |
---|
63 |
typedef std::vector< ConfigRom* >::iterator ConfigRomVectorIterator; |
---|
64 |
|
---|
65 |
class DeviceManager |
---|
66 |
: public Util::OptionContainer, |
---|
67 |
public Control::Container |
---|
68 |
{ |
---|
69 |
public: |
---|
70 |
enum eWaitResult { |
---|
71 |
eWR_OK, |
---|
72 |
eWR_Xrun, |
---|
73 |
eWR_Error, |
---|
74 |
eWR_Shutdown, |
---|
75 |
}; |
---|
76 |
|
---|
77 |
DeviceManager(); |
---|
78 |
~DeviceManager(); |
---|
79 |
|
---|
80 |
bool setThreadParameters(bool rt, int priority); |
---|
81 |
|
---|
82 |
bool initialize(); |
---|
83 |
bool deinitialize(); |
---|
84 |
|
---|
85 |
bool addSpecString(char *); |
---|
86 |
bool isSpecStringValid(std::string s); |
---|
87 |
|
---|
88 |
bool discover(bool useCache=true, bool rediscover=false); |
---|
89 |
bool initStreaming(); |
---|
90 |
bool prepareStreaming(); |
---|
91 |
bool finishStreaming(); |
---|
92 |
bool startStreaming(); |
---|
93 |
bool stopStreaming(); |
---|
94 |
bool resetStreaming(); |
---|
95 |
enum eWaitResult waitForPeriod(); |
---|
96 |
bool setStreamingParams(unsigned int period, unsigned int rate, unsigned int nb_buffers); |
---|
97 |
|
---|
98 |
bool isValidNode( int node ); |
---|
99 |
int getNbDevices(); |
---|
100 |
int getDeviceNodeId( int deviceNr ); |
---|
101 |
|
---|
102 |
FFADODevice* getAvDevice( int nodeId ); |
---|
103 |
FFADODevice* getAvDeviceByIndex( int idx ); |
---|
104 |
unsigned int getAvDeviceCount(); |
---|
105 |
|
---|
106 |
Streaming::StreamProcessor *getSyncSource(); |
---|
107 |
|
---|
108 |
/** |
---|
109 |
* prevents the busreset handler from running. use with care! |
---|
110 |
*/ |
---|
111 |
void lockBusResetHandler() {m_BusResetLock->Lock();}; |
---|
112 |
/** |
---|
113 |
* releases the busreset handlers |
---|
114 |
*/ |
---|
115 |
void unlockBusResetHandler() {m_BusResetLock->Unlock();}; |
---|
116 |
bool registerBusresetNotification(Util::Functor *f) |
---|
117 |
{return registerNotification(m_busResetNotifiers, f);}; |
---|
118 |
bool unregisterBusresetNotification(Util::Functor *f) |
---|
119 |
{return unregisterNotification(m_busResetNotifiers, f);}; |
---|
120 |
|
---|
121 |
bool registerPreUpdateNotification(Util::Functor *f) |
---|
122 |
{return registerNotification(m_preUpdateNotifiers, f);}; |
---|
123 |
bool unregisterPreUpdateNotification(Util::Functor *f) |
---|
124 |
{return unregisterNotification(m_preUpdateNotifiers, f);}; |
---|
125 |
|
---|
126 |
bool registerPostUpdateNotification(Util::Functor *f) |
---|
127 |
{return registerNotification(m_postUpdateNotifiers, f);}; |
---|
128 |
bool unregisterPostUpdateNotification(Util::Functor *f) |
---|
129 |
{return unregisterNotification(m_postUpdateNotifiers, f);}; |
---|
130 |
|
---|
131 |
|
---|
132 |
Util::Configuration& getConfiguration() {return *m_configuration;}; |
---|
133 |
|
---|
134 |
void showDeviceInfo(); |
---|
135 |
void showStreamingInfo(); |
---|
136 |
|
---|
137 |
// the Control::Container functions |
---|
138 |
virtual std::string getName() |
---|
139 |
{return "DeviceManager";}; |
---|
140 |
virtual bool setName( std::string n ) |
---|
141 |
{ return false;}; |
---|
142 |
|
---|
143 |
protected: |
---|
144 |
FFADODevice* getDriverForDeviceDo( ConfigRom *configRom, |
---|
145 |
int id, bool generic ); |
---|
146 |
FFADODevice* getDriverForDevice( ConfigRom *configRom, |
---|
147 |
int id ); |
---|
148 |
FFADODevice* getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ) ); |
---|
149 |
|
---|
150 |
void busresetHandler(Ieee1394Service &); |
---|
151 |
|
---|
152 |
protected: |
---|
153 |
// we have one service for each port |
---|
154 |
// found on the system. We don't allow dynamic addition of ports (yet) |
---|
155 |
Ieee1394ServiceVector m_1394Services; |
---|
156 |
FFADODeviceVector m_avDevices; |
---|
157 |
FunctorVector m_busreset_functors; |
---|
158 |
|
---|
159 |
// the lock protecting the device list |
---|
160 |
Util::Mutex* m_DeviceListLock; |
---|
161 |
// the lock to serialize bus reset handling |
---|
162 |
Util::Mutex* m_BusResetLock; |
---|
163 |
|
---|
164 |
public: // FIXME: this should be better |
---|
165 |
Streaming::StreamProcessorManager& getStreamProcessorManager() |
---|
166 |
{return *m_processorManager;}; |
---|
167 |
private: |
---|
168 |
Streaming::StreamProcessorManager* m_processorManager; |
---|
169 |
DeviceStringParser* m_deviceStringParser; |
---|
170 |
Util::Configuration* m_configuration; |
---|
171 |
bool m_used_cache_last_time; |
---|
172 |
|
---|
173 |
typedef std::vector< Util::Functor* > notif_vec_t; |
---|
174 |
notif_vec_t m_busResetNotifiers; |
---|
175 |
notif_vec_t m_preUpdateNotifiers; |
---|
176 |
notif_vec_t m_postUpdateNotifiers; |
---|
177 |
|
---|
178 |
bool registerNotification(notif_vec_t&, Util::Functor *); |
---|
179 |
bool unregisterNotification(notif_vec_t&, Util::Functor *); |
---|
180 |
void signalNotifiers(notif_vec_t& list); |
---|
181 |
|
---|
182 |
protected: |
---|
183 |
std::vector<std::string> m_SpecStrings; |
---|
184 |
|
---|
185 |
bool m_thread_realtime; |
---|
186 |
int m_thread_priority; |
---|
187 |
|
---|
188 |
// debug stuff |
---|
189 |
public: |
---|
190 |
void setVerboseLevel(int l); |
---|
191 |
private: |
---|
192 |
DECLARE_DEBUG_MODULE; |
---|
193 |
}; |
---|
194 |
|
---|
195 |
#endif |
---|