Class: MINT::Pointer

Inherits:
IRMode show all
Defined in:
lib/MINT-core/model/ir/pointer.rb

Direct Known Subclasses

Mouse, Pointer3D

Constant Summary

Constants inherited from Interactor

Interactor::PUBLISH_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Interactor

class_from_channel_name, #create_attribute_channel_name, create_channel_name, #create_channel_w_name, get, getModel, get_dm, #init_statemachine, #is_in?, #new_states, notify, #process_event, #process_event!, #process_event_vars, #publish_update, #states, #states=, #sync_event, #sync_states, #to_dot, wait

Instance Method Details

#cache_coordinates(x, y) ⇒ Object



26
27
28
29
# File 'lib/MINT-core/model/ir/pointer.rb', line 26

def cache_coordinates(x,y)
  @cached_x = x
  @cached_y = y
end

#consume(id) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/MINT-core/model/ir/pointer.rb', line 12

def consume(id)
  subscription = self.class.create_channel_name+"."+id.to_s+":*"
  RedisConnector.sub.psubscribe(subscription) # TODO all users
  RedisConnector.sub.on(:pmessage) { |key, channel, message|
    if (key.eql? subscription)
      x,y = MultiJson.decode message
      cache_coordinates x,y
      process_event("move") if not is_in? :moving
      restart_timeout
    end
  }
end

#getSCXMLObject



8
9
10
# File 'lib/MINT-core/model/ir/pointer.rb', line 8

def getSCXML
  "#{File.dirname(__FILE__)}/pointer.scxml"
end

#restart_timeoutObject



49
50
51
52
# File 'lib/MINT-core/model/ir/pointer.rb', line 49

def restart_timeout
  stop_timeout
  start_timeout
end

#start_timeoutObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/MINT-core/model/ir/pointer.rb', line 31

def start_timeout
  if not @timer
    @timer = EventMachine::Timer.new(0.1) do
      attribute_set(:x, @cached_x)
      attribute_set(:y, @cached_y)
      process_event("stop")
    end
  else
    puts "timer already started!!!"
  end
end

#stop_timeoutObject



42
43
44
45
46
47
48
# File 'lib/MINT-core/model/ir/pointer.rb', line 42

def stop_timeout
  if @timer
    # p "stopped timer"
    @timer.cancel
    @timer = nil
  end
end