Search in sources :

Example 1 with SimulationEngineChangeListener

use of edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener in project AGREE by loonwerks.

the class DefaultSimulationService method createEngine.

@Override
public SimulationEngine createEngine(final EngineType engineType, final SystemInstance systemInstance) {
    Objects.requireNonNull(engineType, "engineType must not be null");
    Objects.requireNonNull(engineType, "systemInstance must not be null");
    if (!(engineType instanceof DefaultEngineType)) {
        throw new IllegalArgumentException("engineType must be an engine type provided by this simulation service");
    }
    final DefaultEngineType defaultEngineType = (DefaultEngineType) engineType;
    final SimulationEngine newSimulationEngine = defaultEngineType.factory.create(systemInstance, masterExceptionHandler);
    // Notify listeners of the new simulation engine
    for (final SimulationEngineChangeListener l : simulationEngineChangeListeners) {
        l.onSimulationEngineCreated(newSimulationEngine);
    }
    return newSimulationEngine;
}
Also used : SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) SimulationEngineChangeListener(edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener)

Example 2 with SimulationEngineChangeListener

use of edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener in project AGREE by loonwerks.

the class SimulationLaunchConfigurationDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    SimulationService simulationService = null;
    try {
        simulationService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationService.class);
        Objects.requireNonNull(configuration, "configuration must not be null");
        // Find the component implementation
        final String componentImplementationName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.COMPONENT_IMPLEMENTATION_NAME, (String) null);
        final String projectName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.PROJECT_NAME, (String) null);
        final IProject project = projectName == null ? null : findProject(projectName);
        final EObject obj = componentImplementationName == null ? null : findComponentImplementation(project, componentImplementationName);
        if (obj instanceof ComponentImplementation) {
            // Refresh the component implementation
            final ComponentImplementation ci = refreshComponentImplementation((ComponentImplementation) obj);
            // (Re)instantiate the model
            final SystemInstance systemInstance = InstantiateModel.buildInstanceModelFile(ci);
            // Get the selected simulation engine type.
            final String selectedEngineTypeId = Objects.requireNonNull(configuration.getAttribute(SimulationLaunchConfigurationAttributes.ENGINE_TYPE_ID, (String) null), "Simulation Engine must be specified");
            final EngineType engineType = Objects.requireNonNull(simulationService.getEngineTypeById(selectedEngineTypeId), "Unable to find specified simulation engine");
            final SimulationEngine newEngine = simulationService.createEngine(engineType, systemInstance);
            final SimulationService simService = simulationService;
            simulationService.addSimulationEngineChangeListener(new SimulationEngineChangeListener() {

                @Override
                public void onSimulationEngineCreated(final SimulationEngine engine) {
                }

                @Override
                public void onSimulationEngineDisposed(final SimulationEngine engine) {
                    if (engine == newEngine) {
                        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
                        simService.removeSimulationEngineChangeListener(this);
                    }
                }
            });
            if (launch instanceof SimulationLaunch) {
                ((SimulationLaunch) launch).setSimulationEngine(newEngine);
            }
        } else {
            simulationService.getExceptionHandler().handleException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Unable to find Component Implementation.")));
        }
    } catch (final Exception e) {
        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
        if (simulationService == null) {
            throw new RuntimeException(e);
        } else {
            simulationService.getExceptionHandler().handleException(e);
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) CoreException(org.eclipse.core.runtime.CoreException) SystemInstance(org.osate.aadl2.instance.SystemInstance) EObject(org.eclipse.emf.ecore.EObject) SimulationEngineChangeListener(edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener) EngineType(edu.uah.rsesc.aadlsimulator.services.EngineType) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService)

Aggregations

SimulationEngine (edu.uah.rsesc.aadlsimulator.SimulationEngine)2 SimulationEngineChangeListener (edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener)2 EngineType (edu.uah.rsesc.aadlsimulator.services.EngineType)1 SimulationService (edu.uah.rsesc.aadlsimulator.services.SimulationService)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 EObject (org.eclipse.emf.ecore.EObject)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 SystemInstance (org.osate.aadl2.instance.SystemInstance)1