Class: Teletask

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/teletask.rb,
lib/constants.rb

Defined Under Namespace

Modules: Command, Function, Setting

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 55957) ⇒ Teletask

Returns a new instance of Teletask.



17
18
19
20
21
# File 'lib/teletask.rb', line 17

def initialize(host, port = 55957)
	@host = host
	@port = port
	#add_observer(self)
end

Instance Method Details

#closeObject



42
43
44
45
# File 'lib/teletask.rb', line 42

def close()
	puts "closing connection"
	@socket.close
end

#connectObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/teletask.rb', line 27

def connect
	puts "connecting..."
	@socket = TCPSocket.open @host, @port

	@t = Thread.new{ 
		while (data = @socket.recv(1024))
			response = Response.parse data
			if response
		   		changed
		   		notify_observers(self, response)
		    end
		end
	}
end

#finalizeObject



23
24
25
# File 'lib/teletask.rb', line 23

def finalize
	close
end

#get(function, number) ⇒ Object



57
58
59
60
# File 'lib/teletask.rb', line 57

def get function, number 
	f = Request.new Command::GET, function, number
	@socket.write f.to_s
end

#group_getObject

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/teletask.rb', line 62

def group_get
	raise NotImplementedError.new
end

#keep_aliveObject



47
48
49
50
# File 'lib/teletask.rb', line 47

def keep_alive
	f = Request.new Command::KEEPALIVE
	@socket.write f.to_s
end

#log(function, setting) ⇒ Object



66
67
68
69
# File 'lib/teletask.rb', line 66

def log function, setting 
	r = Request.new Command::LOG, function, setting
	@socket.write r.to_s
end

#messageObject

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/teletask.rb', line 75

def message
	raise NotImplementedError.new
end

#report_eventObject

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/teletask.rb', line 71

def report_event
	raise NotImplementedError.new
end

#set(function, number, setting) ⇒ Object



52
53
54
55
# File 'lib/teletask.rb', line 52

def set function, number, setting
	f = Request.new Command::SET, function, number, setting
	@socket.write f.to_s
end