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

Revision 742, 3.8 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

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 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 3 of the License, or
12  * (at your option) any later version.
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 #include "Element.h"
25
26 namespace Control {
27
28 IMPL_DEBUG_MODULE( Element, Element, DEBUG_LEVEL_NORMAL );
29
30 // This serves as an ID
31 // incremented on every Element creation
32 // ID's are unique as long as we don't create
33 // more than 2^64 elements.
34 // if we would create 1000 Elements per second
35 // we'd still need >500000 years to wrap.
36 // I guess we're safe.
37 static uint64_t GlobalElementCounter=0;
38
39 Element::Element()
40 : m_Name ( "NoName" )
41 , m_Label ( "No Label" )
42 , m_Description ( "No Description" )
43 , m_id(GlobalElementCounter++)
44 {
45 }
46
47 Element::Element(std::string n)
48 : m_Name( n )
49 , m_Label ( "No Label" )
50 , m_Description ( "No Description" )
51 , m_id(GlobalElementCounter++)
52 {
53 }
54
55 void
56 Element::show()
57 {
58     debugOutput( DEBUG_LEVEL_NORMAL, "Element %s\n",
59         getName().c_str());
60 }
61
62 void
63 Element::setVerboseLevel(int l)
64 {
65     setDebugLevel(l);
66     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
67 }
68
69 //// --- Container --- ////
70 Container::Container()
71 : Element()
72 {
73 }
74
75 Container::Container(std::string n)
76 : Element(n)
77 {
78 }
79
80 bool
81 Container::addElement(Element *e)
82 {
83     if (e==NULL) {
84         debugWarning("Cannot add NULL element\n");
85         return false;
86     }
87
88     debugOutput( DEBUG_LEVEL_VERBOSE, "Adding Element %s to %s\n",
89         e->getName().c_str(), getName().c_str());
90
91     // don't allow duplicates, only makes life hard
92     for ( ElementVectorIterator it = m_Children.begin();
93       it != m_Children.end();
94       ++it )
95     {
96         if(*it == e) {
97             debugOutput( DEBUG_LEVEL_VERBOSE, "Not adding Element %s, already present\n",
98                 e->getName().c_str());
99             return false;
100         }
101     }
102
103     m_Children.push_back(e);
104     return true;
105 }
106
107 bool
108 Container::deleteElement(Element *e)
109 {
110     assert(e);
111     debugOutput( DEBUG_LEVEL_VERBOSE, "Deleting Element %s from %s\n",
112         e->getName().c_str(), getName().c_str());
113
114     for ( ElementVectorIterator it = m_Children.begin();
115       it != m_Children.end();
116       ++it )
117     {
118         if(*it == e) {
119             m_Children.erase(it);
120             return true;
121         }
122     }
123
124     debugOutput( DEBUG_LEVEL_VERBOSE, "Element %s not found \n",e->getName().c_str());
125     return false; //not found
126 }
127
128 bool
129 Container::clearElements(bool delete_pointers)
130 {
131     while(m_Children.size()) {
132         Element *e=m_Children[0];
133         deleteElement(e);
134         if (delete_pointers) delete e;
135     }
136     return true;
137 }
138
139 void
140 Container::show()
141 {
142     debugOutput( DEBUG_LEVEL_NORMAL, "Container %s (%d Elements)\n",
143         getName().c_str(), m_Children.size());
144
145     for ( ElementVectorIterator it = m_Children.begin();
146       it != m_Children.end();
147       ++it )
148     {
149         (*it)->show();
150     }
151 }
152
153 void
154 Container::setVerboseLevel(int l)
155 {
156     setDebugLevel(l);
157     for ( ElementVectorIterator it = m_Children.begin();
158       it != m_Children.end();
159       ++it )
160     {
161         (*it)->setVerboseLevel(l);
162     }
163     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
164 }
165
166 } // namespace Control
Note: See TracBrowser for help on using the browser.