1 |
/* |
---|
2 |
* Copyright (C) 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 library is free software; you can redistribute it and/or |
---|
10 |
* modify it under the terms of the GNU Lesser General Public |
---|
11 |
* License version 2.1, as published by the Free Software Foundation; |
---|
12 |
* |
---|
13 |
* This library is distributed in the hope that it will be useful, |
---|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 |
* Lesser General Public License for more details. |
---|
17 |
* |
---|
18 |
* You should have received a copy of the GNU Lesser General Public |
---|
19 |
* License along with this library; if not, write to the Free Software |
---|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
21 |
* MA 02110-1301 USA |
---|
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 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); |
---|
66 |
setDebugLevel(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 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); |
---|
157 |
for ( ElementVectorIterator it = m_Children.begin(); |
---|
158 |
it != m_Children.end(); |
---|
159 |
++it ) |
---|
160 |
{ |
---|
161 |
(*it)->setVerboseLevel(l); |
---|
162 |
} |
---|
163 |
} |
---|
164 |
|
---|
165 |
} // namespace Control |
---|