mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
...
This commit is contained in:
parent
2885406590
commit
9b498765ab
2 changed files with 76 additions and 62 deletions
|
@ -20,7 +20,10 @@ import phpdbg.ui.JConsole.MessageType;
|
||||||
public class DebugSocket extends Socket implements Runnable {
|
public class DebugSocket extends Socket implements Runnable {
|
||||||
private final Boolean reader;
|
private final Boolean reader;
|
||||||
private final JConsole main;
|
private final JConsole main;
|
||||||
private Boolean quit;
|
private final Thread thread;
|
||||||
|
|
||||||
|
private volatile Boolean quit;
|
||||||
|
private volatile Boolean started;
|
||||||
|
|
||||||
public DebugSocket(final String host, final Integer port, final JConsole main, Boolean reader) throws IOException {
|
public DebugSocket(final String host, final Integer port, final JConsole main, Boolean reader) throws IOException {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
|
@ -28,10 +31,15 @@ public class DebugSocket extends Socket implements Runnable {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
this.quit = false;
|
this.quit = false;
|
||||||
|
this.started = false;
|
||||||
|
this.thread = new Thread(this);
|
||||||
|
}
|
||||||
|
|
||||||
synchronized(main) {
|
public void start() {
|
||||||
if (!main.isConnected()) {
|
synchronized(this) {
|
||||||
main.setConnected(true);
|
if (!started) {
|
||||||
|
started = true;
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,19 +47,26 @@ public class DebugSocket extends Socket implements Runnable {
|
||||||
public void quit() {
|
public void quit() {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
quit = true;
|
quit = true;
|
||||||
this.notifyAll();
|
started = false;
|
||||||
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
try {
|
try {
|
||||||
|
synchronized(main) {
|
||||||
|
if (!main.isConnected()) {
|
||||||
|
main.setConnected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
do {
|
do {
|
||||||
if (reader) {
|
if (reader) {
|
||||||
String command;
|
String command;
|
||||||
OutputStream output = getOutputStream();
|
OutputStream output = getOutputStream();
|
||||||
|
|
||||||
this.wait();
|
wait();
|
||||||
|
|
||||||
command = main.getInputField().getText();
|
command = main.getInputField().getText();
|
||||||
/* send command to stdin socket */
|
/* send command to stdin socket */
|
||||||
|
@ -67,9 +82,8 @@ public class DebugSocket extends Socket implements Runnable {
|
||||||
/* get data from stdout socket */
|
/* get data from stdout socket */
|
||||||
byte[] bytes = new byte[1];
|
byte[] bytes = new byte[1];
|
||||||
do {
|
do {
|
||||||
/* this is some of the laziest programming I ever done */
|
|
||||||
if (input.available() == 0) {
|
if (input.available() == 0) {
|
||||||
this.wait(400);
|
wait(400);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,20 +19,6 @@ import javax.swing.JTextField;
|
||||||
* @author krakjoe
|
* @author krakjoe
|
||||||
*/
|
*/
|
||||||
public class JConsole extends javax.swing.JDialog {
|
public class JConsole extends javax.swing.JDialog {
|
||||||
public enum MessageType {
|
|
||||||
INFO (JOptionPane.INFORMATION_MESSAGE),
|
|
||||||
WARN (JOptionPane.WARNING_MESSAGE),
|
|
||||||
ERROR (JOptionPane.ERROR_MESSAGE);
|
|
||||||
|
|
||||||
private final Integer type;
|
|
||||||
private MessageType(Integer type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
public Integer getType() { return this.type; }
|
|
||||||
public Boolean equals(Integer other) { return this.type.equals(other); }
|
|
||||||
public Boolean equals(MessageType other) { return this.type.equals(other.getType()); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates user interface
|
* Creates user interface
|
||||||
* @param parent
|
* @param parent
|
||||||
|
@ -197,6 +183,30 @@ public class JConsole extends javax.swing.JDialog {
|
||||||
private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
|
private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
|
||||||
try {
|
try {
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
|
connect();
|
||||||
|
} else {
|
||||||
|
disconnect();
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
messageBox(ex.getMessage(), MessageType.ERROR);
|
||||||
|
}
|
||||||
|
}//GEN-LAST:event_openButtonActionPerformed
|
||||||
|
|
||||||
|
private void resetStdoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetStdoutActionPerformed
|
||||||
|
// TODO add your handling code here:
|
||||||
|
output.setText(null);
|
||||||
|
}//GEN-LAST:event_resetStdoutActionPerformed
|
||||||
|
|
||||||
|
private void disconnect() {
|
||||||
|
if (in != null) {
|
||||||
|
in.quit();
|
||||||
|
}
|
||||||
|
if (out != null) {
|
||||||
|
out.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void connect() throws IOException {
|
||||||
Integer ports[] = new Integer[2];
|
Integer ports[] = new Integer[2];
|
||||||
String address = getHost();
|
String address = getHost();
|
||||||
|
|
||||||
|
@ -209,7 +219,7 @@ public class JConsole extends javax.swing.JDialog {
|
||||||
if (ports[0] > 0) {
|
if (ports[0] > 0) {
|
||||||
in = new DebugSocket(
|
in = new DebugSocket(
|
||||||
address, ports[0], this, true);
|
address, ports[0], this, true);
|
||||||
new Thread(in).start();
|
in.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,28 +227,12 @@ public class JConsole extends javax.swing.JDialog {
|
||||||
if (ports[1] > 0) {
|
if (ports[1] > 0) {
|
||||||
out = new DebugSocket(
|
out = new DebugSocket(
|
||||||
address, ports[1], this, false);
|
address, ports[1], this, false);
|
||||||
new Thread(out).start();
|
out.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (in != null) {
|
|
||||||
in.quit();
|
|
||||||
}
|
}
|
||||||
if (out != null) {
|
|
||||||
out.quit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
messageBox(ex.getMessage(), MessageType.ERROR);
|
|
||||||
}
|
|
||||||
}//GEN-LAST:event_openButtonActionPerformed
|
|
||||||
|
|
||||||
private void resetStdoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetStdoutActionPerformed
|
|
||||||
// TODO add your handling code here:
|
|
||||||
output.setText(null);
|
|
||||||
}//GEN-LAST:event_resetStdoutActionPerformed
|
|
||||||
|
|
||||||
public Boolean isConnected() {
|
public Boolean isConnected() {
|
||||||
return connected;
|
return connected;
|
||||||
|
@ -290,7 +284,6 @@ public class JConsole extends javax.swing.JDialog {
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
messageBox("Invalid stdin port provided !", MessageType.WARN);
|
messageBox("Invalid stdin port provided !", MessageType.WARN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +293,6 @@ public class JConsole extends javax.swing.JDialog {
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
messageBox("Invalid stdout port provided !", MessageType.WARN);
|
messageBox("Invalid stdout port provided !", MessageType.WARN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,12 +337,7 @@ public class JConsole extends javax.swing.JDialog {
|
||||||
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||||
if (in != null)
|
dialog.disconnect();
|
||||||
in.quit();
|
|
||||||
|
|
||||||
if (out != null)
|
|
||||||
out.quit();
|
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -380,4 +367,17 @@ public class JConsole extends javax.swing.JDialog {
|
||||||
private javax.swing.JPopupMenu stdoutPopupMenu;
|
private javax.swing.JPopupMenu stdoutPopupMenu;
|
||||||
private javax.swing.JTextField stdoutPort;
|
private javax.swing.JTextField stdoutPort;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
|
public enum MessageType {
|
||||||
|
INFO (JOptionPane.INFORMATION_MESSAGE),
|
||||||
|
WARN (JOptionPane.WARNING_MESSAGE),
|
||||||
|
ERROR (JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
private final Integer type;
|
||||||
|
private MessageType(Integer type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
public Integer getType() { return this.type; }
|
||||||
|
public Boolean equals(Integer other) { return this.type.equals(other); }
|
||||||
|
public Boolean equals(MessageType other) { return this.type.equals(other.getType()); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue