<commit_before>//
//  PairingService.swift
//  Clink
//
//  Created by <NAME> on 7/5/17.
//

import Foundation
import CoreBluetooth

fileprivate let q = DispatchQueue(label: "pairing-service-q")


class PairingService: NSObject {
    enum Status: Int {
        case initial
        case scanning
        case discoveredRemotePeer
        case remotePeerOutOfRange
        case timedOut
        case completionPendingRemotePeerStatusUpdate
    }
    
    var serviceId = CBUUID(string: "7D912F17-0583-4A1A-A499-205FF6835514")
    var remotePeripheral: CBPeripheral? = nil
    var remotePeripheralRSSI = -999
    var status = Status.initial
    var pairingStatusCharacteristic = CBMutableCharacteristic(
        type: CBUUID(string: "ECC2D7D1-FB7C-4AF2-B068-0525AEFD7F53"),
        properties: .notify,
        value: nil,
        permissions: .readable)
    
    lazy var centralManager: CBCentralManager = {
        return CBCentralManager(delegate: self, queue: q)
    }()
    
    lazy var peripheralManager = CBPeripheralManager = {
        return CBPeripheralManager(delegate: self, queue: q)
    }()
    
    
    public override init() {
        super.init()
        
        self.status = .scanning
    }
}


extension PairingService: CBPeripheralDelegate {
    public func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) {
        guard peripheral.identifier == remotePeripheral?.identifier else { return }
        
        remotePeripheralRSSI = RSSI.intValue
        
        peripheral.readRSSI()
    }<commit_msg>broadcast pairing status to connected peripherals on update<commit_after>//
//  PairingService.swift
//  Clink
//
//  Created by <NAME> on 7/5/17.
//

import Foundation
import CoreBluetooth

fileprivate let q = DispatchQueue(label: "pairing-service-q")


class PairingService: NSObject {
    enum Status: Int {
        case unknown
        case scanning
        case discoveredRemotePeer
        case remotePeerOutOfRange
        case timedOut
        case completionPendingRemotePeerStatusUpdate
    }
    
    var serviceId = CBUUID(string: "7D912F17-0583-4A1A-A499-205FF6835514")
    var remotePeripheral: CBPeripheral? = nil
    var remotePeripheralRSSI = -999
    var remotePeerStatus = Status.unknown
    var pairingStatusCharacteristic = CBMutableCharacteristic(
        type: CBUUID(string: "ECC2D7D1-FB7C-4AF2-B068-0525AEFD7F53"),
        properties: .notify,
        value: nil,
        permissions: .readable)
    
    var status: Status = .unknown {
        didSet {
            peripheralManager.updateValue(
                NSKeyedArchiver.archivedData(withRootObject: status.rawValue),
                for: pairingStatusCharacteristic,
                onSubscribedCentrals: nil)
        }
    }
    
    lazy var centralManager: CBCentralManager = {
        return CBCentralManager(delegate: self, queue: q)
    }()
    
    lazy var peripheralManager = CBPeripheralManager = {
        return CBPeripheralManager(delegate: self, queue: q)
    }()
    
    
    public override init() {
        super.init()
        
        self.status = .scanning
    }
}


extension PairingService: CBPeripheralDelegate {
    public func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) {
        guard peripheral.identifier == remotePeripheral?.identifier else { return }
        
        remotePeripheralRSSI = RSSI.intValue
        
        peripheral.readRSSI()
    }
{'fraction_non_alphanumeric': 0.07998844932139763, 'fraction_numerical': 0.027721628645682932, 'mean_word_length': 2.5346938775510206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3609004', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1011, 'n_words': 231}