lib/automate-em/device/device.rb in automate-em-0.0.2 vs lib/automate-em/device/device.rb in automate-em-0.0.3
- old
+ new
@@ -1,87 +1,6 @@
module AutomateEm
- module ModuleCore
- include Status # The observable pattern (Should not be called directly)
- include Constants
- include Utilities
-
- #
- # Sets up a link for the user code to the eventmachine class
- # This way the namespace is clean.
- #
- def setbase(base)
- @base = base
- end
-
-
- def join_system(system)
- @system_lock.synchronize {
- @systems << system
- }
- end
-
- def leave_system(system)
- @system_lock.synchronize {
- @systems.delete(system)
- return @systems.length
- }
- end
-
- def clear_active_timers
- @schedule.clear_jobs unless @schedule.nil?
- end
-
-
- #def command_successful(result) # TODO:: needs a re-think
- # @base.process_data_result(result)
- #end
-
-
- def logger
- @system_lock.synchronize {
- return @systems[0].logger unless @systems.empty?
- }
- System.logger
- end
-
- attr_reader :systems
- attr_reader :base
-
-
- protected
-
-
- #
- # Configuration and settings
- # => TODO:: We should get all zones that the pod is in with the setting set and select the first setting (vs first zone)
- #
- def setting(name)
- val = config.settings.where("name = ?", name.to_s).first
- if val.nil?
- val = config.control_system.zones.joins(:settings).where('settings.name = ?', name.to_s).first
- val = val.settings.where("name = ?", name.to_s).first unless val.nil?
-
- val = config.dependency.settings.where("name = ?", name.to_s).first if val.nil?
- end
-
- if val.present?
- case val.value_type
- when 0
- return val.text_value
- when 1
- return val.integer_value
- when 2
- return val.float_value
- when 3
- return val.datetime_value
- end
- end
-
- return nil
- end
- end
-
class Device
include ModuleCore
def initialize(tls, makebreak)
@systems = []
@@ -91,10 +10,10 @@
# NOTE:: if changed then change in logic.rb
#
@secure_connection = tls
@makebreak_connection = makebreak
@status = {}
- @status_lock = Mutex.new
+ @status_lock = Object.new.extend(MonitorMixin)
@system_lock = Mutex.new
@status_waiting = false
end