1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
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
;
25 * Thread group reference commands.
29 public enum JDWPHostCommandSetThreadGroupReference
30 implements JDWPCommandHandler
32 /** The name of the group. */
33 NAME(JDWPCommandSetThreadGroupReference
.NAME
)
40 public JDWPPacket
execute(JDWPHostController __controller
,
44 JDWPViewThreadGroup view
= __controller
.viewThreadGroup();
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
));
59 /** The parent thread group. */
60 PARENT(JDWPCommandSetThreadGroupReference
.PARENT
)
67 public JDWPPacket
execute(JDWPHostController __controller
,
72 __controller
.readThreadGroup(__packet
, false);
74 JDWPPacket rv
= __controller
.reply(
75 __packet
.id(), JDWPErrorType
.NO_ERROR
);
77 // There are never any parent thread groups
84 /** The children thread groups and threads. */
85 CHILDREN(JDWPCommandSetThreadGroupReference
.CHILDREN
)
92 public JDWPPacket
execute(JDWPHostController __controller
,
96 JDWPViewThreadGroup groupView
= __controller
.viewThreadGroup();
97 JDWPViewThread threadView
= __controller
.viewThread();
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
))
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
135 /** The base command. */
136 public final JDWPCommand command
;
138 /** The ID of the packet. */
142 * Returns the ID used.
144 * @param __id The ID used.
147 JDWPHostCommandSetThreadGroupReference(JDWPCommand __id
)
150 this.id
= __id
.debuggerId();
158 public final JDWPCommand
command()
168 public final int debuggerId()