From 68e913a61784636cc4203118fbe13a57799c875a Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Wed, 31 Jul 2013 15:50:48 +0900 Subject: [PATCH] communication: define 'test.vm.skinport' option define 'test.vm.skinport' skin option for debugging remove 'vm.ecsport' option & indenting Change-Id: If845e556861eb201e353d30514e505a15eef7726 Signed-off-by: GiWoong Kim --- tizen/src/emul_state.c | 12 -- tizen/src/emul_state.h | 3 - tizen/src/emulator.c | 2 - .../org/tizen/emulator/skin/EmulatorSkin.java | 4 +- .../skin/comm/sock/SocketCommunicator.java | 21 ++- .../emulator/skin/config/EmulatorConfig.java | 11 +- tizen/src/skin/maruskin_client.c | 22 +-- tizen/src/skin/maruskin_server.c | 170 +++++++++--------- 8 files changed, 110 insertions(+), 135 deletions(-) diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index dc2fc132a1..b74666e31a 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -29,7 +29,6 @@ * */ - #include "maru_common.h" #include "emul_state.h" #include "debug_ch.h" @@ -150,17 +149,6 @@ int get_emul_vm_base_port(void) return _emul_info.vm_base_port; } -/* ecs port for emualtor vm */ -void set_emul_vm_ecs_port(int port) -{ - _emul_info.vm_ecs_port = port; -} - -int get_emul_vm_ecs_port(void) -{ - return _emul_info.vm_ecs_port; -} - /* current emulator condition */ int get_emulator_condition(void) { diff --git a/tizen/src/emul_state.h b/tizen/src/emul_state.h index 692c3c2955..ab7a5668de 100644 --- a/tizen/src/emul_state.h +++ b/tizen/src/emul_state.h @@ -83,7 +83,6 @@ typedef struct EmulatorConfigInfo { bool input_touch_enable; int max_touch_point; int vm_base_port; - int vm_ecs_port; /* add here */ } EmulatorConfigInfo; @@ -107,7 +106,6 @@ void set_emul_input_mouse_enable(bool on); void set_emul_input_touch_enable(bool on); void set_emul_max_touch_point(int cnt); void set_emul_vm_base_port(int port); -void set_emul_vm_ecs_port(int port); void set_emulator_condition(int state); void set_emul_rotation(short rotation_type); @@ -124,7 +122,6 @@ bool is_emul_input_mouse_enable(void); bool is_emul_input_touch_enable(void); int get_emul_max_touch_point(void); int get_emul_vm_base_port(void); -int get_emul_vm_ecs_port(void); int get_emulator_condition(void); short get_emul_rotation(void); diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index ba608d3cac..1db3f9e20b 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -377,8 +377,6 @@ static void prepare_basic_features(void) sdb_setup(); /* determine the base port for emulator */ set_emul_vm_base_port(tizen_base_port); - set_emul_vm_ecs_port(tizen_ecs_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", get_emul_vm_base_port(), diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java index ac043922cf..6ab7e5223e 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java @@ -1086,9 +1086,8 @@ public class EmulatorSkin { String emulName = SkinUtil.getVmName(config); int portSdb = config.getArgInt(ArgsConstants.VM_BASE_PORT); - int portEcp = config.getArgInt(ArgsConstants.VM_ECS_PORT); + int portEcp = 0; - /* DataTranfer dataTranfer = communicator.sendDataToQEMU( SendCommand.ECP_PORT_REQ, null, true); byte[] receivedData = communicator.getReceivedData(dataTranfer); @@ -1096,7 +1095,6 @@ public class EmulatorSkin { portEcp |= receivedData[1] << 16; portEcp |= receivedData[2] << 8; portEcp |= receivedData[3]; - */ ProcessBuilder procEcp = new ProcessBuilder(); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java index 134220eef4..ee162332ff 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java @@ -62,7 +62,6 @@ import org.tizen.emulator.skin.util.SkinUtil; * */ public class SocketCommunicator implements ICommunicator { - public class DataTranfer { private boolean isTransferState; @@ -127,8 +126,10 @@ public class SocketCommunicator implements ICommunicator { private ByteArrayOutputStream bao; private DataOutputStream dataOutputStream; + /** + * Constructor + */ public SocketCommunicator(EmulatorConfig config, int uId, EmulatorSkin skin) { - this.config = config; this.uId = uId; this.skin = skin; @@ -158,15 +159,13 @@ public class SocketCommunicator implements ICommunicator { this.heartbeatTimer = new Timer(); try { - - int port = config.getArgInt( ArgsConstants.SERVER_PORT ); - socket = new Socket( "127.0.0.1", port ); - logger.info( "socket.isConnected():" + socket.isConnected() ); - - } catch ( UnknownHostException e ) { - logger.log( Level.SEVERE, e.getMessage(), e ); - } catch ( IOException e ) { - logger.log( Level.SEVERE, e.getMessage(), e ); + int port = config.getArgInt(ArgsConstants.VM_SKIN_PORT); + socket = new Socket("127.0.0.1", port); + logger.info("socket.isConnected() : " + socket.isConnected()); + } catch (UnknownHostException e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } catch (IOException e) { + logger.log(Level.SEVERE, e.getMessage(), e); } this.bao = new ByteArrayOutputStream(); 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 1a7016f9f5..a6f575dca3 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 @@ -73,14 +73,13 @@ public class EmulatorConfig { public interface ArgsConstants { public static final String SIMPLE_MESSAGE = "simple.msg"; public static final String UID = "uid"; - public static final String SERVER_PORT = "svr.port"; public static final String RESOLUTION_WIDTH = "width"; public static final String RESOLUTION_HEIGHT = "height"; public static final String TEST_HEART_BEAT_IGNORE = "test.hb.ignore"; public static final String LOG_LEVEL = "log.level"; public static final String VM_PATH = "vm.path"; + public static final String VM_SKIN_PORT = "vm.skinport"; public static final String VM_BASE_PORT = "vm.baseport"; - public static final String VM_ECS_PORT = "vm.ecsport"; public static final String SKIN_PATH = "skin.path"; public static final String DISPLAY_SHM = "display.shm"; public static final String INPUT_MOUSE = "input.mouse"; @@ -177,19 +176,19 @@ public class EmulatorConfig { } } - if (args.containsKey(ArgsConstants.SERVER_PORT)) { - String serverPort = args.get(ArgsConstants.SERVER_PORT); + if (args.containsKey(ArgsConstants.VM_SKIN_PORT)) { + String serverPort = args.get(ArgsConstants.VM_SKIN_PORT); try { Integer.parseInt(serverPort); } catch (NumberFormatException e) { String msg = INVALID_OPTION_MESSAGE + "The \'" + - ArgsConstants.SERVER_PORT + + ArgsConstants.VM_SKIN_PORT + "\' argument is not numeric.\n: " + serverPort; throw new ConfigException(msg); } } else { String msg = INVALID_OPTION_MESSAGE + "The \'" + - ArgsConstants.SERVER_PORT + "\' is required argument."; + ArgsConstants.VM_SKIN_PORT + "\' is required argument."; throw new ConfigException(msg); } diff --git a/tizen/src/skin/maruskin_client.c b/tizen/src/skin/maruskin_client.c index ecf6d24ca2..6807641db7 100644 --- a/tizen/src/skin/maruskin_client.c +++ b/tizen/src/skin/maruskin_client.c @@ -59,11 +59,10 @@ MULTI_DEBUG_CHANNEL(qemu, skin_client); #define QUOTATION_LEN 2 #define EQUAL_LEN 1 -#define OPT_SVR_PORT "svr.port" #define OPT_UID "uid" #define OPT_VM_PATH "vm.path" +#define OPT_VM_SKIN_PORT "vm.skinport" #define OPT_VM_BASE_PORT "vm.baseport" -#define OPT_VM_ECS_PORT "vm.ecsport" #define OPT_DISPLAY_SHM "display.shm" #define OPT_INPUT_MOUSE "input.mouse" #define OPT_INPUT_TOUCH "input.touch" @@ -95,8 +94,6 @@ static void *run_skin_client(void *arg) INFO("[skin args %d] %s\n", i, skin_argv[i]); } - int skin_server_port = get_skin_server_port(); - //srand( time( NULL ) ); int uid = 0; //rand(); //INFO( "generated skin uid:%d\n", uid ); @@ -104,14 +101,15 @@ static void *run_skin_client(void *arg) char* vm_path = tizen_target_path; //INFO( "vm_path:%s\n", vm_path ); + int skin_server_port = get_skin_server_port(); + int vm_base_port = get_emul_vm_base_port(); + char buf_skin_server_port[16]; char buf_uid[16]; char buf_vm_base_port[16]; - char buf_vm_ecs_port[16]; sprintf(buf_skin_server_port, "%d", skin_server_port); sprintf(buf_uid, "%d", uid); - sprintf(buf_vm_base_port, "%d", get_emul_vm_base_port()); - sprintf(buf_vm_ecs_port, "%d", get_emul_vm_ecs_port()); + sprintf(buf_vm_base_port, "%d", vm_base_port); /* display */ char buf_display_shm[8] = { 0, }; @@ -178,7 +176,7 @@ static void *run_skin_client(void *arg) QUOTATION_LEN + strlen(bin_dir) + strlen(JAR_SKINFILE) + SPACE_LEN + #endif - strlen(OPT_SVR_PORT) + EQUAL_LEN + + strlen(OPT_VM_SKIN_PORT) + EQUAL_LEN + strlen(buf_skin_server_port) + SPACE_LEN + strlen(OPT_UID) + EQUAL_LEN + strlen(buf_uid) + SPACE_LEN + @@ -186,8 +184,6 @@ static void *run_skin_client(void *arg) QUOTATION_LEN + strlen(vm_path) + SPACE_LEN + strlen(OPT_VM_BASE_PORT) + EQUAL_LEN + strlen(buf_vm_base_port) + SPACE_LEN + - strlen(OPT_VM_ECS_PORT) + EQUAL_LEN + - strlen(buf_vm_ecs_port) + SPACE_LEN + strlen(OPT_DISPLAY_SHM) + EQUAL_LEN + strlen(buf_display_shm) + SPACE_LEN + strlen(OPT_INPUT_TOUCH) + EQUAL_LEN + @@ -210,7 +206,6 @@ static void *run_skin_client(void *arg) %s=%d \ %s=\"%s\" \ %s=%d \ -%s=%d \ %s=%s \ %s=%s \ %s=%d \ @@ -221,11 +216,10 @@ static void *run_skin_client(void *arg) #else bin_dir, bin_dir, JAR_SKINFILE, #endif - OPT_SVR_PORT, skin_server_port, + OPT_VM_SKIN_PORT, skin_server_port, OPT_UID, uid, OPT_VM_PATH, vm_path, - OPT_VM_BASE_PORT, get_emul_vm_base_port(), - OPT_VM_ECS_PORT, get_emul_vm_ecs_port(), + OPT_VM_BASE_PORT, vm_base_port, OPT_DISPLAY_SHM, buf_display_shm, OPT_INPUT_TOUCH, buf_input_touch, OPT_MAX_TOUCHPOINT, maxtouchpoint, diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index ec145c2696..933bd835ab 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -90,6 +90,7 @@ MULTI_DEBUG_CHANNEL(qemu, skin_server); #define PORT_RETRY_COUNT 50 #define TEST_HB_IGNORE "test.hb.ignore" +#define TEST_VM_SKINPORT "test.vm.skinport" #define SKIN_CONFIG_PROP ".skinconfig.properties" extern char tizen_target_path[]; @@ -135,6 +136,7 @@ enum { static int seq_req_id = 0; +static int arg_skin_port = 0; static uint16_t svr_port = 0; static int server_sock = 0; static int client_sock = 0; @@ -194,7 +196,7 @@ int start_skin_server(int argc, char** argv, /* arguments have higher priority than '.skinconfig.properties' */ parse_skin_args(); - INFO("ignore_heartbeat:%d\n", ignore_heartbeat); + INFO("ignore_heartbeat : %d\n", ignore_heartbeat); qmu_argc = qemu_argc; qmu_argv = qemu_argv; @@ -415,126 +417,125 @@ int get_skin_server_port(void) static void parse_skinconfig_prop(void) { - int target_path_len = strlen( tizen_target_path ); + int target_path_len = strlen(tizen_target_path); char skin_config_path[target_path_len + 32]; - memset( skin_config_path, 0, target_path_len + 32 ); - strcpy( skin_config_path, tizen_target_path ); + memset(skin_config_path, 0, target_path_len + 32); + strcpy(skin_config_path, tizen_target_path); #ifdef CONFIG_WIN32 - strcat( skin_config_path, "\\" ); + strcat(skin_config_path, "\\"); #else - strcat( skin_config_path, "/" ); + strcat(skin_config_path, "/"); #endif - strcat( skin_config_path, SKIN_CONFIG_PROP ); + strcat(skin_config_path, SKIN_CONFIG_PROP); - FILE* fp = fopen( skin_config_path, "r" ); + FILE* fp = fopen(skin_config_path, "r"); - if ( !fp ) { - INFO( "There is no %s. skin_config_path:%s\n", SKIN_CONFIG_PROP, skin_config_path ); + if (!fp) { + INFO("There is no %s. skin_config_path:%s\n", + SKIN_CONFIG_PROP, skin_config_path); return; } - fseek( fp, 0L, SEEK_END ); - int buf_size = ftell( fp ); - rewind( fp ); + fseek(fp, 0L, SEEK_END); + int buf_size = ftell(fp); + rewind(fp); - if ( 0 >= buf_size ) { - INFO( "%s contents is empty.\n", SKIN_CONFIG_PROP ); - fclose( fp ); + if (0 >= buf_size) { + INFO("%s contents is empty.\n", SKIN_CONFIG_PROP); + fclose(fp); return; } - char* buf = g_malloc0( buf_size ); - if ( !buf ) { - ERR( "Fail to malloc for %s\n", SKIN_CONFIG_PROP ); - fclose( fp ); + char* buf = g_malloc0(buf_size); + if (!buf) { + ERR("Fail to malloc for %s\n", SKIN_CONFIG_PROP); + fclose(fp); return; } int read_cnt = 0; int total_cnt = 0; - while ( 1 ) { - - if ( total_cnt == buf_size ) { + while (1) { + if (total_cnt == buf_size) { break; } - read_cnt = fread( (void*) ( buf + read_cnt ), 1, buf_size - total_cnt, fp ); - if ( 0 > read_cnt ) { + read_cnt = fread((void*) (buf + read_cnt), 1, buf_size - total_cnt, fp); + if (0 > read_cnt) { break; } else { total_cnt += read_cnt; } - } - fclose( fp ); + fclose(fp); - INFO( "====== %s ======\n%s\n====================================\n", SKIN_CONFIG_PROP, buf ); + INFO("====== %s ======\n%s\n====================================\n", + SKIN_CONFIG_PROP, buf); - char hb_ignore_prop[32]; - memset( hb_ignore_prop, 0, 32 ); - strcat( hb_ignore_prop, TEST_HB_IGNORE ); - strcat( hb_ignore_prop, "=true" ); - - char* line_str = strtok( buf, "\n" ); - - while ( 1 ) { + char hb_ignore_prop[32] = { 0, }; + memset(hb_ignore_prop, 0, 32); + strcat(hb_ignore_prop, TEST_HB_IGNORE); + strcat(hb_ignore_prop, "=true"); - if ( line_str ) { + char* line_str = strtok(buf, "\n"); - TRACE( "prop line_str:%s\n", line_str ); + while (1) { + if (line_str) { + TRACE("prop line_str : %s\n", line_str); - if ( 0 == strcmp( line_str, hb_ignore_prop ) ) { + if (0 == strcmp(line_str, hb_ignore_prop)) { ignore_heartbeat = 1; - INFO( "ignore heartbeat by %s\n", SKIN_CONFIG_PROP ); + INFO("ignore heartbeat by %s\n", SKIN_CONFIG_PROP); } - } else { break; } - line_str = strtok( NULL, "\n" ); - + line_str = strtok(NULL, "\n"); } - g_free( buf ); - + g_free(buf); } static void parse_skin_args(void) { - int i; - - for (i = 0; i < skin_argc; i++) { +#define OPT_BOOLEAN_TRUE "true" +#define OPT_BOOLEAN_FALSE "false" + int i = 0; + for ( ; i < skin_argc; i++) { char* arg = NULL; arg = strdup(skin_argv[i]); if (arg) { - char* key = strtok(arg, "="); char* value = strtok(NULL, "="); - INFO("skin params key:%s, value:%s\n", key, value); + INFO("skin parameter key : %s, value : %s\n", + key, value); if (0 == strcmp(TEST_HB_IGNORE, key)) { - if (0 == strcmp("true", value)) { + if (0 == strcmp(OPT_BOOLEAN_TRUE, value)) { ignore_heartbeat = 1; - } else if (0 == strcmp("false", value)) { + } else if (0 == strcmp(OPT_BOOLEAN_FALSE, value)) { ignore_heartbeat = 0; } + } else if (0 == strcmp(TEST_VM_SKINPORT, key)) { + arg_skin_port = atoi(value); + if (arg_skin_port > 65535 || arg_skin_port < 0) { + INFO("invalid skin port argument : %d\n", arg_skin_port); + arg_skin_port = 0; + } } free(arg); - } else { - ERR("fail to strdup."); + ERR("fail to strdup.\n"); } - } - } static void print_fail_log(void) @@ -562,13 +563,15 @@ static void* run_skin_server(void* args) return NULL; } - memset( &server_addr, '\0', sizeof( server_addr ) ); - ( (struct sockaddr_in *) &server_addr )->sin_family = AF_INET; - memcpy( &( (struct sockaddr_in *) &server_addr )->sin_addr, "\177\000\000\001", 4 ); // 127.0.0.1 - ( (struct sockaddr_in *) &server_addr )->sin_port = htons( 0 ); + memset(&server_addr, '\0', sizeof(server_addr)); + ((struct sockaddr_in *) &server_addr)->sin_family = AF_INET; - server_len = sizeof( server_addr ); + memcpy( &((struct sockaddr_in *) &server_addr)->sin_addr, + "\177\000\000\001", 4 ); /* 127.0.0.1 */ + ((struct sockaddr_in *) &server_addr)->sin_port = htons(arg_skin_port); + + server_len = sizeof(server_addr); if (0 != bind(server_sock, &server_addr, server_len)) { ERR("skin server bind error\n"); perror("skin server bind error : "); @@ -588,13 +591,14 @@ static void* run_skin_server(void* args) return NULL; } - memset( &server_addr, '\0', sizeof( server_addr ) ); - getsockname( server_sock, (struct sockaddr *) &server_addr, &server_len ); - svr_port = ntohs( ( (struct sockaddr_in *) &server_addr )->sin_port ); + memset(&server_addr, '\0', sizeof(server_addr)); + getsockname(server_sock, (struct sockaddr *) &server_addr, &server_len); + svr_port = ntohs( ((struct sockaddr_in *) &server_addr)->sin_port ); - INFO("success to bind port[127.0.0.1:%d/tcp] for skin_server in host \n", svr_port); + INFO("success to bind port[127.0.0.1:%d/tcp] for skin_server in host\n", + svr_port); - if (0 > listen( server_sock, 4)) { + if (0 > listen(server_sock, 4)) { ERR("skin_server listen error\n"); perror("skin_server listen error : "); @@ -617,10 +621,9 @@ static void* run_skin_server(void* args) char recvbuf[RECV_BUF_SIZE]; - INFO("skin server start...port:%d\n", svr_port); + INFO("skin server start...port : %d\n", svr_port); while (1) { - if (stop_server) { INFO("close server socket normally.\n"); break; @@ -628,40 +631,42 @@ static void* run_skin_server(void* args) ready_server = 1; - if( !is_started_heartbeat ) { - if ( !start_heart_beat() ) { - ERR( "Fail to start heartbeat thread.\n" ); + if (!is_started_heartbeat) { + if (!start_heart_beat()) { + ERR("Fail to start heartbeat thread.\n"); + shutdown_qemu = 1; break; } } - INFO( "start accepting socket...\n" ); + INFO("start accepting socket...\n"); - if ( 0 > ( client_sock = accept( server_sock, (struct sockaddr *) &client_addr, &client_len ) ) ) { + if (0 > (client_sock = accept( + server_sock, (struct sockaddr *) &client_addr, &client_len))) + { ERR("skin_server accept error\n"); perror("skin_server accept error : "); continue; } - INFO( "accept client : client_sock:%d\n", client_sock ); + INFO("accept client sock : %d\n", client_sock); - while ( 1 ) { - - if ( stop_server ) { - INFO( "stop receiving current client socket.\n" ); + while (1) { + if (stop_server) { + INFO("stop receiving current client socket.\n"); break; } stop_heartbeat = 0; - memset( &recvbuf, 0, RECV_BUF_SIZE ); + memset(&recvbuf, 0, RECV_BUF_SIZE); - int read_cnt = recv_n( client_sock, recvbuf, RECV_HEADER_SIZE ); + int read_cnt = recv_n(client_sock, recvbuf, RECV_HEADER_SIZE); if (0 > read_cnt) { if (is_force_close_client) { - INFO( "force close client socket.\n" ); + INFO("force close client socket.\n"); is_force_close_client = 0; } else { ERR("skin_server read error (%d): %d\n", @@ -670,9 +675,7 @@ static void* run_skin_server(void* args) } break; - } else { - if (0 == read_cnt) { ERR("read_cnt is 0.\n"); break; @@ -1374,7 +1377,6 @@ static void* do_heart_beat(void* args) } return NULL; - } static int start_heart_beat(void) -- 2.34.1