root/trunk/libffado/src/libutil/Configuration.h

Revision 1535, 5.1 kB (checked in by ppalmers, 15 years ago)

add support for the FCA-202, and possibly other Oxford FW-92x devices

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 #ifndef _FFADO_UTIL_CONFIGURATION_
25 #define _FFADO_UTIL_CONFIGURATION_
26
27 #include "debugmodule/debugmodule.h"
28 #include "external/libconfig/libconfigpp.h"
29
30 #include <vector>
31
32 namespace Util {
33 /**
34  * A class that manages several configuration files
35  * the idea is that you can have a system config file
36  * and then a user-defined config file
37  *
38  * note: not thread safe!
39  */
40
41 class Configuration {
42 public:
43     // driver ID's to be used in the config file
44     enum eDrivers {
45         eD_Unknown = 0,
46         eD_BeBoB = 1,
47         eD_FireWorks = 2,
48         eD_GenericAVC = 3,
49         eD_Oxford = 4,
50         eD_MOTU = 10,
51     };
52
53     // the modes a config file can have
54     enum eFileMode {
55         eFM_ReadOnly,
56         eFM_ReadWrite,
57         eFM_Temporary, // this won't be saved to dist
58     };
59
60     // struct to define the supported devices
61     struct VendorModelEntry {
62         VendorModelEntry();
63         VendorModelEntry(const VendorModelEntry& rhs);
64         VendorModelEntry& operator = (const VendorModelEntry& rhs);
65         bool operator == (const VendorModelEntry& rhs) const;
66         virtual ~VendorModelEntry();
67
68         unsigned int vendor_id;
69         unsigned int model_id;
70         std::string vendor_name;
71         std::string model_name;
72         unsigned int driver;
73     };
74
75     typedef std::vector<VendorModelEntry> VendorModelEntryVector;
76
77 private:
78     class ConfigFile : public libconfig::Config {
79     public:
80         ConfigFile(Configuration &c, std::string n, enum eFileMode mode = eFM_ReadOnly)
81         : Config()
82         , m_parent(c)
83         , m_name( n )
84         , m_mode( mode )
85         , m_debugModule(c.m_debugModule)
86         {};
87         ~ConfigFile() {};
88         void readFile();
89         void writeFile();
90         void show();
91         void showSetting(libconfig::Setting &, std::string prefix = "");
92
93         std::string getName() {return m_name;};
94         enum eFileMode getMode() {return m_mode;};
95     private:
96         Configuration &m_parent;
97         std::string    m_name;
98         enum eFileMode m_mode;
99     private:
100         DECLARE_DEBUG_MODULE_REFERENCE;
101     };
102
103 public:
104     Configuration();
105     virtual ~Configuration();
106
107     virtual bool openFile(std::string filename, enum eFileMode = eFM_ReadOnly);
108     virtual bool closeFile(std::string filename);
109     virtual bool saveFile(std::string filename);
110     virtual bool save();
111
112     VendorModelEntry findDeviceVME( unsigned int vendor_id,  unsigned model_id );
113     bool isDeviceVMEPresent( unsigned int vendor_id,  unsigned model_id );
114     static bool isValid( const VendorModelEntry& vme );
115
116     // access functions
117     /**
118      * @brief retrieves a setting for a given path
119      *
120      * the value in the ref parameter is not changed if
121      * the function returns false.
122      *
123      * @param path path to the setting
124      * @param ref reference to the integer that will hold the value.
125      * @return true if successful, false if not
126      */
127     bool getValueForSetting(std::string path, int32_t &ref);
128     bool getValueForSetting(std::string path, int64_t &ref);
129     bool getValueForSetting(std::string path, float &ref);
130
131     /**
132      * @brief retrieves a setting for a given device
133      *
134      * the value in the ref parameter is not changed if
135      * the function returns false.
136      *
137      * @param vendor_id vendor id for the device
138      * @param model_id  model id for the device
139      * @param setting name of the setting
140      * @param ref reference to the integer that will hold the value.
141      * @return true if successful, false if not
142      */
143     bool getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, int32_t &ref);
144     bool getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, int64_t &ref);
145     bool getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, float &ref);
146
147     virtual void setVerboseLevel(int l) {setDebugLevel(l);};
148     virtual void show();
149
150 private:
151     libconfig::Setting *getSetting( std::string path );
152     libconfig::Setting *getDeviceSetting( unsigned int vendor_id, unsigned model_id );
153
154     int findFileName(std::string s);
155
156     // important: keep 1-1 mapping for these two!
157     // cannot use map since we need the vector order to
158     // provide priorities
159     std::vector<ConfigFile *> m_ConfigFiles;
160
161     DECLARE_DEBUG_MODULE;
162 };
163
164
165 } // namespace Util
166
167 #endif // _FFADO_UTIL_CONFIGURATION_
Note: See TracBrowser for help on using the browser.