Class: SkypeAPI::OS::WindowsEventQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/skypeapi/os/window_event_queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(windows) ⇒ WindowsEventQueue

Returns a new instance of WindowsEventQueue.



12
13
14
15
16
# File 'lib/skypeapi/os/window_event_queue.rb', line 12

def initialize windows
  @windows = windows
  @pause_count = 0
  @pause_mutex = Mutex.new
end

Instance Attribute Details

#notify_selectorObject (readonly)

Returns the value of attribute notify_selector.



42
43
44
# File 'lib/skypeapi/os/window_event_queue.rb', line 42

def notify_selector
  @notify_selector
end

#received_countObject



28
29
30
# File 'lib/skypeapi/os/window_event_queue.rb', line 28

def received_count
  @received_count ||= 0
end

Instance Method Details

#_pauseObject



141
142
143
# File 'lib/skypeapi/os/window_event_queue.rb', line 141

def _pause
  @pause_mutex.synchronized{@pause_count += 1}
end

#add_hook(sym, block = Proc.new) ⇒ Object



52
53
54
# File 'lib/skypeapi/os/window_event_queue.rb', line 52

def add_hook sym, block=Proc.new
  hook[sym].push block
end

#callbackObject



34
35
36
# File 'lib/skypeapi/os/window_event_queue.rb', line 34

def callback
  @callback ||= Hash.new
end

#closeObject



122
123
124
125
# File 'lib/skypeapi/os/window_event_queue.rb', line 122

def close
  queue.clear
  queue.push :exit
end

#del_hook(sym, block = nil) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/skypeapi/os/window_event_queue.rb', line 56

def del_hook sym, block=nil
  unless block
    hook[sym] = Array.new
  else
    hook[sym].delete block
  end
end

#exist_hook?(sym) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/skypeapi/os/window_event_queue.rb', line 64

def exist_hook? sym
  if hook[sym].length > 0
    return true
  else
    return false
  end
end

#get_hook(sym) ⇒ Object



72
73
74
# File 'lib/skypeapi/os/window_event_queue.rb', line 72

def get_hook sym
  hook[sym] ? true : false
end

#lengthObject



24
25
26
# File 'lib/skypeapi/os/window_event_queue.rb', line 24

def length
  @queue.length
end

#messageloopObject



103
104
105
106
107
108
109
110
111
# File 'lib/skypeapi/os/window_event_queue.rb', line 103

def messageloop
  @messageloop_flag = true
  while callback = queue.shift
    sleep 0.001 while paused?
    break if callback == :exit
    callback.call
  end
  @messageloop_flag = false
end

#messagepollingObject



113
114
115
116
117
118
119
120
# File 'lib/skypeapi/os/window_event_queue.rb', line 113

def messagepolling
  until queue.empty?
    sleep 0.001 while paused?
    callback = queue.shift
    break if callback == :exit
    callback.call
  end
end

#palyObject



145
146
147
# File 'lib/skypeapi/os/window_event_queue.rb', line 145

def paly
  @pause_mutex.synchronized{@pause_count -=1}
end

#pause(&block) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/skypeapi/os/window_event_queue.rb', line 131

def pause &block
  if block
    _pause
    block.call
    play
  else
    _pause
  end
end

#paused?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/skypeapi/os/window_event_queue.rb', line 127

def paused?
  @pause_count > 0
end

#push(response) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/skypeapi/os/window_event_queue.rb', line 76

def push response
  self.received_count += 1
  response = response.chop
  push_received_hook(response)

  cmd_num, res = response_match(response)
  if cmd_num
    @windows.wmHandler.del_send_buffer cmd_num.to_i
    set_cmd_response(cmd_num, res)
  else
    when_detached if response_detached?(res)
    push_notify res
  end
end

#push_block(block = Proc.new) ⇒ Object



95
96
97
# File 'lib/skypeapi/os/window_event_queue.rb', line 95

def push_block block=Proc.new
  queue.push block
end

#push_detached_hookObject



149
150
151
152
153
# File 'lib/skypeapi/os/window_event_queue.rb', line 149

def push_detached_hook
  #windows.attached = false
  queue.push_block{ call_hook(:detached) }
  #SkypeAPI.attach
end

#push_hook(sym, *args) ⇒ Object



91
92
93
# File 'lib/skypeapi/os/window_event_queue.rb', line 91

def push_hook sym, *args
  queue.push_block{ call_hook(sym, *args) }
end

#set_notify_selector(block = Proc.new) ⇒ Object



38
39
40
# File 'lib/skypeapi/os/window_event_queue.rb', line 38

def set_notify_selector block=Proc.new
  @notify_selector = block
end

#start_messageloopObject



99
100
101
# File 'lib/skypeapi/os/window_event_queue.rb', line 99

def start_messageloop
  @messageloop_thread = Thread.new{messageloop}
end