From 2611438e38861a1e312c9ab56693dc93a34dec92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Thu, 13 Feb 2020 10:53:31 +0100 Subject: [PATCH] [ivette] server control --- ivette/src/frama-c/server.js | 18 ++++++++++++++-- ivette/src/frama-c/states.js | 8 ++++++- ivette/src/renderer/Application.js | 1 + ivette/src/renderer/Controller.js | 34 ++++++++++++++++++++++++++++-- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/ivette/src/frama-c/server.js b/ivette/src/frama-c/server.js index c6d7cfebccd..1363dec2144 100644 --- a/ivette/src/frama-c/server.js +++ b/ivette/src/frama-c/server.js @@ -100,19 +100,31 @@ var killer; // killer timeout // -------------------------------------------------------------------------- export const buffer = new Buffer({ maxlines: 200 }); +export const feedback = '' ; // -------------------------------------------------------------------------- // --- Server Status // -------------------------------------------------------------------------- /** - @summary Current Server `STATUS`. + @summary Current Server Status. @return {STATUS} the current server status @description See [STATUS](module-frama-c_server.html#~STATUS) code definitions. */ export function getStatus() { return status; } +/** + @summary Hook on current server (Custom React Hook). + @return {STATUS} the current server status + @description + See [STATUS](module-frama-c_server.html#~STATUS) code definitions. +*/ +export function useStatus() { + Dome.useUpdate(STATUS); + return status; +} + /** Return `FAILED` status message. */ export function getError() { return error; } @@ -443,6 +455,7 @@ function _close(error) { if (error) { _status(FAILED,error); } else { + if (status === RESTART) setImmediate(start); _status(IDLE); } } @@ -630,7 +643,8 @@ function _receive(resp) { export default { configure, buffer, - getStatus, getError, getPending, isRunning, + getStatus, useStatus, + getError, getPending, isRunning, start, stop, kill, restart, clear, sendGET, sendSET, sendEXEC, onReady, onShutdown, diff --git a/ivette/src/frama-c/states.js b/ivette/src/frama-c/states.js index f5c2c778e53..57f5e122ffc 100644 --- a/ivette/src/frama-c/states.js +++ b/ivette/src/frama-c/states.js @@ -35,7 +35,7 @@ export const PROJECT = 'frama-c.project' ; export const STATE = 'frama-c.state.' ; // -------------------------------------------------------------------------- -// --- Current Project +// --- Synchronized Current Project // -------------------------------------------------------------------------- var currentProject = undefined ; @@ -48,6 +48,12 @@ Server.onReady(() => { }); }); +Server.onShutdown(() => { + currentProject = undefined ; + globalStates = {} ; + Dome.emit(PROJECT); +}); + // -------------------------------------------------------------------------- // --- Project API // -------------------------------------------------------------------------- diff --git a/ivette/src/renderer/Application.js b/ivette/src/renderer/Application.js index 87cb9d4b133..8f934bb378a 100644 --- a/ivette/src/renderer/Application.js +++ b/ivette/src/renderer/Application.js @@ -34,6 +34,7 @@ export default (function() { selected={sidebar} onClick={flipSidebar} /> + <Controller.Control/> <Toolbar.Filler/> <Toolbar.Button icon='ITEMS.GRID' diff --git a/ivette/src/renderer/Controller.js b/ivette/src/renderer/Controller.js index 30c3e2751cf..8afc80bae7f 100644 --- a/ivette/src/renderer/Controller.js +++ b/ivette/src/renderer/Controller.js @@ -7,7 +7,7 @@ import Dome from 'dome' ; import Server from 'frama-c/server' ; import States from 'frama-c/states' ; -import { Filler, Button } from 'dome/layout/toolbars' ; +import { Filler, Button, ButtonGroup } from 'dome/layout/toolbars' ; import { LED } from 'dome/controls/buttons' ; import { Label, Code } from 'dome/controls/labels' ; import { Text } from 'dome/text/editors' ; @@ -39,6 +39,36 @@ Dome.onCommand((argv,cwd) => { Server.start(); }); +// -------------------------------------------------------------------------- +// --- Server Control +// -------------------------------------------------------------------------- + +export const Control = () => { + let status = Server.useStatus(); + let play = { enabled: false } ; + let stop = { enabled: false } ; + let reload = { enabled: false } ; + switch(status) { + case 'IDLE': + play = { enabled: true, onClick:Server.start }; + break; + case 'RUNNING': + stop = { enabled: true, onClick:Server.stop }; + reload = { enabled: true, onClick:Server.restart }; + break; + } + return ( + <ButtonGroup> + <Button icon='MEDIA.PLAY' {...play} + title='Start the server' /> + <Button icon='RELOAD' {...reload} + title='Re-start the server' /> + <Button icon='MEDIA.STOP' {...stop} + title='Shut down the server'/> + </ButtonGroup> + ); +}; + // -------------------------------------------------------------------------- // --- Server Console // -------------------------------------------------------------------------- @@ -109,6 +139,6 @@ export const Stats = () => { // --- Controller Exports // -------------------------------------------------------------------------- -export default { Console, Status, Stats }; +export default { Control, Console, Status, Stats }; // -------------------------------------------------------------------------- -- GitLab