Class: Skype::OS::Mac

Inherits:
Abstruct show all
Defined in:
lib/skype/os/mac.rb

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
  #OSX::NSRunLoop.currentRunLoop.run 
end

Instance Attribute Details

#attachedObject

OSX::NSRunLoop.currentRunLoop.run



74
75
76
# File 'lib/skype/os/mac.rb', line 74

def attached
  @attached
end

#debugObject (readonly)

OSX::NSRunLoop.currentRunLoop.run



74
75
76
# File 'lib/skype/os/mac.rb', line 74

def debug
  @debug
end

#nameObject (readonly)

OSX::NSRunLoop.currentRunLoop.run



74
75
76
# File 'lib/skype/os/mac.rb', line 74

def name
  @name
end

#notify_selectorObject (readonly)

Returns the value of attribute notify_selector.



81
82
83
# File 'lib/skype/os/mac.rb', line 81

def notify_selector
  @notify_selector
end

#responseObject (readonly)

OSX::NSRunLoop.currentRunLoop.run



74
75
76
# File 'lib/skype/os/mac.rb', line 74

def response
  @response
end

Instance Method Details

#attachObject



83
84
85
86
87
# File 'lib/skype/os/mac.rb', line 83

def attach
  unless attached?
    OSX::SkypeAPI.connect
  end
end

#attach_waitObject



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

Returns:

  • (Boolean)


95
96
97
# File 'lib/skype/os/mac.rb', line 95

def attached?
  @attached
end

#closeObject



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
  #OSX::NSApplication.sharedApplication.stop(@msg)
  #OSX::NSApplication.sharedApplication.terminate(@msg)
  #@msg.dealloc
  #@t.kill
  queue.push :exit
end

#dettachObject



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}"
  
  #@queue.push(proc{do_event(:sent, cmd)}) if exist_event? :sent
  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
  #@queue.push(proc{do_event(:received, res)}) if exist_event? :received
  
  res = $1 if res =~ /^#\d+ (.+)$/m
  
  return res
end

#messageloopObject



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

#messagepollingObject



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

Returns:

  • (Boolean)


104
105
106
# File 'lib/skype/os/mac.rb', line 104

def skype_runnging?
  OSX::SkypeAPI.isSkypeRunnging
end

#start_messageloopObject



151
152
153
# File 'lib/skype/os/mac.rb', line 151

def start_messageloop
  Thread.new{messageloop}
end