import java.util.HashMap;
import java.util.List;
-import org.tizen.dynamicanalyzer.communicator.IDECommunicatorThread;
import org.tizen.dynamicanalyzer.handlers.ClearHandler;
import org.tizen.dynamicanalyzer.logparser.InsertLogQueue;
import org.tizen.dynamicanalyzer.logparser.InsertLogThread;
private static Thread startStopThread = null;
private static Thread openTraceInputThread = null;
private static Thread insertLogThread = null;
- private static Thread IDEcommunicatorThread = null;
private static String startBinaryAddr = null;
private static String endBinaryAddr = null;
stopLogQueueObservingThread();
stopInsertLogThread();
- stopIDEcommunicatorThread();
leakDetector = null;
failedChecker = null;
insertLogThread.interrupt();
}
}
-
- public static void startIDECommunicatorThread() {
- if (null == IDEcommunicatorThread || !IDEcommunicatorThread.isAlive()) {
- IDEcommunicatorThread = new Thread(null, new IDECommunicatorThread(),
- AnalyzerConstants.IDE_COMMUNICATOR_THREAD);
- IDEcommunicatorThread.start();
- }
- }
- public static void stopIDEcommunicatorThread() {
- if (null != IDEcommunicatorThread && IDEcommunicatorThread.isAlive()) {
- IDEcommunicatorThread.interrupt();
- }
- }
public static LeakDetector getLeakDectector() {
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStreamWriter;
+import java.io.RandomAccessFile;
import java.net.Socket;
import java.net.UnknownHostException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.tizen.dynamicanalyzer.ui.widgets.DADialog;
import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
-public class IDECommunicatorManager {
+public class IDECommunicator implements Runnable {
+ private final int MAXBUFSIZE = 1024;
private final String IDE_DA_COMMUNICATION_TYPE_1 = "STATUS";
private final String IDE_DA_COMMUNICATION_TYPE_2 = "RUN";
- private final String IDE_DA_COMMUNICATION_TYPE_3 = "SOURCE";
+ private final static String IDE_DA_COMMUNICATION_TYPE_3 = "SOURCE";
private final String IDE_DA_COMMUNICATION_TYPE_1_RECORD = "record";
private final String IDE_DA_COMMUNICATION_TYPE_1_STOP = "stop";
-
- private Socket socket = null;
+ private static Socket socket = null;
private int port = 0;
- private BufferedWriter writer = null;
+ private static BufferedWriter writer = null;
+ private static Thread _instance;
- private static IDECommunicatorManager _instance;
+ public void run() {
+ while (true) {
+ try {
+ resetSocket();
+ // Waiting Start IDE
+ System.out.println(" Waiting Start IDE");
+ while (true) {
+ File file = null;
+ FileLock fileLock = null;
+ FileChannel fchannel = null;
+ try {
+ file = new File(AnalyzerPaths.IDE_ACTIVE_PORT_PATH);
+ fchannel = new RandomAccessFile(file, "rw").getChannel();
+ fileLock = fchannel.tryLock();
+ if (fileLock == null) { // Active IDE
+ break;
+
+ } else {
+ fileLock.release();
+ Thread.sleep(1000);
+ }
+ } catch (Exception e) {
+ continue;
+ }
+ }
+
+ // Read IDE Port
+ if (readActiveIdePort() != true) {
+ System.out.println("Failed Read Active IDE Port");
+ continue;
+ }
+
+ // Connect IDE Socket
+ if (setIDESocket() != true) {
+ System.out.println("Failed Connect IDE Socket");
+ continue;
+ }
+ System.out.println("Connect IDE");
+ int readSize = 0;
+ byte receiveBuffer[] = new byte[MAXBUFSIZE];
+ InputStream in = null;
+ while (true) {
+ try {
+ in = getSocket().getInputStream();
+ System.out.print("IDE recvMessage Wait\n");
+ readSize = in.read(receiveBuffer);
+ if (readSize > 0) {
+ parsingReceiveMessage(new String(receiveBuffer));
+ } else {
+ break;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ break;
+ }
+ }
+ Thread.sleep(100);
+ System.out.println("Disconnect IDE");
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ }
+ public static void startIDECommunicatorThread() {
+ if (null == _instance || !_instance.isAlive()) {
+ _instance = new Thread(null, new IDECommunicator(),
+ AnalyzerConstants.IDE_COMMUNICATOR_THREAD);
+ _instance.start();
+ }
+ }
- public static IDECommunicatorManager getInstance() {
- if (_instance == null) {
- _instance = new IDECommunicatorManager();
+ public static void stopIDEcommunicatorThread() {
+ if (null != _instance && _instance.isAlive()) {
+ _instance.interrupt();
}
- return _instance;
}
- public Socket getSocket(){
+ private Socket getSocket(){
return socket;
}
- public void resetSocket(){
+ private void resetSocket(){
socket = null;
writer = null;
}
- public boolean isConnected() {
+ public static boolean isConnected() {
if (socket == null) {
return false;
}
return true;
}
+ public static void sendCodeInfoToIDE(final String path,
+ final String line) {
+ sendMessageToIDE(sendMessageString(
+ IDE_DA_COMMUNICATION_TYPE_3, path, line));
+ }
+
+ public static boolean sendMessageToIDE( final String message ){
+
+ System.out.println("sendMessageOpenIDE " + message);
+ try {
+ if ( socket != null ) {
+ writer = new BufferedWriter(new OutputStreamWriter(
+ socket.getOutputStream()));
+ writer.write(message);
+ writer.flush();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
// Management Receive Message
- public void parsingReceiveMessage(String msg) {
+ private void parsingReceiveMessage(String msg) {
String[] strMsg = msg.split(AnalyzerConstants.DATA_PARSING_TOKEN);
if (strMsg[0].equals(IDE_DA_COMMUNICATION_TYPE_1)) {
sendDAStatus();
} else if (strMsg[0].equals(IDE_DA_COMMUNICATION_TYPE_2)) {
- recodApplication(strMsg);
+ recordApplication(strMsg);
} else {
System.out.println(" wrong receive message ");
}
}
// trace Application
- private static void recodApplication(String[] strMsg) {
+ private void recordApplication(String[] strMsg) {
final String deviceName = new String(strMsg[1].trim());
final String appName = new String(strMsg[2].trim());
DASingletonFocusManager.setFocusDA();
}
- public void sendCodeInfoToIDE(final String path,
- final String line) {
- sendMessageToIDE(sendMessageString(
- IDE_DA_COMMUNICATION_TYPE_3, path, line));
- }
-
- private static void popupMessage(final String message) {
+ private void popupMessage(final String message) {
Shell shell = AnalyzerUtil.getWorkbenchWindow().getShell();
DADialog warning = new DADialog(shell, SWT.NONE);
warning.setMessage(message);
warning.open();
}
- public boolean readActiveIdePort() {
+ private boolean readActiveIdePort() {
boolean bSuccess = true;
// read port from current_active_ide_port
try {
return bSuccess;
}
- public boolean setIDESocket() {
+ private boolean setIDESocket() {
try {
socket = new Socket(CommonConstants.LOCAL_HOST, port);
} catch (UnknownHostException e) {
}
return true;
}
-
- public boolean sendMessageToIDE( final String message ){
-
- System.out.println("sendMessageOpenIDE " + message);
- try {
- if ( socket != null ) {
- writer = new BufferedWriter(new OutputStreamWriter(
- socket.getOutputStream()));
- writer.write(message);
- writer.flush();
- }
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
}
+++ /dev/null
-/*
- * Dynamic Analyzer
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Hyunjong Park <phjwithyou.park@samsung.com>
- * Juyoung Kim <j0.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-package org.tizen.dynamicanalyzer.communicator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-
-import org.tizen.dynamicanalyzer.common.AnalyzerPaths;
-
-public class IDECommunicatorThread implements Runnable {
- private final int MAXBUFSIZE = 1024;
-
- public void run() {
-
- while (true) {
- try {
- IDECommunicatorManager.getInstance().resetSocket();
- // Waiting Start IDE
- System.out.println(" Waiting Start IDE");
- while (true) {
- File file = null;
- FileLock fileLock = null;
- FileChannel fchannel = null;
- try {
- file = new File(AnalyzerPaths.IDE_ACTIVE_PORT_PATH);
- fchannel = new RandomAccessFile(file, "rw").getChannel();
- fileLock = fchannel.tryLock();
- if (fileLock == null) { // Active IDE
- break;
-
- } else {
- fileLock.release();
- Thread.sleep(1000);
- }
- } catch (Exception e) {
- continue;
- }
- }
-
- // Read IDE Port
- if (IDECommunicatorManager.getInstance().readActiveIdePort() != true) {
- System.out.println("Failed Read Active IDE Port");
- continue;
- }
-
- // Connect IDE Socket
- if (IDECommunicatorManager.getInstance().setIDESocket() != true) {
- System.out.println("Failed Connect IDE Socket");
- continue;
- }
- System.out.println("Connect IDE");
- int readSize = 0;
- byte receiveBuffer[] = new byte[MAXBUFSIZE];
- InputStream in = null;
- while (true) {
- try {
- in = IDECommunicatorManager.getInstance().getSocket()
- .getInputStream();
- System.out.print("IDE recvMessage Wait\n");
- readSize = in.read(receiveBuffer);
- if (readSize > 0) {
- IDECommunicatorManager
- .getInstance().parsingReceiveMessage(new String(
- receiveBuffer));
- } else {
- break;
- }
- } catch (IOException e) {
- e.printStackTrace();
- break;
- }
- }
- Thread.sleep(100);
- System.out.println("Disconnect IDE");
- } catch (InterruptedException e) {
- break;
- }
- }
- }
-}