Class: Idevice::Plist_t

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

Direct Known Subclasses

Plist_t_Unmanaged

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

.from_binary(data) ⇒ Object


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

def self.from_binary(data)
  FFI::MemoryPointer.from_bytes(data) do |plist_bin|
    FFI::MemoryPointer.new(:pointer) do |p_out|
      C.plist_from_bin(plist_bin, plist_bin.size, p_out)
      out = p_out.read_pointer
      if out.null?
        return nil
      else
        return new(out)
      end
    end
  end
end

.from_ruby(obj) ⇒ Object


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/idevice/plist.rb', line 139

def self.from_ruby(obj)
  case obj
  when TrueClass,FalseClass
    new_bool(obj)
  when Hash, Array
    from_xml(obj.to_plist)
  when String
    new_string(obj)
  when StringIO
    new_data(obj.string)
  when Float
    new_real(obj)
  when Integer
    new_uint(obj)
  when Time,DateTime
    raise NotImplementedError # XXX TODO
  else
    raise TypeError, "Unable to convert #{obj.class} to a plist"
  end
end

.from_xml(xml) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/idevice/plist.rb', line 83

def self.from_xml(xml)
  FFI::MemoryPointer.from_bytes(xml) do |plist_xml|
    FFI::MemoryPointer.new(:pointer) do |p_out|
      C.plist_from_xml(plist_xml, plist_xml.size, p_out)
      out = p_out.read_pointer
      if out.null?
        return nil
      else
        return new(out)
      end
    end
  end
end

.new_arrayObject


75
76
77
# File 'lib/idevice/plist.rb', line 75

def self.new_array
  new(C.plist_new_array())
end

.new_bool(val) ⇒ Object


111
112
113
# File 'lib/idevice/plist.rb', line 111

def self.new_bool(val)
  new(C.plist_new_bool(val))
end

.new_data(data) ⇒ Object

end


131
132
133
134
135
136
137
# File 'lib/idevice/plist.rb', line 131

def self.new_data(data)
  FFI::MemoryPointer.from_bytes(data) do |p_data|
    FFI::MemoryPointer.new(:pointer) do |p_out|
      return new(C.plist_new_data(p_data, p_data.size))
    end
  end
end

.new_dictObject


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

def self.new_dict
  new(C.plist_new_dict())
end

.new_real(val) ⇒ Object


119
120
121
# File 'lib/idevice/plist.rb', line 119

def self.new_real(val)
  new(C.plist_new_real(val))
end

.new_string(str) ⇒ Object


115
116
117
# File 'lib/idevice/plist.rb', line 115

def self.new_string(str)
  new(C.plist_new_string(str))
end

.new_uint(val) ⇒ Object


123
124
125
# File 'lib/idevice/plist.rb', line 123

def self.new_uint(val)
  new(C.plist_new_uint(val))
end

.release(ptr) ⇒ Object


67
68
69
70
71
72
73
# File 'lib/idevice/plist.rb', line 67

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

Instance Method Details

#to_plist_tObject


180
181
182
# File 'lib/idevice/plist.rb', line 180

def to_plist_t
  self
end

#to_rubyObject


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/idevice/plist.rb', line 160

def to_ruby
  FFI::MemoryPointer.new(:pointer) do |plist_xml_p|
    FFI::MemoryPointer.new(:pointer) do |length_p|
      C.plist_to_xml(self, plist_xml_p, length_p)
      length = length_p.read_uint32
      if plist_xml_p.null?
        return nil
      else
        ptr = plist_xml_p.read_pointer
        begin
          res = ::Plist.parse_xml(ptr.read_string_length(length).force_encoding('UTF-8'))
        ensure
          C.free(ptr)
        end
        return res
      end
    end
  end
end