Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JNI and NSSelector



At 9:01 PM -0500 10/3/2002, Nathan V. Roberts wrote:
The tricky part here -- the reason I need a callback in the first place -- is that the native code I'm calling sits inside a CFRunLoop. So I plan to spawn a thread with the native code, which then calls back when the system goes to sleep or wakes up. (More on the problem specifics below)

2. Is it even possible to mix Obj-C code into the .jnilib?

This should be possible, I think.

3. Failing these, what's the recommended route for JVM callbacks using JNI? Am I better off using JDirect?

You can't use JDirect in a Cocoa application, so that's out.

I've found the IOKit hooks for sleep and wake, and have C code that works dandily with these. So now I just need a way to notify the Java code from the native code "hey, the system woke up" or "the system is going to sleep now",

How about having your JNI code call notify() on an object that a Java thread is waiting on? You'd do something like this:

In Java, create a Thread and an Object. Pass it through JNI to your native code, which grabs a reference to it and kicks off another thread, registers the thread with the JVM, and creates a CFRunLoop. The Java thread calls wait() on the object, so it blocks.

When the CFRunLoop gets notified via IOKit that the computer just woke up, it calls notify(). The original Java thread wakes up and then does whatever clock management needs to be done before it calls wait() on the object again to wait for the next sleep/wake cycle.

Just a thought,
Eric

--
Eric Albert email@hidden
http://rescomp.stanford.edu/~ejalbert/
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >JNI and NSSelector (From: "Nathan V. Roberts" <email@hidden>)



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.