<commit_before>package darwin

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"log"
	"time"

	"github.com/pkg/errors"
	"github.com/raff/goble/xpc"
	"golang.org/x/net/context"

	"github.com/currantlabs/ble"
	"sync"
)

const (
	evtStateChanged               = 6
	evtAdvertisingStarted         = 16
	evtAdvertisingStopped         = 17
	evtServiceAdded               = 18
	evtReadRequest                = 19
	evtWriteRequest               = 20
	evtSubscribe                  = 21
	evtUnubscribe                 = 22
	evtConfirmation               = 23
	evtPeripheralDiscovered       = 37
	evtPeripheralConnected        = 38
	evtPeripheralDisconnected     = 40
	evtATTMTU                     = 53
	evtRSSIRead                   = 55
	evtServiceDiscovered          = 56
	evtIncludedServicesDiscovered = 63
	evtCharacteristicsDiscovered  = 64
	evtCharacteristicRead         = 71
	evtCharacteristicWritten      = 72
	evtNotificationValueSet       = 74
	evtDescriptorsDiscovered      = 76
	evtDescriptorRead             = 79
	evtDescriptorWritten          = 80
	evtSleveConnectionComplete    = 81
	evtMasterConnectionComplete   = 82
)

// Device is either a Peripheral or Central device.
type Device struct {
	pm xpc.XPC // peripheralManager
	cm xpc.XPC // centralManager

	role int // 1: peripheralManager (server), 0: centralManager (client)

	rspc chan msg

	conns map[string]*conn
	connLock sync.Mutex

	// Only used in client/centralManager implementation
	advHandler ble.AdvHandler
	chConn     chan *conn<commit_msg>Fix last context<commit_after>package darwin

import (
	"bytes"
	"context"
	"encoding/binary"
	"fmt"
	"log"
	"time"

	"github.com/pkg/errors"
	"github.com/raff/goble/xpc"

	"sync"

	"github.com/currantlabs/ble"
)

const (
	evtStateChanged               = 6
	evtAdvertisingStarted         = 16
	evtAdvertisingStopped         = 17
	evtServiceAdded               = 18
	evtReadRequest                = 19
	evtWriteRequest               = 20
	evtSubscribe                  = 21
	evtUnubscribe                 = 22
	evtConfirmation               = 23
	evtPeripheralDiscovered       = 37
	evtPeripheralConnected        = 38
	evtPeripheralDisconnected     = 40
	evtATTMTU                     = 53
	evtRSSIRead                   = 55
	evtServiceDiscovered          = 56
	evtIncludedServicesDiscovered = 63
	evtCharacteristicsDiscovered  = 64
	evtCharacteristicRead         = 71
	evtCharacteristicWritten      = 72
	evtNotificationValueSet       = 74
	evtDescriptorsDiscovered      = 76
	evtDescriptorRead             = 79
	evtDescriptorWritten          = 80
	evtSleveConnectionComplete    = 81
	evtMasterConnectionComplete   = 82
)

// Device is either a Peripheral or Central device.
type Device struct {
	pm xpc.XPC // peripheralManager
	cm xpc.XPC // centralManager

	role int // 1: peripheralManager (server), 0: centralManager (client)

	rspc chan msg

	conns    map[string]*conn
	connLock sync.Mutex

	// Only used in client/centralManager implementation
	advHandler ble.AdvHandler
	chConn     chan *conn
{'fraction_non_alphanumeric': 0.061752988047808766, 'fraction_numerical': 0.03386454183266932, 'mean_word_length': 2.2432723358449946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7101697', 'n_tokens_mistral': 1039, 'n_tokens_neox': 939, 'n_words': 213}