Class: Idevice::HouseArrestClient

Inherits:
C::ManagedOpaquePointer show all
Includes:
LibHelpers
Defined in:
lib/idevice/house_arrest.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
# File 'lib/idevice/house_arrest.rb', line 41

def self.attach(opts={})
  _attach_helper("com.apple.mobile.house_arrest", opts) do |idevice, ldsvc, p_ha|
    err = C.house_arrest_client_new(idevice, ldsvc, p_ha)
    raise HouseArrestError, "house_arrest error: #{err}" if err != :SUCCESS
    ha = p_ha.read_pointer
    raise HouseArrestError, "house_arrest_client_new returned a NULL house_arrest_client_t pointer" if ha.null?
    return new(ha)
  end
end

.release(ptr) ⇒ Object



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

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

Instance Method Details

#afc_clientObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/idevice/house_arrest.rb', line 89

def afc_client
  FFI::MemoryPointer.new(:pointer) do |p_afc|
    err = C.afc_client_new_from_house_arrest_client(self, p_afc)
    raise AFCError, "AFC Error: #{err}" if err != :SUCCESS
    afc = p_afc.read_pointer
    raise AFCError, "afc_client_new_from_house_arrest_client returned a NULL afc_client_t pointer" if afc.null?
    cli =  AFCClient.new(afc)

    # save a reference to ourselves in the afc client to avoid premature garbage collection...
    cli.instance_variable_set(:@house_arrest, self)
    return cli
  end
end

#afc_client_for_container(appid) ⇒ Object



103
104
105
106
# File 'lib/idevice/house_arrest.rb', line 103

def afc_client_for_container(appid)
  vend_container(appid)
  return afc_client
end

#afc_client_for_documents(appid) ⇒ Object



108
109
110
111
# File 'lib/idevice/house_arrest.rb', line 108

def afc_client_for_documents(appid)
  vend_documents(appid)
  return afc_client
end

#get_resultObject



63
64
65
66
67
68
69
70
71
# File 'lib/idevice/house_arrest.rb', line 63

def get_result
  FFI::MemoryPointer.new(:pointer) do |p_result|
    err = C.house_arrest_get_result(self, p_result)
    raise HouseArrestError, "house_arrest error: #{err}" if err != :SUCCESS
    result = p_result.read_pointer.read_plist_t
    raise HouseArrestError, "house_arrest_get_result returned a null plist_t" if result.nil?
    return result
  end
end

#send_command(command, appid) ⇒ Object

Raises:



57
58
59
60
61
# File 'lib/idevice/house_arrest.rb', line 57

def send_command(command, appid)
  err = C.house_arrest_send_command(self, command, appid)
  raise HouseArrestError, "house_arrest error: #{err}" if err != :SUCCESS
  return true
end

#send_request(dict) ⇒ Object

Raises:



51
52
53
54
55
# File 'lib/idevice/house_arrest.rb', line 51

def send_request(dict)
  err = C.house_arrest_send_request(self, dict.to_plist_t)
  raise HouseArrestError, "house_arrest error: #{err}" if err != :SUCCESS
  return true
end

#vend_container(appid) ⇒ Object



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

def vend_container(appid)
  send_command("VendContainer", appid)
  res = get_result
  if res["Error"]
    raise HouseArrestError, "Error vending container to appid: #{appid} - #{res.inspect}"
  end
end

#vend_documents(appid) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/idevice/house_arrest.rb', line 81

def vend_documents(appid)
  send_command("VendDocuments", appid)
  res = get_result
  if res["Error"]
    raise HouseArrestError, "Error vending documents to appid: #{appid} - #{res.inspect}"
  end
end