Skip to content
代码片段 群组 项目
提交 9c8d191c 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Set up server startup sequence across primary and secondary instance.

上级 2d0eba51
No related branches found
No related tags found
无相关合并请求
......@@ -27,7 +27,8 @@
"test:unit:watchAll": "jest --watchAll",
"postinstall": "electron-builder install-app-deps && husky install",
"zap": "node src-script/zap-start.js --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json",
"zap-server": "node src-script/zap-start.js --logToStdout --noUi --gen ./test/gen-template/zigbee/gen-templates.json",
"zap-server": "node src-script/zap-start.js server --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json --reuseZapInstance",
"zap-status": "node src-script/zap-start.js status --reuseZapInstance",
"zaphelp": "node src-script/zap-start.js --help",
"zapc": "node src-script/zap-start.js --logToStdout --gen ./test/gen-template/chip/gen-templates.json",
"zap-dotdot": "node src-script/zap-start.js --logToStdout --zcl ./zcl-builtin/dotdot/library.xml",
......
......@@ -55,16 +55,18 @@ function hookMainInstanceEvents(argv) {
app.exit(1)
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
env.logInfo('Activate...')
windowJs.windowCreateIfNotThere(args.httpPort)
})
if (!argv._.includes('server')) {
console.log('HOOKING UP NON SERVER STUFF!')
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
env.logInfo('Activate...')
windowJs.windowCreateIfNotThere(args.httpPort)
})
}
app.on('will-quit', () => {
startup.shutdown()
......
......@@ -264,6 +264,56 @@ async function startAnalyze(
})
}
/**
* Starts zap in a server mode.
*
* @param {*} options
* @returns promise of a startup
*/
async function startServer() {
let db = await dbApi.initDatabaseAndLoadSchema(
env.sqliteFile(),
env.schemaFile(),
env.zapVersion()
)
watchdog.start(args.watchdogTimer, () => {
if (app != null) {
app.quit()
} else {
process.exit(0)
}
})
mainDatabase = db
return zclLoader
.loadZcl(db, args.zclPropertiesFile)
.then((ctx) =>
generatorEngine.loadTemplates(ctx.db, args.genTemplateJsonFile)
)
.then((ctx) => {
if (ctx.error) {
env.logWarning(ctx.error)
}
return ctx
})
.then((ctx) => {
return httpServer
.initHttpServer(ctx.db, args.httpPort, args.studioHttpPort)
.then(() => {
ipcServer.initServer(ctx.db, args.httpPort)
})
.then(() => ctx)
})
.then((ctx) => {
console.log(`ZAP Server started at: ${httpServer.httpServerUrl()}`)
})
.catch((err) => {
env.logError(err)
throw err
})
}
/**
* Start up applicationa in self-check mode.
*/
......@@ -467,10 +517,13 @@ function startUpSecondaryInstance(argv) {
console.log(data)
})
})
if (argv._.includes('status')) {
ipcClient.emit(ipcServer.eventType.version)
} else if (argv._.includes('new')) {
ipcClient.emit(ipcServer.eventType.new)
} else if (argv._.includes('server')) {
ipcClient.emit(ipcServer.eventType.serverUrl)
} else if (argv._.includes('convert') && argv.zapFiles != null) {
ipcClient.emit(ipcServer.eventType.convert, {
output: argv.output,
......@@ -506,6 +559,8 @@ async function startUpMainInstance(isElectron, argv) {
if (argv.zapFiles.length < 1)
throw 'You need to specify at least one zap file.'
return startAnalyze(argv.zapFiles)
} else if (argv._.includes('server')) {
return startServer()
} else if (argv._.includes('convert')) {
if (argv.zapFiles.length < 1)
throw 'You need to specify at least one zap file.'
......
......@@ -242,8 +242,18 @@ function httpServerPort() {
return 0
}
}
/**
* Returns the URL of the server.
* @returns the server URL
*/
function httpServerUrl() {
return `http://localhost:${httpServerPort()}`
}
// exports
exports.initHttpServer = initHttpServer
exports.shutdownHttpServer = shutdownHttpServer
exports.shutdownHttpServerSync = shutdownHttpServerSync
exports.httpServerPort = httpServerPort
exports.httpServerUrl = httpServerUrl
......@@ -21,6 +21,7 @@ const path = require('path')
const uiUtil = require('../ui/ui-util.js')
const util = require('../util/util.js')
const watchdog = require('../main-process/watchdog.js')
const httpServer = require('../server/http-server.js')
const serverIpc = new ipc.IPC()
......@@ -34,6 +35,7 @@ const eventType = {
open: 'open', // Sent from client to server with array of files to open
convert: 'convert', // Sent from client to server when requesting to convert files
generate: 'generate', // Sent from client to server when requesting generation.
serverUrl: 'serverUrl', // Sent from client to ask for server URL
}
/**
......@@ -78,10 +80,22 @@ function initServer(db = null, httpPort = null) {
serverIpc.server.emit(socket, eventType.pong, data)
})
// Server URL
serverIpc.server.on(eventType.serverUrl, (data, socket) => {
watchdog.reset()
serverIpc.server.emit(
socket,
eventType.overAndOut,
httpServer.httpServerUrl()
)
})
// Server version.
serverIpc.server.on(eventType.version, (data, socket) => {
watchdog.reset()
serverIpc.server.emit(socket, eventType.overAndOut, env.zapVersion())
let ret = env.zapVersion()
ret.url = httpServer.httpServerUrl()
serverIpc.server.emit(socket, eventType.overAndOut, ret)
})
// New file window
......
......@@ -64,6 +64,7 @@ function processCommandLineArguments(argv) {
analyze: 'Analyze the zap file without doing anything.',
convert: 'Convert a zap or ISC file to latest zap file.',
status: 'Query the status of a zap server.',
server: 'Run zap in a server mode.',
new: 'If in client mode, start a new window on a main instance.',
}
let y = yargs
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册