Skip to content
This repository was archived by the owner on Nov 22, 2020. It is now read-only.
Merged
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "v2c-recognizer"]
path = v2c-recognizer
url = git@github.com:V2C-Development-Team/v2c-recognizer
[submodule "v2c-dashboard-backend"]
path = v2c-dashboard-backend
url = git@github.com:V2C-Development-Team/v2c-dashboard-backend.git
5 changes: 4 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
rem pull the repos
git submodule update --init --recursive

rem build this project
call .\gradlew clean shadowJar --refresh-dependencies

rem build the java projects
for %%m in (v2c-desktop-controller-linux v2c-dispatcher) do (
for %%m in (v2c-desktop-controller-linux v2c-dispatcher v2c-dashboard-backend) do (
echo Building %%m
cd %%m
call .\gradlew clean shadowJar --refresh-dependencies
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sourceCompatibility = prjCompat
targetCompatibility = prjCompat

dependencies {
implementation 'com.jcraft:jsch:0.1.55'
implementation 'commons-cli:commons-cli:1.4'
implementation 'org.apache.commons:commons-lang3:3.11'
implementation 'org.json:json:20200518'
Expand Down
8 changes: 1 addition & 7 deletions run.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
@echo off
start "" /d v2c-dispatcher java -jar build\libs\v2c-dispatcher.jar
ping -n 3 127.0.0.1>nul
start "" /d v2c-desktop-controller-linux java -jar build\libs\v2c-desktop-controller-linux.jar -u
start "" /d v2c-recognizer\Recognizer cmd /c "python speech.py"
start "" /d v2c-recognizer\Recognizer cmd /c "python widget.py"
start "" /d v2c-dashboard cmd /c "npm start"
java -jar build\libs\v2c-poc-submission.jar
23 changes: 12 additions & 11 deletions src/main/java/edu/uco/cs/v2c/poc/ModuleID.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
import edu.uco.cs.v2c.poc.control.ModuleHandler.ProcessType;

public enum ModuleID {
HOME,
DISPATCHER(ProcessType.JAVA_PROCESS, "v2c-dispatcher/build/libs/v2c-dispatcher.jar"),
RECOGNIZER(ProcessType.PYTHON_PROCESS, "v2c-recognizer/Recognizer/speech.py"),
DESKTOP_CONTROLLER(ProcessType.JAVA_PROCESS, "v2c-desktop-controller-linux/build/libs/v2c-desktop-controller-linux.jar"),
DASHBOARD_BACKEND(ProcessType.JAVA_PROCESS, "v2c-dashboard-backend/build/libs/v2c-dashboard-backend.jar"),
DASHBOARD_FRONTEND(ProcessType.NPM_PROCESS, "v2c-dashboard");
DISPATCHER(ProcessType.JAVA_PROCESS, "v2c-dispatcher/build/libs/v2c-dispatcher.jar", false),
RECOGNIZER(ProcessType.PYTHON_PROCESS, "v2c-recognizer/Recognizer/speech.py", false),
DESKTOP_CONTROLLER(ProcessType.JAVA_PROCESS, "v2c-desktop-controller-linux/build/libs/v2c-desktop-controller-linux.jar", false),
DASHBOARD_BACKEND(ProcessType.JAVA_PROCESS, "v2c-dashboard-backend/build/libs/v2c-dashboard-backend.jar", true),
DASHBOARD_FRONTEND(ProcessType.NPM_PROCESS, "v2c-dashboard", false);

private boolean hasTunnel = false;
private String name = null;
private String defaultModulePath = null;
private ProcessType processType = null;

private ModuleID() {
this(null, null);
}

private ModuleID(ProcessType processType, String defaultModulePath) {
private ModuleID(ProcessType processType, String defaultModulePath, boolean hasTunnel) {
this.hasTunnel = hasTunnel;
this.processType = processType;
this.defaultModulePath = defaultModulePath;
String[] tokens = name().split("_");
Expand All @@ -35,6 +32,10 @@ private ModuleID(ProcessType processType, String defaultModulePath) {
return name;
}

public boolean hasTunnel() {
return hasTunnel;
}

public ProcessType getProcessType() {
return processType;
}
Expand Down
48 changes: 45 additions & 3 deletions src/main/java/edu/uco/cs/v2c/poc/SubmissionPOC.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
package edu.uco.cs.v2c.poc;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.HashSet;
import java.util.Set;

import javax.swing.JButton;

import edu.uco.cs.v2c.poc.control.ConfigureAction;
import edu.uco.cs.v2c.poc.control.ModuleConfigAction;
import edu.uco.cs.v2c.poc.control.ModuleHandler;
import edu.uco.cs.v2c.poc.control.StartAction;
import edu.uco.cs.v2c.poc.control.StopAction;
import edu.uco.cs.v2c.poc.control.TunnelConfigAction;
import edu.uco.cs.v2c.poc.net.Tunnel;
import edu.uco.cs.v2c.poc.ui.LandingFrame;
import edu.uco.cs.v2c.poc.ui.ModuleComponent;

public class SubmissionPOC {

private static Set<ModuleHandler> handlers = new HashSet<>();

public static void main(String[] args) {
LandingFrame landingFrame = new LandingFrame();

for(ModuleID moduleID : ModuleID.values()) {
if(moduleID.getProcessType() == null) continue;
ModuleComponent moduleComponent = landingFrame.getModule(moduleID);
ModuleHandler moduleHandler = ModuleHandler.build(moduleComponent, moduleID);
ModuleHandler moduleHandler = ModuleHandler.build(landingFrame.getHomeComponent(), moduleComponent, moduleID);
handlers.add(moduleHandler);

JButton startButton = moduleComponent.addButton("START MODULE", new StartAction(moduleHandler));
moduleHandler.addButtonToEnableOnDyingProcess(startButton);
JButton stopButton = moduleComponent.addButton("STOP MODULE", new StopAction(moduleHandler));
stopButton.setEnabled(false);
moduleHandler.addButtonToEnableOnLivingProcess(stopButton);
moduleComponent.addButton("CONFIGURE", new ConfigureAction(moduleHandler));
moduleComponent.addButton("CONFIGURE", new ModuleConfigAction(moduleHandler));

if(moduleID.hasTunnel()) {
Tunnel tunnel = new Tunnel();
moduleComponent.addButton("TUNNEL", new TunnelConfigAction(moduleHandler, tunnel));
moduleHandler.setTunnel(tunnel);
}

landingFrame.getHomeComponent().addModuleHandler(moduleHandler);
}

landingFrame.addWindowListener(new WindowListener() {

@Override public void windowOpened(WindowEvent e) { }

@Override public void windowClosing(WindowEvent e) {
for(ModuleHandler handler : handlers)
handler.terminate();
}

@Override public void windowClosed(WindowEvent e) { }

@Override public void windowIconified(WindowEvent e) { }

@Override public void windowDeiconified(WindowEvent e) { }

@Override public void windowActivated(WindowEvent e) { }

@Override public void windowDeactivated(WindowEvent e) { }

});

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import java.awt.event.ActionEvent;

import edu.uco.cs.v2c.poc.ui.ConfigurationFrame;
import edu.uco.cs.v2c.poc.ui.ModuleConfigFrame;

public class ConfigureAction extends ModuleAction {
public class ModuleConfigAction extends ModuleAction {

public ConfigureAction(ModuleHandler handler) {
private ModuleConfigFrame moduleConfigFrame = null;

public ModuleConfigAction(ModuleHandler handler) {
super(handler);
}

@Override public void actionPerformed(ActionEvent e) {
ConfigurationFrame configurationFrame = new ConfigurationFrame(this);
configurationFrame.setVisible(true);
if(moduleConfigFrame == null)
moduleConfigFrame = new ModuleConfigFrame(this);
moduleConfigFrame.setVisible(true);
}

public void onConfigUpdate(String runtimeBin, String moduleBin) {
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/edu/uco/cs/v2c/poc/control/ModuleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.apache.commons.lang3.SystemUtils;

import edu.uco.cs.v2c.poc.ModuleID;
import edu.uco.cs.v2c.poc.net.Tunnel;
import edu.uco.cs.v2c.poc.ui.HomeComponent;
import edu.uco.cs.v2c.poc.ui.ModuleComponent;

public class ModuleHandler implements Runnable {
Expand Down Expand Up @@ -61,16 +63,19 @@ public String getBin() {

private AtomicBoolean go = new AtomicBoolean();
private AtomicReference<Process> currentProcess = new AtomicReference<>();
private HomeComponent homeComponent = null;
private ModuleComponent moduleComponent = null;
private ModuleID moduleID = null;
private Set<JButton> enabledButtonsOnLivingProcess = new HashSet<>();
private Set<JButton> enabledButtonsOnDyingProcess = new HashSet<>();
private String runtimeBin = null;
private String moduleBin = null;
private Thread thread = null;
private Tunnel tunnel = null;

private ModuleHandler(ModuleComponent moduleComponent, ModuleID moduleID) {
private ModuleHandler(HomeComponent homeComponent, ModuleComponent moduleComponent, ModuleID moduleID) {
this.moduleID = moduleID;
this.homeComponent = homeComponent;
this.moduleComponent = moduleComponent;
if(moduleID != null) {
moduleComponent.setActive(false);
Expand All @@ -79,8 +84,8 @@ private ModuleHandler(ModuleComponent moduleComponent, ModuleID moduleID) {
}
}

public static ModuleHandler build(ModuleComponent moduleComponent, ModuleID moduleID) {
ModuleHandler handler = new ModuleHandler(moduleComponent, moduleID);
public static ModuleHandler build(HomeComponent homeComponent, ModuleComponent moduleComponent, ModuleID moduleID) {
ModuleHandler handler = new ModuleHandler(homeComponent, moduleComponent, moduleID);
handler.thread = new Thread(handler);
handler.thread.setDaemon(true);
handler.thread.start();
Expand Down Expand Up @@ -141,14 +146,19 @@ public void setModuleBin(String moduleBin) {
processBuilder.redirectErrorStream(true);

try {
if(moduleID.hasTunnel() && tunnel != null && tunnel.isEnabled())
tunnel.spinUp();

Process process = processBuilder.start();
currentProcess.set(process);

moduleComponent.setActive(true);
homeComponent.notifyModuleStateChange(moduleID, true);
for(JButton button : enabledButtonsOnLivingProcess)
button.setEnabled(true);
for(JButton button : enabledButtonsOnDyingProcess)
button.setEnabled(false);
moduleComponent.putLine("Starting module...");

try(BufferedReader streamReader = new BufferedReader(
new InputStreamReader(process.getInputStream()))) {
Expand All @@ -163,10 +173,15 @@ public void setModuleBin(String moduleBin) {
} finally {
go.set(false);
moduleComponent.setActive(false);
homeComponent.notifyModuleStateChange(moduleID, false);
for(JButton button : enabledButtonsOnDyingProcess)
button.setEnabled(true);
for(JButton button : enabledButtonsOnLivingProcess)
button.setEnabled(false);
moduleComponent.putLine("Module terminated.");

if(moduleID.hasTunnel() && tunnel != null)
tunnel.spinDown();
}
}
} catch(InterruptedException e) { }
Expand Down Expand Up @@ -205,4 +220,8 @@ public void addButtonToEnableOnLivingProcess(JButton button) {
public void addButtonToEnableOnDyingProcess(JButton button) {
enabledButtonsOnDyingProcess.add(button);
}

public void setTunnel(Tunnel tunnel) {
this.tunnel = tunnel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package edu.uco.cs.v2c.poc.control;

import java.awt.event.ActionEvent;
import java.io.File;

import edu.uco.cs.v2c.poc.net.Tunnel;
import edu.uco.cs.v2c.poc.ui.TunnelConfigFrame;

public class TunnelConfigAction extends ModuleAction {

private Tunnel tunnel = null;
private TunnelConfigFrame tunnelConfigFrame = null;

public TunnelConfigAction(ModuleHandler handler, Tunnel tunnel) {
super(handler);
this.tunnel = tunnel;
}

@Override public void actionPerformed(ActionEvent e) {
if(tunnelConfigFrame == null)
tunnelConfigFrame = new TunnelConfigFrame(this);
tunnelConfigFrame.setVisible(true);
}

public boolean onConfigUpdate(String localPort, String remoteHost, String remotePort,
String internalHost, String internalPort, String username,
String keyfilePath, String keyfilePassword) {

try {
int lPort = Integer.parseInt(localPort);
int iPort = Integer.parseInt(internalPort);
int rPort = Integer.parseInt(remotePort);

tunnel.setLocalPort(lPort)
.setRemoteHost(remoteHost)
.setRemotePort(rPort)
.setInternalHost(internalHost)
.setInternalPort(iPort)
.setKeyfile(keyfilePath, keyfilePassword.isBlank() ? null : keyfilePassword);

return true;

} catch(Exception e) { }

return false;
}

public void setEnabled(boolean enabled) {
tunnel.setEnabled(enabled);
}

}
Loading