Class: Vips::Object

Inherits:
GObject::GObject show all
Defined in:
lib/vips/object.rb

Direct Known Subclasses

Connection, Image, Interpolate, Operation, Region

Defined Under Namespace

Modules: ObjectLayout Classes: ManagedStruct, Struct

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GObject::GObject

ffi_managed_struct, #ffi_managed_struct, #ffi_struct, ffi_struct, #initialize

Constructor Details

This class inherits a constructor from GObject::GObject

Class Method Details

print all active VipsObjects, with their reference counts. Handy for debugging ruby-vips.


174
175
176
177
# File 'lib/vips/object.rb', line 174

def self.print_all
  GC.start
  Vips::vips_object_print_all
end

Instance Method Details

#get(name) ⇒ Object


239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/vips/object.rb', line 239

def get name
  gtype = get_typeof_error name
  gvalue = GObject::GValue.alloc
  gvalue.init gtype
  GObject::g_object_get_property self, name, gvalue
  result = gvalue.get
  gvalue.unset

  GLib::logger.debug("Vips::Object.get") { "#{name} == #{result}" }

  return result
end

#get_pspec(name) ⇒ Object

return a pspec, or nil ... nil wil leave a message in the error log which you must clear


208
209
210
211
212
213
214
215
216
217
218
# File 'lib/vips/object.rb', line 208

def get_pspec name
  ppspec = GObject::GParamSpecPtr.new
  argument_class = Vips::ArgumentClassPtr.new
  argument_instance = Vips::ArgumentInstancePtr.new

  result = Vips::vips_object_get_argument self, name,
      ppspec, argument_class, argument_instance
  return nil if result != 0

  ppspec[:value]
end

#get_typeof(name) ⇒ Object

return a gtype, 0 on not found


229
230
231
232
233
234
235
236
237
# File 'lib/vips/object.rb', line 229

def get_typeof name
  pspec = get_pspec name
  unless pspec
    Vips::vips_error_clear
    return 0
  end

  pspec[:value_type]
end

#get_typeof_error(name) ⇒ Object

return a gtype, raise an error on not found

Raises:


221
222
223
224
225
226
# File 'lib/vips/object.rb', line 221

def get_typeof_error name
  pspec = get_pspec name
  raise Vips::Error unless pspec

  pspec[:value_type]
end

#set(name, value) ⇒ Object


252
253
254
255
256
257
258
259
260
261
# File 'lib/vips/object.rb', line 252

def set name, value
  GLib::logger.debug("Vips::Object.set") { "#{name} = #{value}" }

  gtype = get_typeof_error name
  gvalue = GObject::GValue.alloc
  gvalue.init gtype
  gvalue.set value
  GObject::g_object_set_property self, name, gvalue
  gvalue.unset
end

#signal_connect(name, handler = nil) ⇒ Object

Raises:


263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/vips/object.rb', line 263

def signal_connect name, handler=nil
  marshal = MARSHAL_ALL[name.to_sym]
  raise Vips::Error, "unsupported signal #{name}" if marshal == nil

  if block_given? 
    # This will grab any block given to us and make it into a proc
    prc = Proc.new
  elsif handler
    # We assume the hander is a proc (perhaps we should test)
    prc = handler
  else
    raise Vips::Error, "must supply either block or handler"
  end

  # The marshal function will make a closure with the right type signature 
  # for the selected signal
  callback = marshal.(prc)

  # we need to make sure this is not GCd while self is alive
  @references << callback

  GObject::g_signal_connect_data(self, name.to_s, callback, nil, nil, 0)
end