Class: SkypeAPI::OS::Linux

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

Defined Under Namespace

Classes: Notify

Instance Method Summary collapse

Methods inherited from Abstruct

#add_hook, #del_hook, #exist_hook?, #get_hook, #invoke, #invoke_callback

Constructor Details

#initialize(service_name = "org.ruby.service") ⇒ Linux

Returns a new instance of Linux.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/skypeapi/os/linux.rb', line 15

def initialize service_name="org.ruby.service"
  super()
  bus = DBus.session_bus
  exobj = Notify.new("/com/Skype/Client")
  #exobj.instance_variable_set(:@queue, @queue)
  exobj.instance_variable_set(:@os, self)
  bus.request_service(service_name).export(exobj)
  service = bus.service 'com.Skype.API'
  @invoker = service.object '/com/Skype'
  @invoker.default_iface = 'com.Skype.API'
  @invoker.introspect
  
  #l = DBus::Main.new
  #l << bus
  #Thread.new do
  #  l.run
  #end
end

Instance Method Details

#attach(name) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/skypeapi/os/linux.rb', line 34

def attach name
  invoke "NAME #{name}"
  invoke "PROTOCOL 9999"
  if @first_attached
    @queue.push proc{do_event :attached}
  else
    @queue.push proc{do_event :reattached}
  end
end

#attach_wait(name) ⇒ Object



104
105
106
107
# File 'lib/skypeapi/os/linux.rb', line 104

def attach_wait(name)
    @name = name
    attach(name)
end

#closeObject



61
62
# File 'lib/skypeapi/os/linux.rb', line 61

def close
end

#invoke_callcack(cmd, cb = Proc.new) ⇒ Object



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

def invoke_callcack cmd,cb=Proc.new
  res = send_prototype(cmd)
  cb.call(res)
end

#invoke_prototype(cmd) ⇒ Object Also known as: invoke_block



44
45
46
47
48
49
50
51
52
# File 'lib/skypeapi/os/linux.rb', line 44

def invoke_prototype(cmd)
  res = @invoker.Invoke('#' + @send_count.to_s + ' ' + cmd)[0]
  old_count = @send_count.to_s
  @send_count+=1
  @queue.push proc{do_event :sent, '#' + old_count + ' ' + cmd}
  @queue.push proc{do_event :received, res}
  res =~ /^##{old_count} (.*)$/m
  return $1
end

#pollingObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/skypeapi/os/linux.rb', line 64

def polling
  flag = true
  begin
    while flag
      proc = @queue.shift true
      proc.call
    end
  rescue
    flag = false
  end  
end

#push_queue(res) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/skypeapi/os/linux.rb', line 76

def push_queue res
  @queue.push(proc{do_event(:received, res)})
  
  if res == 'CONNSTATUS LOGGEDOUT'
    @attached = false
    @queue.push(proc{do_event(:detached)})
    SkypeAPI.attach
  end
      
  flag = false
  @notify.each do |reg,action|
    if res =~ reg
      tmp = $1
      @queue.push(proc{action.call(tmp)})
      flag = true
    end
  end
  
  unless flag
    action = @notify[nil]
    @queue.push(proc{action.call(cmd)})
  end
end

#waitObject



101
102
# File 'lib/skypeapi/os/linux.rb', line 101

def wait
end