Class: Smartcard::PCSC::ReaderStateQueries

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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.



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

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.



79
80
81
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 79

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.



72
73
74
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 72

def self._release_states(pointer)
  pointer.free
end

Instance Method Details

#[](index) ⇒ Object

A query in the array.

Raises:

  • (TypeError)


30
31
32
33
34
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 30

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.



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

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

#each(&block) ⇒ Object

Mandatory for Enumerable mixin



37
38
39
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 37

def each(&block)
  @queries.each &block
end

#lengthObject

The number of queries in the array.



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

def length
  @queries.length
end

#with_changesObject

Short cut: Select queries with ‘changed’ event state.

Do some stuff on changed queries after Smartcard::PCSC::Context#wait_for_status_change.

Examples

queries.with_changes.each do |q|

puts "changed: #{q.reader_name}"

end



65
66
67
# File 'lib/smartcard/pcsc/reader_state_queries.rb', line 65

def with_changes
  @queries.select { |query| query.changed? }
end