Class: HomeQ::CP::Server
- Inherits:
-
Object
- Object
- HomeQ::CP::Server
- Includes:
- Base::Configuration, Base::Logging
- Defined in:
- lib/homeq/cp/server.rb
Constant Summary collapse
- DEFAULT_PORT =
56001
- DEFAULT_HOST =
'localhost'
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
Instance Method Summary collapse
-
#initialize(host = nil, port = nil) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Base::Configuration
Methods included from Base::Logging
Constructor Details
#initialize(host = nil, port = nil) ⇒ Server
Returns a new instance of Server.
47 48 49 50 51 |
# File 'lib/homeq/cp/server.rb', line 47 def initialize(host=nil, port=nil) @host = host || DEFAULT_HOST @port = port || DEFAULT_PORT @connections = [] end |
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
39 40 41 |
# File 'lib/homeq/cp/server.rb', line 39 def connections @connections end |
Instance Method Details
#start ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/homeq/cp/server.rb', line 53 def start begin @signature = EventMachine.start_server(@host, @port, CP::Connection) { |conn| conn.server = self } rescue Exception => e msg = "Error starting CP listener #{@host}:#{@port}. " + "Likely it's a config error. " + "Original error: #{e.}" Base::System.instance.die(msg) else logger.info { "Control port running on #{@host}:#{@port}" } end end |
#stop ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/homeq/cp/server.rb', line 72 def stop EventMachine.stop_server(@signature) unless wait_for_connections # Still some running EventMachine.add_periodic_timer(1) { logger.info { '.' } wait_for_connections } end end |