root/branches/libffado-2.0/src/libutil/Configuration.h

Revision 1373, 4.2 kB (checked in by ppalmers, 15 years ago)

make IsoManager? and SPM settings from config.h overridable by the user/distro config file.

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_MOTU = 10,
50     };
51
52     // the modes a config file can have
53     enum eFileMode {
54         eFM_ReadOnly,
55         eFM_ReadWrite,
56         eFM_Temporary, // this won't be saved to dist
57     };
58
59     // struct to define the supported devices
60     struct VendorModelEntry {
61         VendorModelEntry();
62         VendorModelEntry(const VendorModelEntry& rhs);
63         VendorModelEntry& operator = (const VendorModelEntry& rhs);
64         bool operator == (const VendorModelEntry& rhs) const;
65         virtual ~VendorModelEntry();
66
67         unsigned int vendor_id;
68         unsigned int model_id;
69         std::string vendor_name;
70         std::string model_name;
71         unsigned int driver;
72     };
73
74     typedef std::vector<VendorModelEntry> VendorModelEntryVector;
75
76 private:
77     class ConfigFile : public libconfig::Config {
78     public:
79         ConfigFile(Configuration &c, std::string n, enum eFileMode mode = eFM_ReadOnly)
80         : Config()
81         , m_parent(c)
82         , m_name( n )
83         , m_mode( mode )
84         , m_debugModule(c.m_debugModule)
85         {};
86         ~ConfigFile() {};
87         void readFile();
88         void writeFile();
89         void show();
90         void showSetting(libconfig::Setting &, std::string prefix = "");
91
92         std::string getName() {return m_name;};
93         enum eFileMode getMode() {return m_mode;};
94     private:
95         Configuration &m_parent;
96         std::string    m_name;
97         enum eFileMode m_mode;
98     private:
99         DECLARE_DEBUG_MODULE_REFERENCE;
100     };
101
102 public:
103     Configuration();
104     virtual ~Configuration();
105
106     virtual bool openFile(std::string filename, enum eFileMode = eFM_ReadOnly);
107     virtual bool closeFile(std::string filename);
108     virtual bool saveFile(std::string filename);
109     virtual bool save();
110
111     VendorModelEntry findDeviceVME( unsigned int vendor_id,  unsigned model_id );
112     bool isDeviceVMEPresent( unsigned int vendor_id,  unsigned model_id );
113     static bool isValid( const VendorModelEntry& vme );
114
115     // access functions
116     /**
117      * @brief retrieves a setting for a given path
118      *
119      * the value in the ref parameter is not changed if
120      * the function returns false.
121      *
122      * @param path path to the setting
123      * @param ref reference to the integer that will hold the value.
124      * @return true if successful, false if not
125      */
126     bool getValueForSetting(std::string path, int32_t &ref);
127     bool getValueForSetting(std::string path, int64_t &ref);
128
129     virtual void setVerboseLevel(int l) {setDebugLevel(l);};
130     virtual void show();
131
132 private:
133     libconfig::Setting *getSetting( std::string path );
134
135     int findFileName(std::string s);
136
137     // important: keep 1-1 mapping for these two!
138     // cannot use map since we need the vector order to
139     // provide priorities
140     std::vector<ConfigFile *> m_ConfigFiles;
141
142     DECLARE_DEBUG_MODULE;
143 };
144
145
146 } // namespace Util
147
148 #endif // _FFADO_UTIL_CONFIGURATION_
Note: See TracBrowser for help on using the browser.