Class: SMS::Backend::DRB

Inherits:
Base show all
Defined in:
lib/rubysms/backend/drb.rb

Constant Summary collapse

DRB_PORT =
1370

Instance Attribute Summary

Attributes inherited from Thing

#label, #router

Instance Method Summary collapse

Methods inherited from Thing

#outgoing, #stop

Instance Method Details

#incoming(sender, text) ⇒ Object

called from another ruby process, via drb, to simulate an incoming sms message



43
44
45
46
47
# File 'lib/rubysms/backend/drb.rb', line 43

def incoming(sender, text)
	router.incoming(
		SMS::Incoming.new(
			self, sender, Time.now, text))
end

#send_sms(msg) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rubysms/backend/drb.rb', line 26

def send_sms(msg)
	to = msg.phone_number
	super
	
	# if this is the first time that we
	# have communicated with this DRb
	# client, then initialize the object
	unless @injectors.include?(to)
		drbo = DRbObject.new_with_uri("druby://localhost:#{DRB_PORT}#{to}")
		@injectors[to] = drbo
	end
	
	@injectors[to].incoming(msg.text)
end

#startObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rubysms/backend/drb.rb', line 12

def start
	begin
	
		# start the DRb service, listening for connections
		# from the RubySMS virtual device (virtual-device.rb)
		drb = DRb.start_service("druby://localhost:#{DRB_PORT}", self)
		log ["Started DRb Offline Backend", "URI: #{drb.uri}"], :init
		
		# a hash to store incoming
		# connections from drb clients
		@injectors = {}
	end
end