root/branches/ppalmers-streaming/src/libstreaming/util/IsoHandlerManager.h

Revision 705, 4.6 kB (checked in by ppalmers, 13 years ago)

restructure the streaming directory

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #ifndef __FFADO_ISOHANDLERMANAGER__
25 #define __FFADO_ISOHANDLERMANAGER__
26
27 #include "debugmodule/debugmodule.h"
28
29 #include "libutil/Thread.h"
30
31 #include <sys/poll.h>
32 #include <errno.h>
33
34 #include <vector>
35
36 #define USLEEP_AFTER_UPDATE_FAILURE 10
37 #define USLEEP_AFTER_UPDATE 100
38 #define MAX_UPDATE_TRIES 10
39 namespace Util {
40     class PosixThread;
41 }
42
43 namespace Streaming
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 Util::RunnableInterface
69 {
70     friend class StreamProcessorManager;
71
72     public:
73
74         IsoHandlerManager();
75         IsoHandlerManager(bool run_rt, unsigned int rt_prio);
76         virtual ~IsoHandlerManager();
77
78         void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll()
79         int getPollTimeout() {return m_poll_timeout;};  ///< get the timeout used for poll()
80
81         void setVerboseLevel(int l); ///< set the verbose level
82
83         void dumpInfo(); ///< print some information about the manager to stdout/stderr
84
85         bool registerStream(IsoStream *); ///< register an iso stream with the manager
86         bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager
87
88         bool startHandlers(); ///< start the managed ISO handlers
89         bool startHandlers(int cycle); ///< start the managed ISO handlers
90         bool stopHandlers(); ///< stop the managed ISO handlers
91
92         bool reset(); ///< reset the ISO manager and all streams
93
94         bool prepare(); ///< prepare the ISO manager and all streams
95
96         bool init();
97
98         void disablePolling(IsoStream *); ///< disables polling on a stream
99         void enablePolling(IsoStream *); ///< enables polling on a stream
100
101     // RunnableInterface interface
102     public:
103         bool Execute(); // note that this is called in we while(running) loop
104         bool Init();
105         pthread_mutex_t m_debug_lock;
106
107     // the state machine
108     private:
109         enum EHandlerStates {
110             E_Created,
111             E_Prepared,
112             E_Running,
113             E_Error
114         };
115
116         enum EHandlerStates m_State;
117
118     private:
119         /// iterate all child handlers
120         bool iterate();
121
122     private:
123         // note: there is a disctinction between streams and handlers
124         // because one handler can serve multiple streams (in case of
125         // multichannel receive)
126
127         // only streams are allowed to be registered externally.
128         // we allocate a handler if we need one, otherwise the stream
129         // is assigned to another handler
130
131         // the collection of handlers
132         IsoHandlerVector m_IsoHandlers;
133
134         bool registerHandler(IsoHandler *);
135         bool unregisterHandler(IsoHandler *);
136         void pruneHandlers();
137
138         // the collection of streams
139         IsoStreamVector m_IsoStreams;
140
141         // poll stuff
142         int m_poll_timeout;
143         struct pollfd *m_poll_fds;
144         int m_poll_nfds;
145
146         bool rebuildFdMap();
147
148         // threading
149         bool m_realtime;
150         unsigned int m_priority;
151         Util::PosixThread *m_isoManagerThread;
152
153         // debug stuff
154         DECLARE_DEBUG_MODULE;
155
156 };
157
158 }
159
160 #endif /* __FFADO_ISOHANDLERMANAGER__  */
161
162
163
Note: See TracBrowser for help on using the browser.