/**
* Selects application by its name.
*
- * @param application name
- * @return <code>true</code> on success
+ * @param application name.
+ * @return {@link ErrorCode#SUCCESS} if application has been selected
+ * successfully. Otherwise ErrorCode showing error occurred during
+ * application selection will be returned.
*/
- public static boolean selectApp(String appName) {
+ public static ErrorCode selectApp(String appName) {
DeviceInfo devInfo = Global.getCurrentDeviceInfo();
if (devInfo == null) {
Logger.warning("DA failed to set device for " + appName + " application");
- return false;
+ return ErrorCode.ERR_NO_DEVICE;
}
DACommunicator.updateAppListFromTarget();
PackageInfo pkgInfo = devInfo.getPkgInfoByLabel(appName);
if (pkgInfo == null) {
Logger.warning("DA failed to set application " + appName);
- return false;
+ return ErrorCode.ERR_NO_APP;
}
Global.setCurrentApplication(pkgInfo);
List<String> binPaths = pkgInfo.getProcessInformation();
- pkgInfo.getBinaryInformation(binPaths);
- if (!pkgInfo.isPossibleToTrace()) {
+ ErrorCode code = pkgInfo.getBinaryInformation(binPaths);
+ if (code != ErrorCode.SUCCESS) {
Logger.warning("DA is not able to trace application " + appName);
- return false;
+ return code;
}
devInfo.setSelectedPackageLabel(appName);
- return true;
+ return ErrorCode.SUCCESS;
}
/**
*
* @param args tracing arguments
* @return {@link ErrorCode#SUCCESS} if tracing started successfully, <br/>
- * {@link ErrorCode#ERR_NO_DEVICE} if couldn't select requested device, <br/>
- * {@link ErrorCode#ERR_NO_APP} if couldn't select requested application, <br/>
- * {@link ErrorCode#ERR_EXCEPTION_OCCURRED} if couldn't select requested template.
+ * Otherwise ErrorCode showing error occurred during start tracing
+ * process will be returned.
*/
public static ErrorCode startTracing(TracingArguments args) {
Logger.info("Starting tracing...");
}
Logger.debug("Set current device: " + args.getDevice());
- if (!selectApp(args.getApplication())) {
+ ErrorCode code;
+ if ((code = selectApp(args.getApplication())) != ErrorCode.SUCCESS) {
Logger.debug("Failed to select application");
- return ErrorCode.ERR_NO_APP;
+ return code;
}
Logger.debug("Set current app: " + args.getApplication());
package org.tizen.dynamicanalyzer.cli.commands;
-import java.io.File;
import java.rmi.ConnectException;
import org.tizen.dynamicanalyzer.cli.CliInternals;
import org.tizen.dynamicanalyzer.cli.manager.TracingProcessContext;
import org.tizen.dynamicanalyzer.cli.utils.HumanReadableTimeFormat;
import org.tizen.dynamicanalyzer.common.DAResult;
-import org.tizen.dynamicanalyzer.common.path.PathManager;
-import org.tizen.dynamicanalyzer.handlers.CommandAction;
-import org.tizen.dynamicanalyzer.project.Project;
+import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode;
public class StopCommand extends Command {
return ExitCode.EX_OPERATION_FAILED;
}
+ if (ctx.isFinished()) {
+ ErrorCode code = ErrorCode.getErrorCode(ctx.getErrCode());
+ if (code != null)
+ System.out.println("Tracing on device failed due to:\n"
+ + code.getErrorMessage());
+ else
+ System.out
+ .println("Tracing on device failed due to unknown reason.");
+ return ExitCode.EX_OPERATION_FAILED;
+ }
+
// if process not finished yet then stop it
if (!ctx.isFinished()) {
result = CliInternals.stopTracingProcess(device);
case INFO_TRACING_TIME:
tracingTime = Long.parseLong(message.args[0]);
break;
+ case ERROR_OCCURED:
+ ctx.finishContext(Integer.parseInt(message.args[0]));
+ break;
// Wrong requests
case REQUEST_TRACING_TIME:
case STOP_TRACING:
*/
public synchronized ErrorCode startTrace() {
ErrorCode result = CliInternals.startTracing(args);
+ if (result != ErrorCode.SUCCESS) {
+ socketConnection.sendMessage(MessageType.ERROR_OCCURED, Integer.toString(result.getErrorNumber()));
+ return result;
+ }
// Block until StartTraceManager thread starts all needed jobs
try {
DAState.waitPrepared();
public synchronized void stopTrace() {
tracingTime = System.currentTimeMillis() - startTime;
Global.getProject().setTotalStopTime(tracingTime);
- try {
socketConnection.sendMessage(MessageType.INFO_TRACING_TIME,
Long.toString(tracingTime));
- } catch (IOException e) {
- Logger.error("Got Exception while sending tracing time to TracingProcessManager");
- }
CliInternals.stopTracing();
}
* @param message message to socket
* @throws IOException in case of communication error
*/
- public void sendMessage(Message message) throws IOException{
- oos.writeObject(message);
- oos.flush();
+ public void sendMessage(Message message) {
+ try {
+ oos.writeObject(message);
+ oos.flush();
+ } catch (IOException e) {
+ Logger.error("Got Exception while sending message to TracingProcessManager");
+ }
}
/**
* @param args message arguments
* @throws IOException in case of communication error
*/
- public void sendMessage(MessageType messageT, String... args)
- throws IOException {
+ public void sendMessage(MessageType messageT, String... args) {
sendMessage(new Message(messageT, args));
}
/**
STOP_TRACING,
STOP_DONE,
INFO_TRACING_TIME,
- REQUEST_TRACING_TIME
+ REQUEST_TRACING_TIME,
+ ERROR_OCCURED
}
/**
public String getErrorMessage() {
return this.errMessage;
}
+
+ public static ErrorCode getErrorCode(int num) {
+ for (ErrorCode code : ErrorCode.values()) {
+ if (code.errNumber == num)
+ return code;
+ }
+ return null;
+ }
}
// Do not call public method of SUCCESS instance.
Logger.debug(str.toString());
}
+
+ public ErrorCode getErrorCode(){
+ return errCode;
+ }
}
*
* @param binPaths list of paths to binaries to be checked
*/
- public void getBinaryInformation(List<String> binPaths) {
+ public ErrorCode getBinaryInformation(List<String> binPaths) {
if (!binPaths.isEmpty()) {
DAResult hr = new DAResult(ErrorCode.ERR_BIN_INFO_GET_FAIL);
try {
UserErrorWarningLabels.ERROR_APP_SELECT_BY_SECURITY);
Logger.warning("Failed to get binary info by security reason");
setPossibleToTrace(false);
+ return ErrorCode.ERR_BY_SECURITY;
} else if (!hr.isSuccess()) {
UIActionHolder.getUIAction().showWarning(hr);
Logger.warning("Failed to get binary info : " + hr.getMessage());
setPossibleToTrace(false);
+ return hr.getErrorCode();
} else {
setPossibleToTrace(true);
+ return ErrorCode.SUCCESS;
}
}
+ return ErrorCode.ERR_BIN_INFO_GET_FAIL;
}
}