public static ObjCClass getFromObject(long handle) { long classPtr = ObjCRuntime.object_getClass(handle); return toObjCClass(classPtr); }
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()); }
@Callback private static @Pointer long retain(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount); if (count <= 1) { synchronized (CUSTOM_OBJECTS) { ObjCClass cls = ObjCClass.toObjCClass(ObjCRuntime.object_getClass(self)); ObjCObject obj = ObjCObject.toObjCObject(cls.getType(), self, 0); CUSTOM_OBJECTS.put(self, obj); } } long cls = ObjCRuntime.object_getClass(self); if (logRetainRelease) { logRetainRelease(cls, self, count, true); } Super sup = new Super(self, getNativeSuper(cls)); return ObjCRuntime.ptr_objc_msgSendSuper(sup.getHandle(), sel); }
@Callback private static void release(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount); if (count <= 2) { synchronized (CUSTOM_OBJECTS) { CUSTOM_OBJECTS.remove(self); } } long cls = ObjCRuntime.object_getClass(self); if (logRetainRelease) { logRetainRelease(cls, self, count, false); } Super sup = new Super(self, getNativeSuper(cls)); ObjCRuntime.void_objc_msgSendSuper(sup.getHandle(), sel); }
long ownerHandle = isClassMethod ? ObjCRuntime.object_getClass(handle) : handle; if (!ObjCRuntime.class_addMethod(ownerHandle, selector.getHandle(), impl, encoding != null ? VM.getStringUTFChars(encoding) : 0L)) { throw new ObjCClassNotFoundException("Failed to add method " + selName + " to custom Objective-C class for Java class: " + type);
@Callback static void release(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount.getHandle()); if (count == 1) { long owner = VM.getPointer(self + OWNER_IVAR_OFFSET); synchronized (ASSOCIATED_OBJECTS) { ASSOCIATED_OBJECTS.remove(owner); } } if(logRetainRelease) { long cls = ObjCRuntime.object_getClass(self); logRetainRelease(cls, self, count, false); } ObjCRuntime.void_objc_msgSendSuper(new Super(self, NS_OBJECT_CLASS).getHandle(), sel); } }
public static ObjCClass getFromObject(long handle) { long classPtr = ObjCRuntime.object_getClass(handle); return toObjCClass(classPtr); }
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()); }
public static void registerSubclass(Class<? extends PFObject> subclass) { if (subclass == null) { throw new NullPointerException("subclass"); } if (!subclass.isAnnotationPresent(ParseClassName.class)) { throw new UnsupportedOperationException("Class is missing required @ParseClassName annotation: " + subclass.getSimpleName()); } long cls = ObjCClass.getByType(subclass).getHandle(); ObjCRuntime.class_addProtocol(cls, ObjCRuntime.objc_getProtocol(name_PFSubclassing)); long method = VM.getCallbackMethodImpl(cbParseClassName); ObjCRuntime.class_addMethod(ObjCRuntime.object_getClass(cls), sel_parseClassName, method, typeEncodings_parseClassName); ObjCRuntime.void_objc_msgSend(cls, sel_registerSubclass); }
@Callback private static void dealloc(@Pointer long self, @Pointer long sel) { // during dealloc UIView calls removeFromSuperView or other api which will cause // retain to be called due ARC or other logic, which will break java CUSTOM_OBJECTS // mechanism. So let it to deallow with extra retains long cls = ObjCRuntime.object_getClass(self); Super sup = new Super(self, getNativeSuper(cls)); ObjCRuntime.void_objc_msgSendSuper(sup.getHandle(), sel); // and after this remove this peer (as it could be added again due unexpected retain calls) synchronized (CUSTOM_OBJECTS) { CUSTOM_OBJECTS.remove(self); } }
@Callback private static @Pointer long retain(@Pointer long self, @Pointer long sel) { // retain objectm even if retain was called inside of dealloc retainObject(self); int count = ObjCRuntime.int_objc_msgSend(self, retainCount); long cls = ObjCRuntime.object_getClass(self); if (logRetainRelease) { logRetainRelease(cls, self, count, true); } Super sup = new Super(self, getNativeSuper(cls)); return ObjCRuntime.ptr_objc_msgSendSuper(sup.getHandle(), sel); }
long ownerHandle = isClassMethod ? ObjCRuntime.object_getClass(handle) : handle; if (!ObjCRuntime.class_addMethod(ownerHandle, selector.getHandle(), impl, encoding != null ? VM.getStringUTFChars(encoding) : 0L)) { throw new ObjCClassNotFoundException("Failed to add method " + selName + " to custom Objective-C class for Java class: " + type);
@Callback static void release(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount.getHandle()); if (count == 1) { long owner = VM.getPointer(self + OWNER_IVAR_OFFSET); synchronized (ASSOCIATED_OBJECTS) { ASSOCIATED_OBJECTS.remove(owner); } } if(logRetainRelease) { long cls = ObjCRuntime.object_getClass(self); logRetainRelease(cls, self, count, false); } ObjCRuntime.void_objc_msgSendSuper(new Super(self, NS_OBJECT_CLASS).getHandle(), sel); } }
@Callback private static void release(@Pointer long self, @Pointer long sel) { // this callback is required to remove reference to java counterpart once // native part is being released. dealloc can't be used for purpose // as there is direct retain in afterMarshaled for custom objects int count = ObjCRuntime.int_objc_msgSend(self, retainCount); if (count <= 2) { synchronized (CUSTOM_OBJECTS) { // at this moment there is no reference kept for java object // and it is subject for GC if not being referenced anywhere // once GC comes it will cause release() to be called in dispose // which will also release native part CUSTOM_OBJECTS.remove(self); } } long cls = ObjCRuntime.object_getClass(self); if (logRetainRelease) { logRetainRelease(cls, self, count, false); } Super sup = new Super(self, getNativeSuper(cls)); ObjCRuntime.void_objc_msgSendSuper(sup.getHandle(), sel); }