X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsserver%2Fxdsserver.go;h=b6c6f2f593edaca6a127947aec4c69e70440f568;hb=5dc2ff003106f0ced38caadb06033f24c792f9b9;hp=5079553567ee5417610565419b7e39279d2b2e6d;hpb=40d77d7b1d1b41bd1f2f5a00037d21858114e188;p=src%2Fxds%2Fxds-server.git diff --git a/lib/xdsserver/xdsserver.go b/lib/xdsserver/xdsserver.go index 5079553..b6c6f2f 100644 --- a/lib/xdsserver/xdsserver.go +++ b/lib/xdsserver/xdsserver.go @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 "IoT.bzh" + * Copyright (C) 2017-2018 "IoT.bzh" * Author Sebastien Douheret * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,32 +26,34 @@ import ( "syscall" "time" + st "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/syncthing" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xdsconfig" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1" "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" - "github.com/iotbzh/xds-server/lib/xsapiv1" - - "github.com/iotbzh/xds-server/lib/syncthing" - "github.com/iotbzh/xds-server/lib/xdsconfig" ) const cookieMaxAge = "3600" // Context holds the XDS server context type Context struct { - ProgName string - Cli *cli.Context - Config *xdsconfig.Config - Log *logrus.Logger - LogLevelSilly bool - LogSillyf func(format string, args ...interface{}) - SThg *st.SyncThing - SThgCmd *exec.Cmd - SThgInotCmd *exec.Cmd - mfolders *Folders - sdks *SDKs - WWWServer *WebServer - sessions *Sessions - Exit chan os.Signal + ProgName string + Cli *cli.Context + Config *xdsconfig.Config + Log *logrus.Logger + LogLevelSilly bool + LogSillyf func(format string, args ...interface{}) + SThg *st.SyncThing + SThgCmd *exec.Cmd + SThgInotCmd *exec.Cmd + mfolders *Folders + sdks *SDKs + targets *Targets + WWWServer *WebServer + sessions *Sessions + events *Events + lockXdsSrvUpdate LockXdsUpdate + Exit chan os.Signal } // NewXdsServer Create a new instance of XDS server @@ -82,12 +84,13 @@ func NewXdsServer(cliCtx *cli.Context) *Context { // Define default configuration ctx := Context{ - ProgName: cliCtx.App.Name, - Cli: cliCtx, - Log: log, - LogLevelSilly: logSilly, - LogSillyf: sillyFunc, - Exit: make(chan os.Signal, 1), + ProgName: cliCtx.App.Name, + Cli: cliCtx, + Log: log, + LogLevelSilly: logSilly, + LogSillyf: sillyFunc, + lockXdsSrvUpdate: LockXdsUpdate{LockCpt: 0}, + Exit: make(chan os.Signal, 1), } // register handler on SIGTERM / exit @@ -128,7 +131,10 @@ func (ctx *Context) Run() (int, error) { ctx._logPrint("Logging file for HTTP requests: %s\n", logFileHTTPReq) } - // Create syncthing instance when section "syncthing" is present in config.json + // Create events management + ctx.events = EventsConstructor(ctx) + + // Create syncthing instance when section "syncthing" is present in server-config.json if ctx.Config.FileConf.SThgConf != nil { ctx.SThg = st.NewSyncThing(ctx.Config, ctx.Log) } @@ -175,7 +181,7 @@ func (ctx *Context) Run() (int, error) { } // Init model folder - ctx.mfolders = FoldersNew(ctx) + ctx.mfolders = FoldersConstructor(ctx) // Load initial folders config from disk if err := ctx.mfolders.LoadConfig(); err != nil { @@ -183,16 +189,28 @@ func (ctx *Context) Run() (int, error) { } // Init cross SDKs - ctx.sdks, err = NewSDKs(ctx) + ctx.sdks, err = SDKsConstructor(ctx) if err != nil { return -6, err } + // Init target and terminals model + ctx.targets = TargetsConstructor(ctx) + + // Load initial target & terminal config + if err := ctx.targets.LoadConfig(); err != nil { + return -6, err + } + // Create Web Server - ctx.WWWServer = NewWebServer(ctx) + ctx.WWWServer = WebServerConstructor(ctx) // Sessions manager - ctx.sessions = NewClientSessions(ctx, cookieMaxAge) + ctx.sessions = ClientSessionsConstructor(ctx, cookieMaxAge) + + // Check if a new package version is available + // and monitor updates + MonitorUpdates(ctx) // Run Web Server until exit requested (blocking call) if err = ctx.WWWServer.Serve(); err != nil {