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 javax
.microedition
.swm
;
12 import cc
.squirreljme
.runtime
.cldc
.annotation
.Api
;
13 import cc
.squirreljme
.runtime
.cldc
.debug
.Debugging
;
14 import java
.util
.Objects
;
17 * This describes a task which is currently running on the system. Each task
18 * has a starting point which is a {@link javax.microedition.midlet.MIDlet}.
20 * System tasks cannot be started or stopped.
25 public final class Task
27 /** The ID of the task. */
30 /** The suite of this task. */
33 /** The entry class of the task. */
37 * Initializes the task.
39 * @param __tid The task ID, zero is the system task.
40 * @param __s The suite used.
41 * @param __e The entry name of the task.
42 * @throws NullPointerException On null arguments.
45 Task(int __tid
, Suite __s
, String __e
)
46 throws NullPointerException
48 if (__s
== null || __e
== null)
49 throw new NullPointerException("NARG");
57 * Checks if this task is the same as another task, tasks are equal if
58 * they share the same name.
60 * @param __o The other object.
61 * @return {@code true} if this is the same task.
65 public boolean equals(Object __o
)
70 // Must be another task
71 if (!(__o
instanceof Task
))
76 return Objects
.equals(this.getSuite(), o
.getSuite()) &&
77 Objects
.equals(this.getName(), o
.getName());
81 * Returns the estimated number of bytes that a task is using.
83 * @return The number of bytes the task is estimated to be using.
87 public int getHeapUse()
89 throw Debugging
.todo();
91 // Make sure the amount of memory used does not overflow ever
92 long rv = this._task.metric(SystemTaskMetric.MEMORY_USED);
95 else if (rv > Integer.MAX_VALUE)
96 return Integer.MAX_VALUE;
102 * Returns the name of the current task.
104 * @return The name of the task, system tasks always return {@code null}.
108 public String
getName()
110 // System tasks have no name
111 if (this.isSystemTask())
118 * Returns the priority of this task.
120 * @return The task priority.
124 public TaskPriority
getPriority()
126 throw Debugging
.todo();
128 long rv = this._task.metric(SystemTaskMetric.PRIORITY);
130 return TaskPriority.MAX;
132 return TaskPriority.MIN;
133 return TaskPriority.NORM;
138 * Returns the status of this task.
140 * @return The task status.
144 public TaskStatus
getStatus()
146 // If the TID is negative then it failed to start
149 return TaskStatus
.START_FAILED
;
151 return TaskStatus
.__of(Debugging
.<Integer
>todoObject(tid
));
155 * Returns the suite that this task belongs to.
157 * @return The owning suite.
161 public Suite
getSuite()
163 // All system tasks are hidden behind the system suite
164 if (this.isSystemTask())
165 return Suite
.SYSTEM_SUITE
;
171 * Returns the hash code of this task, the hashcode is derived from the
172 * suite and the name.
174 * @return The hash code.
178 public int hashCode()
180 return Objects
.hashCode(this.getSuite()) ^
181 Objects
.hashCode(this.getName());
185 * Returns {@code true} if this is a system task.
187 * @return {@code true} if a system task.
191 public boolean isSystemTask()
193 // System task is always zero
194 return this._tid
== 0;