Class: AutomateEm::DeviceModule

Inherits:
Object
  • Object
show all
Defined in:
lib/automate-em/core/modules.rb

Overview

TODO

Consider allowing different dependancies use the same connection

Means only the first will call received - others must use receive blocks

Constant Summary collapse

@@instances =

db id => @instance

{}
@@dbentry =

db id => db instance

{}
@@devices =

ip:port:udp => @instance

{}
@@lookup =
{}
@@lookup_lock =
Mutex.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(system, controllerDevice, theModule) ⇒ DeviceModule

Returns a new instance of DeviceModule.



62
63
64
65
66
67
68
69
70
71
# File 'lib/automate-em/core/modules.rb', line 62

def initialize(system, controllerDevice, theModule)
	@@lookup_lock.synchronize {
		if @@instances[controllerDevice.id].nil?
			@system = system
			@device = controllerDevice.id
			@@dbentry[controllerDevice.id] = controllerDevice
		end
	}
	instantiate_module(controllerDevice, theModule)
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



108
109
110
# File 'lib/automate-em/core/modules.rb', line 108

def instance
  @instance
end

Class Method Details

.instance_of(db_id) ⇒ Object



101
102
103
104
105
# File 'lib/automate-em/core/modules.rb', line 101

def self.instance_of(db_id)
	@@lookup_lock.synchronize {
		return @@instances[db_id]
	}
end

.lookup(instance) ⇒ Object



95
96
97
98
99
# File 'lib/automate-em/core/modules.rb', line 95

def self.lookup(instance)
	@@lookup_lock.synchronize {
		return @@dbentry[@@lookup[instance][0]]
	}
end

Instance Method Details

#unloadObject

should never be called on the reactor thread so no need to defer



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/automate-em/core/modules.rb', line 74

def unload	# should never be called on the reactor thread so no need to defer
	
	@instance.base.shutdown(@system)
	
	@@lookup_lock.synchronize {
		db = @@lookup[@instance].delete(@device)
		@@instances.delete(db)
		db = @@dbentry.delete(db)
		dev = "#{db.ip}:#{db.port}:#{db.udp}"
		
		if @@lookup[@instance].empty?
			@@lookup.delete(@instance)
			if db.udp
				$datagramServer.remove_device(db)
			end
			@@devices.delete(dev)
		end
	}
end