summaryrefslogtreecommitdiffstats
path: root/lib/agent/xdsserver.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-04 23:42:31 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-04 23:42:33 +0100
commitf1083a8259b3d2f560b5f3ccb8b47c94e297d7fa (patch)
treef737d46443a30c066c29eea738a34174c64ae746 /lib/agent/xdsserver.go
parent45f6472d1e8ecad428da314a6d762143f033865d (diff)
Fixed Xds-server re-connection.
Add a callback on XDS-Server connect in order to properly register to XDS Server events in all cases (IOW on reconnection). Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/agent/xdsserver.go')
-rw-r--r--lib/agent/xdsserver.go37
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/agent/xdsserver.go b/lib/agent/xdsserver.go
index 3ec6123..346bdb9 100644
--- a/lib/agent/xdsserver.go
+++ b/lib/agent/xdsserver.go
@@ -54,16 +54,20 @@ type XdsServer struct {
sockEventsLock *sync.Mutex
// Private fields
- client *common.HTTPClient
- ioSock *sio_client.Client
- logOut io.Writer
- apiRouter *gin.RouterGroup
- cmdList map[string]interface{}
+ client *common.HTTPClient
+ ioSock *sio_client.Client
+ logOut io.Writer
+ apiRouter *gin.RouterGroup
+ cmdList map[string]interface{}
+ cbOnConnect OnConnectedCB
}
// EventCB Event emitter callback
type EventCB func(privData interface{}, evtData interface{}) error
+// OnConnectedCB connect callback
+type OnConnectedCB func(svr *XdsServer) error
+
// caller Used to chain event listeners
type caller struct {
id uuid.UUID
@@ -135,6 +139,12 @@ func (xs *XdsServer) Connect() error {
return err
}
+// ConnectOn Register a callback on events reception
+func (xs *XdsServer) ConnectOn(f OnConnectedCB) error {
+ xs.cbOnConnect = f
+ return nil
+}
+
// IsTempoID returns true when server as a temporary id
func (xs *XdsServer) IsTempoID() bool {
return strings.HasPrefix(xs.ID, _IDTempoPrefix)
@@ -536,15 +546,10 @@ func (xs *XdsServer) _CreateConnectHTTP() error {
// _Reconnect Re-established connection
func (xs *XdsServer) _Reconnect() error {
+
+ // Note that ConnectOn callback will be called (see apiv1.go file)
err := xs._Connect(true)
- if err == nil {
- // Reload projects list for this server
- err = xs.projects.Init(xs)
- }
- if err == nil {
- // Register again to all events
- err = xs.EventRegister(xsapiv1.EVTAll, "")
- }
+
return err
}
@@ -575,6 +580,12 @@ func (xs *XdsServer) _Connect(reConn bool) error {
}
xs.Connected = true
+
+ // Call OnConnect callback
+ if xs.cbOnConnect != nil {
+ xs.cbOnConnect(xs)
+ }
+
xs._NotifyState()
return nil
}