root/branches/streaming-rework/src/libstreaming/IsoHandlerManager.h

Revision 383, 4.3 kB (checked in by pieterpalmers, 17 years ago)

mostly whitespace fixes

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2006 Pieter Palmers <pieterpalmers@users.sourceforge.net>
10  *
11  *   This program is free software {} you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation {} either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program {} if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  *
26  *
27  */
28 #ifndef __FREEBOB_ISOHANDLERMANAGER__
29 #define __FREEBOB_ISOHANDLERMANAGER__
30
31 #include "../debugmodule/debugmodule.h"
32 #include "../libutil/Thread.h"
33
34 #include <sys/poll.h>
35 #include <errno.h>
36
37 #include <vector>
38
39 #define USLEEP_AFTER_UPDATE_FAILURE 10
40 #define USLEEP_AFTER_UPDATE 100
41 #define MAX_UPDATE_TRIES 10
42
43 namespace FreebobStreaming
44 {
45
46 class IsoHandler;
47 class IsoStream;
48
49 typedef std::vector<IsoHandler *> IsoHandlerVector;
50 typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator;
51
52 typedef std::vector<IsoStream *> IsoStreamVector;
53 typedef std::vector<IsoStream *>::iterator IsoStreamVectorIterator;
54
55
56 /*!
57 \brief The ISO Handler management class
58
59  This class manages the use of ISO handlers by ISO streams.
60  You can register an IsoStream with an IsoHandlerManager. This
61  manager will assign an IsoHandler to the stream. If nescessary
62  the manager allocates a new handler. If there is already a handler
63  that can handle the IsoStream (e.g. in case of multichannel receive),
64  it can be assigned.
65
66 */
67
68 class IsoHandlerManager : public FreebobUtil::RunnableInterface
69 {
70     friend class StreamProcessorManager;
71
72     public:
73
74         IsoHandlerManager();
75         virtual ~IsoHandlerManager();
76
77         void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll()
78         int getPollTimeout() {return m_poll_timeout;};  ///< get the timeout used for poll()
79
80         void setVerboseLevel(int l); ///< set the verbose level
81
82         void dumpInfo(); ///< print some information about the manager to stdout/stderr
83
84         bool registerStream(IsoStream *); ///< register an iso stream with the manager
85         bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager
86
87         bool startHandlers(); ///< start the managed ISO handlers
88         bool startHandlers(int cycle); ///< start the managed ISO handlers
89         bool stopHandlers(); ///< stop the managed ISO handlers
90
91                 bool reset() {return true;}; ///< reset the ISO manager and all streams
92
93         bool prepare(); ///< prepare the ISO manager and all streams
94        
95         void disablePolling(IsoStream *); ///< disables polling on a stream
96         void enablePolling(IsoStream *); ///< enables polling on a stream
97
98         public:
99        
100            
101     // RunnableInterface interface
102         bool Execute(); // note that this is called in we while(running) loop
103         bool Init();
104        
105             // iterate all handlers
106             bool iterate();
107     private:
108         // updates the cycle counter caches of all handlers
109         void updateCycleCounters();
110        
111         // note: there is a disctinction between streams and handlers
112         // because one handler can serve multiple streams (in case of
113         // multichannel receive)
114
115         // only streams are allowed to be registered externally.
116         // we allocate a handler if we need one, otherwise the stream
117         // is assigned to another handler
118
119         // the collection of handlers
120         IsoHandlerVector m_IsoHandlers;
121
122         bool registerHandler(IsoHandler *);
123         bool unregisterHandler(IsoHandler *);
124         void pruneHandlers();
125
126         // the collection of streams
127         IsoStreamVector m_IsoStreams;
128
129         // poll stuff
130         int m_poll_timeout;
131         struct pollfd *m_poll_fds;
132         int m_poll_nfds;
133
134         bool rebuildFdMap();
135
136
137         DECLARE_DEBUG_MODULE;
138
139 };
140
141 }
142
143 #endif /* __FREEBOB_ISOHANDLERMANAGER__  */
144
145
146
Note: See TracBrowser for help on using the browser.