Grabba Driver for iOS
Unified driver for Grabba devices on the iOS operating system
GrabbaMRTD_Listener Class Reference

Description

Base MRTD-event listener class, for receiving events related to MRTD reading on Grabba devices.

The following events are supported by this class:

  • Progress - MRTD read progress has advanced
  • Data - MRTD read has completed, and data was read successfully
  • Error - MRTD read encountered an error (e.g. loss of connection)

Each event may invoke callbacks in two ways:

  • Subclassing - the relevant event methods (e.g. dataEvent) are called directly
    • This approach is recommended wherever feasible, due to its simplicity.
    • To use it, create an object of a suitable subclass, which overrides the desired event method(s).
  • Delegation - event methods trigger method calls for a delegate object
    • This approach is only recommended when the callback class must inherit from a different base class
    • To use it, create an object of this class, create an object of a class which implements GrabbaMRTD_Protocol, then set the delegate property of the former to point to the latter.
Note
Delegation will be disabled for an event if that event's method is subclassed, unless the subclass calls the superclass' equivalent method from within its override thereof.

By default, each listener object will register itself for callbacks upon construction, and deregister itself at destruction; the enable and disable methods may be used if an object requires manual control over when its callbacks are triggered.

The default behaviour for each event, if not overridden, on an enabled listener object is as follows:

  • If delegate has not been set, or has been set to null, then take no action
  • If delegate has been set to a non-null pointer, then delegate to the pointed-to object

Overrides need not call the superclass' equivalent method unless it is necessary to preserve the delegation (i.e. to support both subclassing and delegation from a single object).

Thread safety: This interface is intended to be thread-safe; any classes deriving or delegating from it should ensure that the relevant methods are callable from any thread.

See also
GrabbaMRTD_API for related API functions
Inheritance diagram for GrabbaMRTD_Listener:
GrabbaListener< ProtocolType >

Instance Methods

(void) - dataEvent:
 Callback which is invoked when an asynchronous MRTD read completes successfully. More...
 
(void) - disable
 Disable listening for events from this object, if not already disabled. More...
 
(void) - enable
 Enable listening for events from this object, if not already enabled. More...
 
(void) - errorEvent:
 Callback which is invoked when an asynchronous MRTD read fails. More...
 
(instancetype _Nullable) - init
 Default initialiser - builds an object then enables event callbacks to it. More...
 
(instancetype _Nullable) - initWithEnabled:
 Initialiser which allows control over whether event callbacks should be enabled. More...
 
(void) - progressEvent:
 Callback which is invoked when asynchronous MRTD read progress advances. More...
 

Properties

ProtocolType _Nullable delegate
 Delegate for receiving events from non-subclassed listener objects; defaults to nil. More...
 

Method Documentation

◆ dataEvent:()

- (void) dataEvent: (GrabbaBER_TLV *_Nonnull)  data

Callback which is invoked when an asynchronous MRTD read completes successfully.

Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.

Note
Overrides of this method are required to be thread-safe; no guarantees are made about which thread(s) they will be called from.
Parameters
dataContents of the data read from the MRTD, in BER-TLV format

◆ disable()

- (void) disable

Disable listening for events from this object, if not already disabled.

This will remove the listener object from the relevant event handler, if it had previously been added. Callbacks will no longer be triggered on this object, although they may be re-enabled by calling enable.

Note
This method should not be overridden.

◆ enable()

- (void) enable

Enable listening for events from this object, if not already enabled.

This will add the listener object to the relevant event handler, if it has not already been added. Events will then trigger callbacks on this object until it is destroyed or disable is called.

Note
This method should not be overridden.

◆ errorEvent:()

- (void) errorEvent: (GrabbaErrorCode *_Nonnull)  error

Callback which is invoked when an asynchronous MRTD read fails.

Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.

Note
Overrides of this method are required to be thread-safe; no guarantees are made about which thread(s) they will be called from.
Parameters
errorReason why the read operation failed

◆ init()

- (instancetype _Nullable) init

Default initialiser - builds an object then enables event callbacks to it.

Returns
Pointer to initialised object if initialisation succeeded; nil if it failed

◆ initWithEnabled:()

- (instancetype _Nullable) initWithEnabled: (BOOL)  startEnabled

Initialiser which allows control over whether event callbacks should be enabled.

Parameters
startEnabledIf YES, the newly-allocated listener object is added to the relevant event handler, enabling receipt of event callbacks. If NO, no callbacks are received until enable is called.
Returns
Pointer to initialised object if initialisation succeeded; nil if it failed

◆ progressEvent:()

- (void) progressEvent: (uint8_t)  percentage

Callback which is invoked when asynchronous MRTD read progress advances.

Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.

Note
Overrides of this method are required to be thread-safe; no guarantees are made about which thread(s) they will be called from.
Parameters
percentageCurrent read progress percentage

Property Documentation

◆ delegate

- (ProtocolType _Nullable) delegate
readwritenonatomicweakinherited

Delegate for receiving events from non-subclassed listener objects; defaults to nil.

Delegation may be used as an alternative to subclassing for receiving event callbacks. Any Grabba-defined listener class object (as opposed to a subclass thereof) will pass events on to a delegate, if one has been set and it has implemented the relevant protocol method.

If the delegate is to be written to whilst a callback to it is in progress, the write operation will block until that operation has completed. This ensures thread-safety.

Note
Delegates must provide thread-safe implementations of all protocol methods; no guarantees are made about which thread(s) they will be called from.