1 /* Copyright (C) 2011 The Android Open Source Project 2 ** 3 ** This software is licensed under the terms of the GNU General Public 4 ** License version 2, as published by the Free Software Foundation, and 5 ** may be copied, distributed, and modified under those terms. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ** GNU General Public License for more details. 11 */ 12 #ifndef ANDROID_MAIN_COMMON_H 13 #define ANDROID_MAIN_COMMON_H 14 15 #include <stdint.h> 16 #include "android/avd/hw-config.h" 17 #include "android/cmdline-option.h" 18 #include "android/config-file.h" 19 #include "android/skin/keyset.h" 20 #include "android/utils/compiler.h" 21 22 ANDROID_BEGIN_HEADER 23 24 /* Common routines used by both android/main.c and android/main-ui.c */ 25 26 // Reset the value of |*string| to a copy of |new_value|. This 27 // will free() the previous value of |*string| first. 28 void reassign_string(char** string, const char* new_value); 29 30 /** Emulator user configuration (e.g. last window position) 31 **/ 32 33 void user_config_init( void ); 34 void user_config_done( void ); 35 36 void user_config_get_window_pos( int *window_x, int *window_y ); 37 38 #define ONE_MB (1024*1024) 39 40 unsigned convertBytesToMB( uint64_t size ); 41 uint64_t convertMBToBytes( unsigned megaBytes ); 42 43 extern SkinKeyset* android_keyset; 44 void parse_keyset(const char* keyset, AndroidOptions* opts); 45 void write_default_keyset( void ); 46 47 #define NETWORK_SPEED_DEFAULT "full" 48 #define NETWORK_DELAY_DEFAULT "none" 49 50 extern const char* skin_network_speed; 51 extern const char* skin_network_delay; 52 53 /* Find the skin corresponding to our options, and return an AConfig pointer 54 * and the base path to load skin data from 55 */ 56 void parse_skin_files(const char* skinDirPath, 57 const char* skinName, 58 AndroidOptions* opts, 59 AndroidHwConfig* hwConfig, 60 AConfig* *skinConfig, 61 char* *skinPath); 62 63 /* Returns the amount of pixels used by the default display. */ 64 int64_t get_screen_pixels(AConfig* skinConfig); 65 66 void init_sdl_ui(AConfig* skinConfig, 67 const char* skinPath, 68 AndroidOptions* opts); 69 70 /* Sanitize options. This deals with a few legacy options that are now 71 * handled differently. Call before anything else that needs to read 72 * the options list. 73 */ 74 void sanitizeOptions( AndroidOptions* opts ); 75 76 /* Creates and initializes AvdInfo instance for the given options. 77 * Param: 78 * opts - Options passed to the main() 79 * inAndroidBuild - Upon exit contains 0 if AvdInfo has been initialized from 80 * AVD file, or 1 if AvdInfo has been initialized from the build directory. 81 * Return: 82 * AvdInfo instance initialized for the given options. 83 */ 84 struct AvdInfo* createAVD(AndroidOptions* opts, int* inAndroidBuild); 85 86 /* Populate the hwConfig fields corresponding to the kernel/disk images 87 * used by the emulator. This will zero *hwConfig first. 88 */ 89 void findImagePaths( AndroidHwConfig* hwConfig, 90 AndroidOptions* opts ); 91 92 /* Updates hardware configuration for the given AVD and options. 93 * Param: 94 * hwConfig - Hardware configuration to update. 95 * avd - AVD info containig paths for the hardware configuration. 96 * opts - Options passed to the main() 97 * inAndroidBuild - 0 if AVD has been initialized from AVD file, or 1 if AVD 98 * has been initialized from the build directory. 99 */ 100 void updateHwConfigFromAVD(AndroidHwConfig* hwConfig, struct AvdInfo* avd, 101 AndroidOptions* opts, int inAndroidBuild); 102 103 /* Called from android/main.c to handle options specific to the standalone 104 * UI program. This is a no-op otherwise. 105 */ 106 void handle_ui_options( AndroidOptions* opts ); 107 108 /* Called from android/main.c to potentially attach to a core from the 109 * standalone UI program. This is a no-op otherwise. 110 */ 111 int attach_ui_to_core( AndroidOptions* opts ); 112 113 ANDROID_END_HEADER 114 115 #endif /* ANDROID_MAIN_COMMON_H */ 116