Class: Smartware::Interface::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/smartware/interfaces/interface.rb

Direct Known Subclasses

CardReader, CashAcceptor, UserInterface

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, service) ⇒ Interface

Returns a new instance of Interface.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/smartware/interfaces/interface.rb', line 6

def initialize(config, service)
  @config = config
  @service = service

  @status_mutex = Mutex.new
  @status = {
    error: [ nil ],
    model: [ '' ],
    version: [ '' ]
  }

  iface = @config["name"]
  driver = @config["driver"]

  @iface_id = iface.underscore

  require "smartware/drivers/#{@iface_id}/#{driver.underscore}"

  @device = Smartware::Driver.const_get(iface.to_s)
                             .const_get(driver.to_s)
                             .new(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/smartware/interfaces/interface.rb', line 4

def config
  @config
end

Instance Method Details

#errorObject



47
48
49
# File 'lib/smartware/interfaces/interface.rb', line 47

def error
  self.status[:error][0]
end

#modelObject



51
52
53
# File 'lib/smartware/interfaces/interface.rb', line 51

def model
  self.status[:model][0]
end

#repush_events(connection) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/smartware/interfaces/interface.rb', line 39

def repush_events(connection)
  @status_mutex.synchronize do
    @status.each do |key, value|
      connection.publish_event "#{@iface_id}.#{key}", *value
    end
  end
end

#shutdown(callback) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/smartware/interfaces/interface.rb', line 29

def shutdown(callback)
  if @device.respond_to? :shutdown
    @device.shutdown callback

    true
  else
    false
  end
end

#statusObject



59
60
61
# File 'lib/smartware/interfaces/interface.rb', line 59

def status
  @status_mutex.synchronize { @status }
end

#versionObject



55
56
57
# File 'lib/smartware/interfaces/interface.rb', line 55

def version
  self.status[:version][0]
end