taskmanagerTypes.ts 5.85 KB
Newer Older
Dominic's avatar
Dominic committed
1
2
import { Issue, LTSFileData } from '../../../../pseuco-shared-components/fileData';
import { LTSTransition } from '../../../../pseuco-shared-components/lts/lts';
3
import { TranslatorTraceData, TranslatorTraceReturndata } from '../../worker/translatorTrace';
Dominic's avatar
Dominic committed
4
5
import { DataObject } from '../editors/editorTypes';
import { StateKey } from '../editors/ltsEditor/ltsEditorTypes';
6
import { TranslateWorkerData, TranslateWorkerResultData } from '../fileEdit/dataAuthority/DataAuthority';
Dominic's avatar
Dominic committed
7
import { DataForTranslationWorker } from '../fileEdit/dataAuthority/dataAuthorityUtils';
Dominic's avatar
Dominic committed
8
import { ExportLTSFormat } from '../fileEdit/fileEditUi/actionManager/actions/exportLTS/exportLTS';
Dominic's avatar
Dominic committed
9
import { FileTypes } from '../files/fileTypes';
10
import { PossibleImport } from '../files/ImportFile';
11
import { Callback } from '../utils';
12
import { LTSExplorationData, LTSExplorationReturnData } from './ltsExplorer';
13
14
15
16
17
18
19

export type FinishCallback = Callback<any>;
export type ResultCallback = (data: ResultData | null, completed: boolean) => void;
export type CancellationCallback = Callback<any>;
export type TaskID = number;

export type TaskPriority = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
20

21
22
23
24
export type GenericWorkerData = {
    dataId: number
}

25
export type TranslatorWorkerConfiguration = {
26
27
28
29
    trace: {
        workerData: TranslatorTraceData,
        resultData: TranslatorTraceReturndata
    },
30
31
32
33
34
35
36
37
38
39
    dropData: {
        workerData: {
            dataId: number
        }
        resultData: {
            data: null | {
                dataId: number
            },
        }
    },
40
    storeData: {
41
        workerData: { data: LTSFileData },
42
43
44
45
46
        resultData: {
            data: null | {
                dataId: number
            },
        }
47
48
49
50
51
52
53
54
55
56
57
    },
    exploreLts: {
        workerData: LTSExplorationData,
        resultData: LTSExplorationReturnData
    },
    prioritizeStates: {
        workerData: {
            dataId: number,
            states: StateKey[]
        },
        resultData: {
58
            data: null | {
59
60
61

            },
        }
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    },
    minimizeLts: {
        workerData: {
            dataId: number,
        },
        resultData: {
            data: null | {
                command: "minimized",
                data: LTSFileData
            },
        }
    },
    translate: {
        workerData: TranslateWorkerData,
        resultData: TranslateWorkerResultData
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    },
    listActions: {
        workerData: {
            dataId: number
        },
        resultData: {
            data: {
                actions: Array<LTSTransition["label"]>,
                complete: boolean
            },
        }
    },
    traceForAction: {
        workerData: {
            dataId: number,
            action: LTSTransition["label"]
        }, resultData: {
            data: null | {
                command: "failure",
                error: string
            } | {
                command: "trace",
                trace: LTSTransition[]
            },
        }
Dominic's avatar
Dominic committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    },
    exportLts: {
        workerData: {
            dataId: number,
            exportFormat: ExportLTSFormat,
            fileName: string
        }, resultData: {
            data: null | {
                command: "exported",
                data: string
            } | {
                command: "failure",
                error: string
            },
        }
117
118
119
    }
};

120
121
122
123
124
125
126
127
128
129
130
131
132
type MinimalWorkerConfiguration<T> = { [k in keyof T]: {
    workerData: {
    }, resultData: {
        data: unknown,
    }
}}

export type WorkerAPI<Configuration extends MinimalWorkerConfiguration<Configuration>>  = {
    id: TaskID,
    terminateWorker: (FinishCallback?: FinishCallback) => void,
    submitTask: <Task extends keyof Configuration>(
        taskName: Task & string,
        data: Configuration[Task]["workerData"],
133
        resultCallback: null | ((
134
135
            resultData: Configuration[Task]["resultData"]["data"],
            completed: boolean
136
        ) => void),
137
        CancellationCallback : null | (() => void),
138
        priority: TaskPriority
139
140
141
    ) => TaskID,
    cancelTask: (taskId: TaskID) => void,
    isTerminating: () => boolean
142
143
};

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
export type ImporterWorkerConfiguration = {
    parse: {
        workerData: {
            fileType: "lts" | "cpn" | "cpnpp",
            data: string
        },
        resultData: {
            data: {
                possibleImports: PossibleImport[]
            }
        }
    }
}

export type ImporterWorkerAPI = WorkerAPI<ImporterWorkerConfiguration>;

export type TranslatorWorkerAPI = WorkerAPI<TranslatorWorkerConfiguration>;

162
163
export type TaskType = "minimizeLts" | "translate" | "dropData" | "exploreLts" | "prioritizeStates" | "storeData";

164
165
166
167
168
export type PseucoWorkers = {
    translator: TranslatorWorkerAPI,
    importer: ImporterWorkerAPI
}
export type PseucoWorkerType = keyof PseucoWorkers;
169
170
171

export type TaskManagerAPI = {
    getRunningTaskCount: () => number;
172
    requestWorker: <T extends PseucoWorkerType> (type: T & string, crashCallback: (error: any) => void) => PseucoWorkers[T];
173
174
};

Dominic's avatar
Dominic committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
export type WorkerData = {
    dataId: number
} | {
    sourceType: keyof FileTypes,
    translations: Array<{ source: keyof FileTypes, target: keyof FileTypes }>,
    data: DataForTranslationWorker,
    toolchainConfiguration: { ccsPartialEvaluation: boolean }
} | {
    dataId: number,
    stepCount: number
} | {
    dataId: number,
    states: Array<string>
} | {
    core: LTSFileData,
    extended: any
}

export type ResultData = {
    type: keyof FileTypes,
} & ({
    command: "issues" | "translation" | "explorationFinished",
    clearIssuesOn: keyof FileTypes,
    issues: Issue[],
    dataId: number,
    data: DataObject<any, any>
} | {
    command: "addLtsTransitions",
    dataId: number,
    state: StateKey,
    transitions: Array<LTSTransition>
} | {
    command: "addLtsError",
    dataId: number,
    state: StateKey,
    error: string
} | {
    command: "exploredPreGeneratedState",
    dataId: number,
    state: StateKey,
    error: string
});