diff --git a/api/event.go b/api/event.go index 64db960c6c9500ed106d3b2c8ba0cad453575b34..33c647a358fe26f08afaabeff3f5d883a2082b8d 100644 --- a/api/event.go +++ b/api/event.go @@ -11,13 +11,11 @@ import ( "fmt" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/stoppable" "sync" ) -// EventCallbackFunction defines the callback functions for client event reports -type EventCallbackFunction func(priority int, category, evtType, details string) - // ReportableEvent is used to surface events to client users. type reportableEvent struct { Priority int @@ -66,7 +64,7 @@ func (e *eventManager) ReportEvent(priority int, category, evtType, // ReportableEvent objects. It returns the internal index // of the callback so that it can be deleted later. func (e *eventManager) RegisterEventCallback(name string, - myFunc EventCallbackFunction) error { + myFunc interfaces.EventCallbackFunction) error { _, existsAlready := e.eventCbs.LoadOrStore(name, myFunc) if existsAlready { return errors.Errorf("Key %s already exists as event callback", @@ -103,7 +101,7 @@ func (e *eventManager) reportEventsHandler(stop *stoppable.Single) { // the event queue explode. The API will report errors // in the logging any time the event queue gets full. e.eventCbs.Range(func(name, myFunc interface{}) bool { - f := myFunc.(EventCallbackFunction) + f := myFunc.(interfaces.EventCallbackFunction) f(evt.Priority, evt.Category, evt.EventType, evt.Details) return true @@ -122,7 +120,7 @@ func (c *Client) ReportEvent(priority int, category, evtType, details string) { // ReportableEvent objects. It returns the internal index // of the callback so that it can be deleted later. func (c *Client) RegisterEventCallback(name string, - myFunc EventCallbackFunction) error { + myFunc interfaces.EventCallbackFunction) error { return c.events.RegisterEventCallback(name, myFunc) } diff --git a/bindings/event.go b/bindings/event.go index 95f32800a11fac5f252286b3bc22bebf26c557c3..7e28c72e025768a7dc454098e070d923c9832f2f 100644 --- a/bindings/event.go +++ b/bindings/event.go @@ -8,14 +8,14 @@ package bindings import ( - "gitlab.com/elixxir/client/api" + "gitlab.com/elixxir/client/interfaces" ) // RegisterEventCallback records the given function to receive // ReportableEvent objects. It returns the internal index // of the callback so that it can be deleted later. func (c *Client) RegisterEventCallback(name string, - myFunc api.EventCallbackFunction) error { + myFunc interfaces.EventCallbackFunction) error { return c.api.RegisterEventCallback(name, myFunc) } diff --git a/interfaces/event.go b/interfaces/event.go new file mode 100644 index 0000000000000000000000000000000000000000..0aba83b45cae650362d269e0b780c61c07a09238 --- /dev/null +++ b/interfaces/event.go @@ -0,0 +1,11 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +/////////////////////////////////////////////////////////////////////////////// + +package interfaces + +// EventCallbackFunction defines the callback functions for client event reports +type EventCallbackFunction func(priority int, category, evtType, details string)