Class: HomeQ::CP::Connection

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
HomeQ
Defined in:
lib/homeq/cp/connection.rb

Constant Summary collapse

TRACE_REXP =
/^#{Regexp.escape(__FILE__)}/

Constants included from HomeQ

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HomeQ

calculated_homeq_env, calculated_homeq_topology, included, queue_list_for_host_from_topology

Instance Attribute Details

#serverObject

Returns the value of attribute server.



39
40
41
# File 'lib/homeq/cp/connection.rb', line 39

def server
  @server
end

Instance Method Details

#post_initObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/homeq/cp/connection.rb', line 67

def post_init
  @peer = Socket.unpack_sockaddr_in(get_peername)
  logger.info {
    "Control port connection received from " +
      "#{@peer[1]}:#{@peer[0]}."
  }
  
  send_data issue

  # Add all the commands as methods
  self.class.class_eval {
    include HomeQ::Base::Commando::InstanceMethods
  }
end

#receive_data(data) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/homeq/cp/connection.rb', line 41

def receive_data data
  if (data == "\004" || # ^D
      data == "\377\364\377\375\006") # ^C
    close_connection
    return
  end
  
  begin
    send_data("#{eval(data)}\r\n")
  rescue SyntaxError, StandardError, Exception
    trace = []
    stack = $!.backtrace
    trace << stack.pop until stack.first =~ TRACE_REXP
    send_data([$!, $!.message, trace].join("\n\t"))
  end
  
end

#unbindObject



59
60
61
62
63
64
65
# File 'lib/homeq/cp/connection.rb', line 59

def unbind
  server.connections.delete(self) if server
  logger.info {
    "Connection has terminated to control port client " +
      "#{@peer[1]}:#{@peer[0]}."
  }
end