skin: enhance the function call of skin initialization 17/12917/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Mon, 25 Nov 2013 08:25:50 +0000 (17:25 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 26 Nov 2013 02:40:45 +0000 (11:40 +0900)
1. declare initSkin function to express the inheritance clearly.
2. moved initialization source code to proper class.
3. modified variable name (windowHandleId -> displayHandleId)

Change-Id: Ibafa8763433fc1738365897ab179794d78981da5
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/data/StartData.java

index 76375a6..4394193 100644 (file)
@@ -33,7 +33,9 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.eclipse.swt.SWT;
+import org.tizen.emulator.skin.comm.sock.data.StartData;
 import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.dbi.OptionType;
 import org.tizen.emulator.skin.exception.ScreenShotException;
 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
 import org.tizen.emulator.skin.info.SkinInformation;
@@ -54,14 +56,34 @@ public class EmulatorSdlSkin extends EmulatorSkin {
                super(config, skinInfo, SWT.EMBEDDED, isOnTop);
        }
 
-       public long initLayout() {
-               super.initLayout();
+       @Override
+       public StartData initSkin() {
+               initLayout();
+
+               /* maru_sdl uses this handle ID */
+               long id = getDisplayHandleId();
+
+               /* generate a start data */
+               int width = getEmulatorSkinState().getCurrentResolutionWidth();
+               int height = getEmulatorSkinState().getCurrentResolutionHeight();
+               int scale = getEmulatorSkinState().getCurrentScale();
+               short rotation = getEmulatorSkinState().getCurrentRotationId();
+
+               boolean isBlankGuide = true;
+               OptionType option = config.getDbiContents().getOption();
+               if (option != null) {
+                       isBlankGuide = (option.getBlankGuide() == null) ?
+                                       true : option.getBlankGuide().isVisible();
+               }
+
+               StartData startData = new StartData(id,
+                               width, height, scale, rotation, isBlankGuide);
+               logger.info("" + startData);
 
-               /* sdl uses this handle ID */
-               return getWindowHandleId();
+               return startData;
        }
 
-       private long getWindowHandleId() {
+       private long getDisplayHandleId() {
                long windowHandleId = 0;
 
                /* org.eclipse.swt.widgets.Widget */
index d5b9582..9feeb05 100644 (file)
@@ -48,8 +48,10 @@ import org.tizen.emulator.skin.comm.ICommunicator.MouseEventType;
 import org.tizen.emulator.skin.comm.ICommunicator.SendCommand;
 import org.tizen.emulator.skin.comm.sock.data.KeyEventData;
 import org.tizen.emulator.skin.comm.sock.data.MouseEventData;
+import org.tizen.emulator.skin.comm.sock.data.StartData;
 import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
+import org.tizen.emulator.skin.dbi.OptionType;
 import org.tizen.emulator.skin.exception.ScreenShotException;
 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
 import org.tizen.emulator.skin.info.SkinInformation;
@@ -224,6 +226,7 @@ public class EmulatorShmSkin extends EmulatorSkin {
                this.imageGuide = null;
        }
 
+       @Override
        protected void skinFinalize() {
                pollThread.stopRequest();
 
@@ -234,8 +237,9 @@ public class EmulatorShmSkin extends EmulatorSkin {
                super.skinFinalize();
        }
 
-       public long initLayout() {
-               super.initLayout();
+       @Override
+       public StartData initSkin() {
+               initLayout();
 
                finger = new EmulatorFingers(maxTouchPoint, currentState, communicator);
                if (SwtUtil.isMacPlatform() == true) {
@@ -245,12 +249,35 @@ public class EmulatorShmSkin extends EmulatorSkin {
                }
                multiTouchKeySub = SWT.SHIFT;
 
+               initDisplay();
+
+               /* generate a start data */
+               int width = getEmulatorSkinState().getCurrentResolutionWidth();
+               int height = getEmulatorSkinState().getCurrentResolutionHeight();
+               int scale = getEmulatorSkinState().getCurrentScale();
+               short rotation = getEmulatorSkinState().getCurrentRotationId();
+
+               boolean isBlankGuide = true;
+               OptionType option = config.getDbiContents().getOption();
+               if (option != null) {
+                       isBlankGuide = (option.getBlankGuide() == null) ?
+                                       true : option.getBlankGuide().isVisible();
+               }
+
+               StartData startData = new StartData(0,
+                               width, height, scale, rotation, isBlankGuide);
+               logger.info("" + startData);
+
+               return startData;
+       }
+
+       private void initDisplay() {
+               /* initialize shared memory */
                /* base + 1 = sdb port */
                /* base + 2 = shared memory key */
                int shmkey = config.getArgInt(ArgsConstants.VM_BASE_PORT) + 2;
                logger.info("shmkey = " + shmkey);
 
-               /* initialize shared memory */
                int result = shmget(shmkey,
                                currentState.getCurrentResolutionWidth() *
                                currentState.getCurrentResolutionHeight() * 4);
@@ -262,6 +289,7 @@ public class EmulatorShmSkin extends EmulatorSkin {
                                        "Cannot launch this VM.\n" +
                                        "Failed to get identifier of the shared memory segment.",
                                        SWT.ICON_ERROR, config);
+
                        System.exit(-1);
                } else if (result == 2) {
                        logger.severe("Failed to attach the shared memory segment.");
@@ -269,6 +297,7 @@ public class EmulatorShmSkin extends EmulatorSkin {
                                        "Cannot launch this VM.\n" +
                                        "Failed to attach the shared memory segment.",
                                        SWT.ICON_ERROR, config);
+
                        System.exit(-1);
                }
 
@@ -372,8 +401,6 @@ public class EmulatorShmSkin extends EmulatorSkin {
                });
 
                pollThread.start();
-
-               return 0;
        }
 
        @Override
index 87b5554..cf7917b 100755 (executable)
@@ -76,6 +76,7 @@ import org.tizen.emulator.skin.comm.sock.data.BooleanData;
 import org.tizen.emulator.skin.comm.sock.data.DisplayStateData;
 import org.tizen.emulator.skin.comm.sock.data.KeyEventData;
 import org.tizen.emulator.skin.comm.sock.data.MouseEventData;
+import org.tizen.emulator.skin.comm.sock.data.StartData;
 import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
@@ -188,6 +189,7 @@ public class EmulatorSkin {
                this.pressedKeyEventList = new LinkedList<KeyEventData>();
 
                this.isOnTop = isOnTop;
+               this.isOnKbd = false;
                this.isKeyWindow = false;
 
                int style = SWT.NO_TRIM | SWT.DOUBLE_BUFFERED;
@@ -233,7 +235,13 @@ public class EmulatorSkin {
                }
        }
 
-       public long initLayout() {
+       public StartData initSkin() {
+               /* abstract */
+
+               return null;
+       }
+
+       protected long initLayout() {
                logger.info("initialize the skin layout");
 
                imageRegistry = ImageRegistry.getInstance();
@@ -251,7 +259,6 @@ public class EmulatorSkin {
                currentState.setCurrentRotationId(rotationId);
 
                /* create and attach a popup menu */
-               isOnKbd = false;
                popupMenu = new PopupMenu(config, this);
 
                /* build a skin layout */
@@ -269,6 +276,8 @@ public class EmulatorSkin {
 
                lcdCanvas = skinComposer.compose(displayCanvasStyle);
 
+               /* */
+               //TODO: move
                if (config.getArgBoolean(ArgsConstants.INPUT_MOUSE, false) == true) {
                        prev_x = lcdCanvas.getSize().x / 2;
                        prev_y = lcdCanvas.getSize().y / 2;
@@ -283,7 +292,7 @@ public class EmulatorSkin {
                addMainWindowListeners();
                addCanvasListeners();
 
-               setFocus();
+               lcdCanvas.setFocus();
 
                return 0;
        }
@@ -1205,10 +1214,6 @@ public class EmulatorSkin {
                }
        }
 
-       public void setFocus() {
-               lcdCanvas.setFocus();
-       }
-
        public void updateSkin() {
                skinComposer.updateSkin();
        }
index 3c0841d..3a52abc 100644 (file)
@@ -45,6 +45,7 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
+import org.tizen.emulator.skin.comm.sock.data.StartData;
 import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.config.EmulatorConfig.ConfigPropertiesConstants;
@@ -258,8 +259,8 @@ public class EmulatorSkinMain {
                        skin.setCommunicator(communicator);
 
                        /* initialize a skin layout */
-                       long windowHandleId = skin.initLayout();
-                       communicator.setInitialData(windowHandleId);
+                       StartData startData = skin.initSkin();
+                       communicator.setInitialData(startData);
 
                        Socket commSocket = communicator.getSocket();
 
index 2d57105..c6a3e38 100755 (executable)
@@ -53,11 +53,9 @@ import org.tizen.emulator.skin.comm.sock.data.ISendData;
 import org.tizen.emulator.skin.comm.sock.data.StartData;
 import org.tizen.emulator.skin.config.EmulatorConfig;
 import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
-import org.tizen.emulator.skin.dbi.OptionType;
 import org.tizen.emulator.skin.image.ImageRegistry.ResourceImageName;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.util.IOUtil;
-import org.tizen.emulator.skin.util.SkinUtil;
 
 
 /**
@@ -101,7 +99,7 @@ public class SocketCommunicator implements ICommunicator {
 
        private EmulatorConfig config;
        private int uId;
-       private long initialData;
+       private StartData startData;
        private EmulatorSkin skin;
 
        private Socket socket;
@@ -170,8 +168,13 @@ public class SocketCommunicator implements ICommunicator {
                this.dataOutputStream = new DataOutputStream(bao);
        }
 
-       public void setInitialData(long data) {
-               this.initialData = data;
+       public void setInitialData(StartData data) {
+               this.startData = data;
+       }
+
+       private void sendInitialData() {
+               logger.info("send startData");
+               sendToQEMU(SendCommand.SEND_SKIN_OPENED, startData, false);
        }
 
        @Override
@@ -230,23 +233,8 @@ public class SocketCommunicator implements ICommunicator {
                sendThread.setDaemon(true);
                sendThread.start();
 
-               int width = config.getArgInt(ArgsConstants.RESOLUTION_WIDTH);
-               int height = config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT);
-               int scale = SkinUtil.getValidScale(config);
-               short rotation = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
-
-               boolean isBlankGuide = true;
-               OptionType option = config.getDbiContents().getOption();
-               if (option != null) {
-                       isBlankGuide = (option.getBlankGuide() == null) ?
-                                       true : option.getBlankGuide().isVisible();
-               }
-
-               StartData startData = new StartData(initialData,
-                               width, height, scale, rotation, isBlankGuide);
-               logger.info("" + startData);
-
-               sendToQEMU(SendCommand.SEND_SKIN_OPENED, startData, false);
+               /* notify to Qemu */
+               sendInitialData();
 
                boolean ignoreHeartbeat =
                                config.getArgBoolean(ArgsConstants.HEART_BEAT_IGNORE);
index 3a270b3..918da20 100644 (file)
@@ -36,17 +36,17 @@ import java.io.IOException;
  *
  */
 public class StartData extends AbstractSendData {
-       private long windowHandleId;
+       private long displayHandleId;
        private int displayWidth;
        private int displayHeight;
        private int scale;
        private short rotation;
        private boolean isBlankGuide;
        
-       public StartData(long windowHandleId,
+       public StartData(long displayHandleId,
                        int displayWidth, int displayHeight, int scale, short rotation,
                        boolean isBlankGuide) {
-               this.windowHandleId = windowHandleId;
+               this.displayHandleId = displayHandleId;
                this.displayWidth = displayWidth;
                this.displayHeight = displayHeight;
                this.scale = scale;
@@ -56,7 +56,7 @@ public class StartData extends AbstractSendData {
 
        @Override
        protected void write() throws IOException {
-               writeLong(windowHandleId);
+               writeLong(displayHandleId);
                writeInt(displayWidth);
                writeInt(displayHeight);
                writeInt(scale);
@@ -72,8 +72,8 @@ public class StartData extends AbstractSendData {
        @Override
        public String toString() {
                StringBuilder builder = new StringBuilder();
-               builder.append("StartData [windowHandleId=");
-               builder.append(windowHandleId);
+               builder.append("StartData [displayHandleId=");
+               builder.append(displayHandleId);
                builder.append(", display size " + displayWidth + "x" + displayHeight);
                builder.append(", scale=");
                builder.append(scale);