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