Class: SkypeAPI::OS::Windows

Inherits:
Abstruct show all
Defined in:
lib/skypeapi/os/windows.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWindows

Returns a new instance of Windows.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/skypeapi/os/windows.rb', line 32

def initialize
  @send_count = 0
  @queue = WindowsEventQueue.new(self)

  @attached = false
  @first_attached = true
  @raise_when_detached = false
  
  @invoke_mutex = Mutex.new
  @invoke_callback_mutex = Mutex.new
  @cv = ConditionVariable.new
  @detached_mutex = Mutex.new

  add_hook :available do
    SkypeAPI.attach
  end
  
  @wmHandler = SWin::LWFactory.new(SWin::Application.hInstance).newwindow nil, MessageHandler
  @wmHandler.init self, @queue
  
  #@queue.start_process_thread
  start_wmhandler_loop
  start_ping_thread
end

Instance Attribute Details

#attachedObject

,:received,:sent



58
59
60
# File 'lib/skypeapi/os/windows.rb', line 58

def attached
  @attached
end

#cvObject (readonly)

Returns the value of attribute cv.



57
58
59
# File 'lib/skypeapi/os/windows.rb', line 57

def cv
  @cv
end

#first_attachedObject

,:received,:sent



58
59
60
# File 'lib/skypeapi/os/windows.rb', line 58

def first_attached
  @first_attached
end

#invoke_callback_mutexObject (readonly)

Returns the value of attribute invoke_callback_mutex.



57
58
59
# File 'lib/skypeapi/os/windows.rb', line 57

def invoke_callback_mutex
  @invoke_callback_mutex
end

#wmHandlerObject (readonly)

Returns the value of attribute wmHandler.



57
58
59
# File 'lib/skypeapi/os/windows.rb', line 57

def wmHandler
  @wmHandler
end

Instance Method Details

#_pingObject



223
224
225
226
227
228
# File 'lib/skypeapi/os/windows.rb', line 223

def _ping
  result = nil
  invoke_callback('PING'){|res| result = res}
  sleep PING_LIMIT
  result == 'PONG'
end

#add_hook(sym, block = Proc.new) ⇒ Object Also known as: add_event

主にAttachなど、Skypeとのコネクション関係のイベントの通知を受ける為のブロックを設定する。 引数 sym は :attach, :attached, :authorize, :refused, :not_available, :available, :unknown, :detachedを取る。 引数 sym が :attachの場合、ブロックは一つの引数(:success,:authorize,:refused,:not_available,:available,:unknownのどれか)を与えられて呼ばれる。



69
70
71
# File 'lib/skypeapi/os/windows.rb', line 69

def add_hook sym, block=Proc.new
  @queue.add_hook sym, block
end

#attach(name = nil) ⇒ Object

SkypeAPIにAttachする。ブロックはしないのでつながるまで待つならばadd_hookでイベントを追加するか,attach_waitを使う。



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

def attach name = nil #,&block)
  @wmHandler.attach
end

#attach_wait(name = nil) ⇒ Object



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

def attach_wait name = nil
  attach name
  sleep SLEEP_INTERVAL until @attached
end

#closeObject

とりあえず、新しくインスタンスを作るとき、古いものはcloseしないといけない。



207
208
209
210
211
# File 'lib/skypeapi/os/windows.rb', line 207

def close
  break_messageloop
  #@wmHandler.close
  @queue.close
end

#del_hook(sym, block = nil) ⇒ Object Also known as: del_event



73
74
75
# File 'lib/skypeapi/os/windows.rb', line 73

def del_hook sym, block=nil
  @queue.del_hook sym, block
end

#exist_hook?(sym) ⇒ Boolean Also known as: exist_event?

Returns:

  • (Boolean)


77
78
79
# File 'lib/skypeapi/os/windows.rb', line 77

def exist_hook? sym
  @queue.exist_hook? sym
end

#get_hook(sym) ⇒ Object Also known as: get_event



81
82
83
# File 'lib/skypeapi/os/windows.rb', line 81

def get_hook sym
  @queue.get_hook sym
end

#invoke(cmd) ⇒ Object

SkypeAPIにコマンドを発行する。Skypeから返り値が戻ってくるまでブロックする。



110
111
112
# File 'lib/skypeapi/os/windows.rb', line 110

def invoke cmd
  super cmd
end

#messageloopObject

notificationのメッセージループをカレントスレッドで回しはじめます。すなわち帰ってきません。



173
174
175
# File 'lib/skypeapi/os/windows.rb', line 173

def messageloop
  @queue.messageloop
end

#messagepollingObject Also known as: polling

notificationのメッセージループを一度だけ回します。



178
179
180
# File 'lib/skypeapi/os/windows.rb', line 178

def messagepolling
  @queue.messagepolling
end

#set_notify_selector(block = Proc.new) ⇒ Object

引数にmethodかブロックを渡しておくとSkypeAPIのNotification(コマンドのレスポンは除く)があった場合呼ばれる。 ブロックはNotificationの文字列を一つ与えられて呼ばれる。



62
63
64
# File 'lib/skypeapi/os/windows.rb', line 62

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

#start_messageloopObject

notificationのメッセージループを新しいスレッドで回し始めます。



168
169
170
# File 'lib/skypeapi/os/windows.rb', line 168

def start_messageloop
  @queue.start_messageloop
end

#status2detacheObject



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/skypeapi/os/windows.rb', line 154

def status2detache
  @detached_mutex.synchronize do
    if detached?
      @attached = false
      @queue.push_detached_hook
      attach_wait
    else
      #wait?
      #runtimeerro?
    end
  end
end