Commit bb20df5f authored by Kevin Seidel's avatar Kevin Seidel
Browse files

Add ContextKey Vars

parent 1bdba912
package ble
type ContextKey string
var (
ContextKeySig = ContextKey("sig")
ContextKeyCCC = ContextKey("ccc")
)
......@@ -153,12 +153,12 @@ type NotificationHandler func(req []byte)
// WithSigHandler ...
func WithSigHandler(ctx context.Context, cancel func()) context.Context {
return context.WithValue(ctx, ContextKey("sig"), cancel)
return context.WithValue(ctx, ContextKeySig, cancel)
}
// Cleanup for the interrupted case.
func trap(ctx context.Context) chan<- os.Signal {
v := ctx.Value(ContextKey("sig"))
v := ctx.Value(ContextKeySig)
if v == nil {
return nil
}
......
......@@ -162,7 +162,7 @@ func (s *Server) Loop() {
}
for h, ccc := range s.conn.cccs {
if ccc != 0 {
logger.Info("cleanup", ble.ContextKey("ccc"), fmt.Sprintf("0x%02X", ccc))
logger.Info("cleanup", ble.ContextKeyCCC, fmt.Sprintf("0x%02X", ccc))
}
if ccc&cccIndicate != 0 {
s.conn.in[h].Close()
......
......@@ -51,7 +51,7 @@ func loop(dev *hci.HCI, s *gatt.Server, mtu int) {
}
// Initialize the per-connection cccd values.
l2c.SetContext(context.WithValue(l2c.Context(), ble.ContextKey("ccc"), make(map[uint16]uint16)))
l2c.SetContext(context.WithValue(l2c.Context(), ble.ContextKeyCCC, make(map[uint16]uint16)))
l2c.SetRxMTU(mtu)
s.Lock()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment