From 87bcacf5a32b287613aaf31b373763016966a336 Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Tue, 23 Jan 2024 17:50:50 +0000 Subject: [PATCH] Implement get of command handlers. --- .../cc/squirreljme/jdwp/JDWPHostController.java | 95 +++++++++++++++++++++- .../squirreljme/jdwp/host/JDWPCommandHandler.java | 8 ++ .../host/JDWPHostCommandSetArrayReference.java | 10 +++ .../jdwp/host/JDWPHostCommandSetClassLoader.java | 10 +++ .../JDWPHostCommandSetClassObjectReference.java | 10 +++ .../jdwp/host/JDWPHostCommandSetClassType.java | 10 +++ .../jdwp/host/JDWPHostCommandSetEventRequest.java | 10 +++ .../jdwp/host/JDWPHostCommandSetMethod.java | 10 +++ .../host/JDWPHostCommandSetObjectReference.java | 10 +++ .../jdwp/host/JDWPHostCommandSetReferenceType.java | 10 +++ .../jdwp/host/JDWPHostCommandSetStackFrame.java | 10 +++ .../host/JDWPHostCommandSetStringReference.java | 10 +++ .../JDWPHostCommandSetThreadGroupReference.java | 10 +++ .../host/JDWPHostCommandSetThreadReference.java | 10 +++ .../host/JDWPHostCommandSetVirtualMachine.java | 10 +++ 15 files changed, 232 insertions(+), 1 deletion(-) diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/JDWPHostController.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/JDWPHostController.java index a43b66cfe5..283a0a8f9f 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/JDWPHostController.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/JDWPHostController.java @@ -9,6 +9,19 @@ package cc.squirreljme.jdwp; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetArrayReference; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetClassLoader; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetClassObjectReference; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetClassType; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetEventRequest; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetMethod; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetObjectReference; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetReferenceType; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetStackFrame; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetStringReference; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetThreadGroupReference; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetThreadReference; +import cc.squirreljme.jdwp.host.JDWPHostCommandSetVirtualMachine; import cc.squirreljme.jdwp.host.event.JDWPHostCallStackStepping; import cc.squirreljme.jdwp.host.event.JDWPHostFieldOnly; import cc.squirreljme.jdwp.host.event.JDWPHostEventFilter; @@ -33,9 +46,12 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Queue; +import net.multiphasicapps.collections.UnmodifiableMap; /** * This class acts as the main controller interface for JDWP and acts as a kind @@ -55,6 +71,9 @@ public final class JDWPHostController new JDWPViewKind[]{JDWPViewKind.THREAD, JDWPViewKind.THREAD_GROUP, JDWPViewKind.TYPE}; + /** All the command handlers that are available. */ + private static final Map _HANDLERS; + /** The communication link. */ protected final JDWPCommLink commLink; @@ -94,6 +113,63 @@ public final class JDWPHostController /** Is this closed? */ private volatile boolean _closed; + static + { + // Fill out handlers + Map handlers = + new LinkedHashMap<>(); + + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetArrayReference.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetClassLoader.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetClassObjectReference.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetClassType.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetEventRequest.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetMethod.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetObjectReference.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetReferenceType.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetStackFrame.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetStringReference.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetThreadGroupReference.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetThreadReference.values()); + JDWPHostController.__fillIn(handlers, + JDWPHostCommandSetVirtualMachine.values()); + + // Store for later usage + _HANDLERS = UnmodifiableMap.of(handlers); + } + + /** + * Fills in values for the map. + * + * @param __handlers The target handler mapping. + * @param __impls The implementation of the handlers. + * @throws NullPointerException On null arguments. + * @since 2024/01/23 + */ + private static void __fillIn( + Map __handlers, + JDWPCommandHandler[] __impls) + throws NullPointerException + { + if (__handlers == null || __impls == null) + throw new NullPointerException("NARG"); + + for (JDWPCommandHandler impl : __impls) + __handlers.put(impl.command(), impl); + } + /** * Initializes the controller which manages the communication of JDWP. * @@ -320,7 +396,24 @@ public final class JDWPHostController if (__commandSet == null) throw new NullPointerException("NARG"); - throw Debugging.todo(); + return this.commandHandler(__commandSet.command(__command)); + } + + /** + * Returns the command handler for packets. + * + * @param __command The command used. + * @return The handler for commands. + * @throws NullPointerException On null arguments. + * @since 2024/01/23 + */ + public JDWPCommandHandler commandHandler(JDWPCommand __command) + throws NullPointerException + { + if (__command == null) + throw new NullPointerException("NARG"); + + return JDWPHostController._HANDLERS.get(__command); } /** diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPCommandHandler.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPCommandHandler.java index 3ff80c898d..47ee2f907f 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPCommandHandler.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPCommandHandler.java @@ -23,6 +23,14 @@ public interface JDWPCommandHandler extends JDWPCommand { /** + * Returns the command that this handled. + * + * @return The handled command. + * @since 2024/01/23 + */ + JDWPCommand command(); + + /** * Executes the given command. * * @param __controller The controller used. diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetArrayReference.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetArrayReference.java index dd45d6545e..ebb1b6a62e 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetArrayReference.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetArrayReference.java @@ -135,6 +135,16 @@ public enum JDWPHostCommandSetArrayReference /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/19 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassLoader.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassLoader.java index 18c8702655..3071fc4978 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassLoader.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassLoader.java @@ -92,6 +92,16 @@ public enum JDWPHostCommandSetClassLoader /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/04/20 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassObjectReference.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassObjectReference.java index c50d9f8c93..c6c02b1b12 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassObjectReference.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassObjectReference.java @@ -116,6 +116,16 @@ public enum JDWPHostCommandSetClassObjectReference /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/04/30 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassType.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassType.java index 42f2d48425..20ff8196a1 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassType.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetClassType.java @@ -77,6 +77,16 @@ public enum JDWPHostCommandSetClassType /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/14 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetEventRequest.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetEventRequest.java index 5ed7fda455..4b13dc54b8 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetEventRequest.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetEventRequest.java @@ -264,6 +264,16 @@ public enum JDWPHostCommandSetEventRequest /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/12 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetMethod.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetMethod.java index 04e9ab0d10..f01072a365 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetMethod.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetMethod.java @@ -197,6 +197,16 @@ public enum JDWPHostCommandSetMethod /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/14 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetObjectReference.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetObjectReference.java index 0782bc5dbb..05247bfee4 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetObjectReference.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetObjectReference.java @@ -166,6 +166,16 @@ public enum JDWPHostCommandSetObjectReference /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/14 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetReferenceType.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetReferenceType.java index df0380f38e..331ab3e4ed 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetReferenceType.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetReferenceType.java @@ -402,6 +402,16 @@ public enum JDWPHostCommandSetReferenceType /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/13 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStackFrame.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStackFrame.java index 58ae015deb..a272ad0922 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStackFrame.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStackFrame.java @@ -167,6 +167,16 @@ public enum JDWPHostCommandSetStackFrame /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/15 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStringReference.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStringReference.java index 231d1e96b2..8b3fd84ff8 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStringReference.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetStringReference.java @@ -144,6 +144,16 @@ public enum JDWPHostCommandSetStringReference /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/20 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadGroupReference.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadGroupReference.java index 75c88614a0..5d97a6db55 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadGroupReference.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadGroupReference.java @@ -152,6 +152,16 @@ public enum JDWPHostCommandSetThreadGroupReference /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/13 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadReference.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadReference.java index 52fe4d0648..a4e44172c5 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadReference.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetThreadReference.java @@ -381,6 +381,16 @@ public enum JDWPHostCommandSetThreadReference /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/13 */ @Override diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetVirtualMachine.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetVirtualMachine.java index 127829b759..a85ecc3496 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetVirtualMachine.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/host/JDWPHostCommandSetVirtualMachine.java @@ -471,6 +471,16 @@ public enum JDWPHostCommandSetVirtualMachine /** * {@inheritDoc} + * @since 2024/01/23 + */ + @Override + public final JDWPCommand command() + { + return this.command; + } + + /** + * {@inheritDoc} * @since 2021/03/12 */ @Override -- 2.11.4.GIT