Base barcode-event listener class, for receiving events from the Grabba device's barcode reader.
The following events are supported by this class:
Each event may invoke callbacks in two ways:
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:
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.
Instance Methods | |
(void) | - cancelEvent |
Callback which is invoked when barcode scanning operations are cancelled. More... | |
(void) | - dataEvent: |
Callback which is invoked when a barcode is successfully scanned. 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 barcode scanning operations fail. 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) | - startEvent |
Callback which is invoked when the barcode reader commences a scan. More... | |
(void) | - stopEvent |
Callback which is invoked when barcode scanning operations are stopped, regardless of the reason. More... | |
(void) | - timeoutEvent |
Callback which is invoked when barcode scanning operations time out. More... | |
Properties | |
ProtocolType _Nullable | delegate |
Delegate for receiving events from non-subclassed listener objects; defaults to nil. More... | |
- (void) cancelEvent |
Callback which is invoked when barcode scanning operations are cancelled.
Operations may be cancelled by calling stopScan . Note that this callback will only trigger in the event that a running operation was cancelled; if e.g. stopScan is called and there was no scan active at the time, then no callback will be triggered.
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
- (void) dataEvent: | (GrabbaBarcodeData *_Nonnull) | data |
Callback which is invoked when a barcode is successfully scanned.
Operations may be commenced by calling startScan. If scanning succeeds, the barcode scanner will be turned off (beyond which point calling stopScan will cease to have any effect), then this callback will be invoked.
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
data | Contains the data which was read, along with the ID of the symbology which was detected |
- (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.
- (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.
- (void) errorEvent: | (GrabbaErrorCode *_Nonnull) | error |
Callback which is invoked when barcode scanning operations fail.
Scanning may be commenced by calling startScan. If scanning fails, the barcode scanner will be turned off (beyond which point calling stopScan will cease to have any effect), then this callback will be invoked.
error | Error code indicating the reasons for the failure |
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
- (instancetype _Nullable) init |
Default initialiser - builds an object then enables event callbacks to it.
nil
if it failed - (instancetype _Nullable) initWithEnabled: | (BOOL) | startEnabled |
Initialiser which allows control over whether event callbacks should be enabled.
startEnabled | If 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. |
nil
if it failed - (void) startEvent |
Callback which is invoked when the barcode reader commences a scan.
This event may be invoked by calling startScan when a suitable Grabba device is connected.
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
- (void) stopEvent |
Callback which is invoked when barcode scanning operations are stopped, regardless of the reason.
Scanning may be commenced by calling startScan. If scanning succeeds, fails, times out or is cancelled, then the barcode reader will be turned off (beyond which point calling stopScan will cease to have any effect), then this callback will be invoked.
In addition to this callback, one other callback will be triggered, depending on the outcome of the operation:
No guarantees are given as to the order in which the two callbacks are triggered, or whether they will be triggered on the same thread.
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
- (void) timeoutEvent |
Callback which is invoked when barcode scanning operations time out.
Scanning may be commenced by calling startScan. If scanning times out, the barcode scanner will be turned off (beyond which point calling stopScan will cease to have any effect), then this callback will be invoked.
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
|
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.