lib/tamashii/agent/master.rb in tamashii-agent-0.1.11 vs lib/tamashii/agent/master.rb in tamashii-agent-0.2.0

- old
+ new

@@ -1,8 +1,11 @@ +require 'tamashii/agent/common' require 'tamashii/agent/connection' +require 'tamashii/agent/lcd' require 'tamashii/agent/buzzer' require 'tamashii/agent/card_reader' +require 'tamashii/agent/event' require 'thread' module Tamashii module Agent @@ -39,10 +42,11 @@ def create_components @components = {} @components[:connection] = create_component(Connection, self, @host, @port) @components[:buzzer] = create_component(Buzzer) + @components[:lcd] = create_component(LCD) @components[:card_reader] = create_component(CardReader, self) end def create_component(class_name, *args) c = class_name.new(*args) @@ -51,49 +55,54 @@ c.run c end # override - def process_event(ev_type, ev_body) + def process_event(event) super - case ev_type - when EVENT_SYSTEM_COMMAND - logger.info "System command code: #{ev_body}" - case ev_body.to_i + case event.type + when Event::SYSTEM_COMMAND + logger.info "System command code: #{event.body}" + case event.body.to_i when Tamashii::Type::REBOOT system_reboot when Tamashii::Type::POWEROFF system_poweroff when Tamashii::Type::RESTART system_restart when Tamashii::Type::UPDATE system_update end - when EVENT_CONNECTION_NOT_READY - broadcast_event(EVENT_BEEP, "error") + when Event::CONNECTION_NOT_READY + broadcast_event(Event.new(Event::BEEP, "error")) else - broadcast_event(ev_type, ev_body) + broadcast_event(event) end end + def show_message(message) + logger.info message + broadcast_event(Event.new(Event::LCD_MESSAGE, message)) + end + def system_reboot - logger.info "Rebooting..." + show_message "Rebooting" system("reboot &") end def system_poweroff - logger.info "Powering Off..." + show_message "Powering Off" system("poweroff &") end def system_restart - logger.info "Restarting..." + show_message "Restarting" system("systemctl restart tamashii-agent.service &") end def system_update - logger.info "Updating..." + show_message("Updating") system("gem update tamashii-agent") system_restart end # override @@ -103,12 +112,12 @@ c.stop end end - def broadcast_event(ev_type, ev_body) + def broadcast_event(event) @components.each_value do |c| - c.send_event(ev_type, ev_body) + c.send_event(event) end end end end end