From d70b60f1144692f1af2d635d10cbc5f185441c72 Mon Sep 17 00:00:00 2001 From: "gyeongseok.seo" Date: Mon, 16 Jul 2012 14:19:23 +0900 Subject: [PATCH] [Title] Added sdb demon start up code And Fixed command option getting logic [Type] Enhancement [Module] cli [Priority] Major [Jira#] [Redmine#] 5363 [Problem] sdb wrong operation [Cause] sdb connection time [Solution] waiting connection [TestCase] cli Change-Id: I5d252a9c6852c12ce805bad95a1259fe2ba389c1 --- .../org/tizen/cli/exec/TargetDeviceSelector.java | 32 ++++++++++ .../src/org/tizen/cli/exec/WRTLauncher.java | 74 +++++++++++++++++++--- .../src/org/tizen/cli/exec/install/Main.java | 7 +- .../src/org/tizen/cli/exec/query/Main.java | 5 +- .../tizen/cli/exec/TargetDeviceSelectorTest.java | 2 +- 5 files changed, 108 insertions(+), 12 deletions(-) diff --git a/org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java b/org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java index 37f721d..4116f6e 100644 --- a/org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java +++ b/org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java @@ -34,6 +34,7 @@ import org.tizen.common.util.ArrayUtil; import org.tizen.sdblib.IDevice; + /** * common class for WRT command * @@ -44,9 +45,19 @@ public class TargetDeviceSelector { protected Prompter prompter; + protected int sdbtime; + + public int getSdbtime() { + return sdbtime; + } + + public void setSdbtime(int sdbtime) { + this.sdbtime = sdbtime; + } public TargetDeviceSelector(Prompter prompter) { this.prompter = prompter; + this.sdbtime = 3000; } protected SmartDevelopmentBridgeManager createSDBManager() { @@ -54,6 +65,7 @@ TargetDeviceSelector } protected void printDeviceList( IDevice[] devices ) { + prompter.notify( "-----------------------------\n" ); prompter.notify( "currnet connected target List\n" ); prompter.notify( "-----------------------------\n" ); for( int i = 0; i < devices.length; i++ ) { @@ -63,6 +75,22 @@ TargetDeviceSelector public IDevice[] getConnectDevices() { SmartDevelopmentBridgeManager mgr = createSDBManager(); + + int waitTime = getSdbtime(); + while ( !mgr.isConnected() ) { + try { + Thread.sleep( 100 ); + waitTime -= 100; + + if ( waitTime <= 0 ) { + prompter.notify( "SDB can't started" ); + return null; + } + } catch (InterruptedException e) { + prompter.notify( e.getMessage() ); + } + } + return mgr.getDevices(); } @@ -105,6 +133,7 @@ TargetDeviceSelector } if ( devices.length == 1 ) { + prompter.notify( "Select Device is : " + ArrayUtil.pickupFirst( devices ).toString() ); selectDevice = ArrayUtil.pickupFirst( devices ); } else if ( devices.length > 1 ) { Option yes = new Option( "Yes" ); @@ -135,6 +164,9 @@ TargetDeviceSelector prompter.notify( "Process is canceled, please selected device" ); } else { + int index = Integer.parseInt( op.getName() ); + prompter.notify( "select : " + op.getName() ); + selectDevice = ArrayUtil.get( devices, index-1 ); // TODO : Needed implement - select device using option value } } diff --git a/org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java b/org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java index cd68d0a..5cff177 100644 --- a/org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java +++ b/org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java @@ -30,9 +30,15 @@ import java.util.List; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; +import org.tizen.common.core.application.InstallPathConfig; import org.tizen.common.core.command.ExecutionContext; import org.tizen.common.core.command.Prompter; +import org.tizen.common.util.HostUtil; +import org.tizen.common.util.OSChecker; +import org.tizen.common.util.StringUtil; +import org.tizen.common.util.log.Logger; import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.SmartDevelopmentBridge; /** *

@@ -70,6 +76,24 @@ extends AbstractLauncher /** *

+ * Option for sdb demon connection wating time + *

+ */ + protected static final String OPT_SDBTIME = "sdb"; + + /** + *

+ * Description for sdb daemon connection wating time + * + * This is printed out in usage + *

+ * + * @see #OPT_SDBTIME + */ + protected static final String DESC_SDBTIME = "sdb daemon connection wating time (sec)"; + + /** + *

* Target device * * command is running in this device @@ -107,38 +131,70 @@ extends AbstractLauncher { final Options opts = super.getOptions(); opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_DEVICE ).withDescription( DESC_DEVICE ).create( OPT_DEVICE.substring( 0, 1 ) ) ); + opts.addOption( OptionBuilder.hasOptionalArg().withLongOpt( OPT_SDBTIME ).withDescription( DESC_SDBTIME ).create( OPT_SDBTIME.substring( 0, 1 ) ) ); return opts; } + protected void startSDB() { + final Prompter prompter = getPrompter(); + String sdbPath = InstallPathConfig.getSDBPath(); + logger.trace( "sdb lib Path :{}", sdbPath ); + + try { + SmartDevelopmentBridge.init(); + SmartDevelopmentBridge.createBridge(sdbPath, true); + } catch (Throwable t) { + Logger.error("Problem occurred while initializing sdb", t.getMessage(), t); + prompter.notify("Failed to start sdb"); + } + + if (OSChecker.isWindows()) { + String dllPath = InstallPathConfig.getSdbWinUsbApiPath(); + if (!HostUtil.exists(dllPath)) + prompter.notify("There is no " + dllPath + ".\n" + + "It's not mandatory but you may have problem in using sdb through USB."); + } + } + @SuppressWarnings("static-access") + protected void endSDB() { + SmartDevelopmentBridge.getBridge().terminate(); + } + /* (non-Javadoc) * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine) */ @Override @SuppressWarnings("unchecked") protected void execute(CommandLine cmdLine) throws Exception { + startSDB(); final Prompter prompter = getPrompter(); final List args = cmdLine.getArgList(); final TargetDeviceSelector deviceSelector = new TargetDeviceSelector(prompter); + String sdbtime = cmdLine.getOptionValue( OPT_SDBTIME ); + logger.trace( "sdb waiting time :{}", sdbtime ); + if ( !StringUtil.isEmpty( sdbtime ) ) { + deviceSelector.setSdbtime( Integer.parseInt(sdbtime)*1000 ); + } logger.trace( "arguments :{}", args ); logger.trace("check connected devices"); if ( !deviceSelector.isDeviceConnected() ) { prompter.notify( "Device is not connected. Process is canceled" ); + endSDB(); return ; } - int nArgs = args.size(); - // user using device select option - if ( nArgs > 0 ) { - // user select device check - String deviceName = cmdLine.getOptionValue( OPT_DEVICE ); - logger.debug( "Device option :{}", deviceName ); + String deviceName = cmdLine.getOptionValue( OPT_DEVICE ); + logger.trace( "Device option :{}", deviceName ); + if ( !StringUtil.isEmpty( deviceName ) ) { setDevice( deviceSelector.getDevice( deviceName ) ); - } - // user not using device select option - else if ( nArgs == 0 ) { + if ( getDevice() == null ) { + prompter.notify( "Process is stoped, please select connect device" ); + } + } else { + // user not using device select option logger.trace( "user can't use device select option" ); setDevice( deviceSelector.selectDevice() ); } diff --git a/org.tizen.cli/src/org/tizen/cli/exec/install/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/install/Main.java index 7cff754..7a6c36c 100644 --- a/org.tizen.cli/src/org/tizen/cli/exec/install/Main.java +++ b/org.tizen.cli/src/org/tizen/cli/exec/install/Main.java @@ -107,11 +107,14 @@ extends WRTLauncher // local widget file path control String localWidgetFileName = cmdLine.getOptionValue( OPT_WIDGETFILE ); String localWidgetFilePath = (String)fileHandler.get( localWidgetFileName, Attribute.PATH ); + logger.trace( localWidgetFilePath ); // core operation InstallCommand install_command = new InstallCommand(); + install_command.setWidget( localWidgetFileName ); install_command.setDevice( getDevice() ); - String remotePath = install_command.getRemotePath(); + String remotePath = install_command.getRemotePath() + localWidgetFileName; + logger.trace( remotePath ); PushSdbCommand push_command = new PushSdbCommand( localWidgetFilePath, remotePath ); push_command.setDevice( getDevice() ); @@ -120,6 +123,8 @@ extends WRTLauncher getExecutor().execute( push_command ); // widget install getExecutor().execute( install_command ); + + endSDB(); } /* (non-Javadoc) diff --git a/org.tizen.cli/src/org/tizen/cli/exec/query/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/query/Main.java index 0c85455..9bdd8ff 100644 --- a/org.tizen.cli/src/org/tizen/cli/exec/query/Main.java +++ b/org.tizen.cli/src/org/tizen/cli/exec/query/Main.java @@ -76,7 +76,7 @@ extends WRTLauncher // device not connect then exit if ( getDevice() == null ) { - prompter.notify( "Process is stoped, please select connect device" ); + endSDB(); return ; } @@ -84,5 +84,8 @@ extends WRTLauncher QueryCommand command = new QueryCommand(); command.setDevice( getDevice() ); getExecutor().execute( command ); + prompter.notify( command.getResult() ); + + endSDB(); } } diff --git a/org.tizen.cli/test/src/org/tizen/cli/exec/TargetDeviceSelectorTest.java b/org.tizen.cli/test/src/org/tizen/cli/exec/TargetDeviceSelectorTest.java index e616a19..847625a 100644 --- a/org.tizen.cli/test/src/org/tizen/cli/exec/TargetDeviceSelectorTest.java +++ b/org.tizen.cli/test/src/org/tizen/cli/exec/TargetDeviceSelectorTest.java @@ -113,7 +113,6 @@ TargetDeviceSelectorTest { try { testClass.printDeviceList( mockDevices ); - verify( mockPropter ).notify( "-----------------------------\n" ); verify( mockPropter ).notify( "currnet connected target List\n" ); verify( mockPropter ).notify( "1) test1\n" ); verify( mockPropter ).notify( "2) test2\n" ); @@ -125,6 +124,7 @@ TargetDeviceSelectorTest testClass.printDeviceList( null ); verify( mockPropter ).notify( "-----------------------------\n" ); verify( mockPropter ).notify( "currnet connected target List\n" ); + verify( mockPropter ).notify( "-----------------------------\n" ); fail( "devices is null then throw exception" ); } catch (Exception e) {} } -- 2.7.4