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

TerminalFactory

See also

CardTerminal

Author

Andreas Sterbenz

Author

JSR 268 Expert Group

Author

Godfrey Chung

Version

1.0

Date

6 Nov 2017

  • list() Default implementation

    Returns an unmodifiable list of all available terminals.

    Throws

    CardError.operationFailed if the card operation failed

    Default 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 is CardState.cardPresent or CardState.cardAbsent, it returns all CardTerminals where a card is currently present or absent, respectively.

    If state is CardState.cardInsertion or CardState.cardRemoval, it returns all CardTerminals for which an insertion (or removal, respectively) was detected during the last call to waitForChange(). If waitForChange() has not been called on this object, cardInsertion is equivalent to cardPresent and cardRemoval is equivalent to cardAbsent. For an example of the use of cardInsertion, see waitForChange().

    Throws

    CardError.operationFailed if the card operation failed

    Declaration

    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 implementation

    Waits 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 this CardTerminals object does not contain any terminals; CardError.operationFailed if the card operation failed

    Default 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 to waitForChange() 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 after timeout milliseconds even if there is no change in state. In that case, this method returns false; otherwise it returns true.

    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 this CardTerminals object does not contain any terminals; CardError.illegalArgument if timeout is negative; CardError.operationFailed if the card operation failed

    Declaration

    Swift

    func waitForChange(timeout: Int) throws -> Bool

    Parameters

    timeout

    if positive, block for up to timeout milliseconds; if zero, block indefinitely; must not be negative

    Return Value

    false if the method returns due to an expired timeout, true otherwise.