1 | /*␊ |
2 | * ChameleonPropertyList.h␊ |
3 | * ChameleonPrefPane␊ |
4 | *␊ |
5 | * Created by Rekursor on 1/22/10.␊ |
6 | *␊ |
7 | */␊ |
8 | #ifndef __CHBOOT_PROPERTYLIST_LIST_H␊ |
9 | #define __CHBOOT_PROPERTYLIST_LIST_H␊ |
10 | ␊ |
11 | #include "PropertyList.h"␊ |
12 | #include <map>␊ |
13 | ␊ |
14 | //--------------------------------------------------------------------------␊ |
15 | // Chameleon Boot options type␊ |
16 | //--------------------------------------------------------------------------␊ |
17 | typedef enum␊ |
18 | {␊ |
19 | ␉OptionYesNo=0,␉␉// "Yes" or "No"␊ |
20 | ␉OptionString,␉␉// String Content␊ |
21 | ␉OptionUnix,␉␉␉// Unix like command option like -x, -v ...␊ |
22 | ␉OptionKernel,␉␉// kernel cmd like "mach_kernel" or "blacklist=0"␓␊ |
23 | ␉OptionKernel1␉␉// kernel cmd like "mach_kernel" or "blacklist=0"␓␊ |
24 | ␉␊ |
25 | } BootOptionType;␊ |
26 | ␊ |
27 | typedef enum PropertyKind␊ |
28 | {␊ |
29 | ␉KindPreferencesFile,␊ |
30 | ␉KindBootConfigFile,␊ |
31 | ␉KindSmbiosConfigFile␊ |
32 | };␊ |
33 | ␊ |
34 | struct BootOptionDesc;␊ |
35 | ␊ |
36 | typedef bool (*FieldValidator) (BootOptionDesc* bod); ␊ |
37 | ␊ |
38 | //--------------------------------------------------------------------------␊ |
39 | // Boot Option descriptor : ␊ |
40 | // used by all derived class to permit parameters handling automation ...␊ |
41 | //--------------------------------------------------------------------------␊ |
42 | struct BootOptionDesc␊ |
43 | {␊ |
44 | ␉BootOptionDesc(void* i, void * c, BootOptionType t, const char* n, const char* d,␊ |
45 | ␉␉␉␉ FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) :␊ |
46 | ␉␉ID(i), contentID(c), Type(t), Name(n), Default(d),␊ |
47 | ␉␉Validator(validator), Kind(kind) ␊ |
48 | ␉{␊ |
49 | ␉␉␉␊ |
50 | ␉} ␊ |
51 | ␉void*␉␉␉␉ID; // the corresponding button or textfield in the interface␊ |
52 | ␉void*␉␉␉␉contentID; // the corresponding content ID (i.e: the string content for text fields)␊ |
53 | ␉BootOptionType␉␉Type;␊ |
54 | ␉const char *␉␉Name;␊ |
55 | ␉FieldValidator␉␉Validator;␊ |
56 | ␉PropertyKind␉␉Kind;␊ |
57 | ␉const char *␉␉Default;␊ |
58 | ␉␊ |
59 | } ;␊ |
60 | ␊ |
61 | //--------------------------------------------------------------------------␊ |
62 | ␊ |
63 | /**␊ |
64 | * Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features␊ |
65 | */␊ |
66 | class ChameleonPropertyList : public PropertyList␊ |
67 | {␊ |
68 | protected:␊ |
69 | ␉ChameleonPropertyList() {␉}␊ |
70 | public:␊ |
71 | ␉virtual ~ChameleonPropertyList() {␉deleteOptionDesc(); }␊ |
72 | ␉␊ |
73 | ␉// id to map BootOptionDesc handling␊ |
74 | ␉void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault, ␊ |
75 | ␉␉␉␉␉ FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile)␊ |
76 | ␊ |
77 | ␉{␊ |
78 | ␉␉if (ID) _idToDescDict[ID] = ␊ |
79 | ␉␉␉new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");␊ |
80 | ␉␉if (cID) _contentIdToDescDict[cID] = ␊ |
81 | ␉␉␉new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");␊ |
82 | ␉}␊ |
83 | ␉␊ |
84 | ␉// find the desc corresponding to id:␊ |
85 | ␉const BootOptionDesc* findOption(void *ID) const ␊ |
86 | ␉{␊ |
87 | ␉␉std::map<void*, BootOptionDesc*>::const_iterator bod;␉␊ |
88 | ␉␉if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL;␊ |
89 | ␉␉return bod->second;␊ |
90 | ␉}␊ |
91 | ␊ |
92 | ␉// find the option bod corresponding to contentID␊ |
93 | ␉const BootOptionDesc* findOptionContent(void *cID) const ␊ |
94 | ␉{␊ |
95 | ␉␉std::map<void*, BootOptionDesc*>::const_iterator bod;␉␊ |
96 | ␉␉if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL;␊ |
97 | ␉␉return bod->second;␊ |
98 | ␉}␊ |
99 | ␉␊ |
100 | ␉// opaque enumeration for the map␊ |
101 | ␉const BootOptionDesc* firstOption() ␊ |
102 | ␉{␊ |
103 | ␉␉_bod=_idToDescDict.begin();␊ |
104 | ␉␉if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL;␊ |
105 | ␉}␊ |
106 | ␉␊ |
107 | ␉const BootOptionDesc* nextOption() ␊ |
108 | ␉{␊ |
109 | ␉␉if(_bod++ ==_idToDescDict.end()) return NULL;␊ |
110 | ␉␉if (_bod != _idToDescDict.end()) return _bod->second; else return NULL;␊ |
111 | ␉}␊ |
112 | ␉␊ |
113 | ␉␊ |
114 | ␉// remove all elements in dict, calls deleteOptionsDesc()␊ |
115 | ␉void clearOptionDesc();␊ |
116 | ␉␊ |
117 | protected:␊ |
118 | ␉void deleteOptionDesc();␊ |
119 | ␊ |
120 | ␉// dictionary for id -> desc and contentID -> desc association type␊ |
121 | ␉std::map<void *, BootOptionDesc*> _idToDescDict, _contentIdToDescDict; ␊ |
122 | ␉std::map<void*, BootOptionDesc*>::const_iterator _bod;␉␊ |
123 | };␊ |
124 | ␊ |
125 | //--------------------------------------------------------------------------␊ |
126 | // Concrete definition of Chameleon property lists␊ |
127 | // implements the Singleton DP␊ |
128 | //--------------------------------------------------------------------------␊ |
129 | ␊ |
130 | class BootProp : public ChameleonPropertyList {␊ |
131 | public:␊ |
132 | ␉static BootProp& instance() ␊ |
133 | ␉{ ␊ |
134 | ␉␉return _instance ? *_instance : *(_instance=new BootProp()); ␊ |
135 | ␉}␊ |
136 | ␊ |
137 | protected:␊ |
138 | ␉BootProp() : ChameleonPropertyList() {}␊ |
139 | ␉␊ |
140 | private:␊ |
141 | ␉static BootProp* _instance;␊ |
142 | };␊ |
143 | ␊ |
144 | //--------------------------------------------------------------------------␊ |
145 | class PrefsProp : public ChameleonPropertyList {␊ |
146 | public:␊ |
147 | ␉static PrefsProp& instance() ␊ |
148 | ␉{ ␊ |
149 | ␉␉return _instance ? *_instance : *(_instance=new PrefsProp()); ␊ |
150 | ␉}␊ |
151 | ␉␊ |
152 | protected:␊ |
153 | ␉PrefsProp() : ChameleonPropertyList() {}␊ |
154 | ␉␊ |
155 | private:␊ |
156 | ␉static PrefsProp* _instance;␊ |
157 | };␊ |
158 | ␊ |
159 | //--------------------------------------------------------------------------␊ |
160 | class SmbiosProp : public ChameleonPropertyList {␊ |
161 | public:␊ |
162 | ␉static SmbiosProp& instance() ␊ |
163 | ␉{ ␊ |
164 | ␉␉return _instance ? *_instance : *(_instance=new SmbiosProp()); ␊ |
165 | ␉}␊ |
166 | ␉␊ |
167 | protected:␊ |
168 | ␉SmbiosProp() : ChameleonPropertyList() {}␊ |
169 | ␉␊ |
170 | private:␊ |
171 | ␉static SmbiosProp* _instance;␊ |
172 | };␊ |
173 | ␊ |
174 | ␊ |
175 | #endif |