Class: NotificationsHandler

Inherits:
Riddl::Utils::Notifications::Producer::HandlerBase
  • Object
show all
Defined in:
lib/cpee/handler_notifications.rb

Overview

This file is part of CPEE.

CPEE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CPEE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CPEE (file COPYING in the main directory). If not, see <www.gnu.org/licenses/>.

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
# File 'lib/cpee/handler_notifications.rb', line 34

def create
  @data.unserialize_notifications!(:cre,@key)
  @data.notify('properties/handlers/change')
end

#deleteObject



38
39
40
41
# File 'lib/cpee/handler_notifications.rb', line 38

def delete
  @data.unserialize_notifications!(:del,@key)
  @data.notify('properties/handlers/change')
end

#updateObject



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

def update
  @data.unserialize_notifications!(:upd,@key)
  @data.notify('properties/handlers/change')
end

#ws_closeObject



19
20
21
# File 'lib/cpee/handler_notifications.rb', line 19

def ws_close
  @data.del_ws(@key)
end

#ws_message(data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cpee/handler_notifications.rb', line 22

def ws_message(data)
  begin
    doc = XML::Smart::string(data)
    callback = doc.find("string(/vote/@id)")
    result = doc.find("string(/vote)")
    @data.callbacks[callback].callback(result == 'true' ? true : false)
    @data.callbacks.delete(callback)
  rescue
    puts "Invalid message over websocket"
  end
end

#ws_open(socket) ⇒ Object



16
17
18
# File 'lib/cpee/handler_notifications.rb', line 16

def ws_open(socket)
  @data.add_ws(@key,socket)
end