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 {
followerServices *services
clientErrorChannel chan interfaces.ClientError
// Event reporting in event.go
events eventManager
}
// NewClient creates client storage, generates keys, connects, and registers
......@@ -184,6 +187,7 @@ func OpenClient(storageDir string, password []byte, parameters params.Network) (
followerServices: newServices(),
parameters: parameters,
clientErrorChannel: make(chan interfaces.ClientError, 1000),
events: newEventManager(),
}
return c, nil
......@@ -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
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 {
return errors.WithMessage(err, "Failed to start following "+
"the network")
......
......@@ -8,11 +8,11 @@
package api
import (
"fmt"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/stoppable"
"sync"
"github.com/pkg/errors"
"fmt"
)
// EventCallbackFunction defines the callback functions for client event reports
......@@ -25,12 +25,14 @@ type reportableEvent struct {
EventType string
Details string
}
// Holds state for the event reporting system
type eventManager struct {
eventCh chan reportableEvent
eventCbs []EventCallbackFunction
eventLck sync.Mutex
}
func newEventManager() eventManager {
return eventManager{
eventCh: make(chan reportableEvent, 1000),
......@@ -114,12 +116,14 @@ func (e eventManager) reportEventsHandler(stop *stoppable.Single) {
func (c *Client) ReportEvent(priority int, category, evtType, details string) {
c.events.ReportEvent(priority, category, evtType, details)
}
// 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(myFunc EventCallbackFunction) int {
return c.events.RegisterEventCallback(myFunc)
}
// UnregisterEventCallback deletes the callback identified by the
// index. It returns an error if it fails.
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