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_notificationObject



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/idevice/notification_proxy.rb', line 96

def observe_notification
  FFI::MemoryPointer.new(:pointer) do |p_notification|
    err = C.np_observe_notification(self, p_notification)
    raise NotificationProxyError, "Notification Proxy Error: #{err}" if err != :SUCCESS

    notification = p_notification.read_pointer
    unless notification.null?
      ret = notification.read_string
      C.free(notification)
      return ret
    end
  end
end

#observe_notificationsObject



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

def observe_notifications
  FFI::MemoryPointer.new(:pointer) do |p_notifications|
    err = C.np_observe_notifications(self, p_notifications)
    raise NotificationProxyError, "Notification Proxy Error: #{err}" if err != :SUCCESS

    return _unbound_list_to_array(p_notifications)
  end
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



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

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