5 messages in net.java.dev.jna.usersRe: [jna-users] Update: Callback to M...
FromSent OnAttachments
Alan SnyderSep 2, 2008 4:33 pm 
Timothy WallSep 3, 2008 6:02 am 
Timothy WallSep 3, 2008 6:04 am 
prashantSep 3, 2008 10:46 pm 
Timothy WallSep 4, 2008 3:56 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Update: Callback to Mac Carbon APIs.Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Sep 3, 2008 6:02:59 am
List:net.java.dev.jna.users

Make sure you don't have multiple copies of JNA classes in your classpath.

Do you have multiple class loaders?

What happens when you do "x instanceof Callback" explicitly on your new callback instance?

If you're using an IDE, does the graphical inheritance hierarchy look correct?

On Sep 2, 2008, at 7:33 PM, Alan Snyder wrote:

OK, I've done some more investigation of this by running it in a debugger, and it seems that the method convertArgument() should recongnize the class: com.tidebreak....KeyboardHookOSXRunnable.KeyListener as a Callback at the line

else if (arg instanceof Callback)

but it does NOT. I can evaluate "arg" and it does recognize it as

"com.tidebreak....KeyboarkHookOSXRunnable.KeyListener" but not Callback class.

Here is the general strucutre how that class is defined.

** in file: KeyboardHookOSXRunnable.java

public class KeyboardHookOSXRunnable implements Runnable { static final TBCarbon lib = TBCarbon.INSTANCE;

public void run(){ : : lib.InstallEventHandler(lib.GetEventMonitorTarget(),

lib.NewEventHandlerUPP( new KeyListener() ), <-- one of key lines here. ....);

}//run

//NOTE: This is an inner class that is not recongnized as a Callback public class KeyListener implements EventHandlerProPtr{

public KeyListener(){} //an empty constructor.

public OSStatus callback(Pointer nextHandler, Pointer theEvent, Pointer userData) { System.out.println("callback"); return lib.noErr; } }//class - end of inner class.

}// end of class KeyboardHookOSXRunnable

** In a different package and a different file if the defenitions for Carbon's API. This is the relavent subset. public interface TBCarbon extends Library { TBCarbon INSTANCE = (TBCarbon)Native.loadLibrary("/System/ Library/Frameworks/Carbon.framework/Carbon, TBCarbon.class);

/* typedef OSStatus (*EventHandlerProcPtr) ( EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void* inUserData ); */ public interface EventHandlerProcPtr extends Callback { public OSStatus callback(Pointer inHandlerCallRef, Pointer inEvent, Pointer inUserData); }

EventHandlerUPP NewEventHandlerUPP( EventHandlerProcPtr theCallback );

/* typedef EventHandlerProcPtr EventHandlerUPP */ interface EventHandlerUPP extends EventHandlerProcPtr {}

}

I also have noticed that the line number in Function.java seem to be off by about 4 line between the jar file and the source code.

I'm trying to understand why an instanceof wouldn't recognize the inner class KeyListener as a Callback.

Any advice on figuring this out is appreciated.