Class: Idevice::ScreenShotrClient

Inherits:
C::ManagedOpaquePointer show all
Includes:
LibHelpers
Defined in:
lib/idevice/screenshotr.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LibHelpers

included

Methods inherited from C::ManagedOpaquePointer

#initialize

Constructor Details

This class inherits a constructor from Idevice::C::ManagedOpaquePointer

Class Method Details

.attach(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/idevice/screenshotr.rb', line 41

def self.attach(opts={})
  _attach_helper("com.apple.mobile.screenshotr", opts) do |idevice, ldsvc, p_ss|
    err = C.screenshotr_client_new(idevice, ldsvc, p_ss)
    raise ScreenShotrError, "ScreenShotr Error: #{err}" if err != :SUCCESS

    ss = p_ss.read_pointer
    raies ScreenShotrError, "screenshotr_client_new returned a NULL client" if ss.null?
    return new(ss)
  end
end

.release(ptr) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/idevice/screenshotr.rb', line 33

def self.release(ptr)
  C::Freelock.synchronize do
    unless ptr.null?
      C.screenshotr_client_free(ptr)
    end
  end
end

Instance Method Details

#take_screenshotObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/idevice/screenshotr.rb', line 52

def take_screenshot
  FFI::MemoryPointer.new(:pointer) do |p_imgdata|
    FFI::MemoryPointer.new(:uint64) do |p_imgsize|
      err = C.screenshotr_take_screenshot(self, p_imgdata, p_imgsize)
      raise ScreenShotrError, "ScreenShotr Error: #{err}" if err != :SUCCESS

      imgdata = p_imgdata.read_pointer
      unless imgdata.null?
        ret=imgdata.read_bytes(p_imgsize.read_uint64)
        C.free(imgdata)
        return ret
      end
    end
  end
end