root/trunk/libffado/src/libcontrol/Element.h

Revision 1498, 4.4 kB (checked in by ppalmers, 14 years ago)

Merge all changes from 2.0 branch into trunk (since r1361). This _should_ contain all forward merges done in the mean time. At this moment in time both branches should be in sync.

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     virtual bool isControlLocked();
93
94     /**
95      * Update signal handler
96      */
97     bool addSignalHandler( SignalFunctor* functor );
98     bool remSignalHandler( SignalFunctor* functor );
99
100     virtual void show();
101
102     /**
103      * set verbosity level
104      */
105     virtual void setVerboseLevel(int l);
106     virtual int getVerboseLevel() {return getDebugLevel();};
107
108 protected:
109     bool            emitSignal(int id, int value);
110     bool            emitSignal(int id);
111     Util::Mutex&    getLock();
112
113 private:
114     Util::Mutex*    m_element_lock;
115     Element*        m_parent;
116     std::string m_Name;
117     std::string m_Label;
118     std::string m_Description;
119
120     uint64_t m_id;
121     std::vector< SignalFunctor* > m_signalHandlers;
122
123 protected:
124     DECLARE_DEBUG_MODULE;
125
126 };
127 typedef std::vector<Element *> ElementVector;
128 typedef std::vector<Element *>::iterator ElementVectorIterator;
129 typedef std::vector<Element *>::const_iterator ConstElementVectorIterator;
130
131 /*!
132 @brief Base class for control containers
133
134  This class should be subclassed to implement ffado control container elements.
135  Containers are classes that can hold a set of control elements. They themselves
136  are control elements such that hierarchies can be defined using them.
137  
138  Special control containers that act on all of their children can also be
139  implemented.
140 */
141 class Container : public Element
142 {
143 public:
144     Container(Element *);
145     Container(Element *, std::string n);
146     virtual ~Container();
147
148     virtual bool addElement(Element *e);
149     virtual bool deleteElement(Element *e);
150     virtual bool clearElements()
151         {return clearElements(false);};
152     virtual bool clearElements(bool delete_pointers);
153
154     unsigned int countElements();
155
156
157     /**
158      * Returns the element vector. be sure to lock the tree while using
159      * the return value.
160      * @return
161      */
162     const ElementVector & getElementVector();
163
164     virtual void show();
165     virtual void setVerboseLevel(int l);
166
167     enum eSignals {
168         eS_Updated,
169     };
170
171 private:
172     bool deleteElementNoLock(Element *e);
173
174 protected:
175     ElementVector m_Children;
176 };
177
178
179 }; // namespace Control
180
181 #endif // CONTROL_ELEMENT_H
Note: See TracBrowser for help on using the browser.