 
 
 
-

/// session operation serial queue identifier
private let QIDSesOp = "com.keyang.cusp.sessionOperationQ"

/// Bluetooth Low Energy library in swift (使用swift编写的BLE通讯框架)
public class Cusp: NSObject {

	/// Singleton (单例)
	public class var central: Cusp {
		struct Static {
			static let instance: Cusp = Cusp()

		super.init()
	}

	/// main operation concurrent queue, operations (scan, connect, cancel-connect, disconnect) will be submitted to this Q
    internal let mainQ: dispatch_queue_t = dispatch_queue_create(QIDMain, DISPATCH_QUEUE_CONCURRENT)

	/// request operation serial queue, operations (add/remove) on reqs (scan, connect, cancel-connect, disconnect) will be submitted to this Q;
	internal let reqOpQ: dispatch_queue_t = dispatch_queue_create(QIDReqOp, DISPATCH_QUEUE_SERIAL)

	/// session operation serial queue, operations (add/remove) on sessions (with peripheral) will be submitted to this Q;
	internal let sesOpQ: dispatch_queue_t = dispatch_queue_create(QIDSesOp, DISPATCH_QUEUE_SERIAL)

	/// central avator, read only
	private(set) lazy var centralManager: CentralManager = {
		return CentralManager(delegate: self, queue: self.mainQ, options: nil)
	}()

	/// BLE state
	public var state: State {
		return State(rawValue: self.centralManager.state.rawValue)!
	}
