Skip to content

Commit

Permalink
[#1] Can now launch the C++ back-end from the electron app
Browse files Browse the repository at this point in the history
Signed-off-by: Clovis Durand <cd.clovel19@gmail.com>
  • Loading branch information
Clovel committed Apr 10, 2020
1 parent 77d34a0 commit 616f6b0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
57 changes: 50 additions & 7 deletions app/back/backEndLauncher.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,58 @@
const child = require('child_process');
const config = require('../config.json')
const fs = require('fs');

/* Set the back-end's path */
const backEnd = config.backEnd;
const backEndPort = config.backEndPort;
const edsFile = config.edsFile;

let backEnd;

function launchBackEnd() {
let backEnd;
let backEndLibDir;
let backEndPort;
let edsFile;

lConfig = JSON.parse(fs.readFileSync('./app/config.json', 'utf8'));

/* Set the configuration variables */
backEndExe = lConfig.backEndExe;
backEndPort = lConfig.backEndPort;
backEndLibDir = lConfig.backEndLibDir;
edsFile = lConfig.odFileName;


console.log('backEndExe : ' + backEndExe + ' (' + typeof(backEndExe) + ')');
console.log('backEndLibDir : ' + backEndLibDir + ' (' + typeof(backEndLibDir) + ')');
console.log('backEndPort : ' + backEndPort + ' (' + typeof(backEndPort) + ')');
console.log('edsFile : ' + edsFile + ' (' + typeof(edsFile) + ')');

var lEnv = Object.create(process.env);
lEnv.LD_LIBRARY_PATH = backEndLibDir;

var lParameters = [backEndPort, edsFile];
child.execFile(backEnd, lParameters, function(err, data) {
console.log(err);
console.log(data.toString());
console.log('[INFO ] Launching back-end :' + backEndExe + ' ' + backEndPort + ' ' + edsFile);
backEnd = child.spawn(backEndExe, lParameters, { env: lEnv }, function(error, stdout, stderr) {
if(error) {
console.log(error);
return;
}

console.log(stdout);
console.log(stderr);
});

backEnd.stdout.on('data', function(data) {
console.log('[B-END] stdout: ' + data.toString('utf-8'));
});

backEnd.stderr.on('data', function(data) {
console.log('[B-END] stderr: ' + data.toString('utf8'));
});

backEnd.on('exit', function(code) {
console.log('[B-END] child process exited with code ' + code.toString('utf-8'));
});

return;
}

module.exports.launchBackEnd = launchBackEnd;
3 changes: 3 additions & 0 deletions app/back/ipcBack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const {ipcMain} = require('electron')
const backEndLauncher = require('./backEndLauncher')

ipcMain.on('test-button-signal', () => {
console.log('[DEBUG] IPC signal received by main process');
console.log(' Launching back-end');
backEndLauncher.launchBackEnd();
});

ipcMain.on('methodCall', async (event, { method, callId, args }) => {
Expand Down
3 changes: 2 additions & 1 deletion app/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"backEndExe": "/Users/clovel/repository/CAN-CANOpen/OSCO-OD-Gen/generator/dest/bin/OSCO-OD-Gen-util",
"odFileName": "/Users/clovel/repository/CAN-CANOpen/OSCO-OD-Gen/generator/example/od/IO.eds",
"backEndLibDir": "/Users/clovel/repository/CAN-CANOpen/OSCO-OD-Gen/generator/dest/lib",
"odFileName": "/Users/clovel/repository/CAN-CANOpen/OSCO-OD-Gen/generator/examples/od/IO.eds",
"backEndPort": 3000,
"backEndAddr": "http://localhost"
}

0 comments on commit 616f6b0

Please sign in to comment.