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



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 because the real-time clock on board the Mac takes a while to wake up. Mac OS 9 used to take its time so no-one really noticed ;-}. Please file a bug about it, and mention it relates to Radar #2830154.

<snip>

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?

Yes, it's just a pointer. You'll have to store it as a long.

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

Yes.

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

The actual JNI function call needs to be a plain C function, but it can be in a .m file no problem.

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

I believe this restriction may be gone in Jaguar/10.2, but don't shoot me if I'm wrong - check the release notes.

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!

This notification (the lack thereof) is more or less what Radar #2830154 is concerned with.

Cheers,

Andy Belk
Holistic Software Detective, Java, Apple Computer, Inc.
_______________________________________________
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.