You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/03/28 22:41:53 UTC

[56/67] [abbrv] incubator-mynewt-newtmgr git commit: nmxact - Indicate peer in BLE sesn close callback.

nmxact - Indicate peer in BLE sesn close callback.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/commit/ea22bd05
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/ea22bd05
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/ea22bd05

Branch: refs/heads/master
Commit: ea22bd05c0e5161a6d312f9922923f2f1583b5b6
Parents: ae52880
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Mar 28 12:10:51 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Mar 28 15:38:36 2017 -0700

----------------------------------------------------------------------
 nmxact/nmble/ble_fsm.go        |  5 +++--
 nmxact/nmble/ble_oic_sesn.go   | 14 +++++++-------
 nmxact/nmble/ble_plain_sesn.go | 14 +++++++-------
 nmxact/sesn/sesn_cfg.go        |  4 ++--
 4 files changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/ea22bd05/nmxact/nmble/ble_fsm.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_fsm.go b/nmxact/nmble/ble_fsm.go
index 52f61b8..daa930b 100644
--- a/nmxact/nmble/ble_fsm.go
+++ b/nmxact/nmble/ble_fsm.go
@@ -34,7 +34,7 @@ const (
 )
 
 type BleRxNmpFn func(data []byte)
-type BleDisconnectFn func(err error)
+type BleDisconnectFn func(peer BleDev, err error)
 
 type BleFsmParams struct {
 	Bx           *BleXport
@@ -284,8 +284,9 @@ func (bf *BleFsm) connectListen(seq int) error {
 					}
 
 					bf.setState(SESN_STATE_UNCONNECTED)
+					peer := *bf.peerDev
 					bf.peerDev = nil
-					bf.disconnectCb(err)
+					bf.disconnectCb(peer, err)
 					return
 
 				default:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/ea22bd05/nmxact/nmble/ble_oic_sesn.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_oic_sesn.go b/nmxact/nmble/ble_oic_sesn.go
index 98a30e9..949d7aa 100644
--- a/nmxact/nmble/ble_oic_sesn.go
+++ b/nmxact/nmble/ble_oic_sesn.go
@@ -5,7 +5,7 @@ import (
 	"sync"
 	"time"
 
-	"mynewt.apache.org/newt/nmxact/bledefs"
+	. "mynewt.apache.org/newt/nmxact/bledefs"
 	"mynewt.apache.org/newt/nmxact/nmp"
 	"mynewt.apache.org/newt/nmxact/omp"
 	"mynewt.apache.org/newt/nmxact/sesn"
@@ -17,7 +17,7 @@ type BleOicSesn struct {
 	nls          map[*nmp.NmpListener]struct{}
 	od           *omp.OmpDispatcher
 	closeTimeout time.Duration
-	onCloseCb    sesn.OnCloseFn
+	onCloseCb    sesn.BleOnCloseFn
 
 	closeChan chan error
 	mx        sync.Mutex
@@ -28,7 +28,7 @@ func NewBleOicSesn(bx *BleXport, cfg sesn.SesnCfg) *BleOicSesn {
 		nls:          map[*nmp.NmpListener]struct{}{},
 		od:           omp.NewOmpDispatcher(),
 		closeTimeout: cfg.Ble.CloseTimeout,
-		onCloseCb:    cfg.OnCloseCb,
+		onCloseCb:    cfg.Ble.OnCloseCb,
 	}
 
 	svcUuid, err := ParseUuid(NmpOicSvcUuid)
@@ -54,7 +54,7 @@ func NewBleOicSesn(bx *BleXport, cfg sesn.SesnCfg) *BleOicSesn {
 		ReqChrUuid:   reqChrUuid,
 		RspChrUuid:   rspChrUuid,
 		RxNmpCb:      func(d []byte) { bos.onRxNmp(d) },
-		DisconnectCb: func(e error) { bos.onDisconnect(e) },
+		DisconnectCb: func(p BleDev, e error) { bos.onDisconnect(p, e) },
 	})
 
 	return bos
@@ -141,7 +141,7 @@ func (bos *BleOicSesn) onRxNmp(data []byte) {
 	bos.od.Dispatch(data)
 }
 
-func (bos *BleOicSesn) onDisconnect(err error) {
+func (bos *BleOicSesn) onDisconnect(peer BleDev, err error) {
 	for nl, _ := range bos.nls {
 		nl.ErrChan <- err
 	}
@@ -151,7 +151,7 @@ func (bos *BleOicSesn) onDisconnect(err error) {
 		bos.closeChan <- err
 	}
 	if bos.onCloseCb != nil {
-		bos.onCloseCb(bos, err)
+		bos.onCloseCb(bos, peer, err)
 	}
 }
 
@@ -194,5 +194,5 @@ func (bos *BleOicSesn) MtuOut() int {
 		WRITE_CMD_BASE_SZ -
 		omp.OMP_MSG_OVERHEAD -
 		nmp.NMP_HDR_SIZE
-	return util.IntMin(mtu, bledefs.BLE_ATT_ATTR_MAX_LEN)
+	return util.IntMin(mtu, BLE_ATT_ATTR_MAX_LEN)
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/ea22bd05/nmxact/nmble/ble_plain_sesn.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_plain_sesn.go b/nmxact/nmble/ble_plain_sesn.go
index b4fda8e..71133e7 100644
--- a/nmxact/nmble/ble_plain_sesn.go
+++ b/nmxact/nmble/ble_plain_sesn.go
@@ -5,7 +5,7 @@ import (
 	"sync"
 	"time"
 
-	"mynewt.apache.org/newt/nmxact/bledefs"
+	. "mynewt.apache.org/newt/nmxact/bledefs"
 	"mynewt.apache.org/newt/nmxact/nmp"
 	"mynewt.apache.org/newt/nmxact/sesn"
 	"mynewt.apache.org/newt/util"
@@ -16,7 +16,7 @@ type BlePlainSesn struct {
 	nls          map[*nmp.NmpListener]struct{}
 	nd           *nmp.NmpDispatcher
 	closeTimeout time.Duration
-	onCloseCb    sesn.OnCloseFn
+	onCloseCb    sesn.BleOnCloseFn
 
 	closeChan chan error
 	mx        sync.Mutex
@@ -27,7 +27,7 @@ func NewBlePlainSesn(bx *BleXport, cfg sesn.SesnCfg) *BlePlainSesn {
 		nls:          map[*nmp.NmpListener]struct{}{},
 		nd:           nmp.NewNmpDispatcher(),
 		closeTimeout: cfg.Ble.CloseTimeout,
-		onCloseCb:    cfg.OnCloseCb,
+		onCloseCb:    cfg.Ble.OnCloseCb,
 	}
 
 	svcUuid, err := ParseUuid(NmpPlainSvcUuid)
@@ -48,7 +48,7 @@ func NewBlePlainSesn(bx *BleXport, cfg sesn.SesnCfg) *BlePlainSesn {
 		ReqChrUuid:   chrUuid,
 		RspChrUuid:   chrUuid,
 		RxNmpCb:      func(d []byte) { bps.onRxNmp(d) },
-		DisconnectCb: func(e error) { bps.onDisconnect(e) },
+		DisconnectCb: func(p BleDev, e error) { bps.onDisconnect(p, e) },
 	})
 
 	return bps
@@ -135,7 +135,7 @@ func (bps *BlePlainSesn) onRxNmp(data []byte) {
 	bps.nd.Dispatch(data)
 }
 
-func (bps *BlePlainSesn) onDisconnect(err error) {
+func (bps *BlePlainSesn) onDisconnect(peer BleDev, err error) {
 	for nl, _ := range bps.nls {
 		nl.ErrChan <- err
 	}
@@ -145,7 +145,7 @@ func (bps *BlePlainSesn) onDisconnect(err error) {
 		bps.closeChan <- err
 	}
 	if bps.onCloseCb != nil {
-		bps.onCloseCb(bps, err)
+		bps.onCloseCb(bps, peer, err)
 	}
 }
 
@@ -182,5 +182,5 @@ func (bps *BlePlainSesn) MtuIn() int {
 
 func (bps *BlePlainSesn) MtuOut() int {
 	mtu := bps.bf.attMtu - WRITE_CMD_BASE_SZ - nmp.NMP_HDR_SIZE
-	return util.IntMin(mtu, bledefs.BLE_ATT_ATTR_MAX_LEN)
+	return util.IntMin(mtu, BLE_ATT_ATTR_MAX_LEN)
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/ea22bd05/nmxact/sesn/sesn_cfg.go
----------------------------------------------------------------------
diff --git a/nmxact/sesn/sesn_cfg.go b/nmxact/sesn/sesn_cfg.go
index c511d10..9e07c71 100644
--- a/nmxact/sesn/sesn_cfg.go
+++ b/nmxact/sesn/sesn_cfg.go
@@ -13,7 +13,7 @@ const (
 	MGMT_PROTO_OMP
 )
 
-type OnCloseFn func(s Sesn, err error)
+type BleOnCloseFn func(s Sesn, peer bledefs.BleDev, err error)
 
 // Specifies the BLE peer to connect to.
 type BlePeerSpec struct {
@@ -45,12 +45,12 @@ type SesnCfgBle struct {
 	OwnAddrType  bledefs.BleAddrType
 	PeerSpec     BlePeerSpec
 	CloseTimeout time.Duration
+	OnCloseCb    BleOnCloseFn
 }
 
 type SesnCfg struct {
 	// Used with all transport types.
 	MgmtProto MgmtProto
-	OnCloseCb OnCloseFn
 
 	// Only used with BLE transports.
 	Ble SesnCfgBle