diff options
Diffstat (limited to 'src/state.go')
| -rw-r--r-- | src/state.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/state.go b/src/state.go index aa31513..ec927f9 100644 --- a/src/state.go +++ b/src/state.go @@ -19,29 +19,36 @@ type VPNState struct { // The file we keep open for logging LogFile *FileLogger `json:"-"` + // The fsm FSM *FSM `json:"-"` + + // Whether to enable debugging + Debug bool `json:"-"` } -func (state *VPNState) Register(name string, directory string, stateCallback func(string, string, string)) error { - if state.FSM == nil { - state.InitializeFSM() - } +func (state *VPNState) Register(name string, directory string, stateCallback func(string, string, string), debug bool) error { + state.InitializeFSM() if !state.HasTransition(APP_REGISTERED) { return errors.New("app already registered") } state.Name = name state.ConfigDirectory = directory state.StateCallback = stateCallback + state.Debug = debug - // Initialize the logger - // state.InitLog(LOG_WARNING) + LogLevel := LOG_WARNING - // state.Log(LOG_INFO, "App registered") + if debug { + LogLevel = LOG_INFO + } + + // Initialize the logger + state.InitLog(LogLevel) // Try to load the previous configuration if state.LoadConfig() != nil { // This error can be safely ignored, as when the config does not load, the struct will not be filled - // state.Log(LOG_INFO, "Previous configuration not found") + state.Log(LOG_INFO, "Previous configuration not found") } state.GoTransition(APP_REGISTERED, "HALLO") return nil @@ -54,9 +61,8 @@ func (state *VPNState) Deregister() error { // Close the log file state.CloseLog() - // Re-initialize everything - state = &VPNState{} - state.GoTransition(APP_DEREGISTERED, "") + state.Server = &Server{} + state.InitializeFSM() return nil } |
