BMLTCommunicator

class BMLTCommunicator

The main reason for the existence of this class is to make the communications testable. Its structure allows the tester to inject data sources and sinks.

Data sources and sinks are adornments. This allows us to substitute mocks when testing.

This is a lightweight, short-lifetime class. It is meant to be instantiated and destroyed on an as needed basis.

  • This is the definition for the testRootServerURI completion block.

    The routine is called upon completion of a URL connection. When the connection ends (either successfully or not), this routine is called. If it is successful, then the inData parameter will be non-nil. If it failed, then the parameter will be nil, and the inError parameter may have a value.

    Declaration

    Swift

    typealias RequestCompletionBlock = (_ inData: Any?, _ inError: Error?) -> Void

    Parameters

    inData

    The Data returned.

    inError

    Any error that ocurred. Nil, if no error.

  • This contains any error from the call.

    Declaration

    Swift

    var error: Error!
  • This contains the data response (if any).

    Declaration

    Swift

    var data: Data!
  • This is the designated initializer for this class. You have to give a URL, as well as a delegate (sink) and data source. This class executes the connection upon initialization.

    Declaration

    Swift

    init(_ inURI: String, dataSource inDataSource: BMLTCommunicatorDataSourceProtocol, delegate inDelegate: BMLTCommunicatorDataSinkProtocol!, refCon inRefCon: AnyObject? = nil, executeImmediately inExecute: Bool = true)

    Parameters

    inURI

    The URL to be called, as a string.

    dataSource

    The data source.

    delegate

    The delegate object (the sink) to be notified when new data arrives.

    refCon

    This is any object or data that you want to send to the delegate receive method. Default is nil.

    executeImmediately

    If true (the default), the instance executes immediately. The reason for this flag, as opposed to simply overriding the execute() method, is so we have a bit more flexibility. We don’t need to rewrite that method if we don’t want to. Since the parameter has a default, it’s not an issue to ignore it.

  • This actually executes the connection.

    Declaration

    Swift

    func execute()
  • This is the callback for the URL request.

    Declaration

    Swift

    func handleResponseFromHandler(_ inData: Any, inError: Error?)

    Parameters

    inData

    the data from the URL request.

    inError

    Any error that ocurred. Nil, if no error.