| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
You should probably turn the .c file into a .m file, because you won't be able to include any of the Cocoa headers in a C file. Java will be able to find the C function symbols fine, as long as they have the proper export statements in front of them. Since you are calling into Cocoa from Java, there are a number of things you should be aware of: 1) To call most of AppKit safely, you should -performSelectorOnMainThread, because the thread from Java you are coming in from is almost certainly not Thread 0, which is reserved for AppKit's run loop. See http://developer.apple.com/technotes/tn2005/tn2147.html for more detail on these issues. 2) If you are using thread safe Foundation classes, and making Obj-C message sends from a thread that originated in Java, you will need an autorelease pool setup to clean up objects expecting to be deallocated by a run loop's autorelease pool. 3) To be completely pedantic, you should also wrap your calls into Cocoa with @try/@catch blocks to prevent an Objective-C exception throw from completely blowing though a bunch of HotSpot stack frames and bringing your app to unceremonious ending. To help with these issues (at least internally) we have created the JavaNativeFoundation.framework inside of /System/Library/Frameworks/JavaVM.framework/Frameworks. Now, this is not officially API (yet), but you can use this as a reference on how to handle the JNI entry and exit points the same way we do inside of Java runtime. Check out the sections around JNF_COCOA_ENTER() and JNF_COCOA_EXIT() to get a feel for how to structure these checks. Best of luck (your going to need it writing JNI), Mike Swingler Java Runtime Engineer Apple Inc. On Sep 27, 2008, at 10:13 AM, Ken Orr wrote:
|
_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden This email sent to email@hidden
| References: | |
| >XCode JNI project (From: Ken Orr <email@hidden>) | |
| >Re: XCode JNI project (From: Michael Hall <email@hidden>) | |
| >Re: XCode JNI project (From: "Alexei Svitkine" <email@hidden>) | |
| >Re: XCode JNI project (From: Ken Orr <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.