From: giwoong.kim Date: Tue, 2 Apr 2013 06:12:37 +0000 (+0900) Subject: maru_shm: no need to get the shmkey from another shm X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1029 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c07700ca4c54654205e3d4c89e954a6cf7bd633;p=sdk%2Femulator%2Fqemu.git maru_shm: no need to get the shmkey from another shm There is a no need to get the shmkey value from another shared memory. Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index b6d78ede81..ea7144454b 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -57,17 +57,6 @@ int get_emul_skin_enable(void) return _emul_info.skin_enable; } -/* current emulator condition */ -int get_emulator_condition(void) -{ - return _emul_state.emulator_condition; -} - -void set_emulator_condition(int state) -{ - _emul_state.emulator_condition = state; -} - /* lcd screen size */ void set_emul_lcd_size(int width, int height) { @@ -120,6 +109,28 @@ int get_emul_max_touch_point(void) return _emul_info.max_touch_point; } +/* base port for emualtor vm */ +void set_emul_vm_base_port(int port) +{ + _emul_info.vm_base_port = port; +} + +int get_emul_vm_base_port(void) +{ + return _emul_info.vm_base_port; +} + +/* current emulator condition */ +int get_emulator_condition(void) +{ + return _emul_state.emulator_condition; +} + +void set_emulator_condition(int state) +{ + _emul_state.emulator_condition = state; +} + /* emulator window scale */ void set_emul_win_scale(double scale_factor) { @@ -191,7 +202,7 @@ int get_host_lock_key_state(int key) return -1; } -/* manage CapsLock key state for usb keyboard input */ +/* manage CapsLock key state for host keyboard input */ void set_emul_caps_lock_state(int state) { _emul_state.qemu_caps_lock = state; @@ -199,10 +210,10 @@ void set_emul_caps_lock_state(int state) int get_emul_caps_lock_state(void) { - return _emul_state.qemu_caps_lock; + return _emul_state.qemu_caps_lock; } -/* manage NumLock key state for usb keyboard input */ +/* manage NumLock key state for host keyboard input */ void set_emul_num_lock_state(int state) { _emul_state.qemu_num_lock = state; @@ -210,5 +221,6 @@ void set_emul_num_lock_state(int state) int get_emul_num_lock_state(void) { - return _emul_state.qemu_num_lock; + return _emul_state.qemu_num_lock; } + diff --git a/tizen/src/emul_state.h b/tizen/src/emul_state.h index 4a6baf9c7e..efb123230e 100644 --- a/tizen/src/emul_state.h +++ b/tizen/src/emul_state.h @@ -80,7 +80,8 @@ typedef struct EmulatorConfigInfo { int lcd_size_h; int sdl_bpp; int max_touch_point; - //TODO: + int vm_base_port; + /* add here */ } EmulatorConfigInfo; typedef struct EmulatorConfigState { @@ -90,7 +91,7 @@ typedef struct EmulatorConfigState { MultiTouchState qemu_mts; int qemu_caps_lock; int qemu_num_lock; - //TODO: + /* add here */ } EmulatorConfigState; @@ -100,6 +101,8 @@ void set_emul_lcd_size(int width, int height); void set_emul_win_scale(double scale); void set_emul_sdl_bpp(int bpp); void set_emul_max_touch_point(int cnt); +void set_emul_vm_base_port(int port); + void set_emulator_condition(int state); void set_emul_rotation(short rotation_type); void set_emul_caps_lock_state(int state); @@ -112,6 +115,8 @@ int get_emul_lcd_height(void); double get_emul_win_scale(void); int get_emul_sdl_bpp(void); int get_emul_max_touch_point(void); +int get_emul_vm_base_port(void); + int get_emulator_condition(void); short get_emul_rotation(void); MultiTouchState *get_emul_multi_touch_state(void); diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 9651feae7d..c7abf6d65a 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -345,20 +345,20 @@ static void prepare_basic_features(void) tizen_base_port = get_sdb_base_port(); get_host_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); - // using "DNS" provided by default QEMU + /* using "DNS" provided by default QEMU */ g_strlcpy(dns, DEFAULT_QEMU_DNS_IP, strlen(DEFAULT_QEMU_DNS_IP) + 1); check_vm_lock(); socket_init(); make_vm_lock(); - sdb_setup(); + sdb_setup(); /* determine the base port for emulator */ + set_emul_vm_base_port(tizen_base_port); gchar * const tmp_str = g_strdup_printf(" sdb_port=%d," - " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s" - " dns1=%s", tizen_base_port, - http_proxy, https_proxy, ftp_proxy, socks_proxy, - dns); + " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s" + " dns1=%s", get_emul_vm_base_port(), + http_proxy, https_proxy, ftp_proxy, socks_proxy, dns); g_strlcat(maru_kernel_cmdline, tmp_str, LEN_MARU_KERNEL_CMDLINE); diff --git a/tizen/src/hw/maru_vga.c b/tizen/src/hw/maru_vga.c index a6788be930..fbb7f81bf5 100644 --- a/tizen/src/hw/maru_vga.c +++ b/tizen/src/hw/maru_vga.c @@ -2,7 +2,7 @@ * Maru vga device * Based on qemu/hw/vga.c * - * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim @@ -56,12 +56,12 @@ #include #include #include "maru_err_table.h" +#include "emul_state.h" #endif #ifdef CONFIG_USE_SHM void *shared_memory = (void*) 0; int skin_shmid; -int port_shmid; #endif @@ -1873,34 +1873,19 @@ void maru_vga_common_init(VGACommonState *s) vga_dirty_log_start(s); #ifdef CONFIG_USE_SHM - int mykey; - void *temp; + /* base + 1 = sdb port */ + /* base + 2 = shared memory key */ + int mykey = get_emul_vm_base_port() + 2; - port_shmid = shmget((key_t)SHMKEY, (size_t)MAXLEN, 0666 | IPC_CREAT); - if (port_shmid == -1) { - ERR("shmget failed\n"); - perror("maru_vga: "); - exit(1); - } - - temp = shmat(port_shmid, (char*)0x0, 0); - if (temp == (void *)-1) { - ERR("shmat failed\n"); - perror("maru_vga: "); - exit(1); - } - - mykey = atoi(temp); - shmdt(temp); - INFO("shared memory key: %d, vga ram_size : %d\n", mykey, s->vram_size); skin_shmid = shmget((key_t)mykey, (size_t)s->vram_size, 0666 | IPC_CREAT); if (skin_shmid == -1) { ERR("shmget failed\n"); perror("maru_vga: "); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, (char*)"Cannot launch this VM.\n" - "Shared memory is not enough."); + maru_register_exit_msg(MARU_EXIT_UNKNOWN, + (char*) "Cannot launch this VM.\n" + "Shared memory is not enough."); exit(0); } @@ -1929,11 +1914,6 @@ void maru_vga_common_fini(void) ERR("shmctl failed\n"); perror("maru_vga: "); } - - if (shmctl(port_shmid, IPC_RMID, 0) == -1) { - ERR("temp shmctl failed\n"); - perror("maru_vga: "); - } } #endif diff --git a/tizen/src/skin/client/native_src/share.c b/tizen/src/skin/client/native_src/share.c index 6a14d76837..a22fd035c4 100644 --- a/tizen/src/skin/client/native_src/share.c +++ b/tizen/src/skin/client/native_src/share.c @@ -1,7 +1,7 @@ /** + * Transmit the framebuffer from shared memory by JNI * - * - * Copyright ( C ) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim @@ -36,42 +36,29 @@ #include "org_tizen_emulator_skin_EmulatorShmSkin.h" #define MAXLEN 512 -#define SHMKEY 26099 void *shared_memory = (void *)0; int shmid; JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmget - (JNIEnv *env, jobject obj, jint vga_ram_size) + (JNIEnv *env, jobject obj, jint shmkey, jint vga_ram_size) { - void *temp; - int keyval; - shmid = shmget((key_t)SHMKEY, (size_t)MAXLEN, 0666 | IPC_CREAT); - if (shmid == -1) { - fprintf(stderr, "share.c: shmget failed\n"); - exit(1); - } - - temp = shmat(shmid, (char*)0x0, 0); - if (temp == (void *)-1) { - fprintf(stderr, "share.c: shmat failed\n"); - exit(1); - } - keyval = atoi(temp); - fprintf(stdout, "share.c: shared memory key = %d\n", keyval); - shmdt(temp); + fprintf(stdout, "share.c: shared memory key = %d\n", shmkey); + fflush(stdout); - shmid = shmget((key_t)keyval, (size_t)vga_ram_size, 0666 | IPC_CREAT); + shmid = shmget((key_t)shmkey, (size_t)vga_ram_size, 0666 | IPC_CREAT); if (shmid == -1) { fprintf(stderr, "share.c: shmget failed\n"); + fflush(stderr); return 1; } - /* We now make the shared memory accessible to the program. */ + /* We now make the shared memory accessible to the program */ shared_memory = shmat(shmid, (void *)0, 0); if (shared_memory == (void *)-1) { fprintf(stderr, "share.c: shmat failed\n"); + fflush(stderr); return 2; } @@ -79,37 +66,42 @@ JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmget } JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmdt - (JNIEnv *env, jobject obj) + (JNIEnv *env, jobject obj) { /* Lastly, the shared memory is detached */ if (shmdt(shared_memory) == -1) { fprintf(stderr, "share.c: shmdt failed\n"); + fflush(stderr); perror("share.c: "); return 1; } -/* + + /* if (shmctl(shmid, IPC_RMID, 0) == -1) { fprintf(stderr, "share.c: shmctl failed\n"); + fflush(stderr); perror("share.c: "); } -*/ + */ + return 0; } JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_getPixels - (JNIEnv *env, jobject obj, jintArray array) + (JNIEnv *env, jobject obj, jintArray array) { int i = 0; int len = (*env)->GetArrayLength(env, array); if (len <= 0) { fprintf(stderr, "share.c: get length failed\n"); + fflush(stderr); return -1; } int *framebuffer = (int *)shared_memory; jint value = 0xFFFFFFFF; - for(i = 0; i < len; i++) { + for (i = 0; i < len; i++) { value = framebuffer[i]; (*env)->SetIntArrayRegion(env, array, i, 1, &value); } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java index 1718babae2..6cd1bde18e 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java @@ -1,7 +1,7 @@ /** * Emulator Skin Process * - * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim @@ -40,6 +40,7 @@ import org.eclipse.swt.graphics.PaletteData; import org.eclipse.swt.graphics.Transform; import org.eclipse.swt.widgets.Display; import org.tizen.emulator.skin.config.EmulatorConfig; +import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants; import org.tizen.emulator.skin.exception.ScreenShotException; import org.tizen.emulator.skin.image.ImageRegistry.IconName; import org.tizen.emulator.skin.info.SkinInformation; @@ -57,7 +58,7 @@ public class EmulatorShmSkin extends EmulatorSkin { public static final int COLOR_DEPTH = 32; /* define JNI functions */ - public native int shmget(int size); + public native int shmget(int shmkey, int size); public native int shmdt(); public native int getPixels(int[] array); @@ -175,8 +176,13 @@ public class EmulatorShmSkin extends EmulatorSkin { public long initLayout() { super.initLayout(); + /* base + 1 = sdb port */ + /* base + 2 = shared memory key */ + int shmkey = config.getArgInt(ArgsConstants.NET_BASE_PORT) + 2; + logger.info("shmkey = " + shmkey); + /* initialize shared memory */ - int result = shmget( + int result = shmget(shmkey, currentState.getCurrentResolutionWidth() * currentState.getCurrentResolutionHeight()); logger.info("shmget native function returned " + result); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java index d6f72d5af1..d93a1bda2e 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java @@ -176,8 +176,11 @@ public class EmulatorSkinMain { } boolean skinPhoneShape = true; - String skinInfoResolutionW = skinInfoProperties.getProperty(SkinInfoConstants.RESOLUTION_WIDTH); - String skinInfoResolutionH = skinInfoProperties.getProperty(SkinInfoConstants.RESOLUTION_HEIGHT); + String skinInfoResolutionW = + skinInfoProperties.getProperty(SkinInfoConstants.RESOLUTION_WIDTH); + String skinInfoResolutionH = + skinInfoProperties.getProperty(SkinInfoConstants.RESOLUTION_HEIGHT); + if (skinInfoResolutionW.equalsIgnoreCase("all") || skinInfoResolutionH.equalsIgnoreCase("all")) { skinPhoneShape = false; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java index 6dce373125..3048bd4299 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java @@ -103,14 +103,16 @@ public class EmulatorConfig { private Properties configProperties; private String skinPropertiesFilePath; - public EmulatorConfig( Map args, EmulatorUI dbiContents, Properties skinProperties, - String skinPropertiesFilePath, Properties configProperties ) { + public EmulatorConfig(Map args, + EmulatorUI dbiContents, Properties skinProperties, + String skinPropertiesFilePath, Properties configProperties) { this.args = args; this.dbiContents = dbiContents; this.skinProperties = skinProperties; this.skinPropertiesFilePath = skinPropertiesFilePath; this.configProperties = configProperties; - if ( null == configProperties ) { + + if (null == configProperties) { this.configProperties = new Properties(); } } diff --git a/tizen/src/skin/maruskin_client.c b/tizen/src/skin/maruskin_client.c index 24722f9e35..c79503385e 100644 --- a/tizen/src/skin/maruskin_client.c +++ b/tizen/src/skin/maruskin_client.c @@ -59,7 +59,6 @@ MULTI_DEBUG_CHANNEL(qemu, skin_client); #define OPT_MAX_TOUCHPOINT "max.touchpoint" extern char tizen_target_path[]; -extern int tizen_base_port; static int skin_argc; static char** skin_argv; @@ -94,7 +93,7 @@ static void* run_skin_client(void* arg) char buf_tizen_base_port[16]; sprintf(buf_skin_server_port, "%d", skin_server_port); sprintf(buf_uid, "%d", uid); - sprintf(buf_tizen_base_port, "%d", tizen_base_port); + sprintf(buf_tizen_base_port, "%d", get_emul_vm_base_port()); #ifdef CONFIG_WIN32 // find java path in 64bit windows @@ -118,11 +117,12 @@ static void* run_skin_client(void* arg) char* bin_dir = get_bin_path(); #endif INFO("bin directory : %s\n", bin_dir); + int maxtouchpoint = get_emul_max_touch_point(); int len_maxtouchpoint; - if(maxtouchpoint > 9) { + if (maxtouchpoint > 9) { len_maxtouchpoint = 2; - }else { + } else { len_maxtouchpoint = 1; } @@ -150,9 +150,9 @@ static void* run_skin_client(void* arg) OPT_SVR_PORT, skin_server_port, OPT_UID, uid, OPT_VM_PATH, vm_path, - OPT_NET_BASE_PORT, tizen_base_port, + OPT_NET_BASE_PORT, get_emul_vm_base_port(), OPT_MAX_TOUCHPOINT, maxtouchpoint, - argv ); + argv); INFO("command for swt : %s\n", cmd); @@ -261,10 +261,11 @@ int start_skin_client(int argc, char* argv[]) } else { count++; INFO("sleep for ready. count:%d\n", count); + #ifdef CONFIG_WIN32 - Sleep(SKIN_SERVER_SLEEP_TIME); + Sleep(SKIN_SERVER_SLEEP_TIME); #else - usleep(1000 * SKIN_SERVER_SLEEP_TIME); + usleep(1000 * SKIN_SERVER_SLEEP_TIME); #endif } diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index ffb1e2f8d5..b6ade33c46 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -58,7 +58,6 @@ #if defined(CONFIG_USE_SHM) && defined(TARGET_I386) #include int g_shmid; -extern int port_shmid; #endif MULTI_DEBUG_CHANNEL(qemu, skin_operation); @@ -80,11 +79,15 @@ extern pthread_mutex_t mutex_screenshot; extern pthread_cond_t cond_screenshot; extern int tizen_base_port; + static void* run_timed_shutdown_thread(void* args); -static void send_to_emuld(const char* request_type, int request_size, const char* send_buf, int buf_size); +static void send_to_emuld(const char* request_type, + int request_size, const char* send_buf, int buf_size); + void start_display(uint64 handle_id, - int lcd_size_width, int lcd_size_height, double scale_factor, short rotation_type) + int lcd_size_width, int lcd_size_height, + double scale_factor, short rotation_type) { INFO("start_display handle_id:%ld, lcd size:%dx%d, scale_factor:%f, rotation_type:%d\n", (long)handle_id, lcd_size_width, lcd_size_height, scale_factor, rotation_type); @@ -358,7 +361,7 @@ QemuSurfaceInfo* get_screenshot_info(void) info->pixel_data = (unsigned char*) g_malloc0( length ); if ( !info->pixel_data ) { g_free( info ); - ERR( "Fail to malloc for pixel data.\n"); + ERR("Fail to malloc for pixel data.\n"); return NULL; } @@ -371,8 +374,8 @@ QemuSurfaceInfo* get_screenshot_info(void) pthread_mutex_lock(&mutex_screenshot); MaruScreenshot* maru_screenshot = get_maru_screenshot(); - if ( !maru_screenshot || maru_screenshot->isReady != 1) { - ERR( "maru screenshot is NULL or not ready.\n" ); + if (!maru_screenshot || maru_screenshot->isReady != 1) { + ERR("maru screenshot is NULL or not ready.\n"); memset(info->pixel_data, 0x00, length); } else { maru_screenshot->pixel_data = info->pixel_data; @@ -490,6 +493,7 @@ void free_detail_info(DetailInfo* detail_info) void do_open_shell(void) { INFO("open shell\n"); + /* do nothing */ } @@ -535,50 +539,49 @@ void request_close(void) } -void shutdown_qemu_gracefully( void ) { - +void shutdown_qemu_gracefully(void) +{ requested_shutdown_qemu_gracefully = 1; pthread_t thread_id; - if( 0 > pthread_create( &thread_id, NULL, run_timed_shutdown_thread, NULL ) ) { - ERR( "!!! Fail to create run_timed_shutdown_thread. shutdown qemu right now !!!\n" ); + if (0 > pthread_create( + &thread_id, NULL, run_timed_shutdown_thread, NULL)) { + + ERR("!!! Fail to create run_timed_shutdown_thread. shutdown qemu right now !!!\n"); qemu_system_shutdown_request(); } } -int is_requested_shutdown_qemu_gracefully( void ) { +int is_requested_shutdown_qemu_gracefully(void) +{ return requested_shutdown_qemu_gracefully; } -static void* run_timed_shutdown_thread( void* args ) { - - send_to_emuld( "system\n\n\n\n", 10, "shutdown", 8 ); +static void* run_timed_shutdown_thread(void* args) +{ + send_to_emuld("system\n\n\n\n", 10, "shutdown", 8); - int sleep_interval_time = 1000; // milli-seconds + int sleep_interval_time = 1000; /* milli-seconds */ int i; - for ( i = 0; i < TIMEOUT_FOR_SHUTDOWN; i++ ) { + for (i = 0; i < TIMEOUT_FOR_SHUTDOWN; i++) { #ifdef CONFIG_WIN32 - Sleep( sleep_interval_time ); + Sleep(sleep_interval_time); #else - usleep( sleep_interval_time * 1000 ); + usleep(sleep_interval_time * 1000); #endif - // do not use logger to help user see log in console - fprintf( stdout, "Wait for shutdown qemu...%d\n", ( i + 1 ) ); + /* do not use logger to help user see log in console */ + fprintf(stdout, "Wait for shutdown qemu...%d\n", (i + 1)); } - INFO( "Shutdown qemu !!!\n" ); + INFO("Shutdown qemu !!!\n"); + #if defined(CONFIG_USE_SHM) && defined(TARGET_I386) if (shmctl(g_shmid, IPC_RMID, 0) == -1) { ERR("shmctl failed\n"); perror("maruskin_operation.c:g_shmid: "); } - - if (shmctl(port_shmid, IPC_RMID, 0) == -1) { - ERR("shmctl failed\n"); - perror("maruskin_operation.c:port_shmid: "); - } #endif qemu_system_shutdown_request(); @@ -587,8 +590,9 @@ static void* run_timed_shutdown_thread( void* args ) { } -static void send_to_emuld( const char* request_type, int request_size, const char* send_buf, int buf_size ) { - +static void send_to_emuld(const char* request_type, + int request_size, const char* send_buf, int buf_size) +{ int s = tcp_socket_outgoing( "127.0.0.1", (uint16_t) ( tizen_base_port + SDB_TCP_EMULD_INDEX ) ); if ( s < 0 ) {