[Title]new communication testcode
authorLee <jy.exe.lee@samsung.com>
Wed, 27 Mar 2013 07:35:41 +0000 (16:35 +0900)
committerLee <jy.exe.lee@samsung.com>
Wed, 27 Mar 2013 07:35:41 +0000 (16:35 +0900)
[Desc.] -
[Issue] -

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/ResourceCommunicator.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/logparser/MessageProcess.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/range/RangeDataManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/RecordStartStopThread.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/configuration/ConfigurationDialogValues.java

index 7501b8e..96b2e64 100644 (file)
@@ -30,6 +30,7 @@ import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
 \r
 public class AnalyzerConstants {\r
        // if log change occurs then increase save data version!!\r
+       public static final String DA_VERSION = "2.1";\r
        public static final String SAVE_DATA_VERSION = "0.84"; //$NON-NLS-1$\r
        public static final boolean CHECK_INTERNAL = true;\r
 \r
@@ -147,6 +148,9 @@ public class AnalyzerConstants {
        public static final String MSG_START = "100"; //$NON-NLS-1$\r
        public static final String MSG_STOP = "101"; //$NON-NLS-1$\r
        public static final String MSG_OPTION = "103"; //$NON-NLS-1$\r
+       public static final String MSG_VERSION = "999"; //$NON-NLS-1$\r
+       public static final String MSG_OK = "901"; //$NON-NLS-1$\r
+       public static final String MSG_NOT_OK = "902"; //$NON-NLS-1$\r
 \r
        public static final int OPT_OFF = 0x0000;\r
        public static final int OPT_CPUMEM = 0x0001;\r
index 6ce3c16..761fa75 100644 (file)
@@ -70,12 +70,15 @@ public class DACommunicator {
        public static final int LOCAL_PORT = 8000;
        public static final int REMOTE_PORT = 8001;
 
+       private static Socket controlSock = null;
        private static Socket sock = null;
        private static SmartDevelopmentBridge sdbBridge = null;
        private static AppDesktopInfo selectedApp = null;
        private static DeviceInfo currentDevice = null;
        private static BufferedWriter writer = null;
        private static BufferedReader reader = null;
+       private static BufferedWriter controlWriter = null;
+       private static BufferedReader controlReader = null;
        private static boolean isRunning = false;
        private static List<DeviceInfo> devices = null;
        private static List<AppDesktopInfo> appDesktopList = null;
@@ -363,6 +366,35 @@ public class DACommunicator {
                return sock;
        }
 
+       public static Socket createControlSocket(int port) {
+               try {
+
+                       controlSock = new Socket(CommonConstants.LOCAL_HOST, port);
+                       if (null == controlSock) {
+                               System.out.println("failed to create a control socket"); //$NON-NLS-1$
+                               return null;
+                       }
+
+                       controlSock.setSoTimeout(AnalyzerConstants.SOCKET_TIMEOUT);
+                       controlSock.setReuseAddress(true);
+                       controlSock.setTcpNoDelay(true);
+
+                       controlReader = new BufferedReader(new InputStreamReader(
+                                       controlSock.getInputStream()));
+                       controlWriter = new BufferedWriter(new OutputStreamWriter(
+                                       controlSock.getOutputStream()));
+               } catch (SocketTimeoutException e) {
+                       System.out.println("socket timeout."); //$NON-NLS-1$
+                       e.printStackTrace();
+               } catch (UnknownHostException e) {
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+
+               return controlSock;
+       }
+
        public static void closeSocket() {
                AnalyzerUtil.tryClose(reader, writer, sock);
        }
@@ -482,6 +514,32 @@ public class DACommunicator {
                }
        }
 
+       public static String handleControlMessage(String message) {
+               String result = null;
+               try {
+                       if (null != controlSock) {
+                               controlWriter.write(message);
+                               controlWriter.flush();
+                       }
+
+                       System.out.println("wait for ack...");
+                       while (isRunning) {
+                               if (null != (result = controlReader.readLine())
+                                               && !result.isEmpty()) {
+                                       break;
+                               }
+                               System.out.println("wait!!");
+                       }
+                       System.out.println("pass");
+//                     result = "test ack message";
+
+               } catch (IOException e) {
+                       System.out.println(e.getMessage());
+                       return null;
+               }
+               return result;
+       }
+
        public static SyncResult push(String local, String remote) {
                return push(local, remote, SyncService.getNullProgressMonitor());
        }
index e7131f7..b8619bb 100644 (file)
  */
 package org.tizen.dynamicanalyzer.communicator;
 
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
 import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
 import org.tizen.dynamicanalyzer.common.CommonConstants;
 import org.tizen.dynamicanalyzer.model.DeviceInfo;
 import org.tizen.dynamicanalyzer.nl.ConfigureLabels;
+import org.tizen.dynamicanalyzer.resources.ImageResources;
 import org.tizen.dynamicanalyzer.ui.toolbar.ConfigureManager;
+import org.tizen.dynamicanalyzer.ui.widgets.DADialog;
+import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
 
 public class ResourceCommunicator extends DACommunicator {
 
@@ -56,15 +62,51 @@ public class ResourceCommunicator extends DACommunicator {
 
                setRunning(true);
 
-               if (null == createSocket(LOCAL_PORT)) {
+               if (null == createControlSocket(LOCAL_PORT)) {
                        System.out.println("socket creation failed."); //$NON-NLS-1$
                        return false;
                }
-
                return true;
        }
 
-       public static void sendStartMessage() {
+       public static boolean sendVersionMessage() {
+               String message = AnalyzerConstants.MSG_VERSION
+                               + CommonConstants.CMD_SPLIT + AnalyzerConstants.DA_VERSION;
+               System.out.println("Send control message :" + message); //$NON-NLS-1$
+
+               String result = handleControlMessage(message);
+
+               // test
+               result = "901|1|0";
+               // result = "902|3|2.0";
+               if (null != result) {
+                       System.out.println("version message ack :" + result);
+                       String[] splitResult = result.split(CommonConstants.CMD_SPLIT_READ);
+
+                       if (AnalyzerConstants.MSG_NOT_OK.equals(splitResult[0])) {
+                               final String deviceVersion = splitResult[2];
+                               Display.getDefault().syncExec(new Runnable() {
+                                       @Override
+                                       public void run() {
+                                               Shell shell = AnalyzerUtil.getWorkbenchWindow()
+                                                               .getShell();
+                                               DADialog warning = new DADialog(shell, SWT.NONE);
+                                               warning.setMessage("Version is invalid (device :"
+                                                               + deviceVersion + " host :"
+                                                               + AnalyzerConstants.DA_VERSION);
+                                               warning.setIcon(ImageResources.DIALOG_WARNING_ICON);
+                                               warning.open();
+                                       }
+                               });
+                               return false;
+                       } else if (AnalyzerConstants.MSG_OK.equals(splitResult[0])) {
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       public static boolean sendStartMessage() {
                int isArm = 0;
                int isEmul = 0;
                int res = 0;
@@ -80,37 +122,62 @@ public class ResourceCommunicator extends DACommunicator {
                        isEmul = 1;
                }
 
-               String rearMessage = ""+res
-                               + isEmul
-                               + isArm
-                               + CommonConstants.CMD_SPLIT
-                               + getConfiguration()
+               String rearMessage = "" + res + isEmul + isArm
+                               + CommonConstants.CMD_SPLIT + getConfiguration()
                                + CommonConstants.CMD_SPLIT
                                + ResourceCommunicator.getSelectedApp().getExecPath();
 
                String message = AnalyzerConstants.MSG_START
-                               + CommonConstants.CMD_SPLIT
-//                             + (ResourceCommunicator.getSelectedApp().getExecPath().length() + 7)
-                               + rearMessage.length()
-                               + CommonConstants.CMD_SPLIT
-                               + rearMessage;
-//                             + res
-//                             + isEmul
-//                             + isArm
-//                             + CommonConstants.CMD_SPLIT
-//                             + getConfiguration()
-//                             + CommonConstants.CMD_SPLIT
-//                             + ResourceCommunicator.getSelectedApp().getExecPath();
+                               + CommonConstants.CMD_SPLIT + rearMessage.length()
+                               + CommonConstants.CMD_SPLIT + rearMessage;
                System.out.println("Send message :" + message); //$NON-NLS-1$
-               sendMessage(message);
+
+               String result = handleControlMessage(message);
+               if (null != result) {
+                       System.out.println("start message ack :" + result);
+                       String[] splitResult = result.split(CommonConstants.CMD_SPLIT_READ);
+                       if (AnalyzerConstants.MSG_OK.equals(splitResult[0])) {
+                               createSocket(LOCAL_PORT);
+                               return true;
+                       }
+               }
+               return false;
        }
 
-       public static void sendSnapshotMessage(int state) {
+       public static boolean sendStopMessage() {
+               if (ResourceCommunicator.isRunning()) {
+                       String message = AnalyzerConstants.MSG_STOP
+                                       + CommonConstants.CMD_SPLIT + 0 + CommonConstants.CMD_SPLIT;
+                       System.out.println("stop send message :" + message);
+
+                       String result = handleControlMessage(message);
+                       if (null != result) {
+                               System.out.println("stop message ack :" + result);
+                               String[] splitResult = result
+                                               .split(CommonConstants.CMD_SPLIT_READ);
+                               if (AnalyzerConstants.MSG_OK.equals(splitResult[0])) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+
+       public static boolean sendSnapshotMessage(int state) {
                String statestr = Integer.toString(state);
                String message = AnalyzerConstants.MSG_OPTION
-                               + CommonConstants.CMD_SPLIT + statestr.length() + CommonConstants.CMD_SPLIT
-                               + statestr;
-               sendMessage(message);
+                               + CommonConstants.CMD_SPLIT + statestr.length()
+                               + CommonConstants.CMD_SPLIT + statestr;
+
+               String result = handleControlMessage(message);
+               if (null != result) {
+                       System.out.println("snapshot message ack :" + result);
+                       String[] splitResult = result.split(CommonConstants.CMD_SPLIT_READ);
+                       if (AnalyzerConstants.MSG_OK.equals(splitResult[0])) {
+                               return true;
+                       }
+               }
+               return false;
        }
 
        public static int getConfiguration() {
index be61997..43a4e2c 100644 (file)
@@ -251,16 +251,18 @@ public class MessageProcess {
 
                                messages = message.split(CommonConstants.CMD_SPLIT_READ, 2);
 
-                               System.out.println("message :" + message);
                                try {
                                        int index = Integer.parseInt(messages[0]);
                                        if (AnalyzerConstants.MSG_APP_INFO == index) {
                                                sentenceIndex = AnalyzerConstants.MSG_APP_INFO;
                                                sentence = message;
-                                       } else if (AnalyzerConstants.MSG_START.equals(messages[0])) {
-                                               // start application
-                                               DACommunicator.execCommand(ResourceCommunicator.getSelectedApp().getExecPath());
-                                       } else {
+                                       } 
+//                                     else if (AnalyzerConstants.MSG_START.equals(messages[0])) {
+//                                             // start application
+//                                             DACommunicator.execCommand(ResourceCommunicator
+//                                                             .getSelectedApp().getExecPath());
+//                                     } 
+                               else {
                                                if (AnalyzerConstants.MSG_APP_INFO == sentenceIndex) {
                                                        processMessage(sentence);
                                                        sentence = null;
index 66b789c..a92e0a7 100644 (file)
@@ -91,6 +91,8 @@ public class RangeDataManager implements Runnable {
                                DAPageComposite page = AnalyzerManager.getCurrentPage();
                                if (page instanceof RangePage) {
                                        AnalyzerUtil.changePage(TimelinePage.ID);
+                               } else {
+                                       page.updateView();
                                }
 
                                DATabComposite mainTab = AnalyzerUtil.getMainTab();
@@ -256,7 +258,8 @@ public class RangeDataManager implements Runnable {
                                if (logCenters.get(i).getId() != LogCenterConstants.LOG_DEVICE
                                                && logCenters.get(i).getId() != LogCenterConstants.LOG_PROFILING) {
                                        Logs logs = new Logs(logCenters.get(i).getId());
-                                       input = SqlManager.getInstance().selectArea(logCenters.get(i), from, to);
+                                       input = SqlManager.getInstance().selectArea(
+                                                       logCenters.get(i), from, to);
                                        logs.setLogs(input);
                                        logPackage.setLogs(logCenters.get(i).getId(), logs);
                                }
@@ -303,7 +306,8 @@ public class RangeDataManager implements Runnable {
                        for (int i = 0; i < size; i++) {
                                if (logCenters.get(i).getId() == LogCenterConstants.LOG_PROFILING) {
                                        Logs logs = new Logs(logCenters.get(i).getId());
-                                       input = SqlManager.getInstance().selectArea(logCenters.get(i), from, to);
+                                       input = SqlManager.getInstance().selectArea(
+                                                       logCenters.get(i), from, to);
                                        logs.setLogs(input);
                                        profilePackage.setLogs(logCenters.get(i).getId(), logs);
                                }
index 1f3ec6b..b048ee6 100644 (file)
 
 package org.tizen.dynamicanalyzer.ui.toolbar;
 
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
 import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
 import org.tizen.dynamicanalyzer.common.AnalyzerManager;
-import org.tizen.dynamicanalyzer.common.CommonConstants;
-import org.tizen.dynamicanalyzer.common.PathManager;
 import org.tizen.dynamicanalyzer.communicator.ResourceCommunicator;
 import org.tizen.dynamicanalyzer.handlers.ReplayTraceHandler;
 import org.tizen.dynamicanalyzer.logparser.LogParser;
 import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
-import org.tizen.dynamicanalyzer.resources.ImageResources;
 import org.tizen.dynamicanalyzer.services.RecordStateSourceProvider;
 import org.tizen.dynamicanalyzer.ui.file.FileChartManager;
 import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler;
 import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager;
-import org.tizen.dynamicanalyzer.ui.widgets.DADialog;
 import org.tizen.dynamicanalyzer.uirecorder.UIRecorderTool;
 import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
 import org.tizen.dynamicanalyzer.utils.UpdateViewTimer;
@@ -86,13 +80,13 @@ public class RecordStartStopThread implements Runnable {
                                Display.getDefault().syncExec(new Runnable() {
                                        @Override
                                        public void run() {
-                                               final Shell shell = AnalyzerUtil.getWorkbenchWindow()
-                                                               .getShell();
-                                               DADialog dialog = new DADialog(shell, SWT.NONE);
-                                               dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
-                                               dialog.setMessage(AnalyzerLabels.START_TRACE_ERROR
-                                                               + PathManager.getLogPath());
-                                               dialog.open();
+                                               // final Shell shell = AnalyzerUtil.getWorkbenchWindow()
+                                               // .getShell();
+                                               // DADialog dialog = new DADialog(shell, SWT.NONE);
+                                               // dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
+                                               // dialog.setMessage(AnalyzerLabels.START_TRACE_ERROR
+                                               // + PathManager.getLogPath());
+                                               // dialog.open();
 
                                                ToolbarArea.getInstance().setToolbarState(
                                                                ToolbarArea.TOOLBAR_STATE_READY);
@@ -131,8 +125,19 @@ public class RecordStartStopThread implements Runnable {
                        return false;
                }
                if (!AnalyzerManager.isExit()) {
+                       // version check
+                       if (!ResourceCommunicator.sendVersionMessage()) {
+                               return false;
+                       }
+                       // version ok?
+
+                       // send start message
+                       if (!ResourceCommunicator.sendStartMessage()) {
+                               return false;
+                       }
+                       // all right??
+
                        UIRecorderTool.getInstance().startRecorder();
-                       ResourceCommunicator.sendStartMessage();
                        ToolbarArea.getInstance().startTimer();
                        LogParser.startLogParser();
                        FileChartManager.getInstance().startUpdateLogThread();
@@ -160,14 +165,15 @@ public class RecordStartStopThread implements Runnable {
                        }
                });
 
-               if (ResourceCommunicator.isRunning()) {
-                       ResourceCommunicator
-                                       .sendMessage(AnalyzerConstants.MSG_STOP
-                                                       + CommonConstants.CMD_SPLIT + 0
-                                                       + CommonConstants.CMD_SPLIT);
-                       System.out.println("stop send message :"
-                                       + AnalyzerConstants.MSG_STOP + CommonConstants.CMD_SPLIT
-                                       + 0 + CommonConstants.CMD_SPLIT);
-               }
+               // if (ResourceCommunicator.isRunning()) {
+               // ResourceCommunicator
+               // .sendMessage(AnalyzerConstants.MSG_STOP
+               // + CommonConstants.CMD_SPLIT + 0
+               // + CommonConstants.CMD_SPLIT);
+               // System.out.println("stop send message :"
+               // + AnalyzerConstants.MSG_STOP + CommonConstants.CMD_SPLIT
+               // + 0 + CommonConstants.CMD_SPLIT);
+               // }
+               ResourceCommunicator.sendStopMessage();
        }
 }
index ee46b61..2f5b502 100644 (file)
@@ -160,49 +160,49 @@ public class ConfigurationDialogValues {
        public void setSettingValueFromConfigFile() {
 
                // Table Feature
-
-               for (String featureName : ConfigurationDialogValues.getInstance()
-                               .getFeature()) {
-                       // boolean featuresStatus = true;
-
-                       int featuresStatus = Integer.parseInt(mConfig.getValue(featureName));
-                       // if (mConfig.getValue(featureName).equals(ON)) {
-                       // featuresStatus = true;
-                       // } else {
-                       // featuresStatus = false;
-                       // }
-                       if (featureName.equals(ConfigureLabels.FUNCTIONPROFILING)) {
-                               setbFunctionProfilingCall(featuresStatus);
-                       } else if (featureName.equals(ConfigureLabels.ALLOCATION)) {
-                               setbAllocationCall(featuresStatus);
-                       } else if (featureName.equals(ConfigureLabels.FILE)) {
-                               setbFileCall(featuresStatus);
-                       } else if (featureName.equals(ConfigureLabels.THREAD)) {
-                               setbThreadCall(featuresStatus);
-                       } else if (featureName.equals(ConfigureLabels.USERINTERFACE)) {
-                               setbUserInterfaceCall(featuresStatus);
-                       } else if (featureName.equals(ConfigureLabels.SNAPSHOT)) {
-                               setbSnapshotCall(featuresStatus);
-                       } else if (featureName.equals(ConfigureLabels.EVENT)) {
-                               setbEventCall(featuresStatus);
-                       } else if (featureName.equals(ConfigureLabels.RECORDING)) {
-                               setbRecordingCall(featuresStatus);
-                       } else {
-                               System.out.println("failed undefine features");
-                       }
-               }
-
-               // Setting
-               if (mConfig.getValue(ConfigureLabels.SHOW_INITIAL).equals(ON)) {
-                       setShowInitia(true);
-               } else {
-                       setShowInitia(false);
-               }
-               if (mConfig.getValue(ConfigureLabels.AUTO_STOP).equals(ON)) {
-                       setAutoStop(true);
-               } else {
-                       setAutoStop(false);
-               }
+//
+//             for (String featureName : ConfigurationDialogValues.getInstance()
+//                             .getFeature()) {
+//                     // boolean featuresStatus = true;
+//
+//                     int featuresStatus = Integer.parseInt(mConfig.getValue(featureName));
+//                     // if (mConfig.getValue(featureName).equals(ON)) {
+//                     // featuresStatus = true;
+//                     // } else {
+//                     // featuresStatus = false;
+//                     // }
+//                     if (featureName.equals(ConfigureLabels.FUNCTIONPROFILING)) {
+//                             setbFunctionProfilingCall(featuresStatus);
+//                     } else if (featureName.equals(ConfigureLabels.ALLOCATION)) {
+//                             setbAllocationCall(featuresStatus);
+//                     } else if (featureName.equals(ConfigureLabels.FILE)) {
+//                             setbFileCall(featuresStatus);
+//                     } else if (featureName.equals(ConfigureLabels.THREAD)) {
+//                             setbThreadCall(featuresStatus);
+//                     } else if (featureName.equals(ConfigureLabels.USERINTERFACE)) {
+//                             setbUserInterfaceCall(featuresStatus);
+//                     } else if (featureName.equals(ConfigureLabels.SNAPSHOT)) {
+//                             setbSnapshotCall(featuresStatus);
+//                     } else if (featureName.equals(ConfigureLabels.EVENT)) {
+//                             setbEventCall(featuresStatus);
+//                     } else if (featureName.equals(ConfigureLabels.RECORDING)) {
+//                             setbRecordingCall(featuresStatus);
+//                     } else {
+//                             System.out.println("failed undefine features");
+//                     }
+//             }
+//
+//             // Setting
+//             if (mConfig.getValue(ConfigureLabels.SHOW_INITIAL).equals(ON)) {
+//                     setShowInitia(true);
+//             } else {
+//                     setShowInitia(false);
+//             }
+//             if (mConfig.getValue(ConfigureLabels.AUTO_STOP).equals(ON)) {
+//                     setAutoStop(true);
+//             } else {
+//                     setAutoStop(false);
+//             }
        }
 
        private void setConfig(boolean featureStatus, String featureName) {