diff options
author | eutarass | 2008-04-07 19:56:45 +0000 |
---|---|---|
committer | eutarass | 2008-04-07 19:56:45 +0000 |
commit | 3008d4750370013e6e9750ddb00039df362dbb5a (patch) | |
tree | 322ea479c63ff1e54b99994585184875914d1f67 | |
parent | 3c90f4ac3612c74dd8309c85c6a96c77d860156c (diff) | |
download | org.eclipse.tcf-3008d4750370013e6e9750ddb00039df362dbb5a.tar.gz org.eclipse.tcf-3008d4750370013e6e9750ddb00039df362dbb5a.tar.xz org.eclipse.tcf-3008d4750370013e6e9750ddb00039df362dbb5a.zip |
Bug 223520: [tcf] Registers service changes: data formatting is removed from the service.
6 files changed, 220 insertions, 211 deletions
diff --git a/docs/TCF Service - Registers.html b/docs/TCF Service - Registers.html index ef346af69..1638c2306 100644 --- a/docs/TCF Service - Registers.html +++ b/docs/TCF Service - Registers.html @@ -78,8 +78,11 @@ Service sends contextChanged event to notify changes in context data.</p> <li><code><b><font face="Courier New" size=2 color=#333399>"Description" : <i><string></i></font></b></code> - context description. - <li><code><b><font face="Courier New" size=2 color=#333399>"Formats" : <i><array of string></i></font></b></code> - - value formats available for register get/set commands. + <li><code><b><font face="Courier New" size=2 color=#333399>"Size" : <i><boolean></i></font></b></code> + - context size in bytes. Byte arrays in get/set commandss should be same size. + Hardware register can be smaller then this size, for example in case + when register size is not an even number of bytes. In such case implementation + should add/remove padding that consists of necessary number of zero bits. <li><code><b><font face="Courier New" size=2 color=#333399>"Readable" : <i><boolean></i></font></b></code> - true if context value can be read. @@ -151,12 +154,11 @@ R • <i><token></i> • <i><error report></i> • <i><array of context <h3><a name='CmdSetRegister'>Set Register</a></h3> <pre><b><font face="Courier New" size=2 color=#333399> -C • <token> • Registers • set • <i><string: context ID></i> • <i><string: value format></i> • <i><string: value></i> • +C • <token> • Registers • set • <i><string: context ID></i> • <i><string: value></i> • </font></b></pre> <p>Writes value into given register context. Context ID must be one returned by getContexts. -Value format must be one that is supported by the register context. -Client can get list of supported formats from context attributes.</p> +Value is BASE64 encoded byte array of binary data. Array size should match the size of the register.</p> <p>Result message:</p> @@ -170,12 +172,11 @@ of error.</p> <h3><a name='CmdGetRegister'>Get Register</a></h3> <pre><b><font face="Courier New" size=2 color=#333399> -C • <token> • Registers • get • <i><string: context ID></i> • <i><string: value format></i> • +C • <token> • Registers • get • <i><string: context ID></i> • </font></b></pre> <p>Reads register value from given register context. Context ID must be one returned by getContexts. -Value format must be one that is supported by the register context. -Client can get list of supported formats from context attributes.</p> +</p> <p>Result message:</p> @@ -184,7 +185,7 @@ R • <i><token></i> • <i><error report></i> • <i><string: value> </font></b></pre> <p>Error report provides integer error code and a short, human readable explanation -of error. Value is formatted according to requested format.</p> +of error. Value is BASE64 encoded byte array of binary data. Array size should match the size of the register.</p> <h2><a name='Events'>Events</a></h2> @@ -215,7 +216,7 @@ E • Registers • registerChanged • <i><string: context ID></i> • PROP_PROCESS_ID = "ProcessID", PROP_NAME = "Name", PROP_DESCRIPTION = "Description", - PROP_FORMATS = "Formats", + PROP_SIZE = "Size", PROP_READBLE = "Readable", PROP_READ_ONCE = "ReadOnce", PROP_WRITEABLE = "Writeable", @@ -317,11 +318,14 @@ E • Registers • registerChanged • <i><string: context ID></i> • String getDescription(); <font color=#3F5FBF>/** - * Get value formats available for register get/set commands. - * See FORMAT_* for knows format IDs definition. - * <font color=#7F9FBF>@return</font> array of supported format IDs. + * Get context size in bytes. + * Byte arrays in get()/set() methods should be same size. + * Hardware register can be smaller then this size, for example in case + * when register size is not an even number of bytes. In such case implementation + * should add/remove padding that consists of necessary number of zero bits. + * @return context size in bytes. */</font> - String[] getAvailableFormats(); + <font color=#7F0055>int</font> getSize(); <font color=#3F5FBF>/** * Check if context value can be read. @@ -409,20 +413,18 @@ E • Registers • registerChanged • <i><string: context ID></i> • <font color=#3F5FBF>/** * Read value of the context. - * <font color=#7F9FBF>@param</font> format - ID of a format to use for result value. * <font color=#7F9FBF>@param</font> done - call back object. * <font color=#7F9FBF>@return</font> - pending command handle. */</font> - IToken get(String format, DoneGet done); + IToken get(DoneGet done); <font color=#3F5FBF>/** * Set value of the context. - * <font color=#7F9FBF>@param</font> format - ID of a format used for value. * <font color=#7F9FBF>@param</font> value - value to write into the context. * <font color=#7F9FBF>@param</font> done - call back object. * <font color=#7F9FBF>@return</font> - pending command handle. */</font> - IToken set(String format, String value, DoneSet done); + IToken set(byte[] value, DoneSet done); } <font color=#3F5FBF>/** @@ -431,10 +433,10 @@ E • Registers • registerChanged • <i><string: context ID></i> • */</font> <font color=#7F0055>interface</font> NamedValue { <font color=#3F5FBF>/** - * Get number associated with this named value. - * <font color=#7F9FBF>@return</font> the value as a number. + * Get value associated with the name. + * <font color=#7F9FBF>@return</font> the value as an array of bytes. */</font> - Number getValue(); + byte[] getValue(); <font color=#3F5FBF>/** * Get name (mnemonic) of the value. @@ -453,7 +455,7 @@ E • Registers • registerChanged • <i><string: context ID></i> • * 'get' command call back interface. */</font> <font color=#7F0055>interface</font> DoneGet { - <font color=#7F0055>void</font> doneGet(IToken token, Exception error, String value); + <font color=#7F0055>void</font> doneGet(IToken token, Exception error, byte[] value); } <font color=#3F5FBF>/** diff --git a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFSelfTest.java b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFSelfTest.java index f3b19cbac..86e1fe85c 100644 --- a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFSelfTest.java +++ b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFSelfTest.java @@ -926,34 +926,31 @@ class TCFSelfTest { for (final IRegisters.RegistersContext ctx : reg_map.values()) { if (!ctx.isReadable()) continue; if (ctx.isReadOnce()) continue; - String[] fmts = ctx.getAvailableFormats(); - for (final String fmt : fmts) { - cmds.add(ctx.get(fmt, new IRegisters.DoneGet() { - public void doneGet(IToken token, Exception error, String value) { - cmds.remove(token); - if (suspended.get(sc.id) != sc) return; - if (error != null) { - for (IToken t : cmds) t.cancel(); - exit(error); - return; - } - cmds.add(ctx.set(fmt, value, new IRegisters.DoneSet() { - public void doneSet(IToken token, Exception error) { - cmds.remove(token); - if (suspended.get(sc.id) != sc) return; - if (error != null) { - for (IToken t : cmds) t.cancel(); - exit(error); - return; - } - if (cmds.isEmpty()) { - resume(sc); - } - } - })); + cmds.add(ctx.get(new IRegisters.DoneGet() { + public void doneGet(IToken token, Exception error, byte[] value) { + cmds.remove(token); + if (suspended.get(sc.id) != sc) return; + if (error != null) { + for (IToken t : cmds) t.cancel(); + exit(error); + return; } - })); - } + cmds.add(ctx.set(value, new IRegisters.DoneSet() { + public void doneSet(IToken token, Exception error) { + cmds.remove(token); + if (suspended.get(sc.id) != sc) return; + if (error != null) { + for (IToken t : cmds) t.cancel(); + exit(error); + return; + } + if (cmds.isEmpty()) { + resume(sc); + } + } + })); + } + })); } if (cmds.isEmpty()) { resume(sc); diff --git a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFNodeRegister.java b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFNodeRegister.java index 575d3ea14..50a3e44e5 100644 --- a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFNodeRegister.java +++ b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFNodeRegister.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.tm.internal.tcf.debug.ui.model; +import java.math.BigInteger; +import java.util.Arrays; + import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; @@ -43,8 +46,7 @@ public class TCFNodeRegister extends TCFNode { private final TCFDataCache<IRegisters.RegistersContext> context; - private final TCFDataCache<String> hex_value; - private final TCFDataCache<String> dec_value; + private final TCFDataCache<byte[]> value; TCFNodeRegister(TCFNode parent, final String id) { super(parent, id); @@ -61,7 +63,7 @@ public class TCFNodeRegister extends TCFNode { return false; } }; - hex_value = new TCFDataCache<String>(channel) { + value = new TCFDataCache<byte[]>(channel) { @Override protected boolean startDataRetrieval() { if (!context.validate()) { @@ -73,46 +75,8 @@ public class TCFNodeRegister extends TCFNode { set(null, null, null); return true; } - String[] fmts = ctx.getAvailableFormats(); - String fmt = null; - for (String s : fmts) { - if (s.equals(IRegisters.FORMAT_HEX)) fmt = s; - } - if (fmt == null) { - set(null, null, null); - return true; - } - command = ctx.get(fmt, new IRegisters.DoneGet() { - public void doneGet(IToken token, Exception error, String value) { - set(token, error, value); - } - }); - return false; - } - }; - dec_value = new TCFDataCache<String>(channel) { - @Override - protected boolean startDataRetrieval() { - if (!context.validate()) { - context.wait(this); - return false; - } - IRegisters.RegistersContext ctx = context.getData(); - if (ctx == null) { - set(null, null, null); - return true; - } - String[] fmts = ctx.getAvailableFormats(); - String fmt = null; - for (String s : fmts) { - if (s.equals(IRegisters.FORMAT_DECIMAL)) fmt = s; - } - if (fmt == null) { - set(null, null, null); - return true; - } - command = ctx.get(fmt, new IRegisters.DoneGet() { - public void doneGet(IToken token, Exception error, String value) { + command = ctx.get(new IRegisters.DoneGet() { + public void doneGet(IToken token, Exception error, byte[] value) { set(token, error, value); } }); @@ -133,14 +97,14 @@ public class TCFNodeRegister extends TCFNode { else if (ctx != null) { String[] cols = result.getColumnIds(); if (cols == null) { - result.setLabel(ctx.getName() + " = " + hex_value.getData(), 0); + setLabel(result, -1, 16); } else { for (int i = 0; i < cols.length; i++) { String c = cols[i]; if (c.equals(COL_NAME)) result.setLabel(ctx.getName(), i); - else if (c.equals(COL_HEX_VALUE)) setLabel(result, hex_value, i); - else if (c.equals(COL_DEC_VALUE)) result.setLabel(dec_value.getData(), i); + else if (c.equals(COL_HEX_VALUE)) setLabel(result, i, 16); + else if (c.equals(COL_DEC_VALUE)) setLabel(result, i, 10); else if (c.equals(COL_DESCRIPTION)) result.setLabel(ctx.getDescription(), i); else if (c.equals(COL_READBLE)) result.setLabel(bool(ctx.isReadable()), i); else if (c.equals(COL_READ_ONCE)) result.setLabel(bool(ctx.isReadOnce()), i); @@ -158,14 +122,48 @@ public class TCFNodeRegister extends TCFNode { } } - private void setLabel(ILabelUpdate result, TCFDataCache<String> data, int pos) { - Throwable error = data.getError(); + private void setLabel(ILabelUpdate result, int col, int radix) { + IRegisters.RegistersContext ctx = context.getData(); + Throwable error = value.getError(); + byte[] data = value.getData(); if (error != null) { - result.setForeground(new RGB(255, 0, 0), pos); - result.setLabel(error.getClass().getName() + ": " + error.getMessage(), pos); + if (col >= 0) { + result.setForeground(new RGB(255, 0, 0), col); + result.setLabel(error.getMessage(), col); + } + else { + result.setLabel(ctx.getName() + ": " + error.getMessage(), 0); + } } - else if (data.getData() != null) { - result.setLabel(data.getData(), pos); + else if (data != null) { + byte[] temp = new byte[data.length + 1]; + temp[0] = 0; // Extra byte to avoid sign extension by BigInteger + if (ctx.isBigEndian()) { + System.arraycopy(value, 0, temp, 1, data.length); + } + else { + for (int i = 0; i < data.length; i++) { + temp[temp.length - i - 1] = data[i]; + } + } + String s = new BigInteger(temp).toString(radix); + switch (radix) { + case 8: + if (!s.startsWith("0")) s = "0" + s; + break; + case 16: + int l = data.length * 2 - s.length(); + if (l < 0) l = 0; + if (l > 16) l = 16; + s = "0000000000000000".substring(0, l) + s; + break; + } + if (col >= 0) { + result.setLabel(s, col); + } + else { + result.setLabel(ctx.getName() + " = " + s, 0); + } } } @@ -174,29 +172,11 @@ public class TCFNodeRegister extends TCFNode { } private String getMnemonic(IRegisters.RegistersContext ctx) { - if (dec_value.getData() != null) { + if (value.getData() != null) { IRegisters.NamedValue[] arr = ctx.getNamedValues(); if (arr != null) { - if (ctx.isFloat()) { - double v = Double.parseDouble(dec_value.getData()); - for (IRegisters.NamedValue n : arr) { - if (n.getValue().doubleValue() == v) return n.getName(); - } - } - else { - long v = Long.parseLong(dec_value.getData()); - for (IRegisters.NamedValue n : arr) { - if (n.getValue().longValue() == v) return n.getName(); - } - } - } - } - else if (!ctx.isFloat() && hex_value.getData() != null) { - IRegisters.NamedValue[] arr = ctx.getNamedValues(); - if (arr != null) { - long v = Long.parseLong(hex_value.getData(), 16); for (IRegisters.NamedValue n : arr) { - if (n.getValue().longValue() == v) return n.getName(); + if (Arrays.equals(n.getValue(), value.getData())) return n.getName(); } } } @@ -218,40 +198,29 @@ public class TCFNodeRegister extends TCFNode { * Invalidate register value only, keep cached register attributes. */ void onSuspended() { - hex_value.reset(); - dec_value.reset(); + value.reset(); makeModelDelta(IModelDelta.STATE); } void onRegistersChanged() { context.reset(); - hex_value.reset(); - dec_value.reset(); + value.reset(); makeModelDelta(IModelDelta.STATE | IModelDelta.CONTENT); } @Override public void invalidateNode() { context.reset(); - hex_value.reset(); - dec_value.reset(); + value.reset(); } @Override public boolean validateNode(Runnable done) { - boolean ctx_valid = context.validate(); - boolean dec_valid = dec_value.validate(); - boolean hex_valid = hex_value.validate(); - if (!ctx_valid) { - if (done != null) context.wait(done); - return false; - } - if (!dec_valid) { - if (done != null) dec_value.wait(done); - return false; - } - if (!hex_valid) { - if (done != null) hex_value.wait(done); + TCFDataCache<?> pending = null; + if (!context.validate()) pending = context; + if (!value.validate()) pending = value; + if (pending != null) { + pending.wait(done); return false; } return true; diff --git a/plugins/org.eclipse.tm.tcf.dsf/src/org/eclipse/tm/internal/tcf/dsf/services/TCFDSFRegisters.java b/plugins/org.eclipse.tm.tcf.dsf/src/org/eclipse/tm/internal/tcf/dsf/services/TCFDSFRegisters.java index 1614118c3..3093dfeb6 100644 --- a/plugins/org.eclipse.tm.tcf.dsf/src/org/eclipse/tm/internal/tcf/dsf/services/TCFDSFRegisters.java +++ b/plugins/org.eclipse.tm.tcf.dsf/src/org/eclipse/tm/internal/tcf/dsf/services/TCFDSFRegisters.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.tm.internal.tcf.dsf.services; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -100,9 +101,6 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d RegisterGroupDMC(String session_id, IDMContext[] parents, final String id, RegistersCache children) { super(session_id, parents, id, children); context = new org.eclipse.tm.tcf.services.IRegisters.RegistersContext() { - public String[] getAvailableFormats() { - return null; - } public int[] getBitNumbers() { return null; } @@ -121,10 +119,13 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d public NamedValue[] getNamedValues() { return null; } + public int getSize() { + return 0; + } public String getParentID() { return null; } - public Map<String, Object> getProperties() { + public Map<String,Object> getProperties() { return null; } public boolean hasSideEffects() { @@ -154,10 +155,10 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d public boolean isWriteable() { return false; } - public IToken get(String format, DoneGet done) { + public IToken get(DoneGet done) { throw new Error(); } - public IToken set(String format, String value, DoneSet done) { + public IToken set(byte[] value, DoneSet done) { throw new Error(); } }; @@ -494,8 +495,8 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d assert tcf_reg_service != null; assert context != null; assert !disposed; - command = context.get(fmt, new org.eclipse.tm.tcf.services.IRegisters.DoneGet() { - public void doneGet(IToken token, Exception err, String value) { + command = context.get(new org.eclipse.tm.tcf.services.IRegisters.DoneGet() { + public void doneGet(IToken token, Exception err, byte[] value) { if (command != token) return; command = null; if (err != null) { @@ -503,7 +504,32 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d error = err; } else { - data = new FormattedValueDMData(value); + int radix = 10; + if (fmt.equals(HEX_FORMAT)) radix = 16; + else if (fmt.equals(OCTAL_FORMAT)) radix = 8; + byte[] temp = new byte[value.length + 1]; + temp[0] = 0; // Extra byte to avoid sign extension by BigInteger + if (context.isBigEndian()) { + System.arraycopy(value, 0, temp, 1, value.length); + } + else { + for (int i = 0; i < value.length; i++) { + temp[temp.length - i - 1] = value[i]; + } + } + String s = new BigInteger(temp).toString(radix); + switch (radix) { + case 8: + if (!s.startsWith("0")) s = "0" + s; + break; + case 16: + int l = value.length * 2 - s.length(); + if (l < 0) l = 0; + if (l > 16) l = 16; + s = "0000000000000000".substring(0, l) + s; + break; + } + data = new FormattedValueDMData(s); } valid = true; validate(); @@ -588,6 +614,12 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d private final IChannel channel; private final org.eclipse.tm.tcf.services.IRegisters tcf_reg_service; private final Map<String,ObjectDMC> model; + + private final String[] available_formats = { + HEX_FORMAT, + DECIMAL_FORMAT, + OCTAL_FORMAT + }; public TCFDSFRegisters(DsfSession session, IChannel channel, final RequestMonitor monitor) { super(session); @@ -885,7 +917,18 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d rm.done(); return; } - ((ObjectDMC)dmc).context.set(fmt, val, new org.eclipse.tm.tcf.services.IRegisters.DoneSet() { + int radix = 10; + if (fmt.equals(HEX_FORMAT)) radix = 16; + else if (fmt.equals(OCTAL_FORMAT)) radix = 8; + byte[] data = new BigInteger(val, radix).toByteArray(); + if (!((ObjectDMC)dmc).context.isBigEndian()) { + byte[] temp = new byte[data.length]; + for (int i = 0; i < data.length; i++) { + temp[temp.length - i - 1] = data[i]; + } + data = temp; + } + ((ObjectDMC)dmc).context.set(data, new org.eclipse.tm.tcf.services.IRegisters.DoneSet() { public void doneSet(IToken token, Exception error) { if (rm.isCanceled()) return; if (error != null) { @@ -920,9 +963,8 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d if (arr != null) { for (NamedValue nv : arr) { if (nv.getName().equals(mnemonic.getShortName())) { - String fmt = org.eclipse.tm.tcf.services.IRegisters.FORMAT_DECIMAL; - String val = nv.getValue().toString(); - ((ObjectDMC)dmc).context.set(fmt, val, new org.eclipse.tm.tcf.services.IRegisters.DoneSet() { + byte[] val = nv.getValue(); + ((ObjectDMC)dmc).context.set(val, new org.eclipse.tm.tcf.services.IRegisters.DoneSet() { public void doneSet(IToken token, Exception error) { if (rm.isCanceled()) return; if (error != null) { @@ -951,17 +993,7 @@ public class TCFDSFRegisters extends AbstractDsfService implements org.eclipse.d } public void getAvailableFormats(IFormattedDataDMContext dmc, DataRequestMonitor<String[]> rm) { - if (tcf_reg_service == null) { - rm.setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - INVALID_HANDLE, "Registers service is not available", null)); //$NON-NLS-1$ - } - else if (dmc instanceof ObjectDMC) { - rm.setData(((ObjectDMC)dmc).context.getAvailableFormats()); - } - else { - rm.setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - INVALID_HANDLE, "Unknown DMC type", null)); //$NON-NLS-1$ - } + rm.setData(available_formats); rm.done(); } diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RegistersProxy.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RegistersProxy.java index c402ae02c..42424c063 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RegistersProxy.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RegistersProxy.java @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import org.eclipse.tm.tcf.core.Base64; import org.eclipse.tm.tcf.core.Command; import org.eclipse.tm.tcf.protocol.IChannel; import org.eclipse.tm.tcf.protocol.IToken; @@ -36,10 +37,6 @@ public class RegistersProxy implements IRegisters { this.props = props; } - public String[] getAvailableFormats() { - return toStringArray(props.get(PROP_FORMATS)); - } - public int[] getBitNumbers() { return toIntArray(props.get(PROP_BITS)); } @@ -69,6 +66,12 @@ public class RegistersProxy implements IRegisters { public String getParentID() { return (String)props.get(PROP_PARENT_ID); } + + public int getSize() { + Number n = (Number)props.get(PROP_SIZE); + if (n == null) return 0; + return n.intValue(); + } public Map<String, Object> getProperties() { return props; @@ -128,25 +131,26 @@ public class RegistersProxy implements IRegisters { return n.booleanValue(); } - public IToken get(String format, final DoneGet done) { + public IToken get(final DoneGet done) { return new Command(channel, RegistersProxy.this, "get", - new Object[]{ getID(), format }) { + new Object[]{ getID() }) { @Override public void done(Exception error, Object[] args) { - String val = null; + byte[] val = null; if (error == null) { assert args.length == 3; error = toError(args[0], args[1]); - val = (String)args[2]; + String str = (String)args[2]; + if (str != null) val = Base64.toByteArray(str.toCharArray()); } done.doneGet(token, error, val); } }.token; } - public IToken set(String format, String value, final DoneSet done) { + public IToken set(byte[] value, final DoneSet done) { return new Command(channel, RegistersProxy.this, "set", - new Object[]{ getID(), format, value }) { + new Object[]{ getID(), Base64.toBase64(value, 0, value.length) }) { @Override public void done(Exception error, Object[] args) { if (error == null) { @@ -252,6 +256,33 @@ public class RegistersProxy implements IRegisters { return arr; } + private static class NamedValueInfo implements NamedValue { + + private final String desc; + private final String name; + private final byte[] value; + + NamedValueInfo(Map<String,Object> m) { + desc = (String)m.get("Description"); + name = (String)m.get("Name"); + String str = (String)m.get("Value"); + if (str == null) value = null; + else value = Base64.toByteArray(str.toCharArray()); + } + + public String getDescription() { + return desc; + } + + public String getName() { + return name; + } + + public byte[] getValue() { + return value; + } + } + @SuppressWarnings("unchecked") private NamedValue[] toValuesArray(Object o) { Collection<Map<String,Object>> c = (Collection<Map<String,Object>>)o; @@ -259,20 +290,7 @@ public class RegistersProxy implements IRegisters { int i = 0; NamedValue[] arr = new NamedValue[c.size()]; for (final Map<String,Object> m : c) { - arr[i++] = new NamedValue() { - - public String getDescription() { - return (String)m.get("Description"); - } - - public String getName() { - return (String)m.get("Name"); - } - - public Number getValue() { - return (Number)m.get("Value"); - } - }; + arr[i++] = new NamedValueInfo(m); } return arr; } diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/IRegisters.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/IRegisters.java index 5bfed81c2..9fb1de145 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/IRegisters.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/IRegisters.java @@ -32,7 +32,7 @@ public interface IRegisters extends IService { PROP_PROCESS_ID = "ProcessID", PROP_NAME = "Name", PROP_DESCRIPTION = "Description", - PROP_FORMATS = "Formats", + PROP_SIZE = "Size", PROP_READBLE = "Readable", PROP_READ_ONCE = "ReadOnce", PROP_WRITEABLE = "Writeable", @@ -47,16 +47,6 @@ public interface IRegisters extends IService { PROP_VALUES = "Values"; /** - * Standard known formats for register data. - */ - static final String - FORMAT_BINARY = "Binary", - FORMAT_OCTAL = "Octal", - FORMAT_DECIMAL = "Decimal", - FORMAT_HEX = "Hex", - FORMAT_NATURAL = "Natural"; - - /** * Retrieve context info for given context ID. * * @param id – context ID. @@ -134,11 +124,14 @@ public interface IRegisters extends IService { String getDescription(); /** - * Get value formats available for register get/set commands. - * See FORMAT_* for knows format IDs definition. - * @return array of supported format IDs. + * Get context size in bytes. + * Byte arrays in get()/set() methods should be same size. + * Hardware register can be smaller then this size, for example in case + * when register size is not an even number of bytes. In such case implementation + * should add/remove padding that consist of necessary number of zero bits. + * @return context size in bytes. */ - String[] getAvailableFormats(); + int getSize(); /** * Check if context value can be read. @@ -226,20 +219,18 @@ public interface IRegisters extends IService { /** * Read value of the context. - * @param format - ID of a format to use for result value. * @param done - call back object. * @return - pending command handle. */ - IToken get(String format, DoneGet done); + IToken get(DoneGet done); /** * Set value of the context. - * @param format - ID of a format used for value. * @param value - value to write into the context. * @param done - call back object. * @return - pending command handle. */ - IToken set(String format, String value, DoneSet done); + IToken set(byte[] value, DoneSet done); } /** @@ -248,10 +239,10 @@ public interface IRegisters extends IService { */ interface NamedValue { /** - * Get number associated with this named value. - * @return the value as a number. + * Get value associated with the name. + * @return the value as an array of bytes. */ - Number getValue(); + byte[] getValue(); /** * Get name (mnemonic) of the value. @@ -270,7 +261,7 @@ public interface IRegisters extends IService { * 'get' command call back interface. */ interface DoneGet { - void doneGet(IToken token, Exception error, String value); + void doneGet(IToken token, Exception error, byte[] value); } /** |