mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package events
|
|
|
|
import (
|
|
"github.com/hanzozt/zt/v2/controller/event"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (self *Dispatcher) AddConnectEventHandler(handler event.ConnectEventHandler) {
|
|
self.connectEventHandlers.Append(handler)
|
|
}
|
|
|
|
func (self *Dispatcher) RemoveConnectEventHandler(handler event.ConnectEventHandler) {
|
|
self.connectEventHandlers.DeleteIf(func(val event.ConnectEventHandler) bool {
|
|
if val == handler {
|
|
return true
|
|
}
|
|
if w, ok := val.(event.ConnectEventHandlerWrapper); ok {
|
|
return w.IsWrapping(handler)
|
|
}
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (self *Dispatcher) AcceptConnectEvent(evt *event.ConnectEvent) {
|
|
evt.EventSrcId = self.ctrlId
|
|
for _, handler := range self.connectEventHandlers.Value() {
|
|
go handler.AcceptConnectEvent(evt)
|
|
}
|
|
}
|
|
|
|
func (self *Dispatcher) registerConnectEventHandler(_ string, val interface{}, _ map[string]interface{}) error {
|
|
handler, ok := val.(event.ConnectEventHandler)
|
|
|
|
if !ok {
|
|
return errors.Errorf("type %T doesn't implement the event.ConnectEventHandler interface", val)
|
|
}
|
|
|
|
self.AddConnectEventHandler(handler)
|
|
return nil
|
|
}
|
|
|
|
func (self *Dispatcher) unregisterConnectEventHandler(val interface{}) {
|
|
if handler, ok := val.(event.ConnectEventHandler); ok {
|
|
self.RemoveConnectEventHandler(handler)
|
|
}
|
|
}
|