Class: Idevice::NotificationProxyClient

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

Overview

Used to receive and post device notifications

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



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

def self.attach(opts={})
  _attach_helper("com.apple.mobile.notification_proxy", opts) do |idevice, ldsvc, p_np|
    err = C.np_client_new(idevice, ldsvc, p_np)
    raise NotificationProxyError, "Notification Proxy Error: #{err}" if err != :SUCCESS

    np = p_np.read_pointer
    raise NPError, "np_client_new returned a NULL client" if np.null?
    return new(np)
  end
end

.release(ptr) ⇒ Object



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

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

Instance Method Details

#observe_notification(notification_type) ⇒ Object



96
97
98
99
100
# File 'lib/idevice/notification_proxy.rb', line 96

def observe_notification(notification_type)
  err = C.np_observe_notification(self, notification_type)
  raise NotificationProxyError, "Notification Proxy Error: #{err}" if err != :SUCCESS

end

#observe_notifications(notification_types) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/idevice/notification_proxy.rb', line 102

def observe_notifications(notification_types)
	  ntypes_ary = []
	  notification_types.each do |ntype|
		ntypes_ary << FFI::MemoryPointer.from_string(ntype)
	  end
	  ntypes_ary << nil
	  ntypes = FFI::MemoryPointer.new(:pointer, ntypes_ary.length)
	  ntypes_ary.each_with_index do |p, i|
		ntypes[i].put_pointer(0, p)
	  end
	  err = C.np_observe_notifications(self, ntypes)
  raise NotificationProxyError, "Notification Proxy Error: #{err}" if err != :SUCCESS

end

#post_notification(notification) ⇒ Object



89
90
91
92
93
94
# File 'lib/idevice/notification_proxy.rb', line 89

def post_notification(notification)
  err = C.np_post_notification(self, notification)
  raise NotificationProxyError, "Notification Proxy Error: #{err}" if err != :SUCCESS

  return true
end

#set_notify_callback(&block) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/idevice/notification_proxy.rb', line 117

def set_notify_callback(&block)
  err = C.np_set_notify_callback(self, _cb(&block), nil)
  raise NotificationProxyError, "Notification Proxy Error: #{err}" if err != :SUCCESS

  @notify_callback = block
  return true
end