Mailing Lists: Apple Mailing Lists

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

JNI and NSSelector



Maybe this is way too much to hope for, but I'm writing a JNI library that I'm hoping to be able to pass an NSSelector to, which then the JNI library will use as a callback.

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)

I haven't done tons of JNI work, so here are my questions:
1. Is there a way to get an NSSelector inside the JVM and get it to an Obj-C @selector in native code?
2. Is it even possible to mix Obj-C code into the .jnilib?
3. Failing these, what's the recommended route for JVM callbacks using JNI? Am I better off using JDirect?

Here's the problem I'm solving:
I have a Java Cocoa app, a timer, that depends on the system clock (System.currentTimeMillis()). It happens that when you awake from sleep, for the first few seconds (about 10 on my 400 MHz Pismo), the clock is in the past -- it ticks from the time it was put to sleep. And, then, suddenly, it jumps. This is just a display issue, unless the user starts or stops the timer while the clock is in the past: if starts, the timer will tick normally for a few seconds and then (possibly after the user has obscured my app) both clock and timer will jump, possibly hours or days depending on the length of sleep. If the user stops the timer, the timer will not jump with the clock, and so will be short by the amount of time the clock jumps.

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", and then I can check to see whether we got any state changes while in never-never land and perform appropriate fixes if the clock jumps. But this seems a lot less obvious than calling C code from Java. Any help greatly appreciated!

TIA,

Nathan
_______________________________________________
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.



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.