root/trunk/libffado/src/devicemanager.h

Revision 1239, 5.7 kB (checked in by ppalmers, 14 years ago)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 #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
41 #include <vector>
42 #include <string>
43
44 class Ieee1394Service;
45 class FFADODevice;
46 class DeviceStringParser;
47
48 namespace Streaming {
49     class StreamProcessor;
50 }
51
52 typedef std::vector< FFADODevice* > FFADODeviceVector;
53 typedef std::vector< FFADODevice* >::iterator FFADODeviceVectorIterator;
54
55 typedef std::vector< Ieee1394Service* > Ieee1394ServiceVector;
56 typedef std::vector< Ieee1394Service* >::iterator Ieee1394ServiceVectorIterator;
57
58 typedef std::vector< Util::Functor* > FunctorVector;
59 typedef std::vector< Util::Functor* >::iterator FunctorVectorIterator;
60
61 typedef std::vector< ConfigRom* > ConfigRomVector;
62 typedef std::vector< ConfigRom* >::iterator ConfigRomVectorIterator;
63
64 class DeviceManager
65     : public Util::OptionContainer,
66       public Control::Container
67 {
68 public:
69     enum eWaitResult {
70         eWR_OK,
71         eWR_Xrun,
72         eWR_Error,
73         eWR_Shutdown,
74     };
75
76     DeviceManager();
77     ~DeviceManager();
78
79     bool setThreadParameters(bool rt, int priority);
80
81     bool initialize();
82     bool deinitialize();
83
84     bool addSpecString(char *);
85     bool isSpecStringValid(std::string s);
86
87     bool discover(bool useCache=true, bool rediscover=false);
88     bool initStreaming();
89     bool prepareStreaming();
90     bool finishStreaming();
91     bool startStreaming();
92     bool stopStreaming();
93     bool resetStreaming();
94     enum eWaitResult waitForPeriod();
95     bool setStreamingParams(unsigned int period, unsigned int rate, unsigned int nb_buffers);
96
97     bool isValidNode( int node );
98     int getNbDevices();
99     int getDeviceNodeId( int deviceNr );
100
101     FFADODevice* getAvDevice( int nodeId );
102     FFADODevice* getAvDeviceByIndex( int idx );
103     unsigned int getAvDeviceCount();
104
105     Streaming::StreamProcessor *getSyncSource();
106
107     void ignoreBusResets(bool b) {m_ignore_busreset = b;};
108     bool registerBusresetNotification(Util::Functor *f)
109         {return registerNotification(m_busResetNotifiers, f);};
110     bool unregisterBusresetNotification(Util::Functor *f)
111         {return unregisterNotification(m_busResetNotifiers, f);};
112
113     bool registerPreUpdateNotification(Util::Functor *f)
114         {return registerNotification(m_preUpdateNotifiers, f);};
115     bool unregisterPreUpdateNotification(Util::Functor *f)
116         {return unregisterNotification(m_preUpdateNotifiers, f);};
117
118     bool registerPostUpdateNotification(Util::Functor *f)
119         {return registerNotification(m_postUpdateNotifiers, f);};
120     bool unregisterPostUpdateNotification(Util::Functor *f)
121         {return unregisterNotification(m_postUpdateNotifiers, f);};
122
123     void showDeviceInfo();
124     void showStreamingInfo();
125
126     // the Control::Container functions
127     virtual std::string getName()
128         {return "DeviceManager";};
129     virtual bool setName( std::string n )
130         { return false;};
131
132 protected:
133     FFADODevice* getDriverForDeviceDo( ConfigRom *configRom,
134                                        int id, bool generic );
135     FFADODevice* getDriverForDevice( ConfigRom *configRom,
136                                      int id );
137     FFADODevice* getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ) );
138
139     void busresetHandler();
140
141 protected:
142     // we have one service for each port
143     // found on the system. We don't allow dynamic addition of ports (yet)
144     Ieee1394ServiceVector   m_1394Services;
145     FFADODeviceVector       m_avDevices;
146     FunctorVector           m_busreset_functors;
147
148     // the lock protecting the device list
149     Util::Mutex*            m_avDevicesLock;
150     // the lock to serialize bus reset handling
151     Util::Mutex*            m_BusResetLock;
152
153 public: // FIXME: this should be better
154     Streaming::StreamProcessorManager&  getStreamProcessorManager()
155         {return *m_processorManager;};
156 private:
157     Streaming::StreamProcessorManager*  m_processorManager;
158     DeviceStringParser*                 m_deviceStringParser;
159     bool                                m_used_cache_last_time;
160     bool                                m_ignore_busreset;
161
162     typedef std::vector< Util::Functor* > notif_vec_t;
163     notif_vec_t                           m_busResetNotifiers;
164     notif_vec_t                           m_preUpdateNotifiers;
165     notif_vec_t                           m_postUpdateNotifiers;
166
167     bool registerNotification(notif_vec_t&, Util::Functor *);
168     bool unregisterNotification(notif_vec_t&, Util::Functor *);
169     void signalNotifiers(notif_vec_t& list);
170
171 protected:
172     std::vector<std::string>            m_SpecStrings;
173
174     bool m_thread_realtime;
175     int m_thread_priority;
176
177 // debug stuff
178 public:
179     void setVerboseLevel(int l);
180 private:
181     DECLARE_DEBUG_MODULE;
182 };
183
184 #endif
Note: See TracBrowser for help on using the browser.