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

Revision 1566, 4.5 kB (checked in by holin, 15 years ago)

missing includes reported by gcc 4.4. Patch from Martin Michlmayr.

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