Commit 64519b08 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Implement register and forwarding of IPC events.

parent 7675c775
......@@ -9,6 +9,9 @@
package cc.squirreljme.jvm;
import java.util.HashMap;
import java.util.Map;
/**
* This class is used to manage the IPC interface and allow any service to
* register IPC messages and such.
......@@ -17,6 +20,10 @@ package cc.squirreljme.jvm;
*/
public final class IPCManager
{
/** Services that are available. */
private static final Map<Integer, IPCCallback> _IPC_MAP =
new HashMap<>();
/**
* No instances of this class.
*
......@@ -45,7 +52,22 @@ public final class IPCManager
public static final long ipcCall(int __tid, int __ipcid, int __a, int __b,
int __c, int __d, int __e, int __f, int __g, int __h)
{
throw new todo.TODO();
IPCCallback handler = null;
// Find the IPC Callback handler
Map<Integer, IPCCallback> ipcmap = _IPC_MAP;
synchronized (ipcmap)
{
handler = ipcmap.get(__ipcid);
}
// Drop the call if there is no handler
if (handler == null)
return 0;
// Perform the call
return handler.ipcCall(__tid, __ipcid, __a, __b, __c, __d, __e, __f,
__g, __h);
}
/**
......@@ -53,16 +75,27 @@ public final class IPCManager
*
* @param __ipcid The IPC ID to listen on.
* @param __cb The callback for the IPC.
* @throws IllegalArgumentException If IPC ID is zero.
* @throws NullPointerException On null arguments.
* @since 2019/12/28
*/
public static final void register(int __ipcod, IPCCallback __cb)
throws NullPointerException
public static final void register(int __ipcid, IPCCallback __cb)
throws IllegalArgumentException, NullPointerException
{
if (__cb == null)
throw new NullPointerException("NARG");
throw new todo.TODO();
// {@squirreljme.error ZZ3u It is not valid to register the zero
// IPC ID.}
if (__ipcid == 0)
throw new IllegalArgumentException("ZZ3u");
// Lock and register
Map<Integer, IPCCallback> ipcmap = _IPC_MAP;
synchronized (ipcmap)
{
ipcmap.put(__ipcid, __cb);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment