import java.util.Map.Entry;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DragDetectEvent;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
-import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
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.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.dbi.RotationType;
import org.tizen.emulator.skin.image.ImageRegistry;
import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
+import org.tizen.emulator.skin.log.SkinLogger;
import org.tizen.emulator.skin.util.SkinRegion;
import org.tizen.emulator.skin.util.SkinRotation;
import org.tizen.emulator.skin.util.SkinRotation.RotationInfo;
*/
public class EmulatorSkin {
- private static final int GHOST_SHELL_MARGIN = 10000;
+ private Logger logger = SkinLogger.getSkinLogger( EmulatorSkin.class ).getLogger();
private EmulatorConfig config;
private Shell shell;
public int compose() {
- //TODO resolution
imageRegistry = new ImageRegistry( shell.getDisplay(), config );
shell.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_BLACK ) );
String emulatorName = config.getArg( ArgsConstants.EMULATOR_NAME );
shell.setText( emulatorName );
- this.lcdCanvas = new Canvas( shell, SWT.EMBEDDED );
+ this.lcdCanvas = new Canvas( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
lcdCanvas.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_BLACK ) );
-
+
int lcdWidth = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
int lcdHeight = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
try {
Field field = lcdCanvas.getClass().getField( "embeddedHandle" );
windowHandleId = field.getInt( lcdCanvas );
- System.out.println( "lcdCanvas.embeddedHandle:" + windowHandleId );
+ logger.info( "lcdCanvas.embeddedHandle:" + windowHandleId );
} catch ( IllegalArgumentException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
return windowHandleId;
} catch ( IllegalAccessException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
return windowHandleId;
} catch ( SecurityException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
return windowHandleId;
} catch ( NoSuchFieldException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
return windowHandleId;
}
}else if( "win32".equalsIgnoreCase( platform ) ) {
- System.out.println( "lcdCanvas.handle:" + lcdCanvas.handle );
+ logger.info( "lcdCanvas.handle:" + lcdCanvas.handle );
windowHandleId = lcdCanvas.handle;
}else if( "cocoa".equalsIgnoreCase( platform ) ) {
//TODO
}else {
- System.out.println( "Not Supported OS platform:" + platform );
+ logger.severe( "Not Supported OS platform:" + platform );
System.exit( -1 );
}
-
+
addLCDListener( lcdCanvas );
addShellListener( shell );
public void open() {
if ( null == this.communicator ) {
- System.out.println( "communicator is null." );
+ logger.severe( "communicator is null." );
shell.close();
return;
}
}
- private void setGhostShellLocation() {
- Rectangle clientArea = Display.getCurrent().getClientArea();
- int monitorWidth = clientArea.width;
- int monitorHeight = clientArea.height;
- }
-
private void addShellListener( final Shell shell ) {
shell.addListener( SWT.Close, new Listener() {
}
} );
- shell.addListener( SWT.Activate, new Listener() {
- @Override
- public void handleEvent( Event event ) {
- // ghostShell show at main shell loction suddenly in activate main shell. Relocate the ghostShell.
- setGhostShellLocation();
- }
- } );
-
- shell.addListener( SWT.Deactivate, new Listener() {
- @Override
- public void handleEvent( Event event ) {
- // ghostShell show at main shell loction suddenly in deactivate main shell. Relocate the ghostShell.
- setGhostShellLocation();
- }
- } );
-
shell.addPaintListener( new PaintListener() {
@Override
@Override
public void mouseUp( MouseEvent e ) {
if ( 1 == e.button ) { // left button
- System.out.println( "mouseUp in Skin" );
+ logger.info( "mouseUp in Skin" );
EmulatorSkin.this.pressedMouseX = 0;
EmulatorSkin.this.pressedMouseY = 0;
EmulatorSkin.this.isMousePressed = false;
@Override
public void mouseDown( MouseEvent e ) {
if ( 1 == e.button ) { // left button
- System.out.println( "mouseDown in Skin" );
+ logger.info( "mouseDown in Skin" );
EmulatorSkin.this.pressedMouseX = e.x;
EmulatorSkin.this.pressedMouseY = e.y;
@Override
public void dragDetected( DragDetectEvent e ) {
- System.out.println( "dragDetected e.button:" + e.button );
+ logger.fine( "dragDetected e.button:" + e.button );
if ( 1 == e.button && // left button
e.x > 0 && e.x < canvas.getSize().x && e.y > 0 && e.y < canvas.getSize().y ) {
- System.out.println( "dragDetected in LCD" );
+ logger.fine( "dragDetected in LCD" );
EmulatorSkin.this.isDragStartedInLCD = true;
}
if ( 1 == e.button ) { // left button
int[] geometry = convertMouseGeometry( e.x, e.y );
- System.out.println( "mouseUp in LCD" + " x:" + geometry[0] + " y:" + geometry[1] );
+ logger.info( "mouseUp in LCD" + " x:" + geometry[0] + " y:" + geometry[1] );
MouseEventData mouseEventData = new MouseEventData( MouseEventType.UP.value(), geometry[0],
geometry[1], 0 );
communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData );
public void mouseDown( MouseEvent e ) {
if ( 1 == e.button ) { // left button
int[] geometry = convertMouseGeometry( e.x, e.y );
- System.out.println( "mouseDown in LCD" + " x:" + geometry[0] + " y:" + geometry[1] );
+ logger.info( "mouseDown in LCD" + " x:" + geometry[0] + " y:" + geometry[1] );
MouseEventData mouseEventData = new MouseEventData( MouseEventType.DOWN.value(), geometry[0],
geometry[1], 0 );
communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData );
@Override
public void keyReleased( KeyEvent e ) {
- System.out.println( "key released. key event:" + e );
+ logger.info( "key released. key event:" + e );
int keyCode = e.keyCode;
KeyEventData keyEventData = new KeyEventData( KeyEventType.RELEASED.value(), keyCode );
@Override
public void keyPressed( KeyEvent e ) {
- System.out.println( "key pressed. key event:" + e );
+ logger.info( "key pressed. key event:" + e );
int keyCode = e.keyCode;
KeyEventData keyEventData = new KeyEventData( KeyEventType.PRESSED.value(), keyCode );
communicator.sendToQEMU( SendCommand.SEND_KEY_EVENT, keyEventData );
String emulatorName = config.getArg( ArgsConstants.EMULATOR_NAME );
infoItem.setText( emulatorName );
+ //FIXME
+ infoItem.setEnabled( false );
infoItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
- System.out.println( "Selected Info." );
- //TODO
- MessageBox messageBox = new MessageBox( shell, SWT.OK | SWT.APPLICATION_MODAL );
- messageBox.setMessage( "Under construction..." );
- messageBox.open();
+ logger.fine( "Selected Info." );
}
} );
final MenuItem aotItem = new MenuItem( menu, SWT.CHECK );
aotItem.setText( "Always On Top" );
+ //FIXME
+ aotItem.setEnabled( false );
aotItem.addSelectionListener( new SelectionAdapter() {
private boolean isTop;
@Override
public void widgetSelected( SelectionEvent e ) {
- System.out.println( "Selected Always On Top." );
+ logger.fine( "Selected Always On Top." );
isTop = !isTop;
-
//TODO
- MessageBox messageBox = new MessageBox( shell, SWT.OK | SWT.APPLICATION_MODAL );
- messageBox.setMessage( "Under construction..." );
- messageBox.open();
-
}
} );
Menu advancedMenu = createAdvancedMenu( menu.getShell() );
advancedItem.setMenu( advancedMenu );
- final MenuItem shellItem = new MenuItem( menu, SWT.PUSH );
- shellItem.setText( "Shell" );
- shellItem.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( SelectionEvent e ) {
- try {
- //TODO
- new ProcessBuilder("/usr/bin/gnome-terminal", "--disable-factory", "-x",
- "ssh", "-p", "1202", "root@localhost").start();
- /*new ProcessBuilder("/usr/bin/gnome-terminal", "--disable-factory", "-x",
- "sdb", "shell").start();*/
- } catch (Exception e2) {
- //TODO
- }
-
- communicator.sendToQEMU( SendCommand.OPEN_SHELL, null );
- }
- } );
-
- new MenuItem( menu, SWT.SEPARATOR );
+// final MenuItem shellItem = new MenuItem( menu, SWT.PUSH );
+// shellItem.setText( "Shell" );
+// shellItem.addSelectionListener( new SelectionAdapter() {
+// @Override
+// public void widgetSelected( SelectionEvent e ) {
+// try {
+// //TODO
+// new ProcessBuilder("/usr/bin/gnome-terminal", "--disable-factory", "-x",
+// "ssh", "-p", "1202", "root@localhost").start();
+// /*new ProcessBuilder("/usr/bin/gnome-terminal", "--disable-factory", "-x",
+// "sdb", "shell").start();*/
+// } catch (Exception e2) {
+// //TODO
+// }
+//
+// communicator.sendToQEMU( SendCommand.OPEN_SHELL, null );
+// }
+// } );
+//
+// new MenuItem( menu, SWT.SEPARATOR );
MenuItem closeItem = new MenuItem( menu, SWT.PUSH );
closeItem.setText( "Close" );
final MenuItem screenshotItem = new MenuItem( menu, SWT.PUSH );
screenshotItem.setText( "Screen Shot" );
-
+ //FIXME
+ screenshotItem.setEnabled( false );
+
screenshotItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
-
- //TODO
- MessageBox messageBox = new MessageBox( shell, SWT.OK | SWT.APPLICATION_MODAL );
- messageBox.setMessage( "Under construction..." );
- messageBox.open();
// Display display = shell.getDisplay();
// final Image image = new Image( display, lcdCanvas.getBounds() );
final MenuItem usbOffItem = new MenuItem( usbKeyBoardMenu, SWT.RADIO );
usbOffItem.setText( "Off" );
usbOffItem.setSelection( true );
-
+
SelectionAdapter usbSelectionAdaptor = new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
final MenuItem aboutItem = new MenuItem( menu, SWT.PUSH );
aboutItem.setText( "About" );
+ aboutItem.setEnabled( false );
aboutItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
// TODO
- MessageBox messageBox = new MessageBox( shell, SWT.OK | SWT.APPLICATION_MODAL );
- messageBox.setText( "About" );
- messageBox.setMessage( "Under construction..." );
- messageBox.open();
}
} );
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
import org.tizen.emulator.skin.config.EmulatorConfig;
import org.tizen.emulator.skin.dbi.EmulatorUI;
import org.tizen.emulator.skin.exception.JaxbException;
import org.tizen.emulator.skin.image.ImageRegistry;
+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.JaxbUtil;
-
-
+import org.tizen.emulator.skin.util.StringUtil;
/**
*
*
*/
public class EmulatorSkinMain {
-
+
+ private static Logger logger;
+
public static final String PROPERTIES_FILE_NAME = ".skin.properties";
public static final String DBI_FILE_NAME = "default.dbi";
-
+
/**
* @param args
*/
public static void main( String[] args ) {
+ initLog( args );
+
Map<String, String> argsMap = parsArgs( args );
int lcdWidth = Integer.parseInt( argsMap.get( ArgsConstants.RESOLUTION_WIDTH ) );
int lcdHeight = Integer.parseInt( argsMap.get( ArgsConstants.RESOLUTION_HEIGHT ) );
EmulatorUI dbiContents = loadDbi( lcdWidth, lcdHeight );
if ( null == dbiContents ) {
- System.out.println( "Fail to load dbi file." );
+ logger.severe( "Fail to load dbi file." );
return;
}
String propFilePath = vmPath + File.separator + PROPERTIES_FILE_NAME;
Properties properties = loadProperties( propFilePath );
if ( null == properties ) {
- System.out.println( "Fail to load properties file." );
+ logger.severe( "Fail to load properties file." );
return;
}
skin.open();
} else {
- System.out.println( "CommSocket is null." );
+ logger.severe( "CommSocket is null." );
}
}
+ private static void initLog( String[] args ) {
+
+ String logLevel = "";
+ for ( int i = 0; i < args.length; i++ ) {
+ String[] split = args[i].split( "=" );
+ if ( split[0].trim().equalsIgnoreCase( ArgsConstants.LOG_LEVEL ) ) {
+ if ( !StringUtil.isEmpty( split[1].trim() ) ) {
+ logLevel = split[1];
+ break;
+ }
+ }
+ }
+
+ SkinLogLevel skinLogLevel = SkinLogLevel.DEBUG;
+
+ if( !StringUtil.isEmpty( logLevel ) ) {
+ SkinLogLevel[] values = SkinLogLevel.values();
+ for ( SkinLogLevel level : values ) {
+ if ( level.value().equalsIgnoreCase( logLevel ) ) {
+ skinLogLevel = level;
+ break;
+ }
+ }
+ }
+
+ SkinLogger.init( skinLogLevel );
+ logger = SkinLogger.getSkinLogger( EmulatorSkinMain.class ).getLogger();
+
+ }
+
private static Map<String, String> parsArgs( String[] args ) {
Map<String, String> map = new HashMap<String, String>();
- // TODO parse
for ( int i = 0; i < args.length; i++ ) {
String arg = args[i];
- System.out.println( "arg[" + i + "] " + arg );
+ logger.info( "arg[" + i + "] " + arg );
String[] split = arg.split( "=" );
if ( 1 < split.length ) {
- String argKey = split[0];
- String argValue = split[1];
- System.out.println( "argKey:" + argKey + " argValue:" + argValue );
+ String argKey = split[0].trim();
+ String argValue = split[1].trim();
+ logger.info( "argKey:" + argKey + " argValue:" + argValue );
map.put( argKey, argValue );
} else {
- System.out.println( "one argv:" + arg );
+ logger.info( "one argv:" + arg );
}
}
map.put( ArgsConstants.EMULATOR_NAME, "emulator-26100" );
-
- System.out.println( "========================================");
- System.out.println( "args:" + map );
- System.out.println( "========================================");
-
+
+ logger.info( "========================================" );
+ logger.info( "args:" + map );
+ logger.info( "========================================" );
+
return map;
}
private static EmulatorUI loadDbi( int lcdWidth, int lcdHeight ) {
String skinPath = ImageRegistry.getSkinPath( lcdWidth, lcdHeight ) + File.separator + DBI_FILE_NAME;
-
+
FileInputStream fis = null;
EmulatorUI emulatorUI = null;
try {
fis = new FileInputStream( skinPath );
-
+
emulatorUI = JaxbUtil.unmarshal( fis, EmulatorUI.class );
- // XXX
fis = new FileInputStream( skinPath );
- System.out.println( "============ dbi contents ============" );
+ logger.info( "============ dbi contents ============" );
byte[] bytes = IOUtil.getBytes( fis );
- System.out.println( new String( bytes, "UTF-8" ) );
- System.out.println( "=======================================" );
+ logger.info( new String( bytes, "UTF-8" ) );
+ logger.info( "=======================================" );
} catch ( IOException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
} catch ( JaxbException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
} finally {
IOUtil.close( fis );
}
File file = new File( filePath );
if ( !file.exists() ) {
if ( !file.createNewFile() ) {
- System.out.println( "Fail to create new " + filePath + " property file." );
+ logger.severe( "Fail to create new " + filePath + " property file." );
return null;
}
}
properties.load( fis );
} catch ( IOException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
} finally {
IOUtil.close( fis );
}
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.tizen.emulator.skin.EmulatorConstants;
import org.tizen.emulator.skin.EmulatorSkin;
import org.tizen.emulator.skin.config.EmulatorConfig;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
import org.tizen.emulator.skin.config.EmulatorConfig.PropertiesConstants;
+import org.tizen.emulator.skin.log.SkinLogger;
import org.tizen.emulator.skin.util.IOUtil;
*/
public class SocketCommunicator implements ICommunicator {
+ private Logger logger = SkinLogger.getSkinLogger( SocketCommunicator.class ).getLogger();
+
private EmulatorConfig config;
private int uId;
private int windowHandleId;
String portString = config.getArg(ArgsConstants.SERVER_PORT);
int port = Integer.parseInt(portString);
socket = new Socket("127.0.0.1", port);
- System.out.println("socket.isConnected():" + socket.isConnected());
+ logger.info("socket.isConnected():" + socket.isConnected());
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
} catch (IOException e) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
}
}
scale, rotation));
} catch (IOException e) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
terminate();
return;
}
Boolean ignoreHeartbeat = Boolean.parseBoolean( ignoreHeartbeatString );
if( ignoreHeartbeat ) {
- System.out.println( "Ignore Skin heartbeat." );
+ logger.info( "Ignore Skin heartbeat." );
}else {
heartbeatExecutor.scheduleAtFixedRate(new Runnable() {
int reqId = dis.readInt();
short cmd = dis.readShort();
- System.out.print( "= Socket read - reqId:" + reqId + ", command:" + cmd + ", " );
+ logger.fine( "Socket read - reqId:" + reqId + ", command:" + cmd + ", " );
ReceiveCommand command = null;
try {
command = ReceiveCommand.getValue( cmd );
} catch ( IllegalArgumentException e ) {
- System.out.println( "unknown command:" + cmd );
+ logger.severe( "unknown command:" + cmd );
continue;
}
switch ( command ) {
case HEART_BEAT:
resetHeartbeatCount();
- System.out.println( "received HEAR_BEAT from QEMU." );
+ logger.info( "received HEAR_BEAT from QEMU." );
sendToQEMU( SendCommand.RESPONSE_HEART_BEAT, null );
break;
case SENSOR_DAEMON_START:
- System.out.println( "received SENSOR_DAEMON_START from QEMU." );
+ logger.info( "received SENSOR_DAEMON_START from QEMU." );
synchronized ( this ) {
isSensorDaemonStarted = true;
}
}
} catch ( IOException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
break;
}
dos.write(bao.toByteArray());
dos.flush();
- System.out.println("= Socket write - uid:" + uId + ", reqId:" + reqId +
- ", command:" + command.value() + " - " + command.toString() + ", length:" + length );
+ logger.fine( "Socket write - uid:" + uId + ", reqId:" + reqId + ", command:" + command.value() + " - "
+ + command.toString() + ", length:" + length );
- if (0 < length) {
- System.out.println("== data ==");
- System.out.println(data);
+ if ( 0 < length ) {
+ logger.fine( "== data ==" );
+ logger.fine( data.toString() );
}
- } catch (IOException e) {
- System.err.println("Fail to write socket.");
- e.printStackTrace();
+ } catch ( IOException e ) {
+ logger.log( Level.SEVERE, e.getMessage(), e );
}
}
private void increaseHeartbeatCount() {
int count = heartbeatCount.incrementAndGet();
- System.out.println("HB count : " + count);
+ logger.fine("HB count : " + count);
}
private boolean isHeartbeatExpired() {
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.tizen.emulator.skin.dbi.EmulatorUI;
+import org.tizen.emulator.skin.log.SkinLogger;
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 interface ArgsConstants {
- //TODO change as input args
public static final String UID = "uid";
public static final String SERVER_PORT = "svr.port";
public static final String RESOLUTION_WIDTH = "width";
public static final String EMULATOR_NAME = "emulname";
public static final String TEST_HEART_BEAT_IGNORE = "test.hb.ignore";
public static final String VM_PATH = "vm.path";
+ public static final String LOG_LEVEL = "log.level";
}
public interface PropertiesConstants {
properties.store( fos, "Generated automatically by emulator." );
} catch ( IOException e ) {
- e.printStackTrace();
+ logger.log( Level.SEVERE, e.getMessage(), e );
} finally {
IOUtil.close( fos );
}
--- /dev/null
+/**
+ *
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyunjun Son <hj79.son@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.log;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.FileHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+
+/**
+ *
+ *
+ */
+public class SkinLogger {
+
+ public enum SkinLogLevel {
+
+ ERROR(Level.SEVERE, "error"),
+ WARN(Level.WARNING, "warn"),
+ DEBUG(Level.INFO, "debug"),
+ TRACE(Level.FINE, "trace");
+
+ private Level level;
+ private String value;
+ private SkinLogLevel( Level level, String value ) {
+ this.level = level;
+ this.value = value;
+ }
+ public Level level() {
+ return this.level;
+ }
+ public String value() {
+ return this.value;
+ }
+ }
+
+ private static final String FILE_NAME = "emulator-skin.log";
+
+ private static FileHandler fileHandler;
+ private static boolean isInit;
+ private static Map<Class<?>, SkinLogger> loggerMap = new HashMap<Class<?>, SkinLogger>();
+
+ private Logger logger;
+
+ private SkinLogger( Logger logger ) {
+ this.logger = logger;
+ }
+
+ public Logger getLogger() {
+ return this.logger;
+ }
+
+ public static void init( SkinLogLevel logLevel ) {
+
+ if( !isInit ) {
+
+ isInit = true;
+
+ try {
+ fileHandler = new FileHandler( FILE_NAME, false );
+ } catch ( SecurityException e1 ) {
+ e1.printStackTrace();
+ } catch ( IOException e1 ) {
+ e1.printStackTrace();
+ }
+
+ try {
+ fileHandler.setEncoding( "UTF-8" );
+ } catch ( SecurityException e ) {
+ e.printStackTrace();
+ } catch ( UnsupportedEncodingException e ) {
+ e.printStackTrace();
+ }
+
+ SimpleFormatter simpleFormatter = new SimpleFormatter();
+ fileHandler.setFormatter( simpleFormatter );
+
+ fileHandler.setLevel( logLevel.level() );
+
+ }
+
+ }
+
+ public static <T> SkinLogger getSkinLogger( Class<T> clazz ) {
+
+ String name = null;
+
+ if( null == clazz ) {
+ name = SkinLogger.class.getSimpleName();
+ }else {
+ name = clazz.getSimpleName();
+ }
+
+ SkinLogger skinLogger = loggerMap.get( clazz );
+
+ if( null != skinLogger ) {
+ return skinLogger;
+ }else {
+
+ Logger logger = Logger.getLogger( name );
+ logger.addHandler( fileHandler );
+ logger.setLevel( fileHandler.getLevel() );
+ logger.setUseParentHandlers( false );
+
+ SkinLogger sLogger = new SkinLogger( logger );
+ loggerMap.put( clazz, sLogger );
+
+ return sLogger;
+
+ }
+
+ }
+
+}