From 1ae638c690960d7cc290f191c127c19749a07cbd Mon Sep 17 00:00:00 2001 From: Son Hyunjun Date: Wed, 4 Apr 2012 14:12:44 +0900 Subject: [PATCH] [Title] add graceful shutdown api [Type] Feature [Module] Skin [Priority] Minor [CQ#] [Redmine#] [Problem] [Cause] [Solution] Change-Id: Ia40885f645154ad2b5d5ca04f6c2627f27cab6b2 --- tizen/src/skin/maruskin_operation.c | 88 +++++++++++++++++++++-------- tizen/src/skin/maruskin_operation.h | 2 +- tizen/src/skin/maruskin_server.c | 4 +- 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index 0c70b64182..d0bdce4a22 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -30,6 +30,7 @@ #include #include +#include #include "maruskin_operation.h" #include "maru_sdl.h" #include "debug_ch.h" @@ -48,8 +49,11 @@ MULTI_DEBUG_CHANNEL(qemu, skin_operation); #define RESUME_KEY_SEND_INTERVAL 500 // milli-seconds #define CLOSE_POWER_KEY_INTERVAL 1200 // milli-seconds +#define DATA_DELIMITER "#" // in detail info data +#define TIMEOUT_FOR_SHUTDOWN 10 // seconds -#define DATA_DELIMITER "#" +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 ); void start_display( int handle_id, int lcd_size_width, int lcd_size_height, double scale_factor, short rotation_type ) { @@ -168,7 +172,6 @@ void do_rotation_event( int rotation_type) INFO( "do_rotation_event rotation_type:%d", rotation_type); - int buf_size = 32; char send_buf[32] = { 0 }; switch ( rotation_type ) { @@ -189,29 +192,9 @@ void do_rotation_event( int rotation_type) break; } - // send_to_sensor_daemon - int s; + send_to_emuld( "sensor\n\n\n\n", 10, send_buf, 32 ); - s = tcp_socket_outgoing( "127.0.0.1", (uint16_t) ( tizen_base_port + SDB_TCP_EMULD_INDEX ) ); - if ( s < 0 ) { - ERR( "can't create socket to talk to the sdb forwarding session \n"); - ERR( "[127.0.0.1:%d/tcp] connect fail (%d:%s)\n" , tizen_base_port + SDB_TCP_EMULD_INDEX , errno, strerror(errno)); - return; - } - - socket_send( s, "sensor\n\n\n\n", 10 ); - socket_send( s, &buf_size, 4 ); - socket_send( s, send_buf, buf_size ); - - INFO( "send to sensord(size: %d) 127.0.0.1:%d/tcp \n", buf_size, tizen_base_port + SDB_TCP_EMULD_INDEX); - - set_emul_rotation(rotation_type); - -#ifdef _WIN32 - closesocket( s ); -#else - close( s ); -#endif + set_emul_rotation( rotation_type ); } @@ -348,6 +331,61 @@ void request_close( void ) } -void shutdown_qemu( void ) { +void shutdown_qemu_gracefully( void ) { + + 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" ); + qemu_system_shutdown_request(); + } + +} + +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 i; + for ( i = 0; i < TIMEOUT_FOR_SHUTDOWN; i++ ) { +#ifdef _WIN32 + Sleep( sleep_time ); +#else + 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 ) ); + } + + WARN( "Shutdown qemu !!!\n" ); qemu_system_shutdown_request(); + + return NULL; + +} + +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 ) { + ERR( "can't create socket to talk to the sdb forwarding session \n" ); + ERR( "[127.0.0.1:%d/tcp] connect fail (%d:%s)\n" , tizen_base_port + SDB_TCP_EMULD_INDEX , errno, strerror(errno) ); + return; + } + + socket_send( s, (char*)request_type, request_size ); + socket_send( s, &buf_size, 4 ); + socket_send( s, (char*)send_buf, buf_size ); + + INFO( "send to emuld [req_type:%s, send_data:%s, send_size:%d] 127.0.0.1:%d/tcp \n", + request_type, send_buf, buf_size, tizen_base_port + SDB_TCP_EMULD_INDEX ); + +#ifdef _WIN32 + closesocket( s ); +#else + close( s ); +#endif + } diff --git a/tizen/src/skin/maruskin_operation.h b/tizen/src/skin/maruskin_operation.h index 92c8d5c7d4..d1d13deee2 100644 --- a/tizen/src/skin/maruskin_operation.h +++ b/tizen/src/skin/maruskin_operation.h @@ -68,6 +68,6 @@ void onoff_usb_kbd( int on ); void request_close( void ); -void shutdown_qemu( void ); +void shutdown_qemu_gracefully( void ); #endif /* MARUSKIN_OPERATION_H_ */ diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index 218aeb5e36..bd1aad54e4 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -741,7 +741,7 @@ cleanup: ERR( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" ); ERR( "!!! Fail to initialize for skin server operation. Shutdown QEMU !!!\n" ); ERR( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" ); - shutdown_qemu(); + shutdown_qemu_gracefully(); } return NULL; @@ -986,7 +986,7 @@ static void* do_heart_beat( void* args ) { ERR( "!!! Fail to operate with heartbeat from skin client. Shutdown QEMU !!!\n" ); ERR( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" ); - shutdown_qemu(); + shutdown_qemu_gracefully(); } -- 2.34.1