Skip to content
Snippets Groups Projects
Commit fd347973 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Initial event API

parent c42501b1
No related branches found
No related tags found
3 merge requests!23Release,!13Hotfix/no host cooldown + return sende2e TS,!11Client Event Reporting API
...@@ -63,6 +63,9 @@ type Client struct { ...@@ -63,6 +63,9 @@ type Client struct {
followerServices *services followerServices *services
clientErrorChannel chan interfaces.ClientError clientErrorChannel chan interfaces.ClientError
// Event reporting in event.go
events eventManager
} }
// NewClient creates client storage, generates keys, connects, and registers // NewClient creates client storage, generates keys, connects, and registers
...@@ -184,6 +187,7 @@ func OpenClient(storageDir string, password []byte, parameters params.Network) ( ...@@ -184,6 +187,7 @@ func OpenClient(storageDir string, password []byte, parameters params.Network) (
followerServices: newServices(), followerServices: newServices(),
parameters: parameters, parameters: parameters,
clientErrorChannel: make(chan interfaces.ClientError, 1000), clientErrorChannel: make(chan interfaces.ClientError, 1000),
events: newEventManager(),
} }
return c, nil return c, nil
...@@ -370,8 +374,13 @@ func (c *Client) registerFollower() error { ...@@ -370,8 +374,13 @@ func (c *Client) registerFollower() error {
} }
} }
err := c.followerServices.add(c.events.eventService)
if err != nil {
return errors.WithMessage(err, "Couldn't start event reporting")
}
//register the core follower service //register the core follower service
err := c.followerServices.add(func() (stoppable.Stoppable, error) { return c.network.Follow(cer) }) err = c.followerServices.add(func() (stoppable.Stoppable, error) { return c.network.Follow(cer) })
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to start following "+ return errors.WithMessage(err, "Failed to start following "+
"the network") "the network")
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
package api package api
import ( import (
"fmt"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/stoppable"
"sync" "sync"
"github.com/pkg/errors"
"fmt"
) )
// EventCallbackFunction defines the callback functions for client event reports // EventCallbackFunction defines the callback functions for client event reports
...@@ -25,12 +25,14 @@ type reportableEvent struct { ...@@ -25,12 +25,14 @@ type reportableEvent struct {
EventType string EventType string
Details string Details string
} }
// Holds state for the event reporting system // Holds state for the event reporting system
type eventManager struct { type eventManager struct {
eventCh chan reportableEvent eventCh chan reportableEvent
eventCbs []EventCallbackFunction eventCbs []EventCallbackFunction
eventLck sync.Mutex eventLck sync.Mutex
} }
func newEventManager() eventManager { func newEventManager() eventManager {
return eventManager{ return eventManager{
eventCh: make(chan reportableEvent, 1000), eventCh: make(chan reportableEvent, 1000),
...@@ -114,12 +116,14 @@ func (e eventManager) reportEventsHandler(stop *stoppable.Single) { ...@@ -114,12 +116,14 @@ func (e eventManager) reportEventsHandler(stop *stoppable.Single) {
func (c *Client) ReportEvent(priority int, category, evtType, details string) { func (c *Client) ReportEvent(priority int, category, evtType, details string) {
c.events.ReportEvent(priority, category, evtType, details) c.events.ReportEvent(priority, category, evtType, details)
} }
// RegisterEventCallback records the given function to receive // RegisterEventCallback records the given function to receive
// ReportableEvent objects. It returns the internal index // ReportableEvent objects. It returns the internal index
// of the callback so that it can be deleted later. // of the callback so that it can be deleted later.
func (c *Client) RegisterEventCallback(myFunc EventCallbackFunction) int { func (c *Client) RegisterEventCallback(myFunc EventCallbackFunction) int {
return c.events.RegisterEventCallback(myFunc) return c.events.RegisterEventCallback(myFunc)
} }
// UnregisterEventCallback deletes the callback identified by the // UnregisterEventCallback deletes the callback identified by the
// index. It returns an error if it fails. // index. It returns an error if it fails.
func (c *Client) UnregisterEventCallback(index int) error { func (c *Client) UnregisterEventCallback(index int) error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment