SRADA-216: TracingProcess.startTrace() stub implementation added.
authorMaria Guseva <m.guseva@samsung.com>
Sun, 22 May 2016 13:59:48 +0000 (16:59 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Thu, 30 Jun 2016 05:53:43 +0000 (14:53 +0900)
* CliInternals - set Logger to debug mode for now while on active
implementation stage.
* CliInternals.loadConnectedDevices(), .selectApp(), .selectTemplate() - new
helper methods.
* CliInternals.startTracing(), .stopTracing()  -renamed to
startTracingProcess() and stopTracingProcess().
* CliInternals.startTracing() - new method. Setting of selected device,
application and template implemented.

Change-Id: I7730d04889b5c133642c2a5b2dc915060bdd1e73

org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/CliInternals.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/commands/StartCommand.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/commands/StopCommand.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingProcess.java

index 3f9d3cd..d6c1070 100644 (file)
@@ -13,6 +13,7 @@ import org.tizen.dynamicanalyzer.cli.tracing.TracingArguments;
 import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
 import org.tizen.dynamicanalyzer.common.AnalyzerManager;
 import org.tizen.dynamicanalyzer.common.DAResult;
+import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode;
 import org.tizen.dynamicanalyzer.common.Global;
 import org.tizen.dynamicanalyzer.common.UIMode;
 import org.tizen.dynamicanalyzer.common.path.PathManager;
@@ -21,6 +22,7 @@ import org.tizen.dynamicanalyzer.communicator.DeviceInfo;
 import org.tizen.dynamicanalyzer.communicator.DeviceManager;
 import org.tizen.dynamicanalyzer.project.PackageInfo;
 import org.tizen.dynamicanalyzer.setting.SettingDataManager;
+import org.tizen.dynamicanalyzer.setting.TargetData;
 import org.tizen.dynamicanalyzer.setting.Template;
 import org.tizen.dynamicanalyzer.util.InternalLogger;
 import org.tizen.dynamicanalyzer.util.Logger;
@@ -35,7 +37,7 @@ public final class CliInternals {
 
        static {
                // Initialize DA Logger
-               Logger.init(InternalLogger.WARNING);
+               Logger.init(InternalLogger.DEBUG);
 
                // Check if Platform IDE exists and if so make the native platform
                // functionality available.
@@ -189,6 +191,14 @@ public final class CliInternals {
        }
 
        /**
+        * Make DA to check currently connected devices
+        */
+       private static void loadConnectedDevices() {
+               DeviceManager.addDeviceListener();
+               DeviceManager.loadDevices();
+       }
+
+       /**
         * Selects device by its serial number.
         *
         * @param serial device serial number
@@ -199,6 +209,53 @@ public final class CliInternals {
        }
 
        /**
+        * Selects application by its name.
+        *
+        * @param application name
+        * @return <code>true</code> on success
+        */
+       public static boolean selectApp(String appName) {
+               DeviceInfo devInfo = Global.getCurrentDeviceInfo();
+               if (devInfo == null) {
+                       Logger.warning("DA failed to set device for " + appName + " application");
+                       return false;
+               }
+               DACommunicator.updateAppListFromTarget();
+               PackageInfo pkgInfo = devInfo.getPkgInfoByLabel(appName);
+               if (pkgInfo == null) {
+                       Logger.warning("DA failed to set application " + appName);
+                       return false;
+               }
+               Global.setCurrentApplication(pkgInfo);
+               List<String> binPaths = pkgInfo.getProcessInformation();
+               pkgInfo.getBinaryInformation(binPaths);
+               if (!pkgInfo.isPossibleToTrace()) {
+                       Logger.warning("DA is not able to trace application " + appName);
+                       return false;
+               }
+               devInfo.setSelectedPackageLabel(appName);
+               return true;
+       }
+
+       /**
+        * Selects non-custom template to be used for tracing by given Template
+        * value.
+        *
+        * @param template Template instance
+        * @return <code>true</code> on success
+        */
+       private static boolean selectTemplate(Template template) {
+               // TODO Support custom template selection or other way to select
+               // features instead of templates
+               if (template == Template.TEMPLATE_CUSTOM)
+                       return false;
+               TargetData target = SettingDataManager.INSTANCE.getTarget(null);
+               target.setSelectedTemplate(template);
+               target.changeSelectedFeatureList(template);
+               return true;
+       }
+
+       /**
         * Helper function for packages list extraction from selected device.
         *
         * @param dev IDevice object presenting selected device
@@ -226,7 +283,7 @@ public final class CliInternals {
         * @return result of async start tracing task
         * @throws ConnectException in case of connection error
         */
-       public static DAResult startTracing(TracingArguments args) throws ConnectException {
+       public static DAResult startTracingProcess(TracingArguments args) throws ConnectException {
                ProcessManagerMBean pmProxy = getPMProxyInstance();
 
                return pmProxy.startTracing(args);
@@ -240,7 +297,7 @@ public final class CliInternals {
         * @return result of stop tracing request
         * @throws ConnectException in case of connection error
         */
-       public static DAResult stopTracing(String device) throws ConnectException {
+       public static DAResult stopTracingProcess(String device) throws ConnectException {
                ProcessManagerMBean pmProxy = getPMProxyInstance();
 
                return pmProxy.stopTracing(device);
@@ -260,4 +317,42 @@ public final class CliInternals {
                return pmProxy.getContext(device);
        }
 
+       /**
+        * Start tracing with requested parameters: setup given data as selected in
+        * DA and run the StartTraceManager thread
+        *
+        * @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.
+        */
+       public static ErrorCode startTracing(TracingArguments args) {
+               Logger.info("Starting tracing...");
+               initDevices();
+               loadConnectedDevices();
+               if (!selectDevice(args.getDevice())) {
+                       Logger.debug("Failed to select device");
+                       return ErrorCode.ERR_NO_DEVICE;
+               }
+               Logger.debug("Set current device: " + args.getDevice());
+
+               if (!selectApp(args.getApplication())) {
+                       Logger.debug("Failed to select application");
+                       return ErrorCode.ERR_NO_APP;
+               }
+               Logger.debug("Set current app: " + args.getApplication());
+
+               if (!selectTemplate(args.getTemplate())) {
+                       Logger.debug("Failed to select template");
+                       return ErrorCode.ERR_EXCEPTION_OCCURRED;
+               }
+               Logger.debug("Set current template: " + args.getTemplate());
+
+               // TODO Implement main functionality via StartTraceManager thread
+               // invocation
+
+               return ErrorCode.SUCCESS;
+       }
+
 }
index 2ff69c0..56652f7 100644 (file)
@@ -62,7 +62,7 @@ public class StartCommand extends Command {
 
                DAResult result;
                try {
-                       result = CliInternals.startTracing(parsedArgs);
+                       result = CliInternals.startTracingProcess(parsedArgs);
                } catch (ConnectException e) {
                        System.out.println(e.toString());
                        e.printStackTrace();
index 40c626c..3e71cc1 100644 (file)
@@ -29,7 +29,7 @@ public class StopCommand extends Command {
 
                // if process not finished yet then stop it
                if (!ctx.isFinished()) {
-                       result = CliInternals.stopTracing(device);
+                       result = CliInternals.stopTracingProcess(device);
 
                        if (!result.isSuccess()) {
                                System.out.println("Can't stop tracing. " + result.getMessage());
index 84313bf..1c239b8 100644 (file)
@@ -3,6 +3,7 @@ package org.tizen.dynamicanalyzer.cli.tracing;
 import java.util.Arrays;
 
 import org.apache.commons.cli.ParseException;
+import org.tizen.dynamicanalyzer.cli.CliInternals;
 import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode;
 import org.tizen.dynamicanalyzer.util.InternalLogger;
 import org.tizen.dynamicanalyzer.util.Logger;
@@ -29,26 +30,31 @@ public class TracingProcess {
        private volatile ErrorCode status;
 
        /**
+        * Tracing arguments
+        */
+       private final TracingArguments args;
+
+       /**
         * Public constructor.
         *
         * @param args tracing input arguments
         */
        public TracingProcess(TracingArguments args) {
                status = ErrorCode.ERR_UNKNOWN;
+               this.args = args;
        }
 
        /**
         * Start tracing activities.
         * This method should not block caller thread during tracing process itself.
         *
-        * @return {@link ErrorCode#SUCCESS} if tracing started successfully
-        *         TODO complete error codes documentation
+        * @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.
         */
        public synchronized ErrorCode startTrace() {
-               // TODO stuff for start tracing
-
-               // successfully started
-               return ErrorCode.SUCCESS;
+               return CliInternals.startTracing(args);
        }
 
        /**