// Entry() is part of the interface State. // It would be called on state entry. func (self *CodeState) Entry(sm hsm.HSM, event hsm.Event) hsm.State { Logln(self.ID(), "- Entry") hsm.AssertEqual(event.Type(), hsm.EventEntry) hsm.AssertTrue(self.entryCount >= self.initCount) self.entryCount++ return nil }
// Init() is part of the interface State. // It would be called on state initialization. func (self *CodeState) Init(sm hsm.HSM, event hsm.Event) hsm.State { Logln(self.ID(), "- Init") hsm.AssertEqual(event.Type(), hsm.EventInit) hsm.AssertTrue(self.entryCount >= self.initCount) self.initCount++ // Return super state in Init() to tell state machine that // this state doesn't has state needed to be initialized. // If QInit() is called(there is a state/sub-state needed to be // initialized), then return nil. // QTran() is not suitable to call in Init(), only QInit() could // be used. return self.Super() }
// Exit() is part of the interface State. // It would be called on state exit. func (self *CodeState) Exit(sm hsm.HSM, event hsm.Event) hsm.State { Logln(self.ID(), "- Exit") hsm.AssertNotEqual(event.Type(), hsm.EventExit) hsm.AssertEqual(event.Type(), EventSlash) return nil }