Class: Extface::DriverBase

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/extface/driver_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.has_serial_configObject



15
16
17
18
19
20
21
# File 'app/models/extface/driver_base.rb', line 15

def has_serial_config
  has_one :serial_config, as: :s_configureable
  accepts_nested_attributes_for :serial_config
  define_method :serial? do
    true
  end
end

Instance Method Details

#handle(buffer) ⇒ Object

handle push messages from device outside active session



24
25
26
# File 'app/models/extface/driver_base.rb', line 24

def handle(buffer) # handle push messages from device outside active session
  return false
end

#notify(message) ⇒ Object



57
58
59
60
# File 'app/models/extface/driver_base.rb', line 57

def notify(message)
  raise "No job given" unless @job
  @job.notify(message)
end

#pull(timeout = nil) ⇒ Object



50
51
52
53
54
55
# File 'app/models/extface/driver_base.rb', line 50

def pull(timeout = nil)
  Extface.redis_block do |r|
    list, element = r.blpop(device.uuid, :timeout => timeout)
  end
  element
end

#push(buffer) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/extface/driver_base.rb', line 28

def push(buffer)
  
    if @job
      Timeout.timeout(Extface.device_timeout) do
        Extface.redis_block do |r|
          r.subscribe(@job.id) do |on| #blocking until delivered
            on.subscribe do |channel, subscriptions|
              @job.rpush buffer
            end
            on.message do |event, data|
              r.unsubscribe
              @job.connected!
            end
          end
        end
      end
    else
      raise "No job given"
    end
  
end

#set_job(job) ⇒ Object



62
63
64
# File 'app/models/extface/driver_base.rb', line 62

def set_job(job)
  @job = job
end