From 8a89625caa58b1cc08fdc944b5ab5a98bdbc099d Mon Sep 17 00:00:00 2001 From: eutarass Date: Wed, 9 Jun 2010 23:32:17 +0000 Subject: TCF Agent: added handling of error report parameters in errno_to_str() TCF Debugger: diagnostics: added tests for transmitting and receiving TCF error reports --- .../tcf/services/local/DiagnosticsService.java | 24 +++++++++++++++++++ .../tcf/services/remote/DiagnosticsProxy.java | 28 ++++++++++++++++++++++ .../src/org/eclipse/tm/tcf/core/ErrorReport.java | 6 ++--- .../org/eclipse/tm/tcf/services/IDiagnostics.java | 23 ++++++++++++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) (limited to 'plugins/org.eclipse.tm.tcf.core') diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java index 9f6dc3d46..8fd6869c9 100644 --- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java +++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java @@ -11,9 +11,12 @@ package org.eclipse.tm.internal.tcf.services.local; import java.math.BigDecimal; +import java.util.Map; import org.eclipse.tm.internal.tcf.core.Token; +import org.eclipse.tm.tcf.core.Command; import org.eclipse.tm.tcf.protocol.IChannel; +import org.eclipse.tm.tcf.protocol.IErrorReport; import org.eclipse.tm.tcf.protocol.IToken; import org.eclipse.tm.tcf.protocol.JSON; import org.eclipse.tm.tcf.protocol.Protocol; @@ -46,6 +49,12 @@ public class DiagnosticsService implements IDiagnostics { Number n = (Number)args[0]; channel.sendResult(token, JSON.toJSONSequence(new Object[]{ n })); } + else if (name.equals("echoERR")) { + if (args.length != 1) throw new Exception("Invalid number of arguments"); + @SuppressWarnings("unchecked") + Map err = (Map)args[0]; + channel.sendResult(token, JSON.toJSONSequence(new Object[]{ err, Command.toErrorString(err) })); + } else if (name.equals("getTestList")) { if (args.length != 0) throw new Exception("Invalid number of arguments"); channel.sendResult(token, JSON.toJSONSequence(new Object[]{ null, new String[0] })); @@ -85,6 +94,21 @@ public class DiagnosticsService implements IDiagnostics { return token; } + public IToken echoERR(final Throwable err, final DoneEchoERR done) { + final IToken token = new Token(); + Protocol.invokeLater(new Runnable() { + public void run() { + if (err instanceof IErrorReport) { + done.doneEchoERR(token, null, err, Command.toErrorString(((IErrorReport)err).getAttributes())); + } + else { + done.doneEchoERR(token, null, err, err.getMessage()); + } + } + }); + return token; + } + public IToken getTestList(final DoneGetTestList done) { final IToken token = new Token(); Protocol.invokeLater(new Runnable() { diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java index b2a0104fc..a5dbdaca2 100644 --- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java +++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java @@ -12,10 +12,12 @@ package org.eclipse.tm.internal.tcf.services.remote; import java.math.BigDecimal; import java.util.Collection; +import java.util.HashMap; import java.util.Map; import org.eclipse.tm.tcf.core.Command; import org.eclipse.tm.tcf.protocol.IChannel; +import org.eclipse.tm.tcf.protocol.IErrorReport; import org.eclipse.tm.tcf.protocol.IToken; import org.eclipse.tm.tcf.services.IDiagnostics; @@ -108,6 +110,32 @@ public class DiagnosticsProxy implements IDiagnostics { }.token; } + public IToken echoERR(Throwable err, final DoneEchoERR done) { + Map map = null; + if (err instanceof IErrorReport) { + map = ((IErrorReport)err).getAttributes(); + } + else { + map = new HashMap(); + map.put(IErrorReport.ERROR_TIME, new Long(System.currentTimeMillis())); + map.put(IErrorReport.ERROR_CODE, new Integer(IErrorReport.TCF_ERROR_OTHER)); + map.put(IErrorReport.ERROR_FORMAT, err.getMessage()); + } + return new Command(channel, this, "echoERR", new Object[]{ map }) { + @Override + public void done(Exception error, Object[] args) { + Throwable err = null; + String str = null; + if (error == null) { + assert args.length == 2; + err = toError(args[0]); + str = (String)args[1]; + } + done.doneEchoERR(token, error, err, str); + } + }.token; + } + public IToken getTestList(final DoneGetTestList done) { return new Command(channel, this, "getTestList", null) { @Override diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java index 5fcf099fe..d2054ad0e 100644 --- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java +++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java @@ -15,13 +15,13 @@ import java.util.Map; import org.eclipse.tm.tcf.protocol.IErrorReport; -class ErrorReport extends Exception implements IErrorReport { +public class ErrorReport extends Exception implements IErrorReport { private static final long serialVersionUID = 3687543884858739977L; private final Map attrs; @SuppressWarnings("unchecked") - ErrorReport(String msg, Map attrs) { + public ErrorReport(String msg, Map attrs) { super(msg); this.attrs = attrs; Object caused_by = attrs.get(IErrorReport.ERROR_CAUSED_BY); @@ -35,7 +35,7 @@ class ErrorReport extends Exception implements IErrorReport { } } - ErrorReport(String msg, int code) { + public ErrorReport(String msg, int code) { super(msg); attrs = new HashMap(); attrs.put(ERROR_CODE, code); diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java index 98c5addb7..6ffa51237 100644 --- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java +++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java @@ -71,6 +71,29 @@ public interface IDiagnostics extends IService { void doneEchoFP(IToken token, Throwable error, BigDecimal n); } + /** + * 'echoERR' command result returns same error report that was given as command argument. + * The command is used to test remote agent ability to receive and transmit TCF error reports. + * @param error - an error object. + * @param done - command result call back object. + * @return - pending command handle. + */ + IToken echoERR(Throwable error, DoneEchoERR done); + + /** + * Call back interface for 'echoERR' command. + */ + interface DoneEchoERR { + /** + * Called when 'echoERR' command is done. + * @param token - command handle. + * @param error - communication error report or null. + * @param error_obj - error object, should be equal to the command argument. + * @param error_msg - error object converted to a human readable string. + */ + void doneEchoERR(IToken token, Throwable error, Throwable error_obj, String error_msg); + } + /** * Get list of test names that are implemented by the service. * Clients can request remote peer to run a test from the list. -- cgit v1.2.3