Class: Extface::Driver
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Extface::Driver
- Defined in:
- app/models/extface/driver.rb
Direct Known Subclasses
Defined Under Namespace
Classes: GenericPos, StarScp700, StarTsp200
Constant Summary collapse
- NAME =
human driver name
'Extface Driver Base'- GROUP =
Extface::RAW_DRIVER
- DEVELOPMENT =
driver is not ready for production (not passing all tests or has major bugs)
true- RAW =
Select driver features
true- PRINT =
responds to #push(data) and #pull
false- FISCAL =
POS, slip printers
false- REPORT =
cash registers, fiscal printers
false- DRIVER_TYPES =
only transmit data that must be parsed by handler, CDR, report devices
['RAW', 'PRINT', 'FISCAL', 'REPORT'].freeze
Class Method Summary collapse
-
.has_serial_config ⇒ Object
helper for serial devices, provides config for speed, boud rate, parity etc..
Instance Method Summary collapse
-
#handle(buffer) ⇒ Object
handle push messages from device outside active session.
- #notify(message) ⇒ Object
- #pull(timeout = nil) ⇒ Object
- #push(buffer) ⇒ Object
- #set_job(job) ⇒ Object
Class Method Details
.has_serial_config ⇒ Object
helper for serial devices, provides config for speed, boud rate, parity etc..
27 28 29 30 31 32 33 |
# File 'app/models/extface/driver.rb', line 27 def has_serial_config #helper for serial devices, provides config for speed, boud rate, parity etc.. has_one :serial_config, inverse_of: :driver 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
36 37 38 |
# File 'app/models/extface/driver.rb', line 36 def handle(buffer) # handle push messages from device outside active session return false end |
#notify(message) ⇒ Object
69 70 71 72 |
# File 'app/models/extface/driver.rb', line 69 def notify() raise "No job given" unless @job @job.notify() end |
#pull(timeout = nil) ⇒ Object
62 63 64 65 66 67 |
# File 'app/models/extface/driver.rb', line 62 def pull(timeout = nil) Extface.redis_block do |r| list, element = r.blpop(device.uuid, :timeout => timeout) end element end |
#push(buffer) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/extface/driver.rb', line 40 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. do |event, data| r.unsubscribe @job.connected! end end end end else raise "No job given" end end |
#set_job(job) ⇒ Object
74 75 76 |
# File 'app/models/extface/driver.rb', line 74 def set_job(job) @job = job end |