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

Revision 575, 3.1 kB (checked in by ppalmers, 16 years ago)

- Fixed bug in dbus c++ bindings
- First attempt at a decoupled control interface. [WIP]


The src/libcontrol/* elements are the ones that should be
subclassed to implement control elements on the FFADODevice
side.

The tests/controlserver.* files contain some code that
interfaces the DBus calls to these libcontrol elements. The
DBus classes allow for introspection and path discovery,
such that we don't have to care about that anymore.

In the end it should be fairly easy to write another 'backend'
to replace the current DBus one, e.g. to implement OSC support
or MIDI support. (Should we ever want that)

Note that there is no connection between ffado and dbus yet,
this code is merely to experiment with the Control/DBus infra-
structure. Once that is sort-of working, connecting ffado to
this infrastructure is a matter of subclassing the Control::*
classes, creating them on discovery and putting them into one
Container::* that is passed on to the DBus handlers.

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_id(GlobalElementCounter++)
41 {
42 }
43
44 Element::Element(std::string n)
45 : m_Name( n )
46 , m_id(GlobalElementCounter++)
47 {
48 }
49
50 void
51 Element::show()
52 {
53     debugOutput( DEBUG_LEVEL_NORMAL, "Element %s\n",
54         getName().c_str());
55 }
56
57 void
58 Element::setVerboseLevel(int l)
59 {
60     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
61     setDebugLevel(l);
62 }
63
64 //// --- Container --- ////
65 Container::Container()
66 : Element()
67 {
68 }
69
70 Container::Container(std::string n)
71 : Element(n)
72 {
73 }
74
75 bool
76 Container::addElement(Element *e)
77 {
78     assert(e);
79
80     debugOutput( DEBUG_LEVEL_VERBOSE, "Adding Element %s to %s\n",
81         e->getName().c_str(), getName().c_str());
82
83     // don't allow duplicates, only makes life hard
84     for ( ElementVectorIterator it = m_Children.begin();
85       it != m_Children.end();
86       ++it )
87     {
88         if(*it == e) {
89             debugOutput( DEBUG_LEVEL_VERBOSE, "Not adding Element %s, already present\n",
90                 e->getName().c_str());
91             return false;
92         }
93     }
94
95     m_Children.push_back(e);
96     return true;
97 }
98
99 bool
100 Container::deleteElement(Element *e)
101 {
102     assert(e);
103     debugOutput( DEBUG_LEVEL_VERBOSE, "Deleting Element %s from %s\n",
104         e->getName().c_str(), getName().c_str());
105
106     for ( ElementVectorIterator it = m_Children.begin();
107       it != m_Children.end();
108       ++it )
109     {
110         if(*it == e) {
111             m_Children.erase(it);
112             return true;
113         }
114     }
115
116     debugOutput( DEBUG_LEVEL_VERBOSE, "Element %s not found \n",e->getName().c_str());
117     return false; //not found
118 }
119
120 void
121 Container::show()
122 {
123     debugOutput( DEBUG_LEVEL_NORMAL, "Container %s (%d Elements)\n",
124         getName().c_str(), m_Children.size());
125
126     for ( ElementVectorIterator it = m_Children.begin();
127       it != m_Children.end();
128       ++it )
129     {
130         (*it)->show();
131     }
132 }
133
134 } // namespace Control
Note: See TracBrowser for help on using the browser.