Implement get of command handlers.
[SquirrelJME.git] / modules / debug-jdwp / src / main / java / cc / squirreljme / jdwp / host / JDWPHostCommandSetThreadGroupReference.java
blob5d97a6db55974f6dd9d59f3537e61f56f312b366
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.jdwp.host;
12 import cc.squirreljme.jdwp.JDWPCommand;
13 import cc.squirreljme.jdwp.JDWPCommandSetThreadGroupReference;
14 import cc.squirreljme.jdwp.JDWPErrorType;
15 import cc.squirreljme.jdwp.JDWPException;
16 import cc.squirreljme.jdwp.JDWPHostController;
17 import cc.squirreljme.jdwp.JDWPHostUtils;
18 import cc.squirreljme.jdwp.JDWPPacket;
19 import cc.squirreljme.jdwp.host.views.JDWPViewThread;
20 import cc.squirreljme.jdwp.host.views.JDWPViewThreadGroup;
21 import java.util.ArrayList;
22 import java.util.List;
24 /**
25 * Thread group reference commands.
27 * @since 2021/03/13
29 public enum JDWPHostCommandSetThreadGroupReference
30 implements JDWPCommandHandler
32 /** The name of the group. */
33 NAME(JDWPCommandSetThreadGroupReference.NAME)
35 /**
36 * {@inheritDoc}
37 * @since 2021/03/13
39 @Override
40 public JDWPPacket execute(JDWPHostController __controller,
41 JDWPPacket __packet)
42 throws JDWPException
44 JDWPViewThreadGroup view = __controller.viewThreadGroup();
46 // Is this valid?
47 Object group = __controller.readThreadGroup(__packet, false);
49 JDWPPacket rv = __controller.reply(
50 __packet.id(), JDWPErrorType.NO_ERROR);
52 // Matches the string representation of the group
53 rv.writeString(view.name(group));
55 return rv;
59 /** The parent thread group. */
60 PARENT(JDWPCommandSetThreadGroupReference.PARENT)
62 /**
63 * {@inheritDoc}
64 * @since 2021/03/13
66 @Override
67 public JDWPPacket execute(JDWPHostController __controller,
68 JDWPPacket __packet)
69 throws JDWPException
71 // Is this valid?
72 __controller.readThreadGroup(__packet, false);
74 JDWPPacket rv = __controller.reply(
75 __packet.id(), JDWPErrorType.NO_ERROR);
77 // There are never any parent thread groups
78 rv.writeId(0);
80 return rv;
84 /** The children thread groups and threads. */
85 CHILDREN(JDWPCommandSetThreadGroupReference.CHILDREN)
87 /**
88 * {@inheritDoc}
89 * @since 2021/03/13
91 @Override
92 public JDWPPacket execute(JDWPHostController __controller,
93 JDWPPacket __packet)
94 throws JDWPException
96 JDWPViewThreadGroup groupView = __controller.viewThreadGroup();
97 JDWPViewThread threadView = __controller.viewThread();
99 // Is this valid?
100 Object group = __controller.readThreadGroup(__packet, false);
102 JDWPPacket rv = __controller.reply(
103 __packet.id(), JDWPErrorType.NO_ERROR);
105 // Filter out terminated, frameless, and debug threads (callbacks?)
106 List<Object> threads = new ArrayList<>();
107 for (Object thread : groupView.threads(group))
108 if (JDWPHostUtils.isVisibleThread(threadView, thread))
109 threads.add(thread);
111 // Write number of child threads
112 rv.writeInt(threads.size());
114 // Record all of their IDs
115 for (Object thread : threads)
117 Object threadInstance = threadView.instance(thread);
118 __controller.writeObject(rv, threadInstance);
120 // Store for later referencing
121 __controller.getState().items.put(thread);
122 __controller.getState().items.put(threadInstance);
125 // There are never any child thread groups
126 rv.writeInt(0);
128 return rv;
132 /* End. */
135 /** The base command. */
136 public final JDWPCommand command;
138 /** The ID of the packet. */
139 public final int id;
142 * Returns the ID used.
144 * @param __id The ID used.
145 * @since 2021/03/13
147 JDWPHostCommandSetThreadGroupReference(JDWPCommand __id)
149 this.command = __id;
150 this.id = __id.debuggerId();
154 * {@inheritDoc}
155 * @since 2024/01/23
157 @Override
158 public final JDWPCommand command()
160 return this.command;
164 * {@inheritDoc}
165 * @since 2021/03/13
167 @Override
168 public final int debuggerId()
170 return this.id;