private final static String IDE_DA_COMMUNICATION_TYPE_2 = "RUN";
private final static String IDE_DA_COMMUNICATION_TYPE_3 = "SOURCE";
+ private final static String IDE_DA_COMMUNICATION_TYPE_1_RECORD = "record";
+ private final static String IDE_DA_COMMUNICATION_TYPE_1_STOP = "stop";
+
public static void startCommunicationIDE(){
IDECommunicatorThread communicatorThread = new IDECommunicatorThread();
String[] strMsg = msg.split(AnalyzerConstants.DATA_PARSING_TOKEN);
- if (strMsg[0].equals( IDE_DA_COMMUNICATION_TYPE_1 )) {//$NON-NLS-1$
+ if (strMsg[0].equals( IDE_DA_COMMUNICATION_TYPE_1 )) {
sendDAStatus();
- } else if (strMsg[0].equals( IDE_DA_COMMUNICATION_TYPE_2 )) {//$NON-NLS-1$
+ } else if (strMsg[0].equals( IDE_DA_COMMUNICATION_TYPE_2 )) {
traceApplication(strMsg);
} else {
System.out.println(" wrong receive message ");
// Receive Message DA Status , Send DA Status
private static void sendDAStatus() {
- boolean bDAPlay = false;
String state = AnalyzerUtil.getRecordState();
if (state.equals(RecordStateSourceProvider.RECORD_RECORDING)) { // DA
// Trace
// Status
- bDAPlay = true;
- StringBuffer sendMsg = new StringBuffer();
- sendMsg.append( IDE_DA_COMMUNICATION_TYPE_1 )//$NON-NLS-1$
- .append(AnalyzerConstants.DATA_PARSING_TOKEN)
- .append("play")//$NON-NLS-1$
- .append(AnalyzerConstants.DATA_PARSING_TOKEN).append("");//$NON-NLS-1$
- IDECommunicatorThread.sendMessageToIDE(sendMsg.toString());
- } else { // DA Stop Status
- StringBuffer sendMsg = new StringBuffer();
- sendMsg.append( IDE_DA_COMMUNICATION_TYPE_1 )//$NON-NLS-1$
- .append(AnalyzerConstants.DATA_PARSING_TOKEN)
- .append("stop")//$NON-NLS-1$
- .append(AnalyzerConstants.DATA_PARSING_TOKEN).append("");//$NON-NLS-1$
- IDECommunicatorThread.sendMessageToIDE(sendMsg.toString());
- }
-
- if (bDAPlay == true) {
+
+ IDECommunicatorThread.sendMessageToIDE( sendMessageString(IDE_DA_COMMUNICATION_TYPE_1, IDE_DA_COMMUNICATION_TYPE_1_RECORD,"" ) );
DASingletonFocusManager.setFocusDA();
Display.getDefault().syncExec(new Runnable() {
public void run() {
popupMessage(AnalyzerLabels.RE_TRACE_FORM_IDE);
}
});
+
+ } else { // DA Stop Status
+ IDECommunicatorThread.sendMessageToIDE( sendMessageString(IDE_DA_COMMUNICATION_TYPE_1, IDE_DA_COMMUNICATION_TYPE_1_STOP,"" ) );
}
}
+ private static String sendMessageString( String first, String second, String third ){
+
+ StringBuffer sendMsg = new StringBuffer();
+ sendMsg.append( first )
+ .append(AnalyzerConstants.DATA_PARSING_TOKEN)
+ .append( second )
+ .append(AnalyzerConstants.DATA_PARSING_TOKEN)
+ .append( third );
+ return sendMsg.toString();
+
+ }
+
// trace Application
private static void traceApplication(String[] strMsg) {
DASingletonFocusManager.setFocusDA();
}
-
public static void sendMessageSourceOpenIDE( final String path , final String line ) {
- StringBuffer msg = new StringBuffer();
- msg.append( IDE_DA_COMMUNICATION_TYPE_3 ).append( AnalyzerConstants.DATA_PARSING_TOKEN )//$NON-NLS-1$
- .append(path).append( AnalyzerConstants.DATA_PARSING_TOKEN )
- .append( line );
- IDECommunicatorThread.sendMessageToIDE( msg.toString() );
+ IDECommunicatorThread.sendMessageToIDE( sendMessageString( IDE_DA_COMMUNICATION_TYPE_3, path, line ) );
}
private static void popupMessage(final String message) {
public class IDECommunicatorThread extends Thread {
-
+ private final int MAXBUFSIZE = 1024;
private static Socket socket = null;
private int port = 0;
private static BufferedWriter writer = null;
public void run() {
while (true) {
resetSocket();
- acceptIDE(); // Waiting Connect IDE
- IDECommunicatorManager.setCurrentIDECommunicationStatus( true );
+
+ // Waiting Start IDE
+ System.out.println(" Waiting Start IDE");
+ if ( checkActiveIde() != true ) {
+ System.out.println("Failed Set Active File Lock");
+ continue;
+ }
+
+ // Read IDE Port
+ if ( readActiveIdePort() != true ) {
+ System.out.println("Failed Set Active File Lock");
+ continue;
+ }
+
+ // Connect IDE Socket
+ if (setIDESocket() != true) {
+ System.out.println("Failed Connect IDE Socket");
+ continue;
+ }
+
System.out.println("Connect IDE");
- if (setIDESocket() == true) {
- receiveApplicationInfoFromIDE(); // Call Receive Thread, Waiting
- // DisConnect IDE
+ IDECommunicatorManager.setCurrentIDECommunicationStatus(true);
+ while (true) {
+ try {
+ int readSize = 0;
+ byte receiveBuffer[] = null;
+ receiveBuffer = new byte[MAXBUFSIZE];
+ InputStream in = socket.getInputStream();
+ System.out.print("IDE recvMessage Wait\n");
+ readSize = in.read(receiveBuffer);
+ if (readSize > 0) {
+
+ String msg = new String(receiveBuffer);
+ IDECommunicatorManager.commandReceiveMessage(msg);
+ } else {
+ break;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ break;
+ }
}
System.out.println("waiting IDE");
- IDECommunicatorManager.setCurrentIDECommunicationStatus( false );
+ IDECommunicatorManager.setCurrentIDECommunicationStatus(false);
}
}
}
- private boolean acceptIDE() {
+ private boolean readActiveIdePort() {
boolean bSuccess = true;
-
- while (true) {
- // read port from current_active_ide_port
- port = readActiveIdePort();
- if (port > 0) {
- System.out.println("port :" + port);
- break;
- } else {
- // System.out.println("waiting IDE");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ // read port from current_active_ide_port
+ try {
+ File logs = new File(AnalyzerPaths.IDE_ACTIVE_SAVE_PORT_PATH);
+ if (!logs.exists()) {
+ bSuccess = false;
}
+ FileInputStream fis = new FileInputStream(
+ AnalyzerPaths.IDE_ACTIVE_SAVE_PORT_PATH);
+ DataInputStream dis = new DataInputStream(fis);
+ try {
+ port = dis.readInt();
+ } catch (IOException e) {
+ e.printStackTrace();
+ bSuccess = false;
+ }
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ bSuccess = false;
}
return bSuccess;
+
}
private boolean setIDESocket() {
}
return true;
}
-
- private boolean receiveApplicationInfoFromIDE() {
- boolean bSuccess = true;
- final int MAXBUFSIZE = 1024;
- int readSize = 0;
- byte receiveBuffer[] = null;
+ // Check Current IDE Status, File Lock by IDE
+ static boolean checkActiveIde() {
while (true) {
+
+ File file = null;
+ FileLock fileLock = null;
+ FileChannel fchannel = null;
try {
- receiveBuffer = new byte[MAXBUFSIZE];
- InputStream in = socket.getInputStream();
- System.out.print("IDE recvMessage Wait\n");
- readSize = in.read(receiveBuffer);
- if (readSize > 0) {
-
- String msg = new String(receiveBuffer);
- IDECommunicatorManager.commandReceiveMessage(msg);
+ file = new File(AnalyzerPaths.IDE_ACTIVE_PORT_PATH);
+ fchannel = new RandomAccessFile(file, "rw").getChannel();
+ fileLock = fchannel.tryLock();
+ if (fileLock == null) { // Active IDE
+ return true;
} else {
- break;
+ fileLock.release();
+ Thread.sleep(1000);
}
- } catch (IOException e) {
- e.printStackTrace();
- break;
- }
- }
- return bSuccess;
- }
-
- // Check Current IDE Status, File Lock by IDE
- static boolean checkActiveIde() {
-
-
- 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) {
- return true; // Active IDE
- } else {
- fileLock.release();
+ } catch (Exception e) {
return false;
- //
}
- } catch (Exception e) {
- return true;
+
}
}
- static int readActiveIdePort() {
- if ( checkActiveIde() == true) {
- try {
- FileInputStream fis = new FileInputStream( AnalyzerPaths.IDE_ACTIVE_SAVE_PORT_PATH );
- DataInputStream dis = new DataInputStream(fis);
- try {
- return dis.readInt();
- } catch (IOException e) {
- e.printStackTrace();
- return 0;
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return 0;
- }
- } else {
- return 0;
- }
- }
}