From f89492f0f25f1eb1fa6de717bf295c7deffd6a5a Mon Sep 17 00:00:00 2001 From: "munkyu.im" Date: Sun, 18 Mar 2012 21:01:25 +0900 Subject: [PATCH] [Title]notify to sdb server when sdbd started [Type] [Module] [Priority] [CQ#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- tizen/src/emulator.c | 36 +++++++----------------------------- tizen/src/guest_server.c | 2 ++ tizen/src/process.c | 4 ++-- tizen/src/sdb.c | 42 +++++++++++++++++++++++++++--------------- tizen/src/sdb.h | 3 ++- vl.c | 4 ++-- 6 files changed, 42 insertions(+), 49 deletions(-) diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 148fa29..b36f7e0 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -166,26 +166,7 @@ void set_image_and_log_path(char* qemu_argv) } #endif strcat(logfile, LOGFILE); - -} - -void get_tizen_port(char* option) -{ - int i; - int j = 0; - int max_len = 0; - int prefix_len = 0; - char *ptr; - char *path = malloc(MAXLEN); - prefix_len = strlen(SDB_PORT_PREFIX);; - max_len = prefix_len + 5; - for(i = prefix_len , j = 0; i < max_len; i++) - { - path[j++] = option[i]; - } - path[j] = '\0'; - tizen_base_port = strtol(path, &ptr, 0); - // INFO( "tizen_base_port: %d\n", tizen_base_port); + set_log_path(logfile); } void redir_output(void) @@ -206,19 +187,17 @@ void redir_output(void) void extract_info(int qemu_argc, char** qemu_argv) { int i; - char *option = NULL; for(i = 0; i < qemu_argc; ++i) { if(strstr(qemu_argv[i], IMAGE_PATH_PREFIX) != NULL) { set_image_and_log_path(qemu_argv[i]); + break; } - if((option = strstr(qemu_argv[i], SDB_PORT_PREFIX)) != NULL) { - get_tizen_port(option); - write_portfile(tizen_target_path); - } - } + + tizen_base_port = get_sdb_base_port(); + write_portfile(tizen_target_path); } static int skin_argc = 0; @@ -228,7 +207,7 @@ void prepare_maru(void) { INFO("Prepare maru specified feature\n"); - sdb_setup(tizen_base_port); + sdb_setup(); INFO("call construct_main_window\n"); @@ -247,10 +226,9 @@ int main(int argc, char* argv[]) { int qemu_argc = 0; char** qemu_argv = NULL; - + parse_options(argc, argv, &skin_argc, &skin_argv, &qemu_argc, &qemu_argv); extract_info(qemu_argc, qemu_argv); - set_log_path(logfile); INFO("Emulator start !!!\n"); INFO("Prepare running...\n"); diff --git a/tizen/src/guest_server.c b/tizen/src/guest_server.c index 10b781f..4429067 100644 --- a/tizen/src/guest_server.c +++ b/tizen/src/guest_server.c @@ -44,6 +44,7 @@ #include "guest_server.h" #include "skin/maruskin_server.h" #include "debug_ch.h" +#include "sdb.h" MULTI_DEBUG_CHANNEL( qemu, guest_server ); @@ -138,6 +139,7 @@ static void* run_guest_server( void* args ) { TRACE( "----------------------------------------\n" ); if ( strcmp( command, "3\n" ) == 0 ) { TRACE( "command:%s\n", command ); + notify_sdb_daemon_start(); notify_sensor_daemon_start(); } else { ERR( "!!! unknown command : %s\n", command ); diff --git a/tizen/src/process.c b/tizen/src/process.c index 45aba74..31108e4 100644 --- a/tizen/src/process.c +++ b/tizen/src/process.c @@ -169,8 +169,8 @@ int write_portfile(char *path) #else if ((fd = open(portfname, O_RDWR | O_CREAT, 0666)) < 0) { #endif -// ERR("Failed to create .port file\n"); -// ERR("%s at %s(%d)\n", strerror(errno), __FILE__, __LINE__); + ERR("Failed to create .port file\n"); + ERR("%s at %s(%d)\n", strerror(errno), __FILE__, __LINE__); return -1; } diff --git a/tizen/src/sdb.c b/tizen/src/sdb.c index 9aabe2c..9c6abe7 100644 --- a/tizen/src/sdb.c +++ b/tizen/src/sdb.c @@ -276,25 +276,27 @@ int get_sdb_base_port(void) return tizen_base_port; } -void sdb_setup(int port) +void sdb_setup(void) { int tries = 10; const char *base_port = "26100"; int success = 0; - int s; + int port; uint32_t guest_ip; const char *p; char buf[64] = {0,}; inet_strtoip("10.0.2.16", &guest_ip); + port = strtol(base_port, (char **)&p, 0); + for ( ; tries > 0; tries--, port += 10 ) { - // redir form [tcp:26100:10.0.2.16:26101] + // redir form [tcp:26101:10.0.2.16:26101] sprintf(buf, "tcp:%d:10.0.2.16:26101", port+1); if(net_slirp_redir((char*)buf) < 0) continue; - fprintf(stdout,"SDBD established on port %d\n", port+1); + INFO( "SDBD established on port %d\n", port+1); success = 1; break; } @@ -305,26 +307,32 @@ void sdb_setup(int port) exit(1); } -// if( tizen_base_port != port ){ -// ERR( "sdb port is miss match. Aborting\n" ); -// exit(1); -// } + if( tizen_base_port != port ){ + ERR( "sdb port is miss match. Aborting\n" ); + exit(1); + } /* Save base port. */ - INFO( "Port(%d/tcp) listen for SDB \n", port + 1); + tizen_base_port = port; + INFO( "Port(%d/tcp) listen for SDB \n", tizen_base_port + 1); /* for sensort */ - sprintf(buf, "tcp:%d:10.0.2.16:3577", port + SDB_TCP_EMULD_INDEX ); + sprintf(buf, "tcp:%d:10.0.2.16:3577", get_sdb_base_port() + SDB_TCP_EMULD_INDEX ); if(net_slirp_redir((char*)buf) < 0){ ERR( "redirect [%s] fail \n", buf); }else{ INFO("redirect [%s] success\n", buf); } +} - /* send a simple message to the SDB host server to tell it we just started. - * it should be listening on port 26099. if we can't reach it, don't bother +void notify_sdb_daemon_start(void) +{ + int s; + /* + * send a simple message to the SDB host server to tell it we just started. + * it should be listening on port 26099. */ - do + do { char tmp[32] = {0}; @@ -336,12 +344,16 @@ void sdb_setup(int port) } /* length is hex: 0x13 = 19 */ - sprintf(tmp,"0013host:emulator:%d",port+1); - socket_send(s, tmp, 30); + sprintf(tmp,"0013host:emulator:%d", tizen_base_port +1); + + if(socket_send(s, tmp, 30) < 0) { + ERR( "message sending to sdb server error!\n"); + } } while (0); if (s >= 0) socket_close(s); + } diff --git a/tizen/src/sdb.h b/tizen/src/sdb.h index 0b03db6..49618da 100644 --- a/tizen/src/sdb.h +++ b/tizen/src/sdb.h @@ -104,8 +104,9 @@ #define SDB_TCP_OPENGL_INDEX 4 /* opengl server port */ extern int tizen_base_port; #define SDB_UDP_SENSOR_INDEX 3 /* sensor server port */ -void sdb_setup(int port); +void sdb_setup(void); int get_sdb_base_port(void); int inet_strtoip(const char* str, uint32_t *ip); int socket_send(int fd, const void* buf, int buflen); void socket_close(int fd); +void notify_sdb_daemon_start(void); diff --git a/vl.c b/vl.c index 2301a73..f9af8f9 100644 --- a/vl.c +++ b/vl.c @@ -191,6 +191,7 @@ int qemu_main(int argc, char **argv, char **envp); #ifdef CONFIG_MARU #define VIRTIOGL_DEV_NAME "virtio-gl-pci" +extern int tizen_base_port; #endif static const char *data_dir; @@ -2490,8 +2491,7 @@ int main(int argc, char **argv, char **envp) #ifdef CONFIG_MARU gethostproxy(proxy); gethostDNS(dns1, dns2); - - kernel_cmdline = g_strdup_printf("%s proxy=%s dns1=%s dns2=%s", optarg, proxy, dns1, dns2); + kernel_cmdline = g_strdup_printf("%s sdb_port=%d, proxy=%s dns1=%s dns2=%s", optarg, tizen_base_port, proxy, dns1, dns2); fprintf(stdout, "kernel command : %s\n", kernel_cmdline); #else kernel_cmdline = optarg; -- 2.7.4