Class: Skype::OS::Mac
Defined Under Namespace
Classes: MessageHandler
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Abstruct
#add_hook, #del_hook, #exist_hook?, #get_hook, #invoke, #message_polling
Constructor Details
#initialize(client_application_name = 'ruby4skype') ⇒ Mac
Returns a new instance of Mac.
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/skype/os/mac.rb', line 52
def initialize client_application_name='ruby4skype'
@queue = Queue.new
@attached = false
@debug = false
@send_count = 0
@send_count_mutex = Mutex.new
@response = Hash.new
@msg = MessageHandler.alloc.init
@msg._init self, client_application_name
OSX::SkypeAPI.setSkypeDelegate @msg
app = OSX::NSApplication.sharedApplication
unless app.isRunning
@t =Thread.new do
sleep 1
app.run
end
end
end
|
Instance Attribute Details
#attached ⇒ Object
OSX::NSRunLoop.currentRunLoop.run
74
75
76
|
# File 'lib/skype/os/mac.rb', line 74
def attached
@attached
end
|
#debug ⇒ Object
OSX::NSRunLoop.currentRunLoop.run
74
75
76
|
# File 'lib/skype/os/mac.rb', line 74
def debug
@debug
end
|
#name ⇒ Object
OSX::NSRunLoop.currentRunLoop.run
74
75
76
|
# File 'lib/skype/os/mac.rb', line 74
def name
@name
end
|
#notify_selector ⇒ Object
Returns the value of attribute notify_selector.
81
82
83
|
# File 'lib/skype/os/mac.rb', line 81
def notify_selector
@notify_selector
end
|
#response ⇒ Object
OSX::NSRunLoop.currentRunLoop.run
74
75
76
|
# File 'lib/skype/os/mac.rb', line 74
def response
@response
end
|
Instance Method Details
#attach ⇒ Object
83
84
85
86
87
|
# File 'lib/skype/os/mac.rb', line 83
def attach
unless attached?
OSX::SkypeAPI.connect
end
end
|
#attach_wait ⇒ Object
89
90
91
92
93
|
# File 'lib/skype/os/mac.rb', line 89
def attach_wait
attach
sleep 0.123 until attached?
OSX::SkypeAPI.sendSkypeCommand('PROTOCOL 9999')
end
|
#attached? ⇒ Boolean
95
96
97
|
# File 'lib/skype/os/mac.rb', line 95
def attached?
@attached
end
|
#close ⇒ Object
178
179
180
181
182
183
184
185
186
|
# File 'lib/skype/os/mac.rb', line 178
def close
dettach if attached?
OSX::SkypeAPI.removeSkypeDelegate
queue.push :exit
end
|
#dettach ⇒ Object
99
100
101
102
|
# File 'lib/skype/os/mac.rb', line 99
def dettach
self.attached = false
OSX::SkypeAPI.disconnect
end
|
#invoke_callback(cmd, cb = Proc.new) ⇒ Object
144
145
146
147
|
# File 'lib/skype/os/mac.rb', line 144
def invoke_callback cmd,cb=Proc.new
res = invoke_block cmd
cb.call res
end
|
#invoke_prototype(cmd) ⇒ Object
Also known as:
invoke_block
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/skype/os/mac.rb', line 108
def invoke_prototype cmd
send_count = send_count_increment
cmd = "##{send_count} #{cmd}"
p ">#{cmd}" if @debug
res = OSX::SkypeAPI.sendSkypeCommand(cmd).to_s
if res.empty?
begin
timeout(5){sleep 0.123 until response[send_count]}
rescue TimeoutError
raise Skype::Error::API.new("#{cmd} => no response. it may be skype bug")
end
res = response[send_count]
response.delete send_count
end
p "<#{res}" if @debug
res = $1 if res =~ /^#\d+ (.+)$/m
return res
end
|
#messageloop ⇒ Object
155
156
157
158
159
|
# File 'lib/skype/os/mac.rb', line 155
def messageloop
while callback = queue.shift
break unless message_process callback
end
end
|
#messagepolling ⇒ Object
161
162
163
164
|
# File 'lib/skype/os/mac.rb', line 161
def messagepolling
return message_process(queue.shift) unless queue.empty?
return true
end
|
#push_queue(res) ⇒ Object
174
175
176
|
# File 'lib/skype/os/mac.rb', line 174
def push_queue res
queue.push(proc{notify_selector.call res}) if notify_selector
end
|
#set_notify_selector(block = Proc.new) ⇒ Object
78
79
80
|
# File 'lib/skype/os/mac.rb', line 78
def set_notify_selector block=Proc.new
@notify_selector = block
end
|
#skype_runnging? ⇒ Boolean
104
105
106
|
# File 'lib/skype/os/mac.rb', line 104
def skype_runnging?
OSX::SkypeAPI.isSkypeRunnging
end
|
#start_messageloop ⇒ Object
151
152
153
|
# File 'lib/skype/os/mac.rb', line 151
def start_messageloop
Thread.new{messageloop}
end
|