private static void removePeerObject(ObjCObject o) { synchronized (objcBridgeLock) { long handle = o.getHandle(); ObjCObjectRef ref = peers.remove(handle); ObjCObject p = ref != null ? ref.get() : null; if (p != null && o != p) { // Not the same peer. Put it back. peers.put(handle, new ObjCObjectRef(p)); } } }
protected ObjCObject() { long handle = alloc(); setHandle(handle); if (handle != 0) { // Make sure the peer is set immediately even if a different handle // is set later with initObject(). setPeerObject(handle, this); } customClass = getObjCClass().isCustom(); }
private static void setPeerObject(long handle, ObjCObject o) { synchronized (objcBridgeLock) { if (o == null) { peers.remove(handle); } else { peers.put(handle, new ObjCObjectRef(o)); } } }
/*<ptr>*/public static class CIFilterPtr extends Ptr<CIFilter, CIFilterPtr> {}/*</ptr>*/ /*<bind>*/static { ObjCRuntime.bind(CIFilter.class); }/*</bind>*/
/** * Marshaler used for factory methods which have already retained the object * they return. */ public static class NoRetainMarshaler { @MarshalsPointer public static NSObject toObject(Class<? extends NSObject> cls, long handle, long flags) { return Marshaler.toObject(cls, handle, flags, false); } @MarshalsPointer public static long toNative(NSObject o, long flags) { return Marshaler.toNative(o, flags); } }
static long alloc(ObjCClass c) { long h = ObjCRuntime.ptr_objc_msgSend(c.getHandle(), alloc.getHandle()); if (h == 0L) { throw new OutOfMemoryError(); } return h; }
protected static String domain(long handle) { long h = ObjCRuntime.ptr_objc_msgSend(handle, domain.getHandle()); NSString s = ObjCObject.toObjCObject(NSString.class, h, 0); return s.toString(); }
public static ObjCClass getFromObject(ObjCObject id) { long handle = id.getHandle(); ObjCClass c = null; if (handle != 0L) { long classPtr = ObjCRuntime.object_getClass(handle); c = ObjCObject.getPeerObject(classPtr); } if (c != null) { return c; } return getByType(id.getClass()); }
protected static void autorelease(long handle) { ObjCRuntime.void_objc_msgSend(handle, autorelease.getHandle()); }
public static boolean isObjectRetained(ObjCObject object) { synchronized (CUSTOM_OBJECTS) { return CUSTOM_OBJECTS.containsKey(object.getHandle()); } }
protected ObjCObject(long handle) { initObject(handle); customClass = getObjCClass().isCustom(); }
private ListenerWrapper(VoidBlock2<String, NSError> callback, long contextInfo) { this.callback = callback; synchronized (callbacks) { callbacks.put(contextInfo, this); } } @TypeEncoding("v@:@:^v")
public static ObjCClass getFromObject(long handle) { long classPtr = ObjCRuntime.object_getClass(handle); return toObjCClass(classPtr); }
public boolean hasObject() { return descriptor().getHandle() == Wrapper.DESCRIPTOR.getHandle(); }
/** Returns a pseudo-random, uniformly distributed {@code float} value between 0.0 and 1.0 from this random number generator's * sequence. * <p> * This implementation uses {@link #nextLong()} internally. */ @Override public float nextFloat () { return (float)((nextLong() >>> 40) * NORM_FLOAT); }
protected static void retain(long handle) { ObjCRuntime.void_objc_msgSend(handle, retain.getHandle()); }
/** Returns the next pseudo-random, uniformly distributed {@code int} value from this random number generator's sequence. * <p> * This implementation uses {@link #nextLong()} internally. */ @Override public int nextInt () { return (int)nextLong(); }
protected static void release(long handle) { ObjCRuntime.void_objc_msgSend(handle, release.getHandle()); }