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

Revision 1211, 4.3 kB (checked in by ppalmers, 14 years ago)

merge libffado-2.0 r1199:1206 back to trunk (svn merge -r 1199:1206 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0)

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