Class: Smartcard::PCSC::ReaderStateQueries

Inherits:
Object
  • Object
show all
Defined in:
lib/smartcard/pcsc/reader_state_queries.rb

Overview

A continuous array of reader state queries.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num_states) ⇒ ReaderStateQueries

Creates an array of reader state queries.

The states are unusable until they are assigned reader names by calling set_reader_name_of.



19
20
21
22
23
24
25
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 19

def initialize(num_states)
  @_buffer = FFI::MemoryPointer.new :char,
                                    FFILib::ReaderStateQuery.size * num_states
  @queries = (0...num_states).map do |i|
    FFILib::ReaderStateQuery.new @_buffer + FFILib::ReaderStateQuery.size * i
  end
end

Instance Attribute Details

#_bufferObject (readonly)

The low-level SCARD_READERSTATE data.

This should not be used by client code.



57
58
59
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 57

def _buffer
  @_buffer
end

Class Method Details

._release_states(pointer) ⇒ Object

Called by FFI::AutoPointer to release the reader states array.

This should not be called by client code.



50
51
52
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 50

def self._release_states(pointer)
  pointer.free
end

Instance Method Details

#[](index) ⇒ Object

A query in the array.

Raises:

  • (TypeError)


28
29
30
31
32
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 28

def [](index)
  raise TypeError unless index.kind_of? Numeric
  raise IndexError if index >= @queries.length
  @queries[index]
end

#ack_changesObject

Updates all the queries to acknowledge status changes.

This is a convenience method intended to be called after Smartcard::PCSC::Context#wait_for_status_change.



43
44
45
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 43

def ack_changes
  @queries.each { |query| query.current_state = query.event_state }
end

#lengthObject

The number of queries in the array.



35
36
37
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 35

def length
  @queries.length
end