Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrennie2010-12-09 15:16:13 -0500
committermrennie2010-12-09 15:16:13 -0500
commit2fc07f416fecc7240ba69c6bc0d92e4f3018bc4e (patch)
tree19d5fa342b5f7129d0d93a9cb796e3adde9cb457 /development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome
parentc1bf50c0b486d21c06f5c1445189ae951391e508 (diff)
downloadwebtools.jsdt.debug-2fc07f416fecc7240ba69c6bc0d92e4f3018bc4e.tar.gz
webtools.jsdt.debug-2fc07f416fecc7240ba69c6bc0d92e4f3018bc4e.tar.xz
webtools.jsdt.debug-2fc07f416fecc7240ba69c6bc0d92e4f3018bc4e.zip
updated connection + thread experiments
Diffstat (limited to 'development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome')
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/event/EventQueueImpl.java19
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/ThreadImpl.java22
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/VMImpl.java85
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/messages.properties2
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Attributes.java158
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ChromeSocketConnection.java97
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Commands.java68
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/EventPacketImpl.java19
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/JSON.java16
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/PacketImpl.java10
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/RequestPacketImpl.java27
-rw-r--r--development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ResponsePacketImpl.java52
12 files changed, 308 insertions, 267 deletions
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/event/EventQueueImpl.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/event/EventQueueImpl.java
index f60133d..71911ef 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/event/EventQueueImpl.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/event/EventQueueImpl.java
@@ -10,10 +10,14 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.chrome.event;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventQueue;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventSet;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager;
+import org.eclipse.wst.jsdt.debug.internal.chrome.Tracing;
import org.eclipse.wst.jsdt.debug.internal.chrome.jsdi.MirrorImpl;
import org.eclipse.wst.jsdt.debug.internal.chrome.transport.Commands;
import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;
@@ -59,8 +63,19 @@ public class EventQueueImpl extends MirrorImpl implements EventQueue {
Event event = chromeVM().receiveEvent();
if(event != null) {
//TODO
- if(event.getEvent().equals(Commands.INSPECT)) {
- ermanager.breakpointRequests();
+ if(event.getEvent().equals(Commands.NAVIGATED)) {
+ if(TRACE) {
+ Tracing.writeString("got navigated event"); //$NON-NLS-1$
+ }
+ }
+ else if(event.getEvent().equals(Commands.CLOSED)) {
+ List requests = ermanager.threadExitRequests();
+ for(Iterator i = requests.iterator(); i.hasNext();) {
+ //TODO
+ }
+ if(TRACE) {
+ Tracing.writeString("got closed event"); //$NON-NLS-1$
+ }
}
}
}
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/ThreadImpl.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/ThreadImpl.java
index 701f9e9..989caa9 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/ThreadImpl.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/ThreadImpl.java
@@ -20,6 +20,21 @@ import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
*/
public class ThreadImpl extends MirrorImpl implements ThreadReference {
+ Number id = null;
+ String url = null;
+
+ /**
+ * Constructor
+ * @param vm
+ * @param id
+ * @param url
+ */
+ public ThreadImpl(VMImpl vm, Number id, String url) {
+ super(vm);
+ this.id = id;
+ this.url = url;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference#frameCount()
*/
@@ -84,7 +99,10 @@ public class ThreadImpl extends MirrorImpl implements ThreadReference {
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference#name()
*/
public String name() {
- return null;
+ return url;
+ }
+
+ public Number id() {
+ return id;
}
-
}
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/VMImpl.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/VMImpl.java
index a714e0f..a0bef24 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/VMImpl.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/VMImpl.java
@@ -13,6 +13,7 @@ package org.eclipse.wst.jsdt.debug.internal.chrome.jsdi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -71,8 +72,9 @@ public class VMImpl extends MirrorImpl implements VirtualMachine {
private EventQueue queue = new EventQueueImpl(this, ermanager);
private final DebugSession session;
- private Map threads = Collections.synchronizedMap(new HashMap(4));
- private Map scripts = Collections.synchronizedMap(new HashMap(4));
+ private Map threads = null;
+ private Map scripts = null;
+ private String version = null;
/**
* Constructor
@@ -131,27 +133,72 @@ public class VMImpl extends MirrorImpl implements VirtualMachine {
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#version()
*/
- public String version() {
- RequestPacketImpl request = new RequestPacketImpl(Commands.VERSION, Attributes.TOOL_DEVTOOLSRVC);
- Response response = sendRequest(request);
- if(response != null && response.isSuccess()) {
- return (String) response.getBody().get(Commands.VERSION);
+ public synchronized String version() {
+ if(version == null) {
+ RequestPacketImpl request = new RequestPacketImpl(Commands.VERSION, Attributes.TOOL_DEVTOOLSRVC, null);
+ Response response = sendRequest(request);
+ if(response.isSuccess()) {
+ version = (String) response.getBody().get(Attributes.DATA);
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed version request]" + JSON.serialize(request)); //$NON-NLS-1$
+ }
}
- Tracing.writeString("VM [failed version request]" + JSON.serialize(request)); //$NON-NLS-1$
- return null;
+ return version;
}
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#allThreads()
*/
- public List allThreads() {
+ public synchronized List allThreads() {
+ if(threads == null) {
+ threads = Collections.synchronizedMap(new HashMap(4));
+ RequestPacketImpl request = new RequestPacketImpl(Commands.LIST_TABS, Attributes.TOOL_DEVTOOLSRVC, null);
+ Response response = sendRequest(request);
+ if(response.isSuccess()) {
+ List tabs = (List) response.getBody().get(Attributes.DATA);
+ if(tabs != null) {
+ ArrayList values = null;
+ for(Iterator i = tabs.iterator(); i.hasNext();) {
+ values = (ArrayList) i.next();
+ String url = (String)values.get(1);
+ Number id = (Number)values.get(0);
+ ThreadImpl thread = new ThreadImpl(this, id, url);
+ threads.put(id, thread);
+ attach(thread);
+ }
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed all_tabs request]" + JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
return new ArrayList(threads.values());
}
+ /**
+ * Try to attach the debugger to the v8 debugger service for the given thread (tab)
+ *
+ * @param thread
+ */
+ void attach(ThreadImpl thread) {
+ RequestPacketImpl request = new RequestPacketImpl(Commands.ATTACH, Attributes.TOOL_DEVTOOLSRVC, thread.id());
+ Response response = sendRequest(request);
+ if(response.isSuccess()) {
+
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed attach request] " + JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#allScripts()
*/
- public List allScripts() {
+ public synchronized List allScripts() {
+ if(this.scripts == null) {
+ this.scripts = Collections.synchronizedMap(new HashMap(4));
+ }
return new ArrayList(scripts.values());
}
@@ -161,7 +208,19 @@ public class VMImpl extends MirrorImpl implements VirtualMachine {
public synchronized void dispose() {
if(state != DISPOSED) {
//TODO
- state = DISPOSED;
+ try {
+ if(threads != null) {
+ threads.clear();
+ threads = null;
+ }
+ if(scripts != null) {
+ scripts.clear();
+ scripts = null;
+ }
+ }
+ finally {
+ state = DISPOSED;
+ }
}
}
@@ -238,7 +297,7 @@ public class VMImpl extends MirrorImpl implements VirtualMachine {
}
catch(DisconnectedException de) {
disconnectVM();
- handleException(de.getMessage(), de);
+ handleException(de.getMessage(), de.getCause());
}
catch(TimeoutException te) {
ChromePlugin.log(te);
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/messages.properties b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/messages.properties
index e4d4ca2..4247aea 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/messages.properties
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/jsdi/messages.properties
@@ -1,3 +1,3 @@
cannot_mirror_null_number=You cannot mirror a null Number
-chrome_vm=Chrome VM [{0}]
+chrome_vm=Chrome VM
vm_description=The virtual machine for communication with Google Chrome for debugging JavaScript in v8
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Attributes.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Attributes.java
index 240b46a..5cf9557 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Attributes.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Attributes.java
@@ -18,170 +18,66 @@ package org.eclipse.wst.jsdt.debug.internal.chrome.transport;
public interface Attributes {
/**
- * The name for the development tools service
- * <br><br>
- * Value is: <code>DevToolsService</code>
- */
- public static final String TOOL_DEVTOOLSRVC = "DevToolsService"; //$NON-NLS-1$
- /**
- * The name for the V8 debugger service
- * <br><br>
- * Value is: <code>V8Debugger</code>
- */
- public static final String TOOL_V8DEBUGGER = "V8Debugger"; //$NON-NLS-1$
-
- /**
- * The "arguments" attribute
+ * Result meaning everything is OK
*/
- public static final String ARGUMENTS = "arguments"; //$NON-NLS-1$
+ public static final int OK = 0;
/**
- * The "body" attribute
+ * Result meaning that tab is in a state that cannot accept the sent request
*/
- public static final String BODY = "body"; //$NON-NLS-1$
+ public static final int ILLEGAL_TAB_STATE = 1;
/**
- * The "columnOffset" attribute
+ * Result meaning the given tab id does not exist
*/
- public static final String COLUMN_OFFSET = "columnOffset"; //$NON-NLS-1$
+ public static final int UNKNOWN_TAB = 2;
/**
- * The "command" attribute
+ * Result meaning the debugger encountered an error
*/
- public static final String COMMAND = "command"; //$NON-NLS-1$
+ public static final int DEBUGGER_ERROR = 3;
/**
- * the "context_href" attribute
+ * Result meaning the request is unknown
*/
- public static final String CONTEXT_HREF = "context_href"; //$NON-NLS-1$
+ public static final int UNKNOWN_COMMAND = 4;
+
/**
- * The "context_id" attribute
+ * The name for the development tools service
+ * <br><br>
+ * Value is: <code>DevToolsService</code>
*/
- public static final String CONTEXT_ID = "context_id"; //$NON-NLS-1$
+ public static final String TOOL_DEVTOOLSRVC = "DevToolsService"; //$NON-NLS-1$
/**
- * The "contexts" attribute
+ * The name for the V8 debugger service
+ * <br><br>
+ * Value is: <code>V8Debugger</code>
*/
- public static final String CONTEXTS = "contexts"; //$NON-NLS-1$
+ public static final String TOOL_V8DEBUGGER = "V8Debugger"; //$NON-NLS-1$
/**
- * The "crossfire_id" attribute
+ * The "command" attribute
*/
- public static final String CROSSFIRE_ID = "crossfire_id"; //$NON-NLS-1$
+ public static final String COMMAND = "command"; //$NON-NLS-1$
/**
* The "data" attribute
*/
public static final String DATA = "data"; //$NON-NLS-1$
/**
- * The "expression" attribute
- */
- public static final String EXPRESSION = "expression"; //$NON-NLS-1$
- /**
- * The "frame" attribute
- */
- public static final String FRAME = "frame"; //$NON-NLS-1$
- /**
- * The "frames" attribute
+ * The "dest" attribute
*/
- public static final String FRAMES = "frames"; //$NON-NLS-1$
- /**
- * The "fromFrame" attribute
- */
- public static final String FROM_FRAME = "fromFrame"; //$NON-NLS-1$
- /**
- * The "func" attribute
- */
- public static final String FUNC = "func"; //$NON-NLS-1$
- /**
- * The "handle" attribute
- */
- public static final String HANDLE = "handle"; //$NON-NLS-1$
+ public static final String DESTINATION = "dest"; //$NON-NLS-1$
/**
* The "handshake" attribute
*/
public static final String HANDSHAKE = "handshake"; //$NON-NLS-1$
/**
- * The "href" attribute
- */
- public static final String HREF = "href"; //$NON-NLS-1$
- /**
- * The "id" attribute
- */
- public static final String ID = "id"; //$NON-NLS-1$
- /**
- * The "includeScopes" attribute
- */
- public static final String INCLUDE_SCOPES = "includeScopes"; //$NON-NLS-1$
- /**
- * The "includeSource" attribute
- */
- public static final String INCLUDE_SOURCE = "includeSource"; //$NON-NLS-1$
- /**
- * The "index" attribute
- */
- public static final String INDEX = "index"; //$NON-NLS-1$
- /**
- * The "line" attribute
- */
- public static final String LINE = "line"; //$NON-NLS-1$
- /**
- * The "lineCount" attribute
- */
- public static final String LINE_COUNT = "lineCount"; //$NON-NLS-1$
- /**
- * The "lineOffset" attribute
- */
- public static final String LINE_OFFSET = "lineOffset"; //$NON-NLS-1$
- /**
- * The "locals" attribute
- */
- public static final String LOCALS = "locals"; //$NON-NLS-1$
- /**
- * The message attribute for this packet
+ * The "result" attribute
*/
- public static final String MESSAGE = "message"; //$NON-NLS-1$
- /**
- * The "ref" attribute
- */
- public static final String REF = "ref"; //$NON-NLS-1$
- /**
- * The "request_seq" attribute
- */
- public static final String REQUEST_SEQ = "request_seq"; //$NON-NLS-1$
- /**
- * The running attribute for this packet
- */
- public static final String RUNNING = "running"; //$NON-NLS-1$
- /**
- * The "script" attribute
- */
- public static final String SCRIPT = "script"; //$NON-NLS-1$
- /**
- * The "seq" attribute
- */
- public static final String SEQ = "seq"; //$NON-NLS-1$
- /**
- * The "source" attribute
- */
- public static final String SOURCE = "source"; //$NON-NLS-1$
- /**
- * The "sourceLength" attribute
- */
- public static final String SOURCE_LENGTH = "sourceLength"; //$NON-NLS-1$
- /**
- * The success attribute for this packet
- */
- public static final String SUCCESS = "success"; //$NON-NLS-1$
- /**
- * The "this" attribute
- */
- public static final String THIS = "this"; //$NON-NLS-1$
- /**
- * the "tool" attribute
- */
- public static final String TOOL = "tool"; //$NON-NLS-1$
+ public static final String RESULT = "result"; //$NON-NLS-1$
/**
* The "type" attribute
*/
public static final String TYPE = "type"; //$NON-NLS-1$
/**
- * The "url" attribute
+ * the "tool" attribute
*/
- public static final String URL = "url"; //$NON-NLS-1$
+ public static final String TOOL = "tool"; //$NON-NLS-1$
/**
* The "value" attribute
*/
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ChromeSocketConnection.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ChromeSocketConnection.java
index 41cb177..efbb8cf 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ChromeSocketConnection.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ChromeSocketConnection.java
@@ -13,6 +13,7 @@ import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.Socket;
+import java.util.HashSet;
import java.util.Map;
import org.eclipse.wst.jsdt.debug.internal.chrome.ChromePlugin;
@@ -30,6 +31,14 @@ public class ChromeSocketConnection extends SocketConnection {
public static final String HANDSHAKE = "ChromeDevToolsHandshake\r\n"; //$NON-NLS-1$
+ private static final HashSet EVENTS;
+
+ static {
+ EVENTS = new HashSet();
+ EVENTS.add(Commands.CLOSED);
+ EVENTS.add(Commands.NAVIGATED);
+ }
+
/**
* Constructor
*
@@ -39,6 +48,7 @@ public class ChromeSocketConnection extends SocketConnection {
*/
public ChromeSocketConnection(Socket socket) throws IOException {
super(socket);
+
}
/* (non-Javadoc)
@@ -67,7 +77,6 @@ public class ChromeSocketConnection extends SocketConnection {
Writer writer = getWriter();
writer.write(HANDSHAKE);
writer.flush();
- //waitForReadyRead();
}
/**
@@ -116,6 +125,15 @@ public class ChromeSocketConnection extends SocketConnection {
}
r = c == '\r';
}
+ r = false;
+ while(reader.ready() && (c = reader.read()) > -1) {
+ if(r) {
+ if(c == '\n') {
+ break;
+ }
+ }
+ r = c == '\r';
+ }
if(PacketImpl.TRACE) {
Tracing.writeString("READ HANDSHAKE: "+buffer.toString()); //$NON-NLS-1$
}
@@ -128,27 +146,40 @@ public class ChromeSocketConnection extends SocketConnection {
public Packet readPacket() throws IOException {
StringBuffer buffer = new StringBuffer();
int c = -1;
- boolean len = false;
Reader reader = getReader();
+ String dest = null;
+ String tool = null;
+ String len = null;
+ boolean r = false;
while((c = reader.read()) > -1) {
- if(c == '\r') {
- break;
- }
- if(len) {
- buffer.append((char)c);
+ if(r) {
+ if(c == '\n') {
+ String str = buffer.toString();
+ if(str.startsWith(JSON.DESTINATION_HEADER)) {
+ dest = grabAttrib(str);
+ }
+ else if(str.startsWith(JSON.TOOL_HEADER)) {
+ tool = grabAttrib(str);
+ }
+ else if(str.startsWith(JSON.CONTENT_LENGTH)) {
+ len = grabAttrib(str);
+ }
+ else if(str.equals("\r")) { //$NON-NLS-1$
+ break;
+ }
+ buffer = new StringBuffer();
+ r = false;
+ }
continue;
}
- len = c == ':';
+ buffer.append((char)c);
+ r = c == '\r';
}
int length = 0;
try {
- length = Integer.parseInt(buffer.toString());
+ length = Integer.parseInt(len);
} catch (NumberFormatException e) {
- throw new IOException("Failed to parse content length: " + buffer.toString()); //$NON-NLS-1$
- }
- c = reader.read();
- if(c != '\n') {
- throw new IOException("Failed to parse content length: " + buffer.toString() + "next char was not '\n'" + (char)c); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new IOException("Failed to parse content length: " + len); //$NON-NLS-1$
}
char[] message = new char[length];
int n = 0;
@@ -161,19 +192,37 @@ public class ChromeSocketConnection extends SocketConnection {
n += count;
}
if(PacketImpl.TRACE) {
- Tracing.writeString("READ PACKET: [length - "+length+"]"+new String(message)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("READ PACKET: [destination - "+dest+"] [tool - "+tool+"] [length - "+length+"]"+new String(message)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
Map json = (Map) JSON.read(new String(message));
- String type = (String) json.get(Attributes.TYPE);
- if (EventPacketImpl.EVENT.equals(type)) {
- return new EventPacketImpl(json);
- }
- if (RequestPacketImpl.REQUEST.equals(type)) {
- return new RequestPacketImpl(json);
- }
- if (ResponsePacketImpl.RESPONSE.equals(type)) {
+ json.put(Attributes.TOOL, tool);
+ json.put(Attributes.DESTINATION, dest);
+ if(json.containsKey(Attributes.RESULT)) {
+ if(EVENTS.contains(json.get(Attributes.COMMAND))) {
+ json.put(Attributes.TYPE, EventPacketImpl.EVENT);
+ return new EventPacketImpl(json);
+ }
+ json.put(Attributes.TYPE, ResponsePacketImpl.RESPONSE);
return new ResponsePacketImpl(json);
}
- throw new IOException("Unknown packet type: " + type); //$NON-NLS-1$
+ json.put(Attributes.TYPE, RequestPacketImpl.REQUEST);
+ return new RequestPacketImpl(json);
+ }
+
+ /**
+ * Grabs the attribute from the RHS of the header. Where all headers
+ * have the form <code>[name]:[value]</code>.
+ *
+ * @param str the string to parse
+ * @return the <code>[value]</code> from the header
+ */
+ String grabAttrib(String str) {
+ if(str != null) {
+ int idx = str.indexOf(':');
+ if(idx > -1) {
+ return str.substring(idx+1, str.length()-1);
+ }
+ }
+ return null;
}
}
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Commands.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Commands.java
index 79a9f03..c975a37 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Commands.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/Commands.java
@@ -18,73 +18,37 @@ package org.eclipse.wst.jsdt.debug.internal.chrome.transport;
public interface Commands {
/**
- * The "backtrace" command
+ * The "attach" command
*/
- public static final String BACKTRACE = "backtrace"; //$NON-NLS-1$
+ public static final String ATTACH = "attach"; //$NON-NLS-1$
/**
- * The "changebreakpoint" command
+ * The "closed" command
*/
- public static final String CHANGE_BREAKPOINT = "changebreakpoint"; //$NON-NLS-1$
+ public static final String CLOSED = "closed"; //$NON-NLS-1$
/**
- * The "clearbreakpoint" command
+ * The "debugger_command" command
*/
- public static final String CLEAR_BREAKPOINT = "clearbreakpoint"; //$NON-NLS-1$
+ public static final String DEBUGGER_COMMAND = "debugger_command"; //$NON-NLS-1$
/**
- * The "continue" command
+ * The "detach" command
*/
- public static final String CONTINUE = "continue"; //$NON-NLS-1$
+ public static final String DETACH = "detach"; //$NON-NLS-1$
/**
- * The "evaluate" command
+ * The "evaluate_javascript" command
*/
- public static final String EVALUATE = "evaluate"; //$NON-NLS-1$
+ public static final String EVALUATE_JAVASCRIPT = "evaluate_javascript"; //$NON-NLS-1$
/**
- * The "frame" command
+ * The "list_tabs" command
*/
- public static final String FRAME = "frame"; //$NON-NLS-1$
+ public static final String LIST_TABS = "list_tabs"; //$NON-NLS-1$
/**
- * The "getbreakpoint" command
+ * The "navigated" command
*/
- public static final String GET_BREAKPOINT = "getbreakpoint"; //$NON-NLS-1$
+ public static final String NAVIGATED = "navigated"; //$NON-NLS-1$
/**
- * The "getbreakpoints" command
+ * The "ping" command
*/
- public static final String GET_BREAKPOINTS = "getbreakpoints"; //$NON-NLS-1$
- /**
- * The "inspect" command
- */
- public static final String INSPECT = "inspect"; //$NON-NLS-1$
- /**
- * The "listcontexts" command
- */
- public static final String LISTCONTEXTS = "listcontexts"; //$NON-NLS-1$
- /**
- * The "lookup" command
- */
- public static final String LOOKUP = "lookup"; //$NON-NLS-1$
- /**
- * The "scopes" command
- */
- public static final String SCOPES = "scopes"; //$NON-NLS-1$
- /**
- * The "script" command
- */
- public static final String SCRIPT = "script"; //$NON-NLS-1$
- /**
- * The "scripts" command
- */
- public static final String SCRIPTS = "scripts"; //$NON-NLS-1$
- /**
- * The "setbreakpoint" command
- */
- public static final String SET_BREAKPOINT = "setbreakpoint"; //$NON-NLS-1$
- /**
- * The "source" command
- */
- public static final String SOURCE = "source"; //$NON-NLS-1$
- /**
- * The "suspend" command
- */
- public static final String SUSPEND = "suspend"; //$NON-NLS-1$
+ public static final String PING = "ping"; //$NON-NLS-1$
/**
* The "version" command
*/
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/EventPacketImpl.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/EventPacketImpl.java
index 94172d3..c2f5b02 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/EventPacketImpl.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/EventPacketImpl.java
@@ -11,6 +11,7 @@
package org.eclipse.wst.jsdt.debug.internal.chrome.transport;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import org.eclipse.wst.jsdt.debug.transport.packet.Event;
@@ -28,7 +29,8 @@ public class EventPacketImpl extends PacketImpl implements Event {
public static final String EVENT = "event"; //$NON-NLS-1$
private String event = null;
- private Map body = null;
+ protected Number result = null;
+ protected Map body = null;
/**
* Constructor
@@ -55,6 +57,12 @@ public class EventPacketImpl extends PacketImpl implements Event {
if(event == null) {
throw new IllegalArgumentException(Messages.no_event_found_in_json);
}
+ this.result = (Number) json.get(Attributes.RESULT);
+ Object data = json.get(Attributes.DATA);
+ if(data != null) {
+ this.body = new HashMap();
+ this.body.put(Attributes.DATA, data);
+ }
}
/* (non-Javadoc)
@@ -68,10 +76,10 @@ public class EventPacketImpl extends PacketImpl implements Event {
* @see org.eclipse.wst.jsdt.debug.transport.packet.Event#getBody()
*/
public Map getBody() {
- if(body == null) {
+ if(this.body == null) {
return Collections.EMPTY_MAP;
}
- return body;
+ return this.body;
}
/* (non-Javadoc)
@@ -80,8 +88,9 @@ public class EventPacketImpl extends PacketImpl implements Event {
public Map toJSON() {
Map json = super.toJSON();
json.put(Attributes.COMMAND, event);
- if(body != null) {
- json.put(Attributes.BODY, body);
+ json.put(Attributes.RESULT, this.result);
+ if(this.body != null) {
+ json.put(Attributes.DATA, this.body.get(Attributes.DATA));
}
return json;
}
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/JSON.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/JSON.java
index fc327de..be8e435 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/JSON.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/JSON.java
@@ -54,11 +54,16 @@ public final class JSON {
public static final String CONTENT_LENGTH = "Content-Length:"; //$NON-NLS-1$
/**
- * The default <code>Tools:</code> pre-amble
+ * The default <code>Tool:</code> pre-amble
*/
public static final String TOOL_HEADER = "Tool:"; //$NON-NLS-1$
/**
+ * The default <code>Destination:</code> pre-amble
+ */
+ public static final String DESTINATION_HEADER = "Destination:"; //$NON-NLS-1$
+
+ /**
* Enables / Disables tracing in the all of the JSDI implementations
*
* @param trace
@@ -236,6 +241,12 @@ public final class JSON {
buffer.insert(0, buff);
}
+ public static void writeDestinationHeader(StringBuffer buffer, Number destination) {
+ StringBuffer buff = new StringBuffer();
+ buff.append(DESTINATION_HEADER).append(destination).append(LINE_FEED);
+ buffer.insert(0, buff);
+ }
+
/**
* Serializes the given {@link PacketImpl} to a {@link String}
*
@@ -250,6 +261,9 @@ public final class JSON {
int length = buffer.toString().getBytes().length;
writeToolHeader(buffer, packet.tool());
writeContentLength(buffer, length);
+ if(packet.destination() != null) {
+ writeDestinationHeader(buffer, packet.destination());
+ }
if(TRACE) {
Tracing.writeString("SERIALIZE: " + packet.getType() +" packet as "+buffer.toString()); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/PacketImpl.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/PacketImpl.java
index eb47938..3ffef9a 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/PacketImpl.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/PacketImpl.java
@@ -90,12 +90,20 @@ public class PacketImpl implements Packet {
return type;
}
+ /**
+ * Returns the intended tab destination for the packet, default returns <code>null</code>
+ *
+ * @return the tab id or <code>null</code>
+ */
+ public Number destination() {
+ return null;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.transport.packet.Packet#toJSON()
*/
public Map toJSON() {
Map json = new HashMap();
- //json.put(Attributes.TYPE, type);
return json;
}
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/RequestPacketImpl.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/RequestPacketImpl.java
index 7289a92..e9e52bb 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/RequestPacketImpl.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/RequestPacketImpl.java
@@ -27,9 +27,8 @@ public class RequestPacketImpl extends PacketImpl implements Request {
* The type of this packet
*/
public static final String REQUEST = "request"; //$NON-NLS-1$
- private static int next_seq = 0;
private final String command;
- private final int seq;
+ private final Number destination;
private Map args = Collections.synchronizedMap(new HashMap(4));
/**
@@ -37,14 +36,15 @@ public class RequestPacketImpl extends PacketImpl implements Request {
*
* @param command
* @param tool the name of the tools service expected to handle the request
+ * @param dest the tab id destination
*/
- public RequestPacketImpl(String command, String tool) {
+ public RequestPacketImpl(String command, String tool, Number dest) {
super(REQUEST, tool);
if(command == null) {
throw new IllegalArgumentException(Messages.cannot_create_request_null_command);
}
this.command = command;
- this.seq = ++next_seq;
+ this.destination = dest;
}
/**
@@ -57,11 +57,7 @@ public class RequestPacketImpl extends PacketImpl implements Request {
if(command == null) {
throw new IllegalArgumentException(Messages.no_command_in_request_json);
}
- this.seq = ((Number)json.get(Attributes.SEQ)).intValue();
- Map pargs = (Map) json.get(Attributes.ARGUMENTS);
- if(pargs != null) {
- args.putAll(pargs);
- }
+ this.destination = (Number) json.get(Attributes.DESTINATION);
}
/**
@@ -91,10 +87,17 @@ public class RequestPacketImpl extends PacketImpl implements Request {
* @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getSequence()
*/
public int getSequence() {
- return seq;
+ return -1;
}
/* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.chrome.transport.PacketImpl#destination()
+ */
+ public Number destination() {
+ return this.destination;
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getArguments()
*/
public Map getArguments() {
@@ -106,11 +109,7 @@ public class RequestPacketImpl extends PacketImpl implements Request {
*/
public Map toJSON() {
Map json = super.toJSON();
- //json.put(Attributes.SEQ, new Integer(seq));
json.put(Attributes.COMMAND, command);
- if(!args.isEmpty()) {
- json.put(Attributes.ARGUMENTS, args);
- }
return json;
}
diff --git a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ResponsePacketImpl.java b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ResponsePacketImpl.java
index 503eb62..28e25a3 100644
--- a/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ResponsePacketImpl.java
+++ b/development/org.eclipse.wst.jsdt.debug.chrome/src/org/eclipse/wst/jsdt/debug/internal/chrome/transport/ResponsePacketImpl.java
@@ -11,6 +11,7 @@
package org.eclipse.wst.jsdt.debug.internal.chrome.transport;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import org.eclipse.wst.jsdt.debug.transport.packet.Response;
@@ -27,24 +28,20 @@ public class ResponsePacketImpl extends PacketImpl implements Response {
*/
public static final String RESPONSE = "response"; //$NON-NLS-1$
- private int rseq = 0;
private String command = null;
- private Map body = null;
- private boolean success = false;
- private boolean running = false;
+ protected Number result = null;
+ protected Map body = null;
/**
* Constructor
- * @param requestSequence
* @param command
* @param tool the name of the tools service that issued this response
*/
- public ResponsePacketImpl(int requestSequence, String command, String tool) {
+ public ResponsePacketImpl(String command, String tool) {
super(RESPONSE, tool);
if(command == null) {
throw new IllegalArgumentException(Messages.cannot_create_response_null_command);
}
- this.rseq = requestSequence;
this.command = command;
}
@@ -54,14 +51,16 @@ public class ResponsePacketImpl extends PacketImpl implements Response {
*/
public ResponsePacketImpl(Map json) {
super(json);
- this.rseq = ((Integer)json.get(Attributes.REQUEST_SEQ)).intValue();
this.command = (String) json.get(Attributes.COMMAND);
if(command == null) {
throw new IllegalArgumentException(Messages.no_command_in_json_response);
}
- this.body = (Map) json.get(Attributes.BODY);
- this.success = ((Boolean)json.get(Attributes.SUCCESS)).booleanValue();
- this.running = ((Boolean)json.get(Attributes.RUNNING)).booleanValue();
+ this.result = (Number) json.get(Attributes.RESULT);
+ Object data = json.get(Attributes.DATA);
+ if(data != null) {
+ this.body = new HashMap();
+ this.body.put(Attributes.DATA, data);
+ }
}
/* (non-Javadoc)
@@ -75,31 +74,44 @@ public class ResponsePacketImpl extends PacketImpl implements Response {
* @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getRequestSequence()
*/
public int getRequestSequence() {
- return rseq;
+ return -1;
}
+ /**
+ * Returns the result of the request that caused this response
+ * @see Attributes#OK
+ * @see Attributes#ILLEGAL_TAB_STATE
+ * @see Attributes#UNKNOWN_TAB
+ * @see Attributes#DEBUGGER_ERROR
+ * @see Attributes#UNKNOWN_COMMAND
+ * @return the value of the result
+ */
+ public int getResult() {
+ return this.result.intValue();
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getBody()
*/
public Map getBody() {
- if(body == null) {
+ if(this.body == null) {
return Collections.EMPTY_MAP;
}
- return body;
+ return this.body;
}
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.transport.packet.Response#isSuccess()
*/
public boolean isSuccess() {
- return success;
+ return this.result.intValue() == Attributes.OK;
}
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.transport.packet.Response#isRunning()
*/
public boolean isRunning() {
- return running;
+ return true;
}
/* (non-Javadoc)
@@ -108,12 +120,10 @@ public class ResponsePacketImpl extends PacketImpl implements Response {
public Map toJSON() {
Map json = super.toJSON();
json.put(Attributes.COMMAND, command);
- json.put(Attributes.REQUEST_SEQ, new Integer(rseq));
- if(body != null) {
- json.put(Attributes.BODY, body);
+ json.put(Attributes.RESULT, this.result);
+ if(this.body != null) {
+ json.put(Attributes.DATA, this.body.get(Attributes.DATA));
}
- json.put(Attributes.SUCCESS, Boolean.valueOf(success));
- json.put(Attributes.RUNNING, Boolean.valueOf(running));
return json;
}

Back to the top