domotics-core 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cba0e62ef72ca6f4ec6d2e447b7c638756e90d94
4
- data.tar.gz: 17ae8e492429b4d408bb9d2e7a5ccdd9a4d76d6d
3
+ metadata.gz: 02ebecc7f97e80de2536f358cecad8575b774fe0
4
+ data.tar.gz: 5883efe2e1f49b13f602956ddfcbbc79f532709e
5
5
  SHA512:
6
- metadata.gz: 60e225476db67fcbe195379c7581402856a7edb60030b1f254ab13a6aca676fce3033daa7eb8ec235fc5a054ea1f60e4cacdcd27ea21a222f5c52e6da724462e
7
- data.tar.gz: 89f6c92adda473ba4440d873d4a3a8707460e0ae95681094cf66f150c09c357fe1f0aa7071d632dd846c7a166a1ee353ff47eb7ab7b91c5e4584fb41e18b7ff8
6
+ metadata.gz: e27789dbc3e14975c31f149778d2855b28b63c019e3e0afd341fd693e43469bd8ff6f279d4cda8802233400487eee5738f226e98b4f5030bcb9fea624f94407e
7
+ data.tar.gz: 9ba2b8410f2e8b945f577f0988906e1bdd4adc8d569dad18231c27126b53fe3b707caf3291d063086841062e2fe3a4ad2d66b0d734b3ff2df5492913bb0bd4c1
@@ -57,7 +57,7 @@ module Domotics::Core
57
57
  end
58
58
 
59
59
  def to_s
60
- "Element[#{@room.name}@#{@name}](id:#{__id__})"
60
+ "#{@room.name}@#{@name}(id:#{__id__})"
61
61
  end
62
62
  end
63
63
  end
@@ -7,7 +7,7 @@ Thread.class_eval do
7
7
  block.call
8
8
  rescue Exception => e
9
9
  Domotics::Core::Setup.logger.error { e.message }
10
- Domotics::Core::Setup.logger.debug { e.inspect }
10
+ Domotics::Core::Setup.logger.debug { e.backtrace.join $/ }
11
11
  nil
12
12
  end
13
13
  end
@@ -57,7 +57,7 @@ module Domotics::Core
57
57
  # Default - simple prints event
58
58
  def event_handler(msg = {})
59
59
  event, element = msg[:event], msg[:element]
60
- @logger.info { "Event message :#{event} from #{element} with state [#{element.state}]" }
60
+ @logger.info { "[Domotics] event [#{event}] element [#{element}] state [#{element.state}]" }
61
61
  Domotics::Core::WsServer.publish "#{element.room.name}/#{element.name}"
62
62
  end
63
63
 
@@ -37,9 +37,7 @@ module Domotics::Core
37
37
  end
38
38
 
39
39
  def self.run(args = {})
40
- Thread.new do
41
- Rack::Handler::Thin.run self.new, args
42
- end
40
+ Rack::Handler::Thin.run self.new, args
43
41
  end
44
42
 
45
43
  private
@@ -1,6 +1,6 @@
1
1
  module Domotics
2
2
  module Core
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
6
6
 
@@ -1,28 +1,34 @@
1
1
  module Domotics::Core
2
2
  class WsServer
3
- @@channel = EM::Channel.new
3
+ @@parent = nil
4
4
  def initialize(args = {})
5
5
  @logger = Domotics::Core::Setup.logger || Logger.new(STDERR)
6
6
  @args = args
7
+ @@parent, @child = Socket.pair(:UNIX, :DGRAM, 0)
7
8
  end
8
9
  def run
9
- Thread.new do
10
- @logger.info { "Starting WebSocet Server on #{@args[:host]}:#{@args[:port]}" }
10
+ @logger.info { "[WebSocket] server [#{@args[:host]}:#{@args[:port]}]" }
11
+ fork do
12
+ @@parent.close
13
+ channel = EventMachine::Channel.new
14
+ Thread.new { loop { channel.push @child.recv(2**10) }}
11
15
  EventMachine::WebSocket.start(@args) do |ws|
12
16
  ws.onopen do
13
- sid = @@channel.subscribe { |msg| ws.send msg }
17
+ sid = channel.subscribe { |msg| ws.send msg }
18
+ @logger.info { "[WebSocket] client [#{sid}]" }
14
19
  ws.onmessage do |msg|
15
- @logger.info { "WebSocket message [#{msg}] from client [#{sid}]" }
20
+ @logger.info { "[WebSocket] message [#{msg}] from [#{sid}]" }
16
21
  end
17
22
  ws.onclose do
18
- @@channel.unsubscribe(sid)
23
+ channel.unsubscribe(sid)
19
24
  end
20
25
  end
21
26
  end
22
27
  end
28
+ @child.close
23
29
  end
24
30
  def self.publish(msg)
25
- @@channel.push msg
31
+ @@parent.send msg, 0 if @@parent
26
32
  end
27
33
  end
28
34
  end
@@ -3,7 +3,7 @@ module Domotics
3
3
  class CameraElement < Domotics::Core::Element
4
4
  def initialize(args = {})
5
5
  super
6
- set_state @device.mode
6
+ set_state @device.mode if state != @device.mode
7
7
  end
8
8
  def image
9
9
  @device.current_link
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domotics-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - goredar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: domotics-arduino