RVS_ONVIF_Dispatcher

public protocol RVS_ONVIF_Dispatcher : AnyObject

This protocol describes the expectations for generic ONVIF Dispatchers.

DISPATCHERS

These are a specialization of the Delegate Pattern.

Your implementation context will define classes that conform to specializations of the RVS_ONVIF_Dispatcher protocol. They must be classes.

The protocols will have default implementations of all methods and calculated properties except for deliverResponse, but some of the defaults are empty.

Each profile handler will declare a specialization of the ProfileHandlerProtocol, and will take care of profile-specific functionality “behind the scenes.” Each profile handler will also declare a specialization of the RVS_ONVIF_Dispatcher protocol that applies to its own functionality, and the implementation context will then use these specializations to declare its own Dispatchers.

The Dispatchers are “registered” with the main driver, in a manner similar to Delegates. However, Dispatchers are assigned to an Array, and will signal to the RVS_ONVIF instance when they can handle specific calls.

When a call is returned from the device, the RVS_ONVIF driver will iterate the registered Dispatchers, and will stop when a Dispatcher signals that it will handle the response. Commands are handled by protocol-hander-sepcific implementations the RVS_ONVIF_DeviceRequestProtocol protocol, and are “opaque” enums. Basically, the important part of your Dispatcher is that your implementation should implement the isAbleToHandleThisCommand, deliverResponse, and, if applicable, the getParametersForCommand methods. If deliverResponse returns true, then the iteration stops, once the deliverResponse call is made. The deliverResponse call will not be made, unless the Dispatcher returns true from its isAbleToHandleThisCommand method.

deliverResponse is the only method that is required to be implemented by the conforming class, but you should also implement getParametersForCommand if you will provide arguments. All calls are made in the main thread.

  • This is the RVS_ONVIF instance that the dispatcher references. It is required to be implemented (and populated) by the final dispatcher instance.

    Declaration

    Swift

    var owner: RVS_ONVIF! { get set }
  • profileSig Default implementation

    This is a String, returned by the dispatcher, that indicates which profile handler to use for it. It is implemented by the “first level” protocol override.

    Default Implementation

    This is a String, returned by the dispatcher, that indicates which profile handler to use for it. It is implemented by the “first level” protocol override.

    Declaration

    Swift

    var profileSig: String { get }
  • sendRequest(_:) Default implementation

    This method is called to handle sending a command (as opposed to a callback).

    As part of the process, the Dispatcher’s getParametersForCommand method is called, and is expected to provide a Dictionary of parameters for the command.

    Default Implementation

    This is called to handle a command (as opposed to a callback).

    Declaration

    Swift

    @discardableResult
    func sendRequest(_ inCommand: RVS_ONVIF_DeviceRequestProtocol) -> Bool

    Parameters

    inCommand

    The command being sent.

    Return Value

    true, if the command is being handled. Can be ignored.

  • This method is required to be implemented by the final dispatcher. This method is called to deliver the response from the device.

    Declaration

    Swift

    @discardableResult
    func deliverResponse(_ inCommand: RVS_ONVIF_DeviceRequestProtocol, params: Any!) -> Bool

    Parameters

    inCommand

    The command to which this is a response.

    params

    The data returned (and parsed) from the device. It can be any one of the various data types.

    Return Value

    true, if the response was consumed. Can be ignored.

  • getParametersForCommand(_:) Default implementation

    This method is implemented by the final dispatcher, and is used to fetch the parameters for the given command.

    Default Implementation

    This method is implemented by the final dispatcher, and is used to fetch the parameters for the given command. This implementation returns an empty command.

    Declaration

    Swift

    func getParametersForCommand(_ inCommand: RVS_ONVIF_DeviceRequestProtocol) -> [String : Any]!

    Parameters

    inCommand

    The command being sent.

    Return Value

    a Dictionary, with the command parameters.

  • isAbleToHandleThisCommand(_:) Default implementation

    This is a simple test, to see if the instance can handle the given command. It is implemented by this protocol, but is made final by the “first level” protocol override.

    Default Implementation

    This is a simple test, to see if the instance can handle the given command. It is implemented by this protocol, but is made final by the “first level” protocol override.

    Declaration

    Swift

    func isAbleToHandleThisCommand(_ inCommand: RVS_ONVIF_DeviceRequestProtocol) -> Bool

    Parameters

    inCommand

    The command being sent.

    Return Value

    true, if the command can be handled by this instance.