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

Revision 1158, 4.4 kB (checked in by ppalmers, 16 years ago)

make control more thread safe (unfinished)

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 #include "ClockSelect.h"
25 #include "ffadodevice.h"
26
27 namespace Control {
28
29 //// --- ClockSelect --- ////
30 ClockSelect::ClockSelect(FFADODevice &d)
31 : AttributeEnum(&d)
32 , m_Device( d )
33 {
34     setName("ClockSelect");
35     setLabel("Clock Source");
36     setDescription("Select the device clock source");
37 }
38
39 bool
40 ClockSelect::select(int idx)
41 {
42     FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources();
43     if(idx >= (int)v.size()) {
44         debugError("index out of range\n");
45         return false;
46     }
47     if(!m_Device.setActiveClockSource(v.at(idx))) {
48         debugWarning("could not set active clocksource\n");
49         return false;
50     }
51     return true;
52 }
53
54 int
55 ClockSelect::selected()
56 {
57     FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources();
58     FFADODevice::ClockSource active = m_Device.getActiveClockSource();
59     int i=0;
60     for (i=0; i < (int)v.size(); i++) {
61         FFADODevice::ClockSource c = v.at(i);
62         if(c == active) {
63             return i;
64         }
65     }
66     debugError("No active clock source found!\n");
67     return -1;
68 }
69
70 int
71 ClockSelect::count()
72 {
73     return m_Device.getSupportedClockSources().size();
74 }
75
76 std::string
77 ClockSelect::getEnumLabel(int idx)
78 {
79     FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources();
80     if(idx >= (int)v.size()) {
81         debugError("index out of range\n");
82         return false;
83     }
84     return v.at(idx).description;
85 }
86
87 int
88 ClockSelect::attributeCount()
89 {
90 /*
91         /// indicates the type of the clock source (e.g. eCT_ADAT)
92         enum eClockSourceType type;
93         /// indicated the id of the clock source (e.g. id=1 => clocksource is ADAT_1)
94         unsigned int id;
95         /// is the clock source valid (i.e. can be selected) at this moment?
96         bool valid;
97         /// is the clock source active at this moment?
98         bool active;
99         /// is the clock source locked?
100         bool locked;
101         /// is the clock source slipping?
102         bool slipping;
103         /// description of the clock struct (optional)
104         std::string description;
105 */
106     return 7;
107 }
108
109 std::string
110 ClockSelect::getAttributeValue(int attridx)
111 {
112     char tmp[16];
113     std::string retval = "bad attr index";
114     FFADODevice::ClockSource active = m_Device.getActiveClockSource();
115    
116     switch(attridx) {
117         case 0:
118             retval = FFADODevice::ClockSourceTypeToString(active.type);
119             break;
120         case 1:
121             snprintf(tmp, 16, "%u", active.id);
122             retval = tmp;
123             break;
124         case 2:
125             snprintf(tmp, 16, "%u", active.valid);
126             retval = tmp;
127             break;
128         case 3:
129             snprintf(tmp, 16, "%u", active.active);
130             retval = tmp;
131             break;
132         case 4:
133             snprintf(tmp, 16, "%u", active.locked);
134             retval = tmp;
135             break;
136         case 5:
137             snprintf(tmp, 16, "%u", active.slipping);
138             retval = tmp;
139             break;
140         case 6:
141             retval = active.description;
142     }
143     return retval;
144 }
145
146 std::string
147 ClockSelect::getAttributeName(int attridx)
148 {
149     switch(attridx) {
150         case 0: return "type";
151         case 1: return "id";
152         case 2: return "valid";
153         case 3: return "active";
154         case 4: return "locked";
155         case 5: return "slipping";
156         case 6: return "description";
157         default: return "bad attr index";
158     }
159 }
160
161 void
162 ClockSelect::show()
163 {
164     debugOutput( DEBUG_LEVEL_NORMAL, "ClockSelect Element %s, active: %s\n",
165         getName().c_str(), m_Device.getActiveClockSource().description.c_str());
166 }
167
168 } // namespace Control
Note: See TracBrowser for help on using the browser.