*
*/
public interface ICommunicator extends Runnable {
+ /* This values must match the QEMU definitions */
+ public final static short RECV_HEART_BEAT = 1;
+ public final static short RECV_SCREENSHOT_DATA = 2;
+ public final static short RECV_DETAIL_INFO_DATA = 3;
+ public final static short RECV_RAMDUMP_COMPLETED = 4;
+ public final static short RECV_BOOTING_PROGRESS = 5;
+ public final static short RECV_BRIGHTNESS_STATE = 6;
+ public final static short RECV_HOST_KBD_STATE = 8;
+ public final static short RECV_MULTI_TOUCH_STATE = 9;
+
+ public final static short RECV_SENSORD_STARTED = 800;
+ public final static short RECV_SDBD_STARTED = 801;
+ public final static short RECV_ECS_STARTED = 802;
+ public final static short RECV_DRAW_FRAME = 900;
+ public final static short RECV_DRAW_BLANK_GUIDE = 901;
+ public final static short RECV_EMUL_RESET = 998;
+ public final static short RECV_EMUL_SHUTDOWN = 999;
+
public enum MouseButtonType {
LEFT( (short)1 ),
WHEEL( (short)2 ),
}
}
- public enum ReceiveCommand {
- /* This values must match the QEMU definitions */
-
- RECV_HEART_BEAT((short) 1),
- RECV_SCREENSHOT_DATA((short) 2),
- RECV_DETAIL_INFO_DATA((short) 3),
- RECV_RAMDUMP_COMPLETED((short) 4),
- RECV_BOOTING_PROGRESS((short) 5),
- RECV_BRIGHTNESS_STATE((short) 6),
- RECV_HOST_KBD_STATE((short) 8),
- RECV_MULTI_TOUCH_STATE((short) 9),
-
- RECV_SENSORD_STARTED((short) 800),
- RECV_SDBD_STARTED((short) 801),
- RECV_ECS_STARTED((short) 802),
- RECV_DRAW_FRAME((short) 900),
- RECV_DRAW_BLANK_GUIDE((short) 901),
- RECV_EMUL_RESET((short) 998),
- RECV_EMUL_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++) {
- if (values[i].value == Short.parseShort(val)) {
- return values[i];
- }
- }
- throw new IllegalArgumentException(val);
- }
-
- public static ReceiveCommand getValue(short val) {
- ReceiveCommand[] values = ReceiveCommand.values();
- for (int i = 0; i < values.length; i++) {
- if (values[i].value == val) {
- return values[i];
- }
- }
- throw new IllegalArgumentException(Integer.toString(val));
- }
- }
-
public void sendToQEMU(SendCommand command, ISendData data, boolean urgent);
public void terminate();
import org.tizen.emulator.skin.log.SkinLogger;
import org.tizen.emulator.skin.util.IOUtil;
-
/**
*
*
*/
public class SocketCommunicator implements ICommunicator {
+ private static class PacketHeader {
+ int reqId; /* id */
+ short cmd; /* command */
+ int length; /* data length */
+ }
+
public static class DataTranfer {
private boolean isTransferState;
private byte[] receivedData;
sendThread = new Thread("sendThread") {
List<SkinSendData> list = new ArrayList<SkinSendData>();
+ SkinSendData sendData = null;
@Override
public void run() {
}
}
- SkinSendData sendData = null;
while (true) {
sendData = sendQueue.poll();
if (null != sendData) {
heartbeatTimer.schedule(heartbeatExecutor, 1, HEART_BEAT_INTERVAL * 1000);
}
+ PacketHeader header = new PacketHeader();
+
while (true) {
if (isTerminated) {
break;
}
try {
- int reqId = sockInputStream.readInt();
- short cmd = sockInputStream.readShort();
- int length = sockInputStream.readInt();
+ header.reqId = sockInputStream.readInt();
+ header.cmd = sockInputStream.readShort();
+ header.length = sockInputStream.readInt();
if (logger.isLoggable(Level.FINE)) {
- logger.fine("[Socket] read - reqId:" + reqId +
- ", command:" + cmd + ", dataLength:" + length);
+ logger.fine("[Socket] read - reqId:" + header.reqId +
+ ", command:" + header.cmd + ", dataLength:" + header.length);
}
- ReceiveCommand command = null;
-
- try {
- command = ReceiveCommand.getValue(cmd);
- } catch (IllegalArgumentException e) {
- logger.severe("unknown command:" + cmd);
- continue;
- }
-
- switch (command) {
+ switch (header.cmd) {
case RECV_HEART_BEAT: {
resetHeartbeatCount();
}
case RECV_SCREENSHOT_DATA: {
logger.info("received SCREENSHOT_DATA from QEMU");
- receiveData(sockInputStream, screenShotDataTransfer, length);
+ receiveData(sockInputStream, screenShotDataTransfer, header.length);
break;
}
case RECV_DETAIL_INFO_DATA: {
logger.info("received DETAIL_INFO_DATA from QEMU");
- receiveData(sockInputStream, detailInfoTransfer, length);
+ receiveData(sockInputStream, detailInfoTransfer, header.length);
break;
}
//logger.info("received BOOTING_PROGRESS from QEMU");
resetDataTransfer(miscDataTransfer);
- receiveData(sockInputStream, miscDataTransfer, length);
+ receiveData(sockInputStream, miscDataTransfer, header.length);
byte[] receivedData = getReceivedData(miscDataTransfer);
if (null != receivedData) {
String strLayer = new String(receivedData, 0, 1, "UTF-8");
- String strValue = new String(receivedData, 1, length - 2, "UTF-8");
+ String strValue = new String(receivedData, 1, header.length - 2, "UTF-8");
int layer = 0;
int value = 0;
//logger.info("received BRIGHTNESS_STATE from QEMU");
resetDataTransfer(miscDataTransfer);
- receiveData(sockInputStream, miscDataTransfer, length);
+ receiveData(sockInputStream, miscDataTransfer, header.length);
byte[] receivedData = getReceivedData(miscDataTransfer);
if (null != receivedData) {
- String strValue = new String(receivedData, 0, length - 1, "UTF-8");
+ String strValue = new String(receivedData, 0, header.length - 1, "UTF-8");
int value = 1;
try {
logger.info("received HOST_KBD_STATE from QEMU");
resetDataTransfer(miscDataTransfer);
- receiveData(sockInputStream, miscDataTransfer, length);
+ receiveData(sockInputStream, miscDataTransfer, header.length);
byte[] receivedData = getReceivedData(miscDataTransfer);
if (null != receivedData) {
- String strValue = new String(receivedData, 0, length - 1, "UTF-8");
+ String strValue = new String(receivedData, 0, header.length - 1, "UTF-8");
int value = 1;
try {
logger.info("received MULTI_TOUCH_STATE from QEMU");
resetDataTransfer(miscDataTransfer);
- receiveData(sockInputStream, miscDataTransfer, length);
+ receiveData(sockInputStream, miscDataTransfer, header.length);
byte[] receivedData = getReceivedData(miscDataTransfer);
if (null != receivedData) {
- String strValue = new String(receivedData, 0, length - 1, "UTF-8");
+ String strValue = new String(receivedData, 0, header.length - 1, "UTF-8");
int value = 1;
try {
break;
}
default: {
- logger.severe("Unknown command from QEMU. command : " + cmd);
+ logger.severe("Unknown command from QEMU. command : " + header.cmd);
break;
}
}
} else {
byte[] byteData = data.serialize();
length = (short) byteData.length;
+
dataOutputStream.writeShort(length);
dataOutputStream.write(byteData);
}