import org.tizen.sdblib.IDevice;
+
/**
* common class for WRT command
*
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() {
}
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++ ) {
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();
}
}
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" );
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
}
}
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;
/**
* <p>
/**
* <p>
+ * Option for sdb demon connection wating time
+ * </p>
+ */
+ protected static final String OPT_SDBTIME = "sdb";
+
+ /**
+ * <p>
+ * Description for sdb daemon connection wating time
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_SDBTIME
+ */
+ protected static final String DESC_SDBTIME = "sdb daemon connection wating time (sec)";
+
+ /**
+ * <p>
* Target device
*
* command is running in this device
{
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<String> 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() );
}
// 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() );
getExecutor().execute( push_command );
// widget install
getExecutor().execute( install_command );
+
+ endSDB();
}
/* (non-Javadoc)