CardTerminals
public protocol CardTerminals : AnyObject
The set of terminals supported by a TerminalFactory. This class allows applications to enumerate the available CardTerminals, obtain a specific CardTerminal, or wait for the insertion or removal of cards.
This class is multi-threading safe and can be used by multiple threads
concurrently. However, this object keeps track of the card presence state of
each of its terminals. Multiple objects should be used if independent calls
to waitForChange()
are required.
Applications can obtain instances of this class by calling
TerminalFactory.terminals()
.
See also
See also
Version
1.0
Date
6 Nov 2017
-
list()
Default implementationReturns an unmodifiable list of all available terminals.
Throws
CardError.operationFailed
if the card operation failedDefault Implementation
Declaration
Swift
func list() throws -> [CardTerminal]
Return Value
an unmodifiable list of all available terminals
-
Returns an unmodifiable list of all terminals matching the specified state.
If state is
CardState.all
, this method returns all CardTerminals encapsulated by this object. If state isCardState.cardPresent
orCardState.cardAbsent
, it returns all CardTerminals where a card is currently present or absent, respectively.If state is
CardState.cardInsertion
orCardState.cardRemoval
, it returns all CardTerminals for which an insertion (or removal, respectively) was detected during the last call towaitForChange()
. IfwaitForChange()
has not been called on this object,cardInsertion
is equivalent tocardPresent
andcardRemoval
is equivalent tocardAbsent
. For an example of the use ofcardInsertion
, seewaitForChange()
.Throws
CardError.operationFailed
if the card operation failedDeclaration
Swift
func list(state: CardState) throws -> [CardTerminal]
Parameters
state
the state
Return Value
an unmodifiable list of all terminals matching the specified attribute
-
terminal(name:
Default implementation) Returns the terminal with the specified name or
nil
if no such terminal exists.Default Implementation
Declaration
Swift
func terminal(name: String) -> CardTerminal?
Parameters
name
the terminal name
Return Value
the terminal with the specified name or
nil
if no such terminal exists -
waitForChange()
Default implementationWaits for card insertion or removal in any of the terminals of this object.
This call is equivalent to calling
waitForChange(0)
.Throws
CardError.illegalState
if thisCardTerminals
object does not contain any terminals;CardError.operationFailed
if the card operation failedDefault Implementation
Declaration
Swift
func waitForChange() throws
-
Waits for card insertion or removal in any of the terminals of this object or until the timeout expires.
This method examines each CardTerminal of this object. If a card was inserted into or removed from a CardTerminal since the previous call to
waitForChange()
, it returns immediately. Otherwise, or if this is the first call towaitForChange()
on this object, it blocks until a card is inserted into or removed from a CardTerminal.If
timeout
is greater than 0, the method returns aftertimeout
milliseconds even if there is no change in state. In that case, this method returnsfalse
; otherwise it returnstrue
.This method is often used in a loop in combination with
list(CardState.cardInsertion)
, for example:TerminalFactory factory = ... CardTerminals terminals = factory.terminals() while true { for terminal in terminals.list(CardState.cardInsertion) { // examine Card in terminal, return if it matches } terminals.waitForChange() }
Throws
CardError.illegalState
if thisCardTerminals
object does not contain any terminals;CardError.illegalArgument
if timeout is negative;CardError.operationFailed
if the card operation failedDeclaration
Swift
func waitForChange(timeout: Int) throws -> Bool
Parameters
timeout
if positive, block for up to
timeout
milliseconds; if zero, block indefinitely; must not be negativeReturn Value
false
if the method returns due to an expired timeout,true
otherwise.