Commit 1bdba912 authored by Kevin Seidel's avatar Kevin Seidel
Browse files

Add custom type for context keys

parent 2bf67be0
package ble
type ContextKey string
......@@ -153,12 +153,12 @@ type NotificationHandler func(req []byte)
// WithSigHandler ...
func WithSigHandler(ctx context.Context, cancel func()) context.Context {
return context.WithValue(ctx, "sig", cancel)
return context.WithValue(ctx, ContextKey("sig"), cancel)
}
// Cleanup for the interrupted case.
func trap(ctx context.Context) chan<- os.Signal {
v := ctx.Value("sig")
v := ctx.Value(ContextKey("sig"))
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", "ccc", fmt.Sprintf("0x%02X", ccc))
logger.Info("cleanup", ble.ContextKey("ccc"), 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(), "ccc", make(map[uint16]uint16)))
l2c.SetContext(context.WithValue(l2c.Context(), ble.ContextKey("ccc"), 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