From 9ba0c3e820d4e57346652e7a2eb34582e0052d37 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 22 Apr 2019 22:21:48 +0200 Subject: [PATCH] Moving XPCOM stuff --- VirtualComputer-Core/pom.xml | 59 +++------- .../VirtualBox/5.1/VirtualBox-5.1.pom | 9 -- .../VirtualBox/5.2/VirtualBox-5.2.pom | 9 -- .../VirtualBox/maven-metadata-local.xml | 14 --- .../java/sznp/virtualcomputer/Computer.java | 5 +- .../java/sznp/virtualcomputer/PluginMain.java | 4 +- .../events/EventHandlerBase.java | 17 ++- .../renderer/MCFrameBuffer.java | 105 ++--------------- .../java/sznp/virtualcomputer/util/Utils.java | 29 ----- VirtualComputerMSCOM/pom.xml | 2 + VirtualComputerXPCOM/pom.xml | 2 + .../sznp/virtualcomputer/COMFrameBuffer.java | 111 ++++++++++++++++++ .../sznp/virtualcomputer/EventHandler.java | 35 ++++++ .../virtualcomputer/util/COMObjectBase.java | 0 .../sznp/virtualcomputer/util/COMUtils.java | 33 ++++++ .../virtualcomputer/util/IEventHandler.java | 7 ++ .../virtualcomputer/util/IMCFrameBuffer.java | 9 ++ pom.xml | 45 +++++++ .../6.0/VirtualBox-MSCOM-6.0.jar | Bin .../6.0/VirtualBox-MSCOM-6.0.pom | 0 .../VirtualBox-MSCOM/maven-metadata-local.xml | 0 .../VirtualBox/5.1/VirtualBox-5.1-javadoc.jar | Bin .../VirtualBox/5.1/VirtualBox-5.1.jar | Bin .../VirtualBox/5.1/VirtualBox-5.1.pom | 10 ++ .../VirtualBox/5.2/VirtualBox-5.2.jar | Bin .../VirtualBox/5.2/VirtualBox-5.2.pom | 10 ++ .../VirtualBox/6.0/VirtualBox-6.0.jar | Bin .../VirtualBox/6.0/VirtualBox-6.0.pom | 0 .../VirtualBox/maven-metadata-local.xml | 14 +++ 29 files changed, 317 insertions(+), 212 deletions(-) delete mode 100644 VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom delete mode 100755 VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom delete mode 100644 VirtualComputer-Core/repo/org/virtualbox/VirtualBox/maven-metadata-local.xml create mode 100644 VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/COMFrameBuffer.java create mode 100644 VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java rename {VirtualComputer-Core => VirtualComputerXPCOM}/src/main/java/sznp/virtualcomputer/util/COMObjectBase.java (100%) create mode 100644 VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java create mode 100644 VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IEventHandler.java create mode 100644 VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IMCFrameBuffer.java rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.jar (100%) rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.pom (100%) rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox-MSCOM/maven-metadata-local.xml (100%) rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1-javadoc.jar (100%) rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.jar (100%) create mode 100644 repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.jar (100%) create mode 100755 repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.jar (100%) rename {VirtualComputer-Core/repo => repo}/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.pom (100%) create mode 100644 repo/org/virtualbox/VirtualBox/maven-metadata-local.xml diff --git a/VirtualComputer-Core/pom.xml b/VirtualComputer-Core/pom.xml index f5234f1..7cb7c1a 100644 --- a/VirtualComputer-Core/pom.xml +++ b/VirtualComputer-Core/pom.xml @@ -1,9 +1,13 @@ 4.0.0 - io.github.NorbiPeti VirtualComputer-Core 2.1-SNAPSHOT + + io.github.NorbiPeti + VirtualComputer + 2.1-SNAPSHOT + @@ -34,40 +38,11 @@ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - repo - file://${basedir}/repo - - - - org.spigotmc - spigot-api - 1.12-R0.1-SNAPSHOT - provided - - - - - net.java.dev.jna - jna - 4.4.0 - - - - com.github.jnr - jnr-ffi - 2.1.7 + + org.virtualbox + VirtualBox-MSCOM + 6.0 com.aparapi @@ -75,14 +50,14 @@ 1.10.0 - org.projectlombok - lombok - 1.16.16 + io.github.NorbiPeti + VirtualComputer-XPCOM + 2.1-SNAPSHOT - - com.google.code.findbugs - jsr305 - 3.0.0 + + sznp.virtualcomputer + VirtualComputer-MSCOM + 2.1-SNAPSHOT @@ -102,6 +77,7 @@ org.virtualbox:VirtualBox-MSCOM + sznp.virtualcomputer.VirtualComputer-MSCOM @@ -127,6 +103,7 @@ org.virtualbox:VirtualBox + sznp.virtualcomputer.VirtualComputer-XPCOM diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom b/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom deleted file mode 100644 index 35819af..0000000 --- a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - org.virtualbox - VirtualBox - 5.1 - POM was created from install:install-file - diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom b/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom deleted file mode 100755 index fb51ba3..0000000 --- a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - org.virtualbox - VirtualBox - 5.2 - POM was created from install:install-file - diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/maven-metadata-local.xml b/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/maven-metadata-local.xml deleted file mode 100644 index ea3d226..0000000 --- a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/maven-metadata-local.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - org.virtualbox - VirtualBox - - 6.0 - - 5.1 - 5.2 - 6.0 - - 20181221211412 - - diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java index 79592df..065eb07 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java @@ -9,7 +9,6 @@ import org.virtualbox_6_0.*; import sznp.virtualcomputer.events.MachineEventHandler; import sznp.virtualcomputer.events.VBoxEventHandler; import sznp.virtualcomputer.renderer.GPURenderer; -import sznp.virtualcomputer.renderer.MCFrameBuffer; import sznp.virtualcomputer.util.Scancode; import javax.annotation.Nullable; @@ -61,7 +60,7 @@ public final class Computer { //TODO: If we have VirtualBox open, it won't close the server's port //TODO: "The object in question already exists." on second start //machine.launchVMProcess(session, "headless", "").waitForCompletion(10000); //No privileges, start the 'old' way - //session.getConsole().getDisplay().attachFramebuffer(0L, new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay(), false))); + //session.getConsole().getDisplay().attachFramebuffer(0L, new IFramebuffer(new COMFrameBuffer(session.getConsole().getDisplay(), false))); //sendMessage(sender, "§6Computer started with slower screen. Run as root to use a faster method."); } else { sendMessage(sender, "§cFailed to start computer: " + e.getMessage()); @@ -86,7 +85,7 @@ public final class Computer { handler.setProgress(progress); handler.registerTo(progress.getEventSource()); //TODO: Show progress bar some way? console.getDisplay().attachFramebuffer(0L, - new IFramebuffer(new MCFrameBuffer(console.getDisplay(), true))); + new IFramebuffer(new COMFrameBuffer(console.getDisplay(), true))); } private void sendMessage(@Nullable CommandSender sender, String message) { diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java index f38ab70..89e462b 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java @@ -13,7 +13,7 @@ import sznp.virtualcomputer.events.VBoxEventHandler; import sznp.virtualcomputer.renderer.BukkitRenderer; import sznp.virtualcomputer.renderer.GPURenderer; import sznp.virtualcomputer.renderer.IRenderer; -import sznp.virtualcomputer.util.Utils; +import sznp.virtualcomputer.util.COMUtils; import sznp.virtualcomputer.util.VBoxLib; import java.io.File; @@ -67,7 +67,7 @@ public class PluginMain extends JavaPlugin { System.setProperty("sun.boot.library.path", vbpath); if (System.getProperty("java.library.path") == null || System.getProperty("java.library.path").isEmpty()) System.setProperty("java.library.path", vbpath); - Utils.addLibraryPath(vbpath); + COMUtils.addLibraryPath(vbpath); final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath()); VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom"); //TODO: Test for MSCOM vbl.RTR3InitExe(0, "", 0); diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java index 2aafd3d..16757c1 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java @@ -2,12 +2,11 @@ package sznp.virtualcomputer.events; import lombok.val; import org.bukkit.Bukkit; -import org.mozilla.interfaces.IEvent; -import org.mozilla.interfaces.IEventListener; +import org.virtualbox_6_0.IEvent; import org.virtualbox_6_0.IEventSource; import org.virtualbox_6_0.VBoxEventType; -import sznp.virtualcomputer.util.COMObjectBase; -import sznp.virtualcomputer.util.Utils; +import sznp.virtualcomputer.util.COMUtils; +import sznp.virtualcomputer.util.IEventHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -17,7 +16,7 @@ import java.util.Map; /** * A Bukkit-like event system which calls the appropriate methods on an event. */ -public abstract class EventHandlerBase extends COMObjectBase implements IEventListener { +public abstract class EventHandlerBase implements IEventHandler { /** * The events to listen for. It will only look for these handlers. */ @@ -25,23 +24,21 @@ public abstract class EventHandlerBase extends COMObjectBase implements IEventLi private boolean enabled = true; protected EventHandlerBase(Map> eventMap) { - //this.eventMap = eventMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().value(), Map.Entry::getValue)); this.eventMap = eventMap; } @Override public final void handleEvent(IEvent iEvent) { - //val cl=eventMap.get((int)iEvent.getType()); - We can afford to search through the events for this handler if (!enabled) return; - val kv = eventMap.entrySet().stream().filter(e -> e.getKey().value() == iEvent.getType()).findAny(); + val kv = eventMap.entrySet().stream().filter(e -> e.getKey().value() == iEvent.getType().value()).findAny(); if (!kv.isPresent()) return; //Event not supported val cl = kv.get().getValue(); for (Method method : getClass().getMethods()) { if (method.isAnnotationPresent(org.bukkit.event.EventHandler.class) && method.getParameterCount() == 1 && method.getParameterTypes()[0] == cl) { try { - method.invoke(this, Utils.getEvent(iEvent, cl)); + method.invoke(this, COMUtils.getEvent(iEvent, cl)); return; } catch (IllegalAccessException e) { e.printStackTrace(); @@ -54,7 +51,7 @@ public abstract class EventHandlerBase extends COMObjectBase implements IEventLi } public org.virtualbox_6_0.IEventListener registerTo(IEventSource source) { - return Utils.registerListener(source, this, new ArrayList<>(eventMap.keySet())); + return COMUtils.registerListener(source, this, new ArrayList<>(eventMap.keySet())); } public void disable() { diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/MCFrameBuffer.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/MCFrameBuffer.java index a4c49da..353e035 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/MCFrameBuffer.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/MCFrameBuffer.java @@ -1,93 +1,21 @@ package sznp.virtualcomputer.renderer; import com.sun.jna.Pointer; +import lombok.RequiredArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; -import org.mozilla.interfaces.IFramebuffer; -import org.mozilla.interfaces.IFramebufferOverlay; -import org.mozilla.interfaces.nsISupports; -import org.mozilla.xpcom.Mozilla; -import org.virtualbox_6_0.*; +import org.virtualbox_6_0.Holder; +import org.virtualbox_6_0.IDisplay; +import org.virtualbox_6_0.IDisplaySourceBitmap; +import org.virtualbox_6_0.VBoxException; import sznp.virtualcomputer.PluginMain; +import sznp.virtualcomputer.util.IMCFrameBuffer; import sznp.virtualcomputer.util.Timing; -import java.util.Arrays; - -public class MCFrameBuffer implements IFramebuffer { - private IDisplay display; +@RequiredArgsConstructor +public class MCFrameBuffer implements IMCFrameBuffer { + private final IDisplay display; private Holder holder = new Holder<>(); - - public MCFrameBuffer(IDisplay display, boolean VBoxDirect) { //TODO: Implement param - this.display = display; - } - - @Override - public nsISupports queryInterface(String id) { - return Mozilla.queryInterface(this, id); - } - - @Override - public long getBitsPerPixel() { - return 32; - } - - @Override - public long getBytesPerLine() { - return 640L; - } - - @Override - public long[] getCapabilities(long[] arg0) { - try { - System.out.println("Capabilities queried"); - System.out.println("Capabilities: " + Arrays.toString(arg0)); - return new long[]{FramebufferCapabilities.UpdateImage.value()}; - } - catch(Exception e) { - e.printStackTrace(); - return new long[]{}; - } - } - - @Override - public long getHeight() { - return 480; - } - - @Override - public long getHeightReduction() { - return 0; - } - - @Override - public IFramebufferOverlay getOverlay() { - return null; - } - - @Override - public long getPixelFormat() { - return BitmapFormat.BGRA.value(); - } - - @Override - public long getVisibleRegion(byte arg0, long arg1) { - return 0; - } - - @Override - public long getWidth() { - return 640; - } - - @Override - public long getWinId() { - return 0; // Zero means no win id - } - - @Override - public void notify3DEvent(long arg0, byte[] arg1) { - } - private BukkitTask tt; private Pointer pointer; private int width; @@ -135,20 +63,7 @@ public class MCFrameBuffer implements IFramebuffer { } @Override - public void notifyUpdateImage(long arg0, long arg1, long arg2, long arg3, byte[] arg4) { + public void notifyUpdateImage(long x, long y, long width, long height, byte[] image) { System.out.println("Update image!"); } - - @Override - public void setVisibleRegion(byte arg0, long arg1) { - } - - @Override - public void processVHWACommand(byte b, int i, boolean b1) { - } - - @Override - public boolean videoModeSupported(long arg0, long arg1, long arg2) { - return true; - } } diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/util/Utils.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/util/Utils.java index dfe919e..c6a5aad 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/util/Utils.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/util/Utils.java @@ -1,16 +1,7 @@ package sznp.virtualcomputer.util; -import lombok.val; -import org.mozilla.interfaces.IEventListener; -import org.virtualbox_6_0.IEvent; -import org.virtualbox_6_0.IEventSource; -import org.virtualbox_6_0.VBoxEventType; -import org.virtualbox_6_0.xpcom.IUnknown; - import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.util.Arrays; -import java.util.List; public class Utils { /** @@ -38,24 +29,4 @@ public class Utils { newPaths[newPaths.length - 1] = pathToAdd; usrPathsField.set(null, newPaths); } - - //public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) { - public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventListener listener, List types) { - val ret = new org.virtualbox_6_0.IEventListener(listener); - source.registerListener(ret, types, true); - return ret; - } - - @SuppressWarnings("unchecked") - public static T getEvent(org.mozilla.interfaces.IEvent event, Class cl) { - //if (event.getType() != type.value()) return null; - //return (T) T.queryInterface(new IEvent(event)); - Probably won't work - try { - val method = cl.getMethod("queryInterface", IUnknown.class); - return (T) method.invoke(null, new IEvent(event)); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - } } diff --git a/VirtualComputerMSCOM/pom.xml b/VirtualComputerMSCOM/pom.xml index 49668ac..174fe9e 100644 --- a/VirtualComputerMSCOM/pom.xml +++ b/VirtualComputerMSCOM/pom.xml @@ -19,6 +19,8 @@ org.virtualbox VirtualBox-MSCOM 6.0 + true + diff --git a/VirtualComputerXPCOM/pom.xml b/VirtualComputerXPCOM/pom.xml index 9135c5f..f4ea613 100644 --- a/VirtualComputerXPCOM/pom.xml +++ b/VirtualComputerXPCOM/pom.xml @@ -16,6 +16,8 @@ org.virtualbox VirtualBox 6.0 + true + diff --git a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/COMFrameBuffer.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/COMFrameBuffer.java new file mode 100644 index 0000000..6f35793 --- /dev/null +++ b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/COMFrameBuffer.java @@ -0,0 +1,111 @@ +package sznp.virtualcomputer; + +import lombok.RequiredArgsConstructor; +import org.mozilla.interfaces.IFramebuffer; +import org.mozilla.interfaces.IFramebufferOverlay; +import org.mozilla.interfaces.nsISupports; +import org.mozilla.xpcom.Mozilla; +import org.virtualbox_6_0.BitmapFormat; +import org.virtualbox_6_0.FramebufferCapabilities; +import sznp.virtualcomputer.util.IMCFrameBuffer; + +import java.util.Arrays; + +@RequiredArgsConstructor +public class COMFrameBuffer implements IFramebuffer { + private final IMCFrameBuffer frameBuffer; + + @Override + public nsISupports queryInterface(String id) { + return Mozilla.queryInterface(this, id); + } + + @Override + public long getBitsPerPixel() { + return 32; + } + + @Override + public long getBytesPerLine() { + return 640L; + } + + @Override + public long[] getCapabilities(long[] arg0) { + try { + System.out.println("Capabilities queried"); + System.out.println("Capabilities: " + Arrays.toString(arg0)); + return new long[]{FramebufferCapabilities.UpdateImage.value()}; + } catch (Exception e) { + e.printStackTrace(); + return new long[]{}; + } + } + + @Override + public long getHeight() { + return 480; + } + + @Override + public long getHeightReduction() { + return 0; + } + + @Override + public IFramebufferOverlay getOverlay() { + return null; + } + + @Override + public long getPixelFormat() { + return BitmapFormat.BGRA.value(); + } + + @Override + public long getVisibleRegion(byte arg0, long arg1) { + return 0; + } + + @Override + public long getWidth() { + return 640; + } + + @Override + public long getWinId() { + return 0; // Zero means no win id + } + + @Override + public void notify3DEvent(long arg0, byte[] arg1) { + } + + @Override + public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) { + frameBuffer.notifyChange(screenId, xOrigin, yOrigin, width, height); + } + + @Override + public void notifyUpdate(long x, long y, long width, long height) { + frameBuffer.notifyUpdate(x, y, width, height); + } + + @Override + public void notifyUpdateImage(long arg0, long arg1, long arg2, long arg3, byte[] arg4) { + frameBuffer.notifyUpdateImage(arg0, arg1, arg2, arg3, arg4); + } + + @Override + public void setVisibleRegion(byte arg0, long arg1) { + } + + @Override + public void processVHWACommand(byte b, int i, boolean b1) { + } + + @Override + public boolean videoModeSupported(long arg0, long arg1, long arg2) { + return true; + } +} diff --git a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java new file mode 100644 index 0000000..e62ec9f --- /dev/null +++ b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java @@ -0,0 +1,35 @@ +package sznp.virtualcomputer; + +import org.mozilla.interfaces.IEvent; +import org.mozilla.interfaces.IEventListener; +import sznp.virtualcomputer.util.COMObjectBase; + +import java.util.function.Consumer; + +/** + * A Bukkit-like event system which calls the appropriate methods on an event. + */ +public final class EventHandler extends COMObjectBase implements IEventListener { + private final Consumer handler; + private boolean enabled = true; + + /** + * New XPCOM event handler. + * + * @param handler The handle method that handles what needs to be handled + */ + public EventHandler(Consumer handler) { + this.handler = handler; + } + + @Override + public final void handleEvent(IEvent iEvent) { + if (!enabled) + return; + handler.accept(new org.virtualbox_6_0.IEvent(iEvent)); + } + + public void disable() { + enabled = false; + } +} diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/util/COMObjectBase.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMObjectBase.java similarity index 100% rename from VirtualComputer-Core/src/main/java/sznp/virtualcomputer/util/COMObjectBase.java rename to VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMObjectBase.java diff --git a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java new file mode 100644 index 0000000..dafeca7 --- /dev/null +++ b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java @@ -0,0 +1,33 @@ +package sznp.virtualcomputer.util; + +import lombok.val; +import org.virtualbox_6_0.IEvent; +import org.virtualbox_6_0.IEventSource; +import org.virtualbox_6_0.VBoxEventType; +import org.virtualbox_6_0.xpcom.IUnknown; +import sznp.virtualcomputer.EventHandler; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +public final class COMUtils { + private COMUtils() {} + + //public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) { + public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventHandler listener, List types) { + val ret = new org.virtualbox_6_0.IEventListener(new EventHandler(listener::handleEvent)); + source.registerListener(ret, types, true); + return ret; + } + + @SuppressWarnings("unchecked") + public static T getEvent(IEvent event, Class cl) { + try { + val method = cl.getMethod("queryInterface", IUnknown.class); + return (T) method.invoke(null, event); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IEventHandler.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IEventHandler.java new file mode 100644 index 0000000..6c2dc19 --- /dev/null +++ b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IEventHandler.java @@ -0,0 +1,7 @@ +package sznp.virtualcomputer.util; + +import org.virtualbox_6_0.IEvent; + +public interface IEventHandler { + void handleEvent(IEvent iEvent); +} diff --git a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IMCFrameBuffer.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IMCFrameBuffer.java new file mode 100644 index 0000000..ebec8d0 --- /dev/null +++ b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/IMCFrameBuffer.java @@ -0,0 +1,9 @@ +package sznp.virtualcomputer.util; + +public interface IMCFrameBuffer { + void notifyUpdate(long x, long y, long width, long height); + + void notifyUpdateImage(long x, long y, long width, long height, byte[] image); + + void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height); +} diff --git a/pom.xml b/pom.xml index 0803a46..98d78ce 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,17 @@ 1.8 + + + repo + file://${basedir}/repo + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + junit @@ -31,6 +42,40 @@ 4.11 test + + org.projectlombok + lombok + 1.16.16 + + + + net.java.dev.jna + jna + 4.4.0 + + + + com.github.jnr + jnr-ffi + 2.1.7 + + + com.google.code.findbugs + jsr305 + 3.0.0 + + + org.spigotmc + spigot-api + 1.12-R0.1-SNAPSHOT + provided + + diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.jar b/repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.jar similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.jar rename to repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.jar diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.pom b/repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.pom similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.pom rename to repo/org/virtualbox/VirtualBox-MSCOM/6.0/VirtualBox-MSCOM-6.0.pom diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox-MSCOM/maven-metadata-local.xml b/repo/org/virtualbox/VirtualBox-MSCOM/maven-metadata-local.xml similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox-MSCOM/maven-metadata-local.xml rename to repo/org/virtualbox/VirtualBox-MSCOM/maven-metadata-local.xml diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1-javadoc.jar b/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1-javadoc.jar similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1-javadoc.jar rename to repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1-javadoc.jar diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.jar b/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.jar similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.jar rename to repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.jar diff --git a/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom b/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom new file mode 100644 index 0000000..981a7b7 --- /dev/null +++ b/repo/org/virtualbox/VirtualBox/5.1/VirtualBox-5.1.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + org.virtualbox + VirtualBox + 5.1 + POM was created from install:install-file + diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.jar b/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.jar similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.jar rename to repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.jar diff --git a/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom b/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom new file mode 100755 index 0000000..783c0c8 --- /dev/null +++ b/repo/org/virtualbox/VirtualBox/5.2/VirtualBox-5.2.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + org.virtualbox + VirtualBox + 5.2 + POM was created from install:install-file + diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.jar b/repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.jar similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.jar rename to repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.jar diff --git a/VirtualComputer-Core/repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.pom b/repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.pom similarity index 100% rename from VirtualComputer-Core/repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.pom rename to repo/org/virtualbox/VirtualBox/6.0/VirtualBox-6.0.pom diff --git a/repo/org/virtualbox/VirtualBox/maven-metadata-local.xml b/repo/org/virtualbox/VirtualBox/maven-metadata-local.xml new file mode 100644 index 0000000..9841bc8 --- /dev/null +++ b/repo/org/virtualbox/VirtualBox/maven-metadata-local.xml @@ -0,0 +1,14 @@ + + + org.virtualbox + VirtualBox + + 6.0 + + 5.1 + 5.2 + 6.0 + + 20181221211412 + +