Class: Idevice::Idevice

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from C::ManagedOpaquePointer

#initialize

Constructor Details

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

Class Method Details

.attach(opts = {}) ⇒ Object

Use this instead of 'new' to attach to an idevice using libimobiledevice and instantiate a new idevice_t handle


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/idevice/idevice.rb', line 40

def self.attach(opts={})
  @udid = opts[:udid]

  FFI::MemoryPointer.new(:pointer) do |tmpptr|
    err = C.idevice_new(tmpptr, @udid)
    raise IdeviceLibError, "Idevice error: #{err}" if err != :SUCCESS

    idevice_t = tmpptr.read_pointer
    if idevice_t.null?
      raise IdeviceLibError, "idevice_new created a null pointer"
    else
      return new(tmpptr.read_pointer)
    end
  end
end

.release(ptr) ⇒ Object


30
31
32
33
34
35
36
# File 'lib/idevice/idevice.rb', line 30

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

Instance Method Details

#connect(port) ⇒ Object


80
81
82
# File 'lib/idevice/idevice.rb', line 80

def connect port
  IdeviceConnection.connect(self, port)
end

#handleObject


71
72
73
74
75
76
77
78
# File 'lib/idevice/idevice.rb', line 71

def handle
  @handle = nil
  FFI::MemoryPointer.new(:uint32) do |tmpptr|
    err = C.idevice_get_handle(self, tmpptr)
    raise IdeviceLibError, "Idevice error: #{err}" if err != :SUCCESS
    return tmpptr.read_uint32
  end
end

#udidObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/idevice/idevice.rb', line 56

def udid
  return @udid if @udid

  @udid = nil
  FFI::MemoryPointer.new(:pointer) do |udid_ptr|
    err = C.idevice_get_udid(self, udid_ptr)
    raise IdeviceLibError, "Idevice error: #{err}" if err != :SUCCESS
    unless udid_ptr.read_pointer.null?
      @udid = udid_ptr.read_pointer.read_string
      C.free(udid_ptr.read_pointer)
    end
  end
  return @udid
end