root/branches/libffado-2.0/src/libcontrol/Element.h

Revision 1385, 4.4 kB (checked in by ppalmers, 12 years ago)

Implement a mechanism to disable the samplerate and clock source controls while the device is streaming in order to avoid changes that could mess up jack. The saffire pro controls that cause a device reset to
happen are also disabled while streaming is active.

Line 
1 /*
2  * Copyright (C) 2005-2008 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 program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program 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
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef CONTROL_ELEMENT_H
25 #define CONTROL_ELEMENT_H
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <vector>
30 #include <string>
31
32 #include "libutil/Mutex.h"
33 #include "libutil/Functors.h"
34
35 namespace Control {
36
37 class Element;
38
39 /*!
40 @brief Base class for control signal functors
41
42  This class should be subclassed to implement ffado control signal handlers.
43 */
44 class SignalFunctor
45 {
46     friend class Element;
47 public:
48     SignalFunctor(int signal_id)
49     : m_id(signal_id) {};
50     virtual ~SignalFunctor() {}
51
52     virtual void operator() () = 0;
53     virtual void operator() (int) = 0;
54 protected:
55     int m_id;
56 };
57
58 /*!
59 @brief Base class for control elements
60
61  This class should be subclassed to implement ffado control elements.
62 */
63 class Element
64 {
65 public:
66     Element(Element *);
67     Element(Element *, std::string n);
68     virtual ~Element();
69
70     virtual std::string getName() {return m_Name;};
71     virtual bool setName( std::string n )
72         { m_Name=n; return true;};
73
74     virtual std::string getLabel() {return m_Label;};
75     virtual bool setLabel( std::string n )
76         { m_Label=n; return true;};
77
78     virtual std::string getDescription() {return m_Description;};
79     virtual bool setDescription( std::string n )
80         { m_Description=n; return true;};
81
82     uint64_t getId()
83         {return m_id;};
84
85     // can the value of this element change?
86     virtual bool canChangeValue();
87
88     // these allow to prevent external access to the control elements
89     // e.g. when the config tree is rebuilt
90     virtual void lockControl();
91     virtual void unlockControl();
92
93     /**
94      * Update signal handler
95      */
96     bool addSignalHandler( SignalFunctor* functor );
97     bool remSignalHandler( SignalFunctor* functor );
98
99     virtual void show();
100
101     /**
102      * set verbosity level
103      */
104     virtual void setVerboseLevel(int l);
105     virtual int getVerboseLevel() {return getDebugLevel();};
106
107 protected:
108     bool            emitSignal(int id, int value);
109     bool            emitSignal(int id);
110     Util::Mutex&    getLock();
111
112 private:
113     Util::Mutex*    m_element_lock;
114     Element*        m_parent;
115     std::string m_Name;
116     std::string m_Label;
117     std::string m_Description;
118
119     uint64_t m_id;
120     std::vector< SignalFunctor* > m_signalHandlers;
121
122 protected:
123     DECLARE_DEBUG_MODULE;
124
125 };
126 typedef std::vector<Element *> ElementVector;
127 typedef std::vector<Element *>::iterator ElementVectorIterator;
128 typedef std::vector<Element *>::const_iterator ConstElementVectorIterator;
129
130 /*!
131 @brief Base class for control containers
132
133  This class should be subclassed to implement ffado control container elements.
134  Containers are classes that can hold a set of control elements. They themselves
135  are control elements such that hierarchies can be defined using them.
136  
137  Special control containers that act on all of their children can also be
138  implemented.
139 */
140 class Container : public Element
141 {
142 public:
143     Container(Element *);
144     Container(Element *, std::string n);
145     virtual ~Container();
146
147     virtual bool addElement(Element *e);
148     virtual bool deleteElement(Element *e);
149     virtual bool clearElements()
150         {return clearElements(false);};
151     virtual bool clearElements(bool delete_pointers);
152
153     unsigned int countElements();
154
155
156     /**
157      * Returns the element vector. be sure to lock the tree while using
158      * the return value.
159      * @return
160      */
161     const ElementVector & getElementVector();
162
163     virtual void show();
164     virtual void setVerboseLevel(int l);
165
166     enum eSignals {
167         eS_Updated,
168     };
169
170 private:
171     bool deleteElementNoLock(Element *e);
172
173 protected:
174     ElementVector m_Children;
175 };
176
177
178 }; // namespace Control
179
180 #endif // CONTROL_ELEMENT_H
Note: See TracBrowser for help on using the browser.