1 // 2 // Copyright 2005 The Android Open Source Project 3 // 4 // Simulated device definition. 5 // 6 // The "root" of the data structures here is PhoneCollection, which may 7 // discard the entire set if the user asks to re-scan the phone definitions. 8 // These structures should be considered read-only. 9 // 10 // PhoneCollection (single global instance) 11 // -->PhoneData 12 // -->PhoneDisplay 13 // -->PhoneMode 14 // -->PhoneView 15 // 16 #ifndef _SIM_PHONE_DATA_H 17 #define _SIM_PHONE_DATA_H 18 19 #include <stdio.h> 20 #include "tinyxml.h" 21 22 #include "PhoneButton.h" 23 #include "LoadableImage.h" 24 #include <ui/PixelFormat.h> 25 #include "utils.h" 26 27 28 /* 29 * This represents the keyboard type of the simulated device 30 */ 31 class PhoneKeyboard { 32 public: 33 PhoneKeyboard(void) 34 : mQwerty(false), mKeyMap(NULL) 35 {} 36 ~PhoneKeyboard(void) { 37 free((void*)mKeyMap); 38 } 39 40 PhoneKeyboard(const PhoneKeyboard& src) 41 : mQwerty(false), mKeyMap(NULL) 42 { 43 CopyMembers(src); 44 } 45 PhoneKeyboard& operator=(const PhoneKeyboard& src) { 46 if (this != &src) // self-assignment 47 CopyMembers(src); 48 return *this; 49 } 50 void CopyMembers(const PhoneKeyboard& src) { 51 mQwerty = src.mQwerty; 52 mKeyMap = src.mKeyMap ? strdup(src.mKeyMap) : NULL; 53 } 54 55 bool ProcessAndValidate(TiXmlNode* pNode); 56 57 bool getQwerty() { return mQwerty; } 58 59 const char *getKeyMap() { return mKeyMap; } 60 private: 61 bool mQwerty; 62 const char * mKeyMap; 63 }; 64 65 /* 66 * This represents a single display device, usually an LCD screen. 67 * It also includes an optional surrounding graphic, usually a picture of 68 * the device itself. 69 */ 70 class PhoneDisplay { 71 public: 72 PhoneDisplay(void) 73 : mName(NULL) 74 {} 75 ~PhoneDisplay(void) { 76 delete[] mName; 77 } 78 79 PhoneDisplay(const PhoneDisplay& src) 80 : mName(NULL) 81 { 82 CopyMembers(src); 83 } 84 PhoneDisplay& operator=(const PhoneDisplay& src) { 85 if (this != &src) // self-assignment 86 CopyMembers(src); 87 return *this; 88 } 89 void CopyMembers(const PhoneDisplay& src) { 90 // Can't memcpy and member-copy the container classes, because the 91 // containers have already been constructed, and for operator= they 92 // might even have stuff in them. 93 delete[] mName; 94 mName = android::strdupNew(src.mName); 95 mWidth = src.mWidth; 96 mHeight = src.mHeight; 97 mFormat = src.mFormat; 98 mRefresh = src.mRefresh; 99 } 100 101 bool ProcessAndValidate(TiXmlNode* pNode); 102 103 const char* GetName(void) const { return mName; } 104 int GetWidth(void) const { return mWidth; } 105 int GetHeight(void) const { return mHeight; } 106 android::PixelFormat GetFormat(void) const { return mFormat; } 107 int GetRefresh(void) const { return mRefresh; } 108 109 static bool IsCompatible(PhoneDisplay* pDisplay1, PhoneDisplay* pDisplay2); 110 111 private: 112 char* mName; 113 114 // display dimensions, in pixels 115 int mWidth; 116 int mHeight; 117 118 // frame buffer format 119 android::PixelFormat mFormat; 120 121 // display refresh rate, in fps 122 int mRefresh; 123 }; 124 125 /* 126 * This is a "view" of a device, which includes the display, a background 127 * image, and perhaps some clickable keys for input. 128 * 129 * Because the key graphics are associated with a particular display, we 130 * hold a list of keys here. (It also allows the possibility of handling 131 * a situation where the same key shows up in multiple background images, 132 * e.g. a flip phone with a "volume" key on the side. If we include the 133 * key in both places, we can highlight it on both displays.) 134 */ 135 class PhoneView { 136 public: 137 PhoneView(void) 138 : mDisplayName(NULL) 139 {} 140 ~PhoneView(void) { 141 delete[] mDisplayName; 142 } 143 144 PhoneView(const PhoneView& src) { 145 CopyMembers(src); 146 } 147 PhoneView& operator=(const PhoneView& src) { 148 if (this != &src) // self-assignment 149 CopyMembers(src); 150 return *this; 151 } 152 void CopyMembers(const PhoneView& src) { 153 // Can't memcpy and member-copy the container classes, because the 154 // containers have already been constructed, and for operator= they 155 // might even have stuff in them. 156 mImageList = src.mImageList; 157 mButtonList = src.mButtonList; 158 mDisplayName = android::strdupNew(src.mDisplayName); 159 mXOffset = src.mXOffset; 160 mYOffset = src.mYOffset; 161 mRotation = src.mRotation; 162 } 163 164 // load or unload resources, e.g. wxBitmaps from image files 165 bool LoadResources(void); 166 bool UnloadResources(void); 167 168 // simple accessors 169 int GetXOffset(void) const { return mXOffset; } 170 int GetYOffset(void) const { return mYOffset; } 171 const char* GetDisplayName(void) const { return mDisplayName; } 172 173 // image list access 174 int GetBkgImageCount(void) const; 175 const LoadableImage* GetBkgImage(int idx) const; 176 177 // find the first button that covers the specified coords 178 PhoneButton* FindButtonHit(int x, int y); 179 180 // find the first button with a matching key code 181 PhoneButton* FindButtonByKey(int32_t keyCode); 182 183 bool ProcessAndValidate(TiXmlNode* pNode, const char* directory); 184 bool ProcessImage(TiXmlNode* pNode, const char* directory); 185 bool ProcessButton(TiXmlNode* pNode, const char* directory); 186 187 private: 188 // background images for the phone picture that surrounds the display 189 android::List<LoadableImage> mImageList; 190 191 // list of accessible buttons, some of which have highlight graphics 192 android::List<PhoneButton> mButtonList; 193 194 char* mDisplayName; 195 196 // these determine where in the image the display output goes 197 int mXOffset; 198 int mYOffset; 199 200 // clockwise rotation of the output; sim must rotate in opposite direction 201 typedef enum Rotation { 202 kRotUnknown = 0, 203 kRot0, 204 kRot90, 205 kRot180, 206 kRot270, 207 } Rotation; 208 Rotation mRotation; 209 }; 210 211 /* 212 * One mode of a phone. Simple devices only have one mode. Flip phones 213 * have two (opened and closed). Other devices might have more. The 214 * mode is communicated to the runtime because it may need to process 215 * input events differently. 216 */ 217 class PhoneMode { 218 public: 219 PhoneMode(void) 220 : mName(NULL) 221 {} 222 ~PhoneMode(void) { 223 delete[] mName; 224 } 225 226 PhoneMode(const PhoneMode& src) 227 : mName(NULL) 228 { 229 CopyMembers(src); 230 } 231 PhoneMode& operator=(const PhoneMode& src) { 232 if (this != &src) // self-assignment 233 CopyMembers(src); 234 return *this; 235 } 236 void CopyMembers(const PhoneMode& src) { 237 delete[] mName; 238 mName = android::strdupNew(src.mName); 239 mViewList = src.mViewList; 240 } 241 242 243 // load or unload resources for this object and all members of mViewList 244 bool LoadResources(void); 245 bool UnloadResources(void); 246 247 // get the #of views 248 int GetNumViews(void) const { return mViewList.size(); } 249 // get the Nth display 250 PhoneView* GetPhoneView(int viewNum); 251 252 const char* GetName(void) const { return mName; } 253 void SetName(const char* name) { 254 delete[] mName; 255 mName = android::strdupNew(name); 256 } 257 258 // load the <mode> section from the config file 259 bool ProcessAndValidate(TiXmlNode* pNode, const char* directory); 260 261 private: 262 char* mName; 263 264 android::List<PhoneView> mViewList; 265 }; 266 267 /* 268 * This holds the data for one device. 269 * 270 * Each device may have multiple "modes", e.g. a flip-phone that can be 271 * open or shut. Each mode has different configurations for the visible 272 * displays and active keys. 273 */ 274 class PhoneData { 275 public: 276 PhoneData(void) : 277 mName(NULL), mTitle(NULL), mDirectory(NULL) 278 {} 279 virtual ~PhoneData(void) { 280 delete[] mName; 281 delete[] mTitle; 282 delete[] mDirectory; 283 } 284 285 PhoneData(const PhoneData& src) 286 : mName(NULL), mTitle(NULL), mDirectory(NULL) 287 { 288 CopyMembers(src); 289 } 290 PhoneData& operator=(const PhoneData& src) { 291 if (this != &src) // self-assignment 292 CopyMembers(src); 293 return *this; 294 } 295 void CopyMembers(const PhoneData& src) { 296 delete[] mName; 297 delete[] mTitle; 298 delete[] mDirectory; 299 mName = android::strdupNew(src.mName); 300 mTitle = android::strdupNew(src.mTitle); 301 mDirectory = android::strdupNew(src.mDirectory); 302 mModeList = src.mModeList; 303 mDisplayList = src.mDisplayList; 304 mKeyboardList = src.mKeyboardList; 305 } 306 307 // initialize the object with the phone data in the specified dir 308 bool Create(const char* directory); 309 310 // load or unload resources, e.g. wxBitmaps from image files 311 bool LoadResources(void); 312 bool UnloadResources(void); 313 314 // simple accessors 315 const char* GetName(void) const { return mName; } 316 void SetName(const char* name) { 317 delete[] mName; 318 mName = android::strdupNew(name); 319 } 320 const char* GetTitle(void) const { return mTitle; } 321 void SetTitle(const char* title) { 322 delete[] mTitle; 323 mTitle = android::strdupNew(title); 324 } 325 const char* GetDirectory(void) const { return mDirectory; } 326 void SetDirectory(const char* dir) { 327 delete[] mDirectory; 328 mDirectory = android::strdupNew(dir); 329 } 330 331 332 // get number of modes 333 int GetNumModes(void) const { return mModeList.size(); } 334 // get the specified mode object 335 PhoneMode* GetPhoneMode(int idx); 336 PhoneMode* GetPhoneMode(const char* modeName); 337 338 // get number of displays 339 int GetNumDisplays(void) const { return mDisplayList.size(); } 340 // get the specified display object 341 PhoneDisplay* GetPhoneDisplay(int idx); 342 PhoneDisplay* GetPhoneDisplay(const char* displayName); 343 // get the index of the matching display 344 int GetPhoneDisplayIndex(const char* displayName); 345 346 // get number of keyboards 347 int GetNumKeyboards(void) const { return mKeyboardList.size(); } 348 // get the specified display object 349 PhoneKeyboard* GetPhoneKeyboard(int idx); 350 351 private: 352 bool ProcessAndValidate(TiXmlDocument* pDoc); 353 bool ProcessDevice(TiXmlNode* pNode); 354 bool ProcessTitle(TiXmlNode* pNode); 355 356 char* mName; 357 char* mTitle; 358 char* mDirectory; 359 360 android::List<PhoneMode> mModeList; 361 android::List<PhoneDisplay> mDisplayList; 362 android::List<PhoneKeyboard> mKeyboardList; 363 }; 364 365 #endif // _SIM_PHONE_DATA_H 366