Class: Idevice::DiagnosticsRelayClient

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

Constant Summary collapse

FLAG_WAIT_FOR_DISCONNECT =
(1 << 1)
FLAG_DISPLAY_PASS =
(1 << 2)
FLAG_DISPLAY_FAIL =
(1 << 3)
REQUEST_TYPES =
[
  "All",
  "HDMI",
  "WiFi",
  "GasGaugue",
  "NAND",
]

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


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/idevice/diagnostics_relay.rb', line 54

def self.attach(opts={})
  # Note, we're not using LibHelpers#_attach_helper since we need to do the fallback to
  # the old relay service name below

  idevice = opts[:idevice] || Idevice.attach(opts)
  ldsvc = opts[:lockdown_service]
  unless ldsvc
    ldclient = opts[:lockdown_client] || LockdownClient.attach(opts.merge(idevice:idevice))
    ldsvc = begin
              ldclient.start_service("com.apple.mobile.diagnostics_relay")
            rescue LockdownError
              # fall-back to old diagnostics relay service name
              ldclient.start_service("com.apple.iosdiagnostics.relay")
            end
  end

  FFI::MemoryPointer.new(:pointer) do |p_drc|
    err = C.diagnostics_relay_client_new(idevice, ldsvc, p_drc)
    raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
    drc = p_drc.read_pointer
    raise DiagnosticsRelayError, "diagnostics_relay_client_new returned a NULL diagnostics_relay_client_t pointer" if drc.null?
    return new(drc)
  end
end

.release(ptr) ⇒ Object


45
46
47
48
49
50
51
# File 'lib/idevice/diagnostics_relay.rb', line 45

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

Instance Method Details

#diagnostics(type = "All") ⇒ Object


79
80
81
82
83
84
85
86
87
88
# File 'lib/idevice/diagnostics_relay.rb', line 79

def diagnostics(type="All")
  FFI::MemoryPointer.new(:pointer) do |p_diags|
    err = C.diagnostics_relay_request_diagnostics(self, type, p_diags)
    raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS

    diags = p_diags.read_pointer.read_plist_t
    raise DiagnosticsRelayError, "diagnostics_relay_request_diagnostics returned null diagnostics" if diags.nil?
    return diags
  end
end

#goodbyeObject


120
121
122
123
124
# File 'lib/idevice/diagnostics_relay.rb', line 120

def goodbye
  err = C.diagnostics_relay_goodbye(self)
  raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
  return true
end

#ioregistry_entry(name, klass) ⇒ Object


100
101
102
103
104
105
106
107
108
# File 'lib/idevice/diagnostics_relay.rb', line 100

def ioregistry_entry(name, klass)
  FFI::MemoryPointer.new(:pointer) do |p_result|
    err = C.diagnostics_relay_query_ioregistry_entry(self, name, klass, p_result)
    raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
    result = p_result.read_pointer.read_plist_t
    raise DiagnosticsRelayError, "diagnostics_relay_query_ioregistry_entry returned a null result" if result.nil?
    return result
  end
end

#ioregistry_plane(plane) ⇒ Object


110
111
112
113
114
115
116
117
118
# File 'lib/idevice/diagnostics_relay.rb', line 110

def ioregistry_plane(plane)
  FFI::MemoryPointer.new(:pointer) do |p_result|
    err = C.diagnostics_relay_query_ioregistry_plane(self, plane, p_result)
    raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
    result = p_result.read_pointer.read_plist_t
    raise DiagnosticsRelayError, "diagnostics_relay_query_ioregistry_plane returned a null result" if result.nil?
    return result
  end
end

#mobilegestalt(*keys) ⇒ Object


90
91
92
93
94
95
96
97
98
# File 'lib/idevice/diagnostics_relay.rb', line 90

def mobilegestalt(*keys)
  FFI::MemoryPointer.new(:pointer) do |p_result|
    err = C.diagnostics_relay_query_mobilegestalt(self, Plist_t.from_ruby(keys), p_result)
    raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
    result = p_result.read_pointer.read_plist_t
    raise DiagnosticsRelayError, "diagnostics_relay_query_mobilegestalt returned a null result" if result.nil?
    return result
  end
end

#restart(flags = 0) ⇒ Object


132
133
134
135
136
# File 'lib/idevice/diagnostics_relay.rb', line 132

def restart(flags=0)
  err = C.diagnostics_relay_restart(self, flags)
  raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
  return true
end

#shutdown(flags = 0) ⇒ Object


138
139
140
141
142
# File 'lib/idevice/diagnostics_relay.rb', line 138

def shutdown(flags=0)
  err = C.diagnostics_relay_shutdown(self, flags)
  raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
  return true
end

#sleepObject


126
127
128
129
130
# File 'lib/idevice/diagnostics_relay.rb', line 126

def sleep
  err = C.diagnostics_relay_sleep(self)
  raise DiagnosticsRelayError, "Diagnostics Relay error: #{err}" if err != :SUCCESS
  return true
end