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

Pass events api down to network manager

parent 592a6805
Branches
Tags
3 merge requests!23Release,!13Hotfix/no host cooldown + return sende2e TS,!11Client Event Reporting API
...@@ -241,8 +241,8 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie ...@@ -241,8 +241,8 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie
} }
// Initialize network and link it to context // Initialize network and link it to context
c.network, err = network.NewManager(c.storage, c.switchboard, c.rng, c.comms, c.network, err = network.NewManager(c.storage, c.switchboard, c.rng,
parameters, def) c.events, c.comms, parameters, def)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -301,8 +301,8 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte, ...@@ -301,8 +301,8 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte,
} }
// Initialize network and link it to context // Initialize network and link it to context
c.network, err = network.NewManager(c.storage, c.switchboard, c.rng, c.comms, c.network, err = network.NewManager(c.storage, c.switchboard, c.rng,
parameters, def) c.events, c.comms, parameters, def)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -42,10 +42,9 @@ func newEventManager() *eventManager { ...@@ -42,10 +42,9 @@ func newEventManager() *eventManager {
} }
} }
// ReportEvent reports an event from the client to api users, providing a // Report reports an event from the client to api users, providing a
// priority, category, eventType, and details // priority, category, eventType, and details
func (e *eventManager) ReportEvent(priority int, category, evtType, func (e *eventManager) Report(priority int, category, evtType, details string) {
details string) {
re := reportableEvent{ re := reportableEvent{
Priority: priority, Priority: priority,
Category: category, Category: category,
...@@ -113,7 +112,7 @@ func (e *eventManager) reportEventsHandler(stop *stoppable.Single) { ...@@ -113,7 +112,7 @@ func (e *eventManager) reportEventsHandler(stop *stoppable.Single) {
// ReportEvent reports an event from the client to api users, providing a // ReportEvent reports an event from the client to api users, providing a
// priority, category, eventType, and details // priority, category, eventType, and details
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.Report(priority, category, evtType, details)
} }
// RegisterEventCallback records the given function to receive // RegisterEventCallback records the given function to receive
......
...@@ -34,10 +34,10 @@ func TestEventReporting(t *testing.T) { ...@@ -34,10 +34,10 @@ func TestEventReporting(t *testing.T) {
} }
// Send a few events // Send a few events
evtMgr.ReportEvent(10, "Hi", "TypityType", "I'm an event") evtMgr.Report(10, "Hi", "TypityType", "I'm an event")
evtMgr.ReportEvent(1, "Hi", "TypeII", "Type II errors are the worst") evtMgr.Report(1, "Hi", "TypeII", "Type II errors are the worst")
evtMgr.ReportEvent(20, "Hi", "TypityType3", "eventy details") evtMgr.Report(20, "Hi", "TypityType3", "eventy details")
evtMgr.ReportEvent(22, "Hi", "TypityType4", "I'm an event 2") evtMgr.Report(22, "Hi", "TypityType4", "I'm an event 2")
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
...@@ -67,10 +67,10 @@ func TestEventReporting(t *testing.T) { ...@@ -67,10 +67,10 @@ func TestEventReporting(t *testing.T) {
// Delete callback // Delete callback
evtMgr.UnregisterEventCallback("test") evtMgr.UnregisterEventCallback("test")
// Send more events // Send more events
evtMgr.ReportEvent(10, "Hi", "TypityType", "I'm an event") evtMgr.Report(10, "Hi", "TypityType", "I'm an event")
evtMgr.ReportEvent(1, "Hi", "TypeII", "Type II errors are the worst") evtMgr.Report(1, "Hi", "TypeII", "Type II errors are the worst")
evtMgr.ReportEvent(20, "Hi", "TypityType3", "eventy details") evtMgr.Report(20, "Hi", "TypityType3", "eventy details")
evtMgr.ReportEvent(22, "Hi", "TypityType4", "I'm an event 2") evtMgr.Report(22, "Hi", "TypityType4", "I'm an event 2")
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
......
...@@ -9,3 +9,8 @@ package interfaces ...@@ -9,3 +9,8 @@ package interfaces
// EventCallbackFunction defines the callback functions for client event reports // EventCallbackFunction defines the callback functions for client event reports
type EventCallbackFunction func(priority int, category, evtType, details string) type EventCallbackFunction func(priority int, category, evtType, details string)
// EventManager reporting api (used internally)
type EventManager interface {
Report(priority int, category, evtType, details string)
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package internal package internal
import ( import (
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/network/health" "gitlab.com/elixxir/client/network/health"
"gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/switchboard" "gitlab.com/elixxir/client/switchboard"
...@@ -37,4 +38,7 @@ type Internal struct { ...@@ -37,4 +38,7 @@ type Internal struct {
//channels //channels
NodeRegistration chan network.NodeGateway NodeRegistration chan network.NodeGateway
// Event Reporting
Events interfaces.EventManager
} }
...@@ -55,12 +55,16 @@ type manager struct { ...@@ -55,12 +55,16 @@ type manager struct {
// Address space size // Address space size
addrSpace *ephemeral.AddressSpace addrSpace *ephemeral.AddressSpace
// Event reporting api
events interfaces.EventManager
} }
// NewManager builds a new reception manager object using inputted key fields // NewManager builds a new reception manager object using inputted key fields
func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, func NewManager(session *storage.Session, switchboard *switchboard.Switchboard,
rng *fastRNG.StreamGenerator, comms *client.Comms, rng *fastRNG.StreamGenerator, events interfaces.EventManager,
params params.Network, ndf *ndf.NetworkDefinition) (interfaces.NetworkManager, error) { comms *client.Comms, params params.Network,
ndf *ndf.NetworkDefinition) (interfaces.NetworkManager, error) {
//start network instance //start network instance
instance, err := network.NewInstance(comms.ProtoComms, ndf, nil, nil, network.None, params.FastPolling) instance, err := network.NewInstance(comms.ProtoComms, ndf, nil, nil, network.None, params.FastPolling)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment