CGA_Bluetooth_Service

public class CGA_Bluetooth_Service : CGA_Bluetooth_Service_Protocol_Internal
extension CGA_Bluetooth_Service: CGA_Class_Protocol_UpdateDescriptor
extension CGA_Bluetooth_Service: CGA_ServiceFactory

This class “wraps” instances of CBService, adding some functionality, and linking the hierarchy.

Public Properties

  • This is the type we’re aggregating.

    Declaration

    Swift

    public typealias Element = CGA_Bluetooth_Characteristic
  • This is our main cache Array. It contains wrapped instances of our aggregate CB type.

    Declaration

    Swift

    public var sequence_contents: Array<Element>
  • This is used to reference an “owning instance” of this instance, and it should be a CGA_Bluetooth_Peripheral

    Declaration

    Swift

    public weak var parent: CGA_Class_Protocol?
  • id

    This returns a unique UUID String for the instance.

    Declaration

    Swift

    public var id: String { get }
  • This returns the parent Central Manager

    Declaration

    Swift

    public var central: RVS_BlueThoth? { get }

Public Methods

Internal Properties

  • Root class does nothing.

    Declaration

    Swift

    internal class var uuid: String { get }
  • This holds the instance of CBService that is used by this instance.

    Declaration

    Swift

    internal weak var cbElementInstance: CBService!
  • This casts the parent as a Peripheral Wrapper.

    Declaration

    Swift

    public var peripheral: CGA_Bluetooth_Peripheral? { get }
  • This will contain any required scan criteria. It simply passes on the Central criteria.

    Declaration

    Swift

    internal var scanCriteria: RVS_BlueThoth.ScanCriteria! { get }
  • This is a “preview cache.” It will aggregate instances of Characteristic wrappers that are still in discovery.

    Declaration

    Swift

    internal var stagedCharacteristics: Array<Element>
  • This is the init that should always be used.

    Declaration

    Swift

    internal required convenience init(parent inParent: CGA_Bluetooth_Peripheral, cbElementInstance inCBService: CBService)

    Parameters

    parent

    The Service instance that “owns” this instance.

    cbElementInstance

    This is the actual CBService instance to be associated with this instance.

Private Properties

  • This holds a list of UUIDs, holding the IDs of Characteristics we are looking for. It is initialized when the class is instantiated.

    Declaration

    Swift

    private var _discoveryFilter: [CBUUID]

Instance Methods

  • Called to tell the instance to discover its characteristics.

    Declaration

    Swift

    internal func discoverCharacteristics(characteristics inCharacteristics: [String] = [])

    Parameters

    characteristics

    An optional parameter that is an Array, holding the String UUIDs of Characteristics we are filtering for. If left out, all available Characteristics are found. If specified, this overrides the scanCriteria.

  • Called to tell the instance about its newly discovered Characteristics. This method creates new Characteristic wrappers, and stages them. It then asks each Characteristic to discover its Descriptors.

    Declaration

    Swift

    internal func discoveredCharacteristics(_ inCharacteristics: [CBCharacteristic])

    Parameters

    inCharacteristics

    The discovered Core Bluetooth Characteristics.

  • Called to add a Characteristic to our “keeper” Array.

    Declaration

    Swift

    internal func addCharacteristic(_ inCharacteristic: CGA_Bluetooth_Characteristic)

    Parameters

    inCharacteristic

    The Characteristic to add.

CGA_Class_UpdateDescriptor Conformance

  • This eliminates all of the stored and staged results.

    Declaration

    Swift

    public func clear()
  • This eliminates all of the stored results, and asks the Bluetooth subsystem to start over from scratch.

    Declaration

    Swift

    public func startOver()

CGA_Class_Protocol Conformance

  • This searches the hierarchy, and will return any instance that has an ID that matches the string passed in. This could be a Peripheral, Service, Characteristic or Descriptor. The response will need to be cast.

    Declaration

    Swift

    public func findEntityByUUIDString(_ inUUIDString: String) -> CGA_Class_Protocol?

    Parameters

    inUUIDString

    The String for the UUID for which we are searching.

    Return Value

    Any element in the hierarchy with a UUID that matches the one passed in, or nil.

CGA_ServiceFactory Conformance

  • This creates an instance of the class, using the subclass-defined factory method.

    Declaration

    Swift

    internal class func createInstance(parent inParent: CGA_Bluetooth_Peripheral, cbElementInstance inCBService: CBService) -> CGA_Bluetooth_Service?

    Parameters

    parent

    The Peripheral that “owns” this Service

    cbElementInstance

    The CB element for this Service.

    Return Value

    A new instance of CGA_Bluetooth_Service, or a subclass, thereof. Nil, if it fails.