SRADA-972,SRADA-971 StopCommand output contains ErrorCode.
authorp.privalov <p.privalov@partner.samsung.com>
Thu, 28 Jul 2016 16:43:05 +0000 (19:43 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Sat, 30 Jul 2016 10:42:10 +0000 (13:42 +0300)
If error occured during application selection in Cli mode  TracingProcess
will be stopped and stop command output will contain error description.

Changes:
 * TracingProcess now able to send message to tracingProcessManager in case of
   error occured during startTrace() execution. New message type introduced.
 * CliInternals.selectApp now returns ErrorCode.
 * PackageInfo.getBinaryInformation() now returns ErrorCode.
 * Imlemented method getErrorCode(int) in ErrorCode - to get error code by it's
   number.
 * in stop command now checked case if TracingProcess is already stopped.

In case of wrong application "dacli devices -u" will not show specified device.

Change-Id: I73b58b411daa5064294eebf92f67a987841ef10e

org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/CliInternals.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/commands/StopCommand.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/manager/TracingProcessManager.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingProcess.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/utils/Message.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/DAResult.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/PackageInfo.java

index 9746eb9..46aac74 100644 (file)
@@ -238,30 +238,32 @@ public final class CliInternals {
        /**
         * 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;
        }
 
        /**
@@ -425,9 +427,8 @@ public final class CliInternals {
         *
         * @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...");
@@ -443,9 +444,10 @@ public final class CliInternals {
                }
                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());
 
index 1406376..72bbbd5 100644 (file)
@@ -1,15 +1,12 @@
 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 {
 
@@ -31,6 +28,17 @@ 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);
index 68de458..b8d0b03 100644 (file)
@@ -367,6 +367,9 @@ public class TracingProcessManager {
                                        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:
index 57da32b..b90b28d 100644 (file)
@@ -85,6 +85,10 @@ public class TracingProcess {
         */
        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();
@@ -106,12 +110,8 @@ public class TracingProcess {
        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();
        }
 
@@ -270,9 +270,13 @@ public class TracingProcess {
                 * @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");
+                       }
                }
 
                /**
@@ -283,8 +287,7 @@ public class TracingProcess {
                 * @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));
                }
                /**
index 47c7e7a..5345ffc 100644 (file)
@@ -12,7 +12,8 @@ public class Message implements Serializable {
                STOP_TRACING,
                STOP_DONE,
                INFO_TRACING_TIME,
-               REQUEST_TRACING_TIME
+               REQUEST_TRACING_TIME,
+               ERROR_OCCURED
        }
 
        /**
index 2013697..9c86d15 100644 (file)
@@ -116,6 +116,14 @@ public class DAResult implements Serializable {
                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.
@@ -227,4 +235,8 @@ public class DAResult implements Serializable {
 
                Logger.debug(str.toString());
        }
+
+       public ErrorCode getErrorCode(){
+               return errCode;
+       }
 }
index 937a347..4b8d8a6 100644 (file)
@@ -189,7 +189,7 @@ public class PackageInfo {
         *
         * @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 {
@@ -205,13 +205,17 @@ public class PackageInfo {
                                                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;
        }
 }