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

Revision 581, 3.2 kB (checked in by ppalmers, 15 years ago)

- First attempt at mixer control (still disfunctional)
- moved vendor specific code in bebob/*

Line 
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     assert(e);
84
85     debugOutput( DEBUG_LEVEL_VERBOSE, "Adding Element %s to %s\n",
86         e->getName().c_str(), getName().c_str());
87
88     // don't allow duplicates, only makes life hard
89     for ( ElementVectorIterator it = m_Children.begin();
90       it != m_Children.end();
91       ++it )
92     {
93         if(*it == e) {
94             debugOutput( DEBUG_LEVEL_VERBOSE, "Not adding Element %s, already present\n",
95                 e->getName().c_str());
96             return false;
97         }
98     }
99
100     m_Children.push_back(e);
101     return true;
102 }
103
104 bool
105 Container::deleteElement(Element *e)
106 {
107     assert(e);
108     debugOutput( DEBUG_LEVEL_VERBOSE, "Deleting Element %s from %s\n",
109         e->getName().c_str(), getName().c_str());
110
111     for ( ElementVectorIterator it = m_Children.begin();
112       it != m_Children.end();
113       ++it )
114     {
115         if(*it == e) {
116             m_Children.erase(it);
117             return true;
118         }
119     }
120
121     debugOutput( DEBUG_LEVEL_VERBOSE, "Element %s not found \n",e->getName().c_str());
122     return false; //not found
123 }
124
125 void
126 Container::show()
127 {
128     debugOutput( DEBUG_LEVEL_NORMAL, "Container %s (%d Elements)\n",
129         getName().c_str(), m_Children.size());
130
131     for ( ElementVectorIterator it = m_Children.begin();
132       it != m_Children.end();
133       ++it )
134     {
135         (*it)->show();
136     }
137 }
138
139 } // namespace Control
Note: See TracBrowser for help on using the browser.