From 7479c9bc4aa2fdc51d9f2e7e500471da4eeeddbc Mon Sep 17 00:00:00 2001 From: incastrix Date: Wed, 24 Dec 2008 17:35:22 +0000 Subject: [PATCH 1/1] Refactor. --- .../xdebug/core/xdebug/ResponseList.java | 3 +- .../xdebug/core/xdebug/ResponseListener.java | 103 ++++++-------------- .../xdebug/core/xdebug/XDebugConnection.java | 4 + 3 files changed, 37 insertions(+), 73 deletions(-) diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java index 2bc1f66..bf0f967 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java @@ -13,7 +13,8 @@ public class ResponseList { fList = new HashMap(); } - public synchronized void add(XDebugResponse response, int id) { + public synchronized void add(XDebugResponse response/*, int id*/) { + int id = response.getTransactionID(); fList.put(new Integer(id), response); fLastId = id; notifyAll(); diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java index 345bd3d..d1ea8f8 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java @@ -49,7 +49,16 @@ public class ResponseListener extends Job { private String fAddress; private String fIdeKey; - public synchronized void setParentNode(String xmlInput) { + public XDebugResponse(String XMLInput) { + fTransactionID = -1; + fCommand = ""; + fStatus = ""; + fReason = ""; + fName= ""; + setParentNode(XMLInput); + } + + /*public*/private synchronized void setParentNode(String xmlInput) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; Document doc = null; @@ -109,11 +118,11 @@ public class ResponseListener extends Job { int code = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "code")); String text = (child.getFirstChild()).getNodeValue(); XDebugCorePlugin.log(IStatus.ERROR," ERROR "+code+": "+text); - setError(true); + fError = true; return; } } - setError(false); + fError = false; fStatus = getAttributeValue("status"); fReason = getAttributeValue("reason"); @@ -137,6 +146,8 @@ public class ResponseListener extends Job { if( firstChild1 != null ) { fValue = firstChild1.getNodeValue(); + } else { + fValue = ""; } } catch (Exception e) { // TODO: handle exception @@ -174,14 +185,10 @@ public class ResponseListener extends Job { return parentNode; } - public synchronized String getIdeKey(){ - return fIdeKey; - } - - public synchronized String getCommand() { + /*public*/private synchronized String getCommand() { return fCommand; } - public synchronized String getName() { + /*public*/private synchronized String getName() { return fName; } @@ -189,18 +196,6 @@ public class ResponseListener extends Job { return fValue; } - public synchronized String getType() { - return fType; - } - - public synchronized String getAddress() { - return fAddress; - } - - public XDebugResponse(String XMLInput) { - setParentNode(XMLInput); - } - public synchronized String getReason() { return fReason; } @@ -213,69 +208,40 @@ public class ResponseListener extends Job { return fTransactionID; } - public boolean isError() { + public boolean isError() { return fError; } - - public void setError(boolean error) { - fError = error; - } - - XDebugResponse() { - fTransactionID = -1; - fCommand = ""; - fStatus = ""; - fReason = ""; - fName= ""; - } } + private XDebugConnection fConnection; - private XDebugResponse lastResponse; - + private ResponseList fResponseList; + public ResponseListener(XDebugConnection connection) { super("XDebug Event Dispatch"); setSystem(true); fConnection = connection; - lastResponse = new XDebugResponse(); fResponseList = new ResponseList(); } private void checkResponse(XDebugResponse response) { - Node node = response.getParentNode(); - if (node.hasChildNodes()) { - Node child = node.getFirstChild(); - if (child.getNodeName().equals("error")) { - int code = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "code")); - String text=(child.getFirstChild()).getNodeValue(); - XDebugCorePlugin.log(IStatus.ERROR," ERROR "+code+": "+text); - lastResponse.setError(true); - return; - } - } - lastResponse.setError(false); if (response.getStatus().equals("stopping") || response.getStatus().equals("stopped")) { this.cancel(); - fireEvent(IPHPDebugEvent.STOPPED); + fireEvent(IPHPDebugEvent.STOPPED, null); } else if (response.getStatus().equals("break") && response.getReason().equals("ok")){ if (response.getCommand().equals("run")) { fireEvent(IPHPDebugEvent.BREAKPOINT_HIT, null); } else if (response.getCommand().equals("step_into")) { - fireEvent(IPHPDebugEvent.STEP_END); + fireEvent(IPHPDebugEvent.STEP_END, null); } else if (response.getCommand().equals("step_over")) { - fireEvent(IPHPDebugEvent.STEP_END); + fireEvent(IPHPDebugEvent.STEP_END, null); } else if (response.getCommand().equals("step_out")) { - fireEvent(IPHPDebugEvent.STEP_END); + fireEvent(IPHPDebugEvent.STEP_END, null); } } } - protected void fireEvent(int detail) { - DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, detail); - DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); - } - - protected void fireEvent(int detail, Object data) { + private void fireEvent(int detail, Object data) { DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, detail); event.setData(data); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); @@ -286,33 +252,26 @@ public class ResponseListener extends Job { */ protected IStatus run(IProgressMonitor monitor) { String InputXML = ""; - while (!fConnection.isClosed() && (InputXML != null)) { + while (!fConnection.isClosed()) { if (!monitor.isCanceled()) { try { - if(!fConnection.isClosed()) { InputXML = fConnection.readData(); - } } catch (Exception e) { ; // } if (InputXML != null) { XDebugCorePlugin.log(IStatus.INFO, InputXML); - lastResponse.setParentNode(InputXML); - if (lastResponse.getName() == "response") { - addResponse(lastResponse, lastResponse.getTransactionID()); - checkResponse(lastResponse); + XDebugResponse response = new XDebugResponse(InputXML); + if (response.getName() == "response") { + fResponseList.add(response); + checkResponse(response); } } } } return Status.OK_STATUS; } - private ResponseList fResponseList; - - protected void addResponse(XDebugResponse response, int id) { - fResponseList.add(response, id); - } - + public XDebugResponse getResponse(int id) { return fResponseList.get(id); } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java index 19e6a2f..a2b9a03 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java @@ -114,6 +114,10 @@ public class XDebugConnection { } private synchronized int _sendRequest(String command, String arguments) { + if (fDebugSocket == null) { + return 0; + } + XDebugCorePlugin.log(IStatus.INFO,command+" -i "+fTransactionID+" "+arguments); synchronized (fDebugSocket) { try { -- 1.7.1