1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
/* -*- mode: C++; tab-width: 4 -*- */
/* ================================================================================== */
/* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
/* ================================================================================== */
#ifndef _PREFERENCEMGR_H_
#define _PREFERENCEMGR_H_
#include "EmulatorTypes.h" // FileRefList, DatabaseInfoList, DeviceType
#include "omnithread.h" // omni_mutex, omni_mutex_lock
#include "Platform_Files.h" // FileReference
#include "Skins.h" // SkinNameList
#include <map>
#include <vector>
/*
This file contains the routines for loading, saving, and accessing a collection
of preferences/settings.
All settings are accessed via the Preference class. This is a templatized class
that is specialized on the type of the setting and parameterized on the name of
the setting. This sounds nasty, but in practice is simple. For example, say you
needed to access whether or not NetLib redirection was turned on. You would use
the following:
Preference<bool> pref(kPrefKeyRedirectNetLib);
if (*pref)
{
// It's on.
}
Changing a value works similarly:
Preference<DeviceType> pref(kPrefKeyDeviceType);
*pref = kDevicePalmIII;
When the Preference object is destructed, it's new value is written back out to
the Preference Manager.
The Preference Manager is the "container" for all the preferences used by the
application. You can think of it as a map/dictionary/associative array. You
directly access the Preference Manager in order to create it, have it load the
collection of preferences from disk, have it save them to disk, and to destroy
it. While there are GetPref and SetPref methods on this class, those are for
the use of the Preference objects.
All preferences are saved as text in the form:
<key>=<value>
<key> is any unique string. It can consist of any text characters except for
'='. Keys can have subparts separated by '.', and can indicate array indices
with "[#]". For example:
Scale=2
GremlinInfo.fNumber=100
PRC_MRU[0]=MyApplication.prc
GremlinInfo.fAppList[0].name=AddressBook
With the Preference class, it's possible to pull in all or part of the
hierarchical information. For instance:
Preference<GremlinInfo> pref("GremlinInfo");
Preference<DatabaseInfoList> pref("GremlinInfo.fAppList");
Preference<DatabaseInfo> pref("GremlinInfo.fAppList[0]");
Preference<string> pref("GremlinInfo.fAppList[0].name");
*/
typedef const char* PrefKeyType;
class BasePreference
{
public:
BasePreference (PrefKeyType name, bool = true);
BasePreference (long index, bool = true);
virtual ~BasePreference (void);
bool Loaded (void) { return fLoaded; }
void Flush (void) { this->Save (); }
protected:
void Load (void);
void Save (void);
protected:
virtual bool DoLoad (void) = 0;
virtual void DoSave (void) = 0;
protected:
string fName;
bool fLoaded;
bool fChanged;
bool fAcquireLock;
};
template <class T>
class Preference : public BasePreference
{
public:
Preference (PrefKeyType name, bool = true);
Preference (long index, bool = true);
virtual ~Preference (void);
// I would *like* to have these operators. That way, I could pass in a
// "Preference<Foo>" any place that accepts a "const Foo&" as a parameter.
// However, CodeWarrior seems to use the conversion operators here in place
// that accept merely a "Foo&", which has lead to some problems.
// operator const T&() const { return *GetValue (); }
// operator const T*() const { return GetValue (); }
const T& operator*() const { return *GetValue (); }
const T* operator->() const { return GetValue (); }
const T* GetValue () const { assert (fLoaded); return &fValue; }
const T& operator=(const T& rhs) { fValue = rhs;
fLoaded = true;
fChanged = true;
this->Flush ();
return fValue; }
protected:
virtual bool DoLoad (void);
virtual void DoSave (void);
private:
T fValue;
};
typedef void (*PrefNotifyFunc)(PrefKeyType);
typedef StringList PrefKeyList;
class Preferences
{
public:
Preferences (void);
virtual ~Preferences (void);
virtual void Load (void);
virtual void Save (void);
// This should work, but CW doesn't appear to like it.
// private:
// template <class T> friend class Preference;
public:
bool GetPref (const string& key, string& value);
void SetPref (const string& key, const string& value);
void DeletePref (const string& key);
public:
void PushPrefix (const string& prefix);
void PushPrefix (long index);
void PopPrefix (void);
string ExpandKey (const string& name);
string AppendName (string key, const string& name);
public:
void AddNotification (PrefNotifyFunc, PrefKeyType);
void AddNotification (PrefNotifyFunc, const PrefKeyList&);
void RemoveNotification (PrefNotifyFunc);
void RemoveNotification (PrefNotifyFunc, PrefKeyType);
void RemoveNotification (PrefNotifyFunc, const PrefKeyList&);
void DoNotify (const string& key);
protected:
virtual void WriteBanner (FILE*);
virtual bool ReadBanner (FILE*);
virtual void StripUnused (void);
protected:
typedef StringStringMap PrefList;
typedef PrefList::value_type PrefPairType;
typedef PrefList::iterator iterator;
PrefList fPreferences;
typedef StringList PrefixType;
PrefixType fPrefixes;
typedef map<PrefNotifyFunc, PrefKeyList> PrefNotifyList;
PrefNotifyList fNotifications;
public:
static omni_mutex fgPrefsMutex;
};
extern Preferences* gPrefs;
class EmulatorPreferences : public Preferences
{
public:
EmulatorPreferences (void);
virtual ~EmulatorPreferences(void);
virtual void Load (void);
FileReference GetIndPRCMRU (int);
FileReference GetIndRAMMRU (int);
FileReference GetIndMRU (const FileRefList&, int);
void UpdatePRCMRU (const FileReference&);
void UpdateRAMMRU (const FileReference&);
void UpdateMRU (FileRefList&, const FileReference&);
void RemovePRCMRU (const FileReference&);
void RemoveRAMMRU (const FileReference&);
void RemoveMRU (FileRefList&, const FileReference&);
int UseLoggingOptions (int newType);
protected:
virtual void WriteBanner (FILE*);
virtual bool ReadBanner (FILE*);
virtual void StripUnused (void);
int fCurLoggingType;
};
extern EmulatorPreferences* gEmuPrefs;
/*
The FOR_EACH_PREF macro is used to manage the preferences keys. Preferences
are accessed via keys passed to the Preference constructor. These keys have
the symbolic form:
kPrefKey<Label>
The macro below is used to declare the keys used to access the settings, define
the keys, initialize the settings to default values.
*/
#define FOR_EACH_PREF(DO_TO_PREF) \
FOR_EACH_UNINIT_PREF(DO_TO_PREF) \
FOR_EACH_INIT_PREF(DO_TO_PREF)
#define FOR_EACH_UNINIT_PREF(DO_TO_PREF) \
DO_TO_PREF(WindowLocation, unused, unused) \
DO_TO_PREF(GCWLocation, unused, unused) \
DO_TO_PREF(BackgroundColor, unused, unused) \
DO_TO_PREF(HighlightColor, unused, unused)
#define FOR_EACH_INIT_PREF(DO_TO_PREF) \
DO_TO_PREF(CloseAction, CloseActionType, (kSaveAsk)) \
DO_TO_PREF(CommPort, string, ("")) \
DO_TO_PREF(RedirectNetLib, bool, (false)) \
\
DO_TO_PREF(ReportCorruptedHeap, bool, (true)) \
DO_TO_PREF(ReportFreeChunkAccess, bool, (true)) \
DO_TO_PREF(ReportHardwareRegisterAccess, bool, (true)) \
DO_TO_PREF(ReportInvalidPC, bool, (true)) \
DO_TO_PREF(ReportLowMemoryAccess, bool, (true)) \
DO_TO_PREF(ReportLowStackAccess, bool, (true)) \
DO_TO_PREF(ReportMemMgrDataAccess, bool, (true)) \
DO_TO_PREF(ReportMemMgrSemaphore, bool, (true)) \
DO_TO_PREF(ReportScreenAccess, bool, (true)) \
DO_TO_PREF(ReportStackAlmostOverflow, bool, (true)) \
DO_TO_PREF(ReportStackOverflow, bool, (true)) \
DO_TO_PREF(ReportStorageHeapAccess, bool, (true)) \
DO_TO_PREF(ReportSysFatalAlert, bool, (true)) \
DO_TO_PREF(ReportSystemGlobalAccess, bool, (true)) \
DO_TO_PREF(ReportUnhandledException, bool, (true)) \
DO_TO_PREF(ReportUnimplementedTrap, bool, (true)) \
DO_TO_PREF(ReportUninitializedChunkAccess, bool, (true)) \
DO_TO_PREF(ReportUninitializedStackAccess, bool, (true)) \
DO_TO_PREF(ReportUnlockedChunkAccess, bool, (true)) \
\
DO_TO_PREF(LogErrorMessages, uae_u8, (0)) \
DO_TO_PREF(LogWarningMessages, uae_u8, (0)) \
DO_TO_PREF(LogGremlins, uae_u8, (0)) \
DO_TO_PREF(LogCPUOpcodes, uae_u8, (0)) \
DO_TO_PREF(LogEnqueuedEvents, uae_u8, (0)) \
DO_TO_PREF(LogDequeuedEvents, uae_u8, (0)) \
DO_TO_PREF(LogSystemCalls, uae_u8, (0)) \
DO_TO_PREF(LogApplicationCalls, uae_u8, (0)) \
DO_TO_PREF(LogSerial, uae_u8, (0)) \
DO_TO_PREF(LogSerialData, uae_u8, (0)) \
DO_TO_PREF(LogNetLib, uae_u8, (0)) \
DO_TO_PREF(LogNetLibData, uae_u8, (0)) \
DO_TO_PREF(LogExgMgr, uae_u8, (0)) \
DO_TO_PREF(LogExgMgrData, uae_u8, (0)) \
DO_TO_PREF(LogHLDebugger, uae_u8, (0)) \
DO_TO_PREF(LogHLDebuggerData, uae_u8, (0)) \
DO_TO_PREF(LogLLDebugger, uae_u8, (0)) \
DO_TO_PREF(LogLLDebuggerData, uae_u8, (0)) \
DO_TO_PREF(LogRPC, uae_u8, (0)) \
DO_TO_PREF(LogRPCData, uae_u8, (0)) \
\
DO_TO_PREF(ReportMemoryLeaks, bool, (false)) \
DO_TO_PREF(ReportLockedRecords, bool, (false)) \
\
DO_TO_PREF(DebuggerSocketPort, long, (6414)) \
DO_TO_PREF(RPCSocketPort, long, (6415)) \
\
DO_TO_PREF(InterceptSysFatalAlert, bool, (true)) \
\
DO_TO_PREF(AskAboutStartMenu, bool, (true)) \
DO_TO_PREF(StartMenuItem, FileReference, ()) \
\
DO_TO_PREF(FillNewBlocks, bool, (false)) \
DO_TO_PREF(FillResizedBlocks, bool, (false)) \
DO_TO_PREF(FillDisposedBlocks, bool, (false)) \
DO_TO_PREF(FillStack, bool, (false)) \
\
DO_TO_PREF(LastConfiguration, Configuration, (kDevicePalmIII, 1024, FileReference())) \
\
DO_TO_PREF(GremlinInfo, GremlinInfo, ()) \
DO_TO_PREF(HordeInfo, HordeInfo, ()) \
\
DO_TO_PREF(LastPSF, FileReference, ()) \
\
DO_TO_PREF(PRC_MRU, FileRefList, ()) \
DO_TO_PREF(PSF_MRU, FileRefList, ()) \
\
DO_TO_PREF(Skins, SkinNameList, ()) \
DO_TO_PREF(Scale, ScaleType, (2)) \
\
DO_TO_PREF(UserName, string, ("Palm OS Emulator"))
// Declare all the keys
#define DECLARE_PREF_KEYS(name, type, init) extern PrefKeyType kPrefKey##name;
FOR_EACH_PREF(DECLARE_PREF_KEYS)
#endif // _PREFERENCEMGR_H_
|