The Pedigree Project  0.1
ConfigurationManager.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef CONFIG_MANAGER_H
21 #define CONFIG_MANAGER_H
22 
23 #include "pedigree/kernel/processor/types.h"
25 #include "pedigree/kernel/utilities/String.h"
26 
28 
29 #define MAX_WATCHERS 4
30 
32 typedef void (*ConfigurationWatcher)(void);
33 
34 enum ConfigValueType
35 {
36  Invalid,
37  Number,
38  Str,
39  Bool
40 };
42 {
43  ConfigValue() : str(""), num(0), b(false), type(Invalid)
44  {
45  for (int i = 0; i < MAX_WATCHERS; i++)
46  watchers[i] = 0;
47  }
48  ConfigValue(const ConfigValue &cv)
49  : str(cv.str), num(cv.num), b(cv.b), type(cv.type)
50  {
51  for (int i = 0; i < MAX_WATCHERS; i++)
52  watchers[i] = cv.watchers[i];
53  }
54  String str;
55  size_t num;
56  bool b;
57  ConfigValueType type;
58  ConfigurationWatcher watchers[MAX_WATCHERS];
59 };
60 
71 {
72  public:
74  virtual ~ConfigurationManager();
75 
76  static ConfigurationManager &instance();
77 
78  size_t createTable(const String &configStore, const String &table);
81  void insert(
82  const String &configStore, const String &table, const String &key,
83  const ConfigValue &value);
86  ConfigValue &
87  select(const String &configStore, const String &table, const String &key);
88 
90  void watch(
91  const String &configStore, const String &table, const String &key,
92  ConfigurationWatcher watcher);
94  void unwatch(
95  const String &configStore, const String &table, const String &key,
96  ConfigurationWatcher watcher);
97 
98  bool installBackend(
99  ConfigurationBackend *pBackend, const String &configStore = String(""));
100  void removeBackend(const String &configStore);
101 
102  bool backendExists(const String &configStore);
103 
104  private:
105  static ConfigurationManager m_Instance;
106 
108 };
109 
110 #endif
Definition: String.h:49
Implements a Radix Tree, a kind of Trie with compressed keys.