From 6076490b070592284beff2447a3791985875355d Mon Sep 17 00:00:00 2001 From: "giwoong.kim" Date: Wed, 12 Dec 2012 14:58:21 +0900 Subject: [PATCH] skin: added protocol of booting progress Emulator can notify the booting progress to skin. Signed-off-by: GiWoong Kim --- .../tizen/emulator/skin/comm/ICommunicator.java | 39 +++++++--- .../skin/comm/sock/SocketCommunicator.java | 31 +++++++- .../emulator/skin/window/CustomProgressBar.java | 19 ++++- tizen/src/skin/maruskin_operation.c | 2 +- tizen/src/skin/maruskin_server.c | 84 ++++++++++++++++++---- tizen/src/skin/maruskin_server.h | 2 + 6 files changed, 151 insertions(+), 26 deletions(-) mode change 100755 => 100644 tizen/src/skin/maruskin_server.c diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/ICommunicator.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/ICommunicator.java index f57edc7..22cc55d 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/ICommunicator.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/comm/ICommunicator.java @@ -64,9 +64,11 @@ public interface ICommunicator extends Runnable { MouseButtonType( short value ) { this.value = value; } + public short value() { return this.value; } + public static MouseButtonType getValue( String val ) { MouseButtonType[] values = MouseButtonType.values(); for (int i = 0; i < values.length; i++) { @@ -76,6 +78,7 @@ public interface ICommunicator extends Runnable { } throw new IllegalArgumentException( val ); } + public static MouseButtonType getValue( short val ) { MouseButtonType[] values = MouseButtonType.values(); for (int i = 0; i < values.length; i++) { @@ -99,9 +102,11 @@ public interface ICommunicator extends Runnable { MouseEventType( short value ) { this.value = value; } + public short value() { return this.value; } + public static MouseEventType getValue( String val ) { MouseEventType[] values = MouseEventType.values(); for (int i = 0; i < values.length; i++) { @@ -111,6 +116,7 @@ public interface ICommunicator extends Runnable { } throw new IllegalArgumentException( val ); } + public static MouseEventType getValue( short val ) { MouseEventType[] values = MouseEventType.values(); for (int i = 0; i < values.length; i++) { @@ -131,9 +137,11 @@ public interface ICommunicator extends Runnable { KeyEventType( short value ) { this.value = value; } + public short value() { return this.value; } + public static KeyEventType getValue( String val ) { KeyEventType[] values = KeyEventType.values(); for (int i = 0; i < values.length; i++) { @@ -143,6 +151,7 @@ public interface ICommunicator extends Runnable { } throw new IllegalArgumentException( val ); } + public static KeyEventType getValue( short val ) { KeyEventType[] values = KeyEventType.values(); for (int i = 0; i < values.length; i++) { @@ -171,12 +180,15 @@ public interface ICommunicator extends Runnable { this.id = id; this.angle = ratio; } + public String value() { return this.value; } + public int angle() { return this.angle; } + public short id() { return this.id; } @@ -194,7 +206,8 @@ public interface ICommunicator extends Runnable { } public enum SendCommand { - + /* This values must match the QEMU definitions */ + SEND_START( (short)1 ), SEND_MOUSE_EVENT( (short)10 ), @@ -216,9 +229,11 @@ public interface ICommunicator extends Runnable { SendCommand( short value ) { this.value = value; } + public short value() { return this.value; } + public static SendCommand getValue( String val ) { SendCommand[] values = SendCommand.values(); for (int i = 0; i < values.length; i++) { @@ -228,6 +243,7 @@ public interface ICommunicator extends Runnable { } throw new IllegalArgumentException( val ); } + public static SendCommand getValue( short val ) { SendCommand[] values = SendCommand.values(); for (int i = 0; i < values.length; i++) { @@ -240,21 +256,25 @@ public interface ICommunicator extends Runnable { } public enum ReceiveCommand { - - HEART_BEAT( (short)1 ), - SCREEN_SHOT_DATA( (short)2 ), - DETAIL_INFO_DATA( (short)3 ), - RAMDUMP_COMPLETE( (short)4 ), - SENSOR_DAEMON_START( (short)800 ), - SHUTDOWN( (short)999 ); - + /* This values must match the QEMU definitions */ + + HEART_BEAT((short) 1), + SCREEN_SHOT_DATA((short) 2), + DETAIL_INFO_DATA((short) 3), + RAMDUMP_COMPLETE((short) 4), + BOOTING_PROGRESS((short) 5), + SENSOR_DAEMON_START((short) 800), + SHUTDOWN((short) 999); + private short value; ReceiveCommand( short value ) { this.value = value; } + public short value() { return this.value; } + public static ReceiveCommand getValue( String val ) { ReceiveCommand[] values = ReceiveCommand.values(); for (int i = 0; i < values.length; i++) { @@ -264,6 +284,7 @@ public interface ICommunicator extends Runnable { } throw new IllegalArgumentException( val ); } + public static ReceiveCommand getValue( short val ) { ReceiveCommand[] values = ReceiveCommand.values(); for (int i = 0; i < values.length; i++) { 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 24d3d40..2e93863 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 @@ -116,6 +116,7 @@ public class SocketCommunicator implements ICommunicator { private DataTranfer screenShotDataTransfer; private DataTranfer detailInfoTransfer; + private DataTranfer progressDataTransfer; private Thread sendThread; private LinkedList sendQueue; @@ -134,7 +135,11 @@ public class SocketCommunicator implements ICommunicator { this.detailInfoTransfer.sleep = DETAIL_INFO_WAIT_INTERVAL; this.detailInfoTransfer.maxWaitTime = DETAIL_INFO_WAIT_LIMIT; - this.heartbeatCount = new AtomicInteger( 0 ); + this.progressDataTransfer = new DataTranfer(); + this.progressDataTransfer.sleep = DETAIL_INFO_WAIT_INTERVAL; + this.progressDataTransfer.maxWaitTime = DETAIL_INFO_WAIT_LIMIT; + + this.heartbeatCount = new AtomicInteger(0); this.heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(); try { @@ -305,6 +310,30 @@ public class SocketCommunicator implements ICommunicator { setRamdumpFlag(false); break; } + case BOOTING_PROGRESS: { + logger.info("received BOOTING_PROGRESS from QEMU."); + receiveData(progressDataTransfer, length); + + byte[] receivedData = getReceivedData(progressDataTransfer); + if (null != receivedData) { + String strValue = new String(receivedData, 0, length - 1); + + int value = 0; + try { + value = Integer.parseInt(strValue); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + + /* draw progress bar */ + if (skin.bootingProgress != null) { + skin.bootingProgress.setSelection(value); + } + } + //TODO: resetDataTransfer(progressDataTransfer) + + break; + } case SENSOR_DAEMON_START: { logger.info( "received SENSOR_DAEMON_START from QEMU." ); synchronized ( this ) { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/CustomProgressBar.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/CustomProgressBar.java index abc523b..e9f04ff 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/CustomProgressBar.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/CustomProgressBar.java @@ -28,6 +28,8 @@ package org.tizen.emulator.skin.window; +import java.util.logging.Logger; + import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Color; @@ -35,13 +37,21 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; +import org.tizen.emulator.skin.dialog.DetailInfoDialog; +import org.tizen.emulator.skin.log.SkinLogger; public class CustomProgressBar extends Canvas { + private Logger logger = + SkinLogger.getSkinLogger(CustomProgressBar.class).getLogger(); + + private Composite parent; private int selection = 0; public CustomProgressBar(final Composite parent, int style) { super(parent, style); + this.parent = parent; + this.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { @@ -63,7 +73,14 @@ public class CustomProgressBar extends Canvas { } selection = value; - redraw(); + logger.info("progress : " + selection); + + parent.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + redraw(); + } + }); } public int getSelection() { diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index 04c50d7..a142823 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -485,7 +485,7 @@ void do_guestmemory_dump(void) { INFO("dump guest memory!\n"); - //TODO: + /* TODO: */ } void request_close(void) diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c old mode 100755 new mode 100644 index f5f1f42..052f085 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -58,10 +58,16 @@ #include #include #include + +#define socket_error() WSAGetLastError() + #else #include #include #include + +#define socket_error() errno + #endif #include "debug_ch.h" @@ -93,6 +99,9 @@ MULTI_DEBUG_CHANNEL(qemu, skin_server); #define SKIN_CONFIG_PROP ".skinconfig.properties" enum { + /* This values must match the Java definitions + in Skin process */ + RECV_START = 1, RECV_MOUSE_EVENT = 10, RECV_KEY_EVENT = 11, @@ -110,10 +119,14 @@ enum { }; enum { + /* This values must match the Java definitions + in Skin process */ + SEND_HEART_BEAT = 1, SEND_SCREEN_SHOT = 2, SEND_DETAIL_INFO = 3, SEND_RAMDUMP_COMPLETE = 4, + SEND_BOOTING_PROGRESS = 5, SEND_SENSOR_DAEMON_START = 800, SEND_SHUTDOWN = 999, }; @@ -249,12 +262,16 @@ void shutdown_skin_server( void ) { } -void notify_sensor_daemon_start( void ) { - INFO( "notify_sensor_daemon_start\n" ); +void notify_sensor_daemon_start(void) +{ + INFO("notify_sensor_daemon_start\n"); + is_sensord_initialized = 1; - if ( client_sock ) { - if ( 0 > send_skin_header_only( client_sock, SEND_SENSOR_DAEMON_START, 1 ) ) { - ERR( "fail to send SEND_SENSOR_DAEMON_START to skin.\n" ); + if (client_sock) { + if (0 > send_skin_header_only( + client_sock, SEND_SENSOR_DAEMON_START, 1)) { + + ERR("fail to send SEND_SENSOR_DAEMON_START to skin.\n"); } } } @@ -264,12 +281,49 @@ void notify_ramdump_completed(void) INFO("ramdump completed!\n"); if (client_sock) { - if (0 > send_skin_header_only( client_sock, SEND_RAMDUMP_COMPLETE, 1)) { + if (0 > send_skin_header_only( + client_sock, SEND_RAMDUMP_COMPLETE, 1)) { + ERR("fail to send SEND_RAMDUMP_COMPLETE to skin.\n"); } } } +void notify_booting_progress(int progress_value) +{ +#define PROGRESS_DATA_LENGTH 4 + + char progress_data[PROGRESS_DATA_LENGTH] = { 0, }; + int len = 1; + + INFO("notify_booting_progress\n"); + + /* percentage */ + if (progress_value < 0) { + progress_value = 0; + len = 1; + } else if (progress_value < 10) { + len = 1; + } else if (progress_value < 100) { + len = 2; + } else if (progress_value = 100) { + len = 3; + } else if (progress_value > 100) { + progress_value = 100; + len = 3; + } + + snprintf(progress_data, len + 1, "%d", progress_value); + INFO("booting...%s\%\n", progress_data); + + if (client_sock) { + if (0 > send_skin_data(client_sock, + SEND_BOOTING_PROGRESS, progress_data, len + 1, 1)) { + + ERR("fail to send SEND_BOOTING_PROGRESS to skin.\n"); + } + } +} int is_ready_skin_server(void) { @@ -507,8 +561,9 @@ static void* run_skin_server(void* args) INFO( "start accepting socket...\n" ); if ( 0 > ( client_sock = accept( server_sock, (struct sockaddr *) &client_addr, &client_len ) ) ) { - ERR( "skin_servier accept error\n" ); - perror( "skin_servier accept error : " ); + ERR("skin_server accept error\n"); + perror("skin_server accept error : "); + continue; } @@ -526,15 +581,16 @@ static void* run_skin_server(void* args) int read_cnt = recv_n( client_sock, recvbuf, RECV_HEADER_SIZE ); - if ( 0 > read_cnt ) { - - if( is_force_close_client ) { + if (0 > read_cnt) { + if (is_force_close_client) { INFO( "force close client socket.\n" ); is_force_close_client = 0; - }else { - ERR( "skin_server read error:%d\n", read_cnt ); - perror( "skin_server read error : " ); + } else { + ERR("skin_server read error (%d): %d\n", + socket_error(), read_cnt); + perror("skin_server read error : "); } + break; } else { diff --git a/tizen/src/skin/maruskin_server.h b/tizen/src/skin/maruskin_server.h index 3ef909f..adac225 100644 --- a/tizen/src/skin/maruskin_server.h +++ b/tizen/src/skin/maruskin_server.h @@ -32,8 +32,10 @@ int start_skin_server(int argc, char** argv, int qemu_argc, char** qemu_argv); void shutdown_skin_server(void); + void notify_sensor_daemon_start(void); void notify_ramdump_complete(void); +void notify_booting_progress(int progress_value); int is_ready_skin_server(void); int get_skin_server_port(void); -- 2.7.4