Commit 844da224 authored by Dominic's avatar Dominic
Browse files

Rename WorkerAPI => TranslationWorkerAPI

parent 703a5855
......@@ -76,7 +76,7 @@ angular.module('cp.app').config(["$routeProvider", "localStorageServiceProvider"
controller: 'newFileCtrl'
})
.when('/import/:fileType', {
templateUrl: 'partials/import.html',
template: '<div id="importfile-react-container"></div>',
controller: 'importFileCtrl'
})
.when('/edit/:location/:fileId', {
......
import "FILES/files.js";
import React from "react";
import ReactDOM from "react-dom";
import "TASKS/taskManager.js";
import { ImportFile } from "../../../../ts/ui/files/ImportFile";
import { AngularShim } from "../../../../ts/ui/util/AngularShim";
export const importFileCtrl = ['$scope', '$routeParams', 'fileTypes', 'taskManager', '$timeout', 'files', '$location', function ($scope, $routeParams, fileTypes, taskManager, $timeout, files, $location) {
export const importFileCtrl = ['$rootScope', '$routeParams', 'fileTypes', 'taskManager', '$timeout', 'files', '$location', function ($rootScope, $routeParams, fileTypes, taskManager, $timeout, files, $location) {
"use strict";
$scope.tasks = taskManager;
$scope.fileType = fileTypes[$routeParams.fileType];
$scope.possibleImports = [];
$scope.worker = taskManager.requestWorker("importer", function (e) {
console.log(e);
$location.path('/error').search({ error: 'translationWorkerCrash', details: e });
});
$scope.currentTask = null;
$scope.$on('$destroy', function () {
$scope.worker.terminateWorker();
});
$scope.parse = function () {
if ($scope.currentTask !== null) $scope.worker.cancelTask($scope.currentTask);
$scope.worker.submitTask('parse', {
data: $scope.importData,
fileType: $routeParams.fileType
}, function resultCallback (data) {
$scope.possibleImports = data.possibleImports;
}, null, 5);
};
$scope.$watch('importData', function () {
if ($scope.parsingPromise) $timeout.cancel($scope.parsingPromise);
$scope.parsingPromise = $timeout(function () {
$scope.parse();
}, 200);
}, true);
$scope.import = function (possibleImport) {
var file = files.createFile($routeParams.fileType);
files.setFileContent(file, possibleImport.data);
$location.path('edit/local/' + file.id);
const fileType = $routeParams.fileType;
const container = document.getElementById("importfile-react-container");
const importFiles = React.createElement(ImportFile, { fileType: fileType }, null);
const render = () => {
ReactDOM.render(
React.createElement(
AngularShim,
{
rootScope: $rootScope,
settingsString: JSON.stringify($rootScope.settings),
},
importFiles
),
container
);
};
render();
$rootScope.$watch("settings", render, true);
}];
\ No newline at end of file
......@@ -11,14 +11,14 @@ import { NoticeModal, NoticeModalProps } from '../../globalModal/NoticeModal';
import { FeatureContext } from '../../util/features/features';
import LtsExplorer from '../../util/ltsExplorer';
import { SettingsContext } from '../../util/settings/settings';
import { WorkerAPI } from '../../util/taskmanagerTypes';
import { TranslatorWorkerAPI } from '../../util/taskmanagerTypes';
import { pluralize } from '../../utils';
import { Editor } from '../editorTypes';
import './LtsEditor.scss';
import { StateKey } from './ltsEditorTypes';
const LTSEditor: Editor<LTSFileData, { worker?: WorkerAPI, ltsExplorer?: LtsExplorer }> = ({ data, visibility: _visibility, worker, ltsExplorer }) => {
const LTSEditor: Editor<LTSFileData, { worker?: TranslatorWorkerAPI, ltsExplorer?: LtsExplorer }> = ({ data, visibility: _visibility, worker, ltsExplorer }) => {
const { settings, setSettings } = useContext(SettingsContext);
......
......@@ -4,7 +4,7 @@ import { LTSFileData } from "../../../../../pseuco-shared-components/fileData";
import { FileTypes } from "../../files/fileTypes";
import { getExercisesStatus } from "../../util/features/features";
import { SettingsContext } from "../../util/settings/settings";
import { TaskManagerAPI, WorkerAPI } from "../../util/taskmanagerTypes";
import { TaskManagerAPI, TranslatorWorkerAPI } from "../../util/taskmanagerTypes";
import { ExerciseNames, exercises, markExerciseCompleted } from "../exercises";
export const ExerciseHost: React.FC<{
......
......@@ -7,7 +7,7 @@ import { FilesAPI } from '../../files/filesAPI';
import { FileTypes } from '../../files/fileTypes';
import LtsExplorer from '../../util/ltsExplorer';
import { Settings, SettingsContext, SettingsGetterAndSetter } from '../../util/settings/settings';
import { TaskID, WorkerAPI } from '../../util/taskmanagerTypes';
import { TaskID, TranslatorWorkerAPI } from '../../util/taskmanagerTypes';
import { debounce } from '../../utils';
import { AnticipatedDataAuthorityError, DataAuthorityAPI, DataAuthorityData, DataAuthorityProps, DataForTranslationWorker, EditorData, EditorDataUpdate, prepareDataForWorker, storeLTSData, tryFetchFile, tryGenerateToolchainConfiguration } from './dataAuthorityUtils';
......@@ -58,7 +58,7 @@ export class DataAuthority extends React.Component<DataAuthorityProps, DataAutho
this.worker = this.props.taskManager.requestWorker("translator", (e: unknown) => {
this.setState({status:"error", message: `The translation worker crashed ${e}`, });
});
this.ltsExplorer = new LtsExplorer(this.worker as WorkerAPI, () => {
this.ltsExplorer = new LtsExplorer(this.worker as TranslatorWorkerAPI, () => {
this.forceUpdate(); // manually force a render cycle as updateExtendedCallback
});
this.fileDirty = false;
......@@ -66,7 +66,7 @@ export class DataAuthority extends React.Component<DataAuthorityProps, DataAutho
fileDirty: boolean; // was the file changed since the last translation?
worker: WorkerAPI;
worker: TranslatorWorkerAPI;
ltsExplorer: LtsExplorer; // To pass to the LTSEditor for the data.lts.core exploration
currentTask: TaskID | null = null; // taskId of the current translation job, or null
unmounting = false;
......
......@@ -9,7 +9,7 @@ import { FileTypes, RemoteFile, StoredFileSignature } from "../../files/fileType
import LtsExplorer from "../../util/ltsExplorer";
import { PasteAPI } from "../../util/paste";
import { Settings } from "../../util/settings/settings";
import { TaskManagerAPI, WorkerAPI } from "../../util/taskmanagerTypes";
import { TaskManagerAPI, TranslatorWorkerAPI } from "../../util/taskmanagerTypes";
import { firstKey } from "../../utils";
import { editorConfigurations, Toolchain } from "../editorConfiguration";
import { IDEApi } from "../ideConnection/ideConnection";
......@@ -50,7 +50,7 @@ export type DataAuthorityData = {
toolchainNameFromSettings: string,
toolchainConfiguration: Settings["toolchainConfiguration"],
api: {
worker: WorkerAPI,
worker: TranslatorWorkerAPI,
touched: boolean,
onEditorDataChange?: (update: EditorDataUpdate) => void,
updateFileName: (newFileName: string) => void,
......@@ -265,7 +265,7 @@ export const prepareDataForWorker = (file: DataAuthorityFile, data: EditorData):
return out;
};
export const storeLTSData = (file: DataAuthorityFile, data: EditorData, worker: WorkerAPI): void => {
export const storeLTSData = (file: DataAuthorityFile, data: EditorData, worker: TranslatorWorkerAPI): void => {
if (file.type === 'lts') {
// we are working with an LTS file
// submit it to the worker, so that exploration and actions have access to it
......
import React from 'react';
import { WorkerAPI } from '../../util/taskmanagerTypes';
import { TranslatorWorkerAPI } from '../../util/taskmanagerTypes';
import { Heading } from '../helpUtils';
import CCS from './CCS';
import LTS from './LTS';
import Pseuco from './Pseuco';
const FileTypes: React.FC<{ worker: WorkerAPI }> = ({ worker}) => {
const FileTypes: React.FC<{ worker: TranslatorWorkerAPI }> = ({ worker}) => {
return <>
<Heading anchorName="filetypes">File Types</Heading>
<LTS worker={worker} />
......
......@@ -3,16 +3,16 @@ import { LTSFileData } from '../../../../../pseuco-shared-components/fileData';
import '../../../../legacy/css/help.scss';
import LTSEditor from '../../editors/ltsEditor/LtsEditor';
import LtsExplorer from '../../util/ltsExplorer';
import { WorkerAPI } from '../../util/taskmanagerTypes';
import { TranslatorWorkerAPI } from '../../util/taskmanagerTypes';
import { Heading } from '../helpUtils';
const LTS: React.FC<{ worker: WorkerAPI }> = ({ worker: worker }) => {
const LTS: React.FC<{ worker: TranslatorWorkerAPI }> = ({ worker: worker }) => {
const ltsData: LTSFileData = {
core: { "initialState": "x.X", "states": { "0": { "transitions": [] }, "x.X": { "transitions": [{ "label": "x", "detailsLabel": false, "target": "X" }] }, "X": { "transitions": [{ "label": "a", "detailsLabel": false, "target": "b.(c.X + x.x.X) + δ.0" }] }, "b.(c.X + x.x.X) + δ.0": { "transitions": [{ "label": "b", "detailsLabel": false, "target": "c.X + x.x.X" }, { "label": "δ", "detailsLabel": false, "target": "0" }] }, "c.X + x.x.X": { "transitions": [{ "label": "c", "detailsLabel": false, "target": "X" }, { "label": "x", "detailsLabel": false, "target": "x.X" }] } } },
extended: { explored: true }
};
const [ltsExplorer] = useState(new LtsExplorer(worker as WorkerAPI));
const [ltsExplorer] = useState(new LtsExplorer(worker as TranslatorWorkerAPI));
return <>
<Heading as="h3" anchorName="lts">Labelled Transition Systems</Heading>
......
import { LTSFileData } from "../../../../pseuco-shared-components/fileData";
import { LTSTransition } from "../../../../pseuco-shared-components/lts/lts";
import { StateKey } from "../editors/ltsEditor/ltsEditorTypes";
import { WorkerAPI } from "./taskmanagerTypes";
import { TranslatorWorkerAPI } from "./taskmanagerTypes";
export type LTSExplorationData = {
dataId: number,
......@@ -31,11 +31,11 @@ export type LTSExplorationReturnData = {
class LtsExplorer {
worker: WorkerAPI;
worker: TranslatorWorkerAPI;
updateExtendedCallback: () => void;
finishCallback: (ltsData: LTSFileData) => void;
constructor(worker: WorkerAPI, updateExtendedCallback?: () => void, finishCallback?: (ltsData: LTSFileData) => void) {
constructor(worker: TranslatorWorkerAPI, updateExtendedCallback?: () => void, finishCallback?: (ltsData: LTSFileData) => void) {
this.worker = worker;
this.updateExtendedCallback = updateExtendedCallback ?? (() => { return; });
this.finishCallback = finishCallback ?? (() => { return; });
......
......@@ -124,7 +124,7 @@ export type WorkerConfigurations = {
};
// TODO: make resultData less redundant, flatten resultData into resultData.data and remove taskCompleted:boolean
export type WorkerAPI = {
export type TranslatorWorkerAPI = {
id: TaskID;
terminateWorker: (finishCallback?: FinishCallback) => void;
submitTask: <T extends keyof WorkerConfigurations>(
......@@ -143,11 +143,11 @@ export type WorkerAPI = {
export type TaskType = "minimizeLts" | "translate" | "dropData" | "exploreLts" | "prioritizeStates" | "storeData";
export type PseucoWorkerType = "translator";
export type PseucoWorkerType = "translator" | "importer";
export type TaskManagerAPI = {
getRunningTaskCount: () => number;
requestWorker: (type: PseucoWorkerType, crashCallback: (error: any) => void) => WorkerAPI;
requestWorker: (type: PseucoWorkerType, crashCallback: (error: any) => void) => TranslatorWorkerAPI;
};
export type WorkerData = {
......
......@@ -13,9 +13,9 @@
import { LTSFileData } from '../../../pseuco-shared-components/fileData';
import { FileTypes } from '../ui/files/fileTypes';
import LtsExplorer from '../ui/util/ltsExplorer';
import { WorkerAPI } from '../ui/util/taskmanagerTypes';
import { TranslatorWorkerAPI } from '../ui/util/taskmanagerTypes';
export const oneStopLtsTranslator = (worker: WorkerAPI, source: string, sourceType: keyof FileTypes, translationChain: Array<{ source: keyof FileTypes, target: keyof FileTypes }>, explorationBound: number): Promise<LTSFileData> =>
export const oneStopLtsTranslator = (worker: TranslatorWorkerAPI, source: string, sourceType: keyof FileTypes, translationChain: Array<{ source: keyof FileTypes, target: keyof FileTypes }>, explorationBound: number): Promise<LTSFileData> =>
new Promise<LTSFileData>((resolve, reject) => {
try {
let erroredOut = false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment