import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType;
import org.tizen.emulator.skin.comm.ICommunicator.MouseEventType;
-import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
+import org.tizen.emulator.skin.comm.ICommunicator.Scale;
import org.tizen.emulator.skin.comm.ICommunicator.SendCommand;
import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
import org.tizen.emulator.skin.comm.sock.data.BooleanData;
import org.tizen.emulator.skin.util.SkinRegion;
import org.tizen.emulator.skin.util.SkinRotation;
import org.tizen.emulator.skin.util.SkinUtil;
-import org.tizen.emulator.skin.util.StringUtil;
/**
*
this.lcdCanvas = new Canvas( shell, SWT.EMBEDDED );
- int x = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_X, 50 );
- int y = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_Y, 50 );
- int lcdWidth = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
- int lcdHeight = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
+ int x = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_X, EmulatorConfig.DEFAULT_WINDOW_X );
+ int y = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_Y, EmulatorConfig.DEFAULT_WINDOW_Y );
+ int lcdWidth = config.getArgInt( ArgsConstants.RESOLUTION_WIDTH );
+ int lcdHeight = config.getArgInt( ArgsConstants.RESOLUTION_HEIGHT );
int scale = SkinUtil.getValidScale( config );
- // int rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION, RotationInfo.PORTRAIT.id() );
+// int rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION,
+// EmulatorConfig.DEFAULT_WINDOW_ROTATION );
// has to be portrait mode at first booting time
- short rotationId = RotationInfo.PORTRAIT.id();
+ short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
composeInternal( lcdCanvas, x, y, lcdWidth, lcdHeight, scale, rotationId );
int keyCode = SkinUtil.getHardKeyCode( e.x, e.y, currentRotationId, currentScale );
- if ( EmulatorConstants.UNKNOWN_KEYCODE != keyCode ) {
+ if ( SkinUtil.UNKNOWN_KEYCODE != keyCode ) {
if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
shell.redraw();
} else {
int keyCode = SkinUtil.getHardKeyCode( e.x, e.y, currentRotationId, currentScale );
- if ( EmulatorConstants.UNKNOWN_KEYCODE != keyCode ) {
+ if ( SkinUtil.UNKNOWN_KEYCODE != keyCode ) {
// draw the button region as the cropped keyPressed image area
SkinRegion region = SkinUtil.getHardKeyArea( e.x, e.y, currentRotationId, currentScale );
}
String sdbPath = SkinUtil.getSdbPath();
- String portNumber = StringUtil.nvl( config.getArg( ArgsConstants.NET_BASE_PORT ) );
+ int portSdb = config.getArgInt( ArgsConstants.NET_BASE_PORT );
- if ( !StringUtil.isEmpty( portNumber ) && !StringUtil.isEmpty( portNumber ) ) {
- int portSdb = Integer.parseInt( portNumber );
+ ProcessBuilder procSdb = new ProcessBuilder();
- ProcessBuilder procSdb = new ProcessBuilder();
-
- if ( SkinUtil.isLinuxPlatform() ) {
- procSdb.command( "/usr/bin/gnome-terminal", "--disable-factory",
- "--title=" + SkinUtil.makeEmulatorName( config ), "-x", sdbPath, "-s", "emulator-"
- + portSdb, "shell" );
- } else if ( SkinUtil.isWindowsPlatform() ) {
- procSdb.command( "cmd.exe", "/c", "start", sdbPath, "-s", "emulator-" + portSdb, "shell" );
- }
- logger.log( Level.INFO, procSdb.command().toString() );
+ if ( SkinUtil.isLinuxPlatform() ) {
+ procSdb.command( "/usr/bin/gnome-terminal", "--disable-factory",
+ "--title=" + SkinUtil.makeEmulatorName( config ), "-x", sdbPath, "-s", "emulator-"
+ + portSdb, "shell" );
+ } else if ( SkinUtil.isWindowsPlatform() ) {
+ procSdb.command( "cmd.exe", "/c", "start", sdbPath, "-s", "emulator-" + portSdb, "shell" );
+ }
+ logger.log( Level.INFO, procSdb.command().toString() );
- try {
- procSdb.start(); // open sdb shell
- } catch ( Exception ee ) {
- logger.log( Level.SEVERE, ee.getMessage(), ee );
- SkinUtil.openMessage( shell, null, "Fail to open Shell.", SWT.ICON_ERROR, config );
- }
+ try {
+ procSdb.start(); // open sdb shell
+ } catch ( Exception ee ) {
+ logger.log( Level.SEVERE, ee.getMessage(), ee );
+ SkinUtil.openMessage( shell, null, "Fail to open Shell.", SWT.ICON_ERROR, config );
}
communicator.sendToQEMU( SendCommand.OPEN_SHELL, null );
final MenuItem scaleOneItem = new MenuItem( menu, SWT.RADIO );
scaleOneItem.setText( "1x" );
- scaleOneItem.setData( 100 );
+ scaleOneItem.setData( Scale.SCALE_100 );
scaleList.add( scaleOneItem );
final MenuItem scaleThreeQtrItem = new MenuItem( menu, SWT.RADIO );
scaleThreeQtrItem.setText( "3/4x" );
- scaleThreeQtrItem.setData( 75 );
+ scaleThreeQtrItem.setData( Scale.SCALE_75 );
scaleList.add( scaleThreeQtrItem );
final MenuItem scalehalfItem = new MenuItem( menu, SWT.RADIO );
scalehalfItem.setText( "1/2x" );
- scalehalfItem.setData( 50 );
+ scalehalfItem.setData( Scale.SCALE_50 );
scaleList.add( scalehalfItem );
final MenuItem scaleOneQtrItem = new MenuItem( menu, SWT.RADIO );
scaleOneQtrItem.setText( "1/4x" );
- scaleOneQtrItem.setData( 25 );
+ scaleOneQtrItem.setData( Scale.SCALE_25 );
scaleList.add( scaleOneQtrItem );
SelectionAdapter selectionAdapter = new SelectionAdapter() {
return;
}
- int scale = (Integer) item.getData();
+ int scale = ( (Scale) item.getData() ).value();
arrangeSkin( currentLcdWidth, currentLcdHeight, scale, currentRotationId );
LcdStateData lcdStateData = new LcdStateData( scale, currentRotationId );
for ( MenuItem menuItem : scaleList ) {
- int scale = (Integer) menuItem.getData();
+ int scale = ( (Scale) menuItem.getData() ).value();
if ( scale == storedScale ) {
menuItem.setSelection( true );
}
// able to use log file after loading properties
initLog( argsMap, configProperties );
+ EmulatorConfig.validateArgs( argsMap );
+ EmulatorConfig.validateSkinProperties( skinProperties );
+ EmulatorConfig.validateSkinConfigProperties( configProperties );
+
int lcdWidth = Integer.parseInt( argsMap.get( ArgsConstants.RESOLUTION_WIDTH ) );
int lcdHeight = Integer.parseInt( argsMap.get( ArgsConstants.RESOLUTION_HEIGHT ) );
String argSkinPath = (String) argsMap.get( ArgsConstants.SKIN_PATH );
EmulatorSkin skin = new EmulatorSkin( config, isOnTop );
int windowHandleId = skin.compose();
- int uid = Integer.parseInt( config.getArg( ArgsConstants.UID ) );
+ int uid = config.getArgInt( ArgsConstants.UID );
SocketCommunicator communicator = new SocketCommunicator( config, uid, windowHandleId, skin );
skin.setCommunicator( communicator );
}else if( !StringUtil.isEmpty( configPropertyLogLevel ) ) {
logLevel = configPropertyLogLevel;
}else {
- logLevel = SkinLogLevel.DEBUG.value();
+ logLevel = EmulatorConfig.DEFAULT_LOG_LEVEL.value();
}
- SkinLogLevel skinLogLevel = SkinLogLevel.DEBUG;
+ SkinLogLevel skinLogLevel = EmulatorConfig.DEFAULT_LOG_LEVEL;
SkinLogLevel[] values = SkinLogLevel.values();
*/
public interface ICommunicator extends Runnable {
+ public enum Scale {
+ SCALE_25(25),
+ SCALE_50(50),
+ SCALE_75(75),
+ SCALE_100(100);
+
+ private int value;
+
+ Scale( int value ) {
+ this.value = value;
+ }
+
+ public int value() {
+ return this.value;
+ }
+ }
+
public enum MouseEventType {
DOWN( (short)1 ),
UP( (short)2 ),
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;
-import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
import org.tizen.emulator.skin.log.SkinLogger;
import org.tizen.emulator.skin.util.IOUtil;
import org.tizen.emulator.skin.util.SkinUtil;
-import org.tizen.emulator.skin.util.StringUtil;
/**
try {
- String portString = config.getArg( ArgsConstants.SERVER_PORT );
- int port = Integer.parseInt( portString );
+ int port = config.getArgInt( ArgsConstants.SERVER_PORT );
socket = new Socket( "127.0.0.1", port );
logger.info( "socket.isConnected():" + socket.isConnected() );
dis = new DataInputStream( socket.getInputStream() );
dos = new DataOutputStream( socket.getOutputStream() );
- int width = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
- int height = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
+ int width = config.getArgInt( ArgsConstants.RESOLUTION_WIDTH );
+ int height = config.getArgInt( ArgsConstants.RESOLUTION_HEIGHT );
int scale = SkinUtil.getValidScale( config );
- short rotation = config.getSkinPropertyShort( SkinPropertiesConstants.WINDOW_ROTATION, RotationInfo.PORTRAIT.id() );
-
+// short rotation = config.getSkinPropertyShort( SkinPropertiesConstants.WINDOW_ROTATION,
+// EmulatorConfig.DEFAULT_WINDOW_ROTATION );
+ // has to be portrait mode at first booting time
+ short rotation = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
StartData startData = new StartData( windowHandleId, width, height, scale, rotation );
sendToQEMU( SendCommand.SEND_START, startData );
return;
}
- String ignoreHeartbeatString = config.getArg( ArgsConstants.TEST_HEART_BEAT_IGNORE );
- if ( StringUtil.isEmpty( ignoreHeartbeatString ) ) {
- ignoreHeartbeatString = config.getConfigProperty( ConfigPropertiesConstants.TEST_HEART_BEAT_IGNORE,
- Boolean.FALSE.toString() );
- }
-
- Boolean ignoreHeartbeat = Boolean.parseBoolean( ignoreHeartbeatString );
+ boolean ignoreHeartbeat = config.getArgBoolean( ArgsConstants.TEST_HEART_BEAT_IGNORE );
if ( ignoreHeartbeat ) {
logger.info( "Ignore Skin heartbeat." );
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
+import org.tizen.emulator.skin.comm.ICommunicator.Scale;
import org.tizen.emulator.skin.dbi.EmulatorUI;
+import org.tizen.emulator.skin.exception.ConfigException;
import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.log.SkinLogger.SkinLogLevel;
import org.tizen.emulator.skin.util.IOUtil;
import org.tizen.emulator.skin.util.StringUtil;
*
*/
public class EmulatorConfig {
-
+
private Logger logger = SkinLogger.getSkinLogger( EmulatorConfig.class ).getLogger();
-
+
+ public static final int DEFAULT_WINDOW_SCALE = Scale.SCALE_50.value();
+ public static final short DEFAULT_WINDOW_ROTATION = RotationInfo.PORTRAIT.id();
+ public static final int DEFAULT_WINDOW_X = 50;
+ public static final int DEFAULT_WINDOW_Y = 50;
+ public static final SkinLogLevel DEFAULT_LOG_LEVEL = SkinLogLevel.DEBUG;
+
public interface ArgsConstants {
public static final String UID = "uid";
public static final String SERVER_PORT = "svr.port";
public static final String LOG_LEVEL = "log.level";
}
- private Map<String,String> args;
+ private Map<String, String> args;
private EmulatorUI dbiContents;
private Properties skinProperties;
private Properties configProperties;
private String skinPropertiesFilePath;
-
+
public EmulatorConfig( Map<String, String> args, EmulatorUI dbiContents, Properties skinProperties,
String skinPropertiesFilePath, Properties configProperties ) {
this.args = args;
this.skinProperties = skinProperties;
this.skinPropertiesFilePath = skinPropertiesFilePath;
this.configProperties = configProperties;
- if( null == configProperties ) {
+ if ( null == configProperties ) {
this.configProperties = new Properties();
}
}
+ public static void validateArgs( Map<String, String> args ) throws ConfigException {
+ if ( null == args ) {
+ return;
+ }
+
+ String uid = args.get( ArgsConstants.UID );
+ try {
+ Integer.parseInt( uid );
+ } catch ( NumberFormatException e ) {
+ String msg = ArgsConstants.UID + " argument is not numeric. : " + uid;
+ throw new ConfigException( msg );
+ }
+
+ String serverPort = args.get( ArgsConstants.SERVER_PORT );
+ try {
+ Integer.parseInt( serverPort );
+ } catch ( NumberFormatException e ) {
+ String msg = ArgsConstants.SERVER_PORT + " argument is not numeric. : " + serverPort;
+ throw new ConfigException( msg );
+ }
+
+ String width = args.get( ArgsConstants.RESOLUTION_WIDTH );
+ try {
+ Integer.parseInt( width );
+ } catch ( NumberFormatException e ) {
+ String msg = ArgsConstants.RESOLUTION_WIDTH + " argument is not numeric. : " + width;
+ throw new ConfigException( msg );
+ }
+
+ String height = args.get( ArgsConstants.RESOLUTION_HEIGHT );
+ try {
+ Integer.parseInt( height );
+ } catch ( NumberFormatException e ) {
+ String msg = ArgsConstants.RESOLUTION_HEIGHT + " argument is not numeric. : " + height;
+ throw new ConfigException( msg );
+ }
+
+ }
+
+ public static void validateSkinProperties( Properties skinProperties ) throws ConfigException {
+ if ( null == skinProperties ) {
+ return;
+ }
+
+ String x = skinProperties.getProperty( SkinPropertiesConstants.WINDOW_X );
+ try {
+ Integer.parseInt( x );
+ } catch ( NumberFormatException e ) {
+ String msg = SkinPropertiesConstants.WINDOW_X + " in .skin.properties is not numeric. : " + x;
+ throw new ConfigException( msg );
+ }
+
+ String y = skinProperties.getProperty( SkinPropertiesConstants.WINDOW_Y );
+ try {
+ Integer.parseInt( y );
+ } catch ( NumberFormatException e ) {
+ String msg = SkinPropertiesConstants.WINDOW_Y + " in .skin.properties is not numeric. : " + y;
+ throw new ConfigException( msg );
+ }
+
+ String rotation = skinProperties.getProperty( SkinPropertiesConstants.WINDOW_ROTATION );
+ try {
+ Integer.parseInt( rotation );
+ } catch ( NumberFormatException e ) {
+ String msg = SkinPropertiesConstants.WINDOW_ROTATION + " in .skin.properties is not numeric. : " + rotation;
+ throw new ConfigException( msg );
+ }
+
+ String scale = skinProperties.getProperty( SkinPropertiesConstants.WINDOW_SCALE );
+ try {
+ Integer.parseInt( scale );
+ } catch ( NumberFormatException e ) {
+ String msg = SkinPropertiesConstants.WINDOW_SCALE + " in .skin.properties is not numeric. : " + scale;
+ throw new ConfigException( msg );
+ }
+
+ }
+
+ public static void validateSkinConfigProperties( Properties skinConfigProperties ) throws ConfigException {
+ if ( null == skinConfigProperties ) {
+ return;
+ }
+ }
+
public void saveSkinProperties() {
File file = new File( skinPropertiesFilePath );
}
}
+ public int getArgInt( String argKey ) {
+ String arg = args.get( argKey );
+ if ( StringUtil.isEmpty( arg ) ) {
+ return 0;
+ }
+ return Integer.parseInt( arg );
+ }
+
+ public int getArgInt( String argKey, int defaultValue ) {
+ String arg = args.get( argKey );
+ if ( StringUtil.isEmpty( arg ) ) {
+ return defaultValue;
+ }
+ return Integer.parseInt( arg );
+ }
+
+ public boolean getArgBoolean( String argKey ) {
+ String arg = args.get( argKey );
+ return Boolean.parseBoolean( arg );
+ }
+
private String getProperty( Properties properties, String key ) {
return properties.getProperty( key );
}
}
// skin properties //
-
+
public String getSkinProperty( String key ) {
return getProperty( skinProperties, key );
}
}
// config properties //
-
+
public String getConfigProperty( String key ) {
return getProperty( configProperties, key );
}
exec = exec.substring( 0, exec.length() - 4 );
}
}
- logger.info( "exec:" + exec );
+
if ( exec.endsWith( "x86" ) ) {
cpu = "X86";
} else if ( exec.endsWith( "arm" ) ) {
if ( "-m".equals( arg ) ) {
ram = split[i + 1].trim();
- logger.info( "ram:" + ram );
} else if ( "-drive".equals( arg ) ) {
result.put( "Name", SkinUtil.getVmName( config ) );
result.put( "CPU", cpu );
- String width = config.getArg( ArgsConstants.RESOLUTION_WIDTH );
- String height = config.getArg( ArgsConstants.RESOLUTION_HEIGHT );
+ int width = config.getArgInt( ArgsConstants.RESOLUTION_WIDTH );
+ int height = config.getArgInt( ArgsConstants.RESOLUTION_HEIGHT );
result.put( "Display Resolution", width + "x" + height );
result.put( "Display Density", dpi );
*
*/
-package org.tizen.emulator.skin;
+package org.tizen.emulator.skin.exception;
/**
*
*
*/
-public interface EmulatorConstants {
-
- public static final int UNKNOWN_KEYCODE = -1;
-
+public class ConfigException extends EmulatorException {
+
+ private static final long serialVersionUID = -1363305002416148505L;
+
+ public ConfigException() {
+ super();
+ }
+
+ public ConfigException( Throwable cause ) {
+ super( cause );
+ }
+
+ public ConfigException( String message ) {
+ super( message );
+ }
+
+ public ConfigException( String message, Throwable cause ) {
+ super( message, cause );
+ }
+
}
this.display = Display.getDefault();
- int lcdWidth = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
- int lcdHeight = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
- this.argSkinPath = (String) config.getArg( ArgsConstants.SKIN_PATH );
+ int lcdWidth = config.getArgInt( ArgsConstants.RESOLUTION_WIDTH );
+ int lcdHeight = config.getArgInt( ArgsConstants.RESOLUTION_HEIGHT );
+ this.argSkinPath = config.getArg( ArgsConstants.SKIN_PATH );
this.resolutionWidth = lcdWidth;
this.resolutionHeight = lcdHeight;
public void dispose() {
- Collection<Image> images = skinImageMap.values();
+ if ( null != skinImageMap ) {
- Iterator<Image> imageIterator = images.iterator();
+ Collection<Image> images = skinImageMap.values();
+
+ Iterator<Image> imageIterator = images.iterator();
+
+ while ( imageIterator.hasNext() ) {
+ Image image = imageIterator.next();
+ image.dispose();
+ }
- while ( imageIterator.hasNext() ) {
- Image image = imageIterator.next();
- image.dispose();
}
- Collection<Image> icons = iconMap.values();
+ if ( null != iconMap ) {
- Iterator<Image> iconIterator = icons.iterator();
+ Collection<Image> icons = iconMap.values();
+
+ Iterator<Image> iconIterator = icons.iterator();
+
+ while ( iconIterator.hasNext() ) {
+ Image image = iconIterator.next();
+ image.dispose();
+ }
- while ( iconIterator.hasNext() ) {
- Image image = iconIterator.next();
- image.dispose();
}
}
this.image.dispose();
}
- int width = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
- int height = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
+ int width = config.getArgInt( ArgsConstants.RESOLUTION_WIDTH );
+ int height = config.getArgInt( ArgsConstants.RESOLUTION_HEIGHT );
ImageData imageData = new ImageData( width, height, COLOR_DEPTH, paletteData, 1, receivedData );
RotationInfo rotation = getCurrentRotation();
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
-import org.tizen.emulator.skin.EmulatorConstants;
import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
+import org.tizen.emulator.skin.comm.ICommunicator.Scale;
import org.tizen.emulator.skin.config.EmulatorConfig;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
*/
public class SkinUtil {
- public static final int DEFAULT_SCALE = 50; // 1/2x
+ public static final int UNKNOWN_KEYCODE = -1;
public static final int SCALE_CONVERTER = 100;
public static final String EMULATOR_PREFIX = "emulator";
vmName = EMULATOR_PREFIX;
}
- String portNumber = StringUtil.nvl( config.getArg( ArgsConstants.NET_BASE_PORT ) );
-
- if ( StringUtil.isEmpty( portNumber ) ) {
- return vmName;
- } else {
- return vmName + ":" + portNumber;
- }
+ int portNumber = config.getArgInt( ArgsConstants.NET_BASE_PORT );
+ return vmName + ":" + portNumber;
}
}
}
- return EmulatorConstants.UNKNOWN_KEYCODE;
+ return UNKNOWN_KEYCODE;
}
public static int getValidScale( EmulatorConfig config ) {
- int storedScale = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_SCALE, DEFAULT_SCALE );
-
+ int storedScale = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_SCALE,
+ EmulatorConfig.DEFAULT_WINDOW_SCALE );
+
if ( !SkinUtil.isValidScale( storedScale ) ) {
- return DEFAULT_SCALE;
+ return EmulatorConfig.DEFAULT_WINDOW_SCALE;
}else {
return storedScale;
}
}
public static boolean isValidScale( int scale ) {
- if ( 100 == scale || 75 == scale || 50 == scale || 25 == scale ) {
+ if ( Scale.SCALE_100.value() == scale || Scale.SCALE_75.value() == scale
+ || Scale.SCALE_50.value() == scale || Scale.SCALE_25.value() == scale ) {
return true;
} else {
return false;