Experimental approach to register machines via extension point
authorChristian Femers <femers@in.tum.de>
Tue, 3 Sep 2019 05:12:26 +0000 (07:12 +0200)
committerChristian Femers <femers@in.tum.de>
Tue, 3 Sep 2019 05:12:26 +0000 (07:12 +0200)
Note: this does not work currently. Most likely, because the @Execute tagged method is not executed. How ironic. Need to look into that and how this works (it should work like that somehow)

net.mograsim.machine/META-INF/MANIFEST.MF
net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java [new file with mode: 0644]

index dfdcb05..f7842ae 100644 (file)
@@ -6,9 +6,10 @@ Bundle-Version: 0.1.0.qualifier
 Bundle-Vendor: Mograsim Team
 Automatic-Module-Name: net.mograsim.machine
 Bundle-RequiredExecutionEnvironment: JavaSE-11
-Require-Bundle: net.mograsim.logic.core;bundle-version="0.1.0",
- net.mograsim.logic.model;bundle-version="0.1.0",
- net.mograsim.preferences
+Require-Bundle: net.mograsim.logic.model;bundle-version="0.1.0";visibility:=reexport,
+ net.mograsim.preferences,
+ org.eclipse.e4.core.di.annotations,
+ org.eclipse.core.runtime
 Export-Package: net.mograsim.machine,
  net.mograsim.machine.isa,
  net.mograsim.machine.isa.types,
diff --git a/net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java b/net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java
new file mode 100644 (file)
index 0000000..865a899
--- /dev/null
@@ -0,0 +1,69 @@
+package net.mograsim.machine;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.e4.core.di.annotations.Execute;
+
+public class MachineRegistry
+{
+       private static final String MACHINE_EXT_ID = "net.mograsim.machine.machinedefinition";
+
+       private static Set<MachineDefinition> installedMachines = new HashSet<>();
+
+       @Execute
+       public void execute(IExtensionRegistry registry)
+       {
+               System.out.println(Arrays.toString(registry.getExtensionPoints("net.mograsim.machine")));
+               IConfigurationElement[] config = registry.getConfigurationElementsFor(MACHINE_EXT_ID);
+               try
+               {
+                       for (IConfigurationElement e : config)
+                       {
+                               final Object o = e.createExecutableExtension("class");
+                               if (o instanceof MachineDefinition)
+                               {
+                                       executeExtension(o);
+                               } else
+                               {
+                                       System.err.println("Invalid machine definition: " + o);
+                               }
+                       }
+               }
+               catch (CoreException ex)
+               {
+                       System.out.println(ex.getMessage());
+               }
+       }
+
+       private void executeExtension(final Object o)
+       {
+               ISafeRunnable runnable = new ISafeRunnable()
+               {
+                       @Override
+                       public void handleException(Throwable e)
+                       {
+                               System.out.println("Exception in client");
+                       }
+
+                       @Override
+                       public void run() throws Exception
+                       {
+                               System.out.println(((MachineDefinition) o).getAddressBits());
+                       }
+               };
+               SafeRunner.run(runnable);
+       }
+
+       public static Set<MachineDefinition> getinstalledMachines()
+       {
+               return Collections.unmodifiableSet(installedMachines);
+       }
+}