Initial commit
Some checks failed
Gradle Build / build (push) Has been cancelled

This commit is contained in:
CaiXiang
2024-11-30 18:36:13 +08:00
commit aa56926258
2134 changed files with 232943 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.kernelcontrolcenter;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.multibindings.Multibinder;
import jakarta.inject.Singleton;
import org.opentcs.components.kernelcontrolcenter.ControlCenterPanel;
import org.opentcs.customizations.controlcenter.ControlCenterInjectionModule;
import org.opentcs.kernelcontrolcenter.peripherals.PeripheralsPanel;
import org.opentcs.kernelcontrolcenter.util.KernelControlCenterConfiguration;
import org.opentcs.kernelcontrolcenter.vehicles.DriverGUI;
/**
* Configures the default extensions of the openTCS kernel control center application.
*/
public class DefaultKernelControlCenterExtensionsModule
extends
ControlCenterInjectionModule {
/**
* Creates a new instance.
*/
public DefaultKernelControlCenterExtensionsModule() {
}
@Override
protected void configure() {
configureControlCenterDependencies();
}
private void configureControlCenterDependencies() {
KernelControlCenterConfiguration configuration
= getConfigBindingProvider().get(
KernelControlCenterConfiguration.PREFIX,
KernelControlCenterConfiguration.class
);
bind(KernelControlCenterConfiguration.class).toInstance(configuration);
// Ensure these binders are initialized.
commAdapterPanelFactoryBinder();
peripheralCommAdapterPanelFactoryBinder();
Multibinder<ControlCenterPanel> modellingBinder = controlCenterPanelBinderModelling();
// No extensions for modelling mode, yet.
Multibinder<ControlCenterPanel> operatingBinder = controlCenterPanelBinderOperating();
operatingBinder.addBinding().to(DriverGUI.class);
if (configuration.enablePeripheralsPanel()) {
operatingBinder.addBinding().to(PeripheralsPanel.class);
}
install(new FactoryModuleBuilder().build(ControlCenterInfoHandlerFactory.class));
bind(KernelControlCenter.class).in(Singleton.class);
}
}

View File

@@ -0,0 +1,172 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.kernelcontrolcenter;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import jakarta.inject.Singleton;
import java.io.File;
import java.util.List;
import java.util.Locale;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.opentcs.access.KernelServicePortal;
import org.opentcs.access.SslParameterSet;
import org.opentcs.access.rmi.KernelServicePortalBuilder;
import org.opentcs.access.rmi.factories.NullSocketFactoryProvider;
import org.opentcs.access.rmi.factories.SecureSocketFactoryProvider;
import org.opentcs.access.rmi.factories.SocketFactoryProvider;
import org.opentcs.common.DefaultPortalManager;
import org.opentcs.common.GuestUserCredentials;
import org.opentcs.common.KernelClientApplication;
import org.opentcs.common.PortalManager;
import org.opentcs.customizations.ApplicationEventBus;
import org.opentcs.customizations.ApplicationHome;
import org.opentcs.customizations.ConfigurableInjectionModule;
import org.opentcs.customizations.ServiceCallWrapper;
import org.opentcs.kernelcontrolcenter.exchange.DefaultServiceCallWrapper;
import org.opentcs.kernelcontrolcenter.exchange.SslConfiguration;
import org.opentcs.kernelcontrolcenter.util.KernelControlCenterConfiguration;
import org.opentcs.kernelcontrolcenter.vehicles.LocalVehicleEntryPool;
import org.opentcs.util.CallWrapper;
import org.opentcs.util.event.EventBus;
import org.opentcs.util.event.EventHandler;
import org.opentcs.util.event.EventSource;
import org.opentcs.util.event.SimpleEventBus;
import org.opentcs.util.gui.dialog.ConnectionParamSet;
import org.opentcs.virtualvehicle.AdapterPanelComponentsFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A Guice module for the openTCS kernel control center application.
*/
public class DefaultKernelControlCenterInjectionModule
extends
ConfigurableInjectionModule {
/**
* This class' logger.
*/
private static final Logger LOG
= LoggerFactory.getLogger(DefaultKernelControlCenterInjectionModule.class);
/**
* Creates a new instance.
*/
public DefaultKernelControlCenterInjectionModule() {
}
@Override
protected void configure() {
File applicationHome = new File(System.getProperty("opentcs.home", "."));
bind(File.class)
.annotatedWith(ApplicationHome.class)
.toInstance(applicationHome);
bind(LocalVehicleEntryPool.class)
.in(Singleton.class);
bind(KernelClientApplication.class)
.to(KernelControlCenterApplication.class)
.in(Singleton.class);
install(new FactoryModuleBuilder().build(AdapterPanelComponentsFactory.class));
configureEventBus();
configureKernelControlCenterDependencies();
configureExchangeInjectionModules();
}
private void configureEventBus() {
EventBus newEventBus = new SimpleEventBus();
bind(EventHandler.class)
.annotatedWith(ApplicationEventBus.class)
.toInstance(newEventBus);
bind(EventSource.class)
.annotatedWith(ApplicationEventBus.class)
.toInstance(newEventBus);
bind(EventBus.class)
.annotatedWith(ApplicationEventBus.class)
.toInstance(newEventBus);
}
private void configureExchangeInjectionModules() {
bind(PortalManager.class)
.to(DefaultPortalManager.class)
.in(Singleton.class);
}
private void configureKernelControlCenterDependencies() {
KernelControlCenterConfiguration configuration
= getConfigBindingProvider().get(
KernelControlCenterConfiguration.PREFIX,
KernelControlCenterConfiguration.class
);
bind(KernelControlCenterConfiguration.class)
.toInstance(configuration);
configureKernelControlCenter(configuration);
configureSocketConnections();
bind(CallWrapper.class)
.annotatedWith(ServiceCallWrapper.class)
.to(DefaultServiceCallWrapper.class)
.in(Singleton.class);
bind(new TypeLiteral<List<ConnectionParamSet>>() {
})
.toInstance(configuration.connectionBookmarks());
}
private void configureSocketConnections() {
SslConfiguration sslConfiguration = getConfigBindingProvider().get(
SslConfiguration.PREFIX,
SslConfiguration.class
);
//Create the data object for the ssl configuration
SslParameterSet sslParamSet = new SslParameterSet(
SslParameterSet.DEFAULT_KEYSTORE_TYPE,
null,
null,
new File(sslConfiguration.truststoreFile()),
sslConfiguration.truststorePassword()
);
bind(SslParameterSet.class).toInstance(sslParamSet);
SocketFactoryProvider socketFactoryProvider;
if (sslConfiguration.enable()) {
socketFactoryProvider = new SecureSocketFactoryProvider(sslParamSet);
}
else {
LOG.warn("SSL encryption disabled, connections will not be secured!");
socketFactoryProvider = new NullSocketFactoryProvider();
}
//Bind socket provider to the kernel portal
bind(KernelServicePortal.class)
.toInstance(
new KernelServicePortalBuilder(
GuestUserCredentials.USER,
GuestUserCredentials.PASSWORD
)
.setSocketFactoryProvider(socketFactoryProvider)
.build()
);
}
private void configureKernelControlCenter(KernelControlCenterConfiguration configuration) {
Locale.setDefault(Locale.forLanguageTag(configuration.locale()));
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException ex) {
LOG.warn("Could not set look-and-feel", ex);
}
// Show tooltips for 30 seconds (Default: 4 sec)
ToolTipManager.sharedInstance().setDismissDelay(30 * 1000);
}
}

View File

@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.kernelcontrolcenter;
import org.opentcs.customizations.controlcenter.ControlCenterInjectionModule;
import org.opentcs.virtualvehicle.LoopbackCommAdapterPanelFactory;
/**
* Registers the loopback adapter's panels.
*/
public class LoopbackCommAdapterPanelsModule
extends
ControlCenterInjectionModule {
/**
* Creates a new instance.
*/
public LoopbackCommAdapterPanelsModule() {
}
// tag::documentation_createCommAdapterPanelsModule[]
@Override
protected void configure() {
commAdapterPanelFactoryBinder().addBinding().to(LoopbackCommAdapterPanelFactory.class);
}
// end::documentation_createCommAdapterPanelsModule[]
}

View File

@@ -0,0 +1,123 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.kernelcontrolcenter;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.util.Modules;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import org.opentcs.configuration.ConfigurationBindingProvider;
import org.opentcs.configuration.gestalt.GestaltConfigurationBindingProvider;
import org.opentcs.customizations.ConfigurableInjectionModule;
import org.opentcs.customizations.controlcenter.ControlCenterInjectionModule;
import org.opentcs.util.Environment;
import org.opentcs.util.logging.UncaughtExceptionLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The kernel control center process's default entry point.
*/
public class RunKernelControlCenter {
/**
* This class' logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(RunKernelControlCenter.class);
/**
* Prevents external instantiation.
*/
private RunKernelControlCenter() {
}
/**
* The kernel control center client's main entry point.
*
* @param args the command line arguments
*/
public static void main(final String[] args) {
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger(false));
Environment.logSystemInfo();
Injector injector = Guice.createInjector(customConfigurationModule());
injector.getInstance(KernelControlCenterApplication.class).initialize();
}
/**
* Builds and returns a Guice module containing the custom configuration for the kernel control
* center application, including additions and overrides by the user.
*
* @return The custom configuration module.
*/
private static Module customConfigurationModule() {
ConfigurationBindingProvider bindingProvider = configurationBindingProvider();
ConfigurableInjectionModule kernelControlCenterInjectionModule
= new DefaultKernelControlCenterInjectionModule();
kernelControlCenterInjectionModule.setConfigBindingProvider(bindingProvider);
return Modules.override(kernelControlCenterInjectionModule)
.with(findRegisteredModules(bindingProvider));
}
/**
* Finds and returns all Guice modules registered via ServiceLoader.
*
* @return The registered/found modules.
*/
private static List<ControlCenterInjectionModule> findRegisteredModules(
ConfigurationBindingProvider bindingProvider
) {
List<ControlCenterInjectionModule> registeredModules = new ArrayList<>();
for (ControlCenterInjectionModule module : ServiceLoader.load(
ControlCenterInjectionModule.class
)) {
LOG.info(
"Integrating injection module {} (source: {})",
module.getClass().getName(),
module.getClass().getProtectionDomain().getCodeSource()
);
module.setConfigBindingProvider(bindingProvider);
registeredModules.add(module);
}
return registeredModules;
}
private static ConfigurationBindingProvider configurationBindingProvider() {
String chosenProvider = System.getProperty("opentcs.configuration.provider", "gestalt");
switch (chosenProvider) {
case "gestalt":
default:
LOG.info("Using gestalt as the configuration provider.");
return gestaltConfigurationBindingProvider();
}
}
private static ConfigurationBindingProvider gestaltConfigurationBindingProvider() {
return new GestaltConfigurationBindingProvider(
Paths.get(
System.getProperty("opentcs.base", "."),
"config",
"opentcs-kernelcontrolcenter-defaults-baseline.properties"
)
.toAbsolutePath(),
Paths.get(
System.getProperty("opentcs.base", "."),
"config",
"opentcs-kernelcontrolcenter-defaults-custom.properties"
)
.toAbsolutePath(),
Paths.get(
System.getProperty("opentcs.home", "."),
"config",
"opentcs-kernelcontrolcenter.properties"
)
.toAbsolutePath()
);
}
}

View File

@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: The openTCS Authors
# SPDX-License-Identifier: MIT
org.opentcs.kernelcontrolcenter.DefaultKernelControlCenterExtensionsModule
org.opentcs.kernelcontrolcenter.LoopbackCommAdapterPanelsModule