Jat*_*tin 25 java macos java-native-interface jna
我在Windows上工作,但我被困在Mac上.我有佳能SDK,并JNA在它上面构建了一个包装器.它适用于Windows,需要一些Mac帮助.在sdk中,有一个函数可以注册回调函数.基本上当相机发生事件时,它会调用回调函数.
在Windows上,注册后,我需要用来User32获取事件并通过以下方式调度事件:
private static final User32 lib = User32.INSTANCE;
boolean hasMessage = lib.PeekMessage( msg, null, 0, 0, 1 ); // peek and remove
if( hasMessage ){
lib.TranslateMessage( msg );
lib.DispatchMessage( msg ); //message gets dispatched and hence the callback function is called
}
Run Code Online (Sandbox Code Playgroud)
在api中,我在Mac中找不到类似的类.我怎么去这个?
该解决方案使用 Cocoa 框架。Cocoa 已被弃用,我不知道有任何其他替代解决方案。但下面的效果就像魅力一样。
最后我找到了使用框架的解决方案Carbon。这是我的MCarbon界面,它定义了我需要的调用。
public interface MCarbon extends Library {
MCarbon INSTANCE = (MCarbon) Native.loadLibrary("Carbon", MCarbon.class);
Pointer GetCurrentEventQueue();
int SendEventToEventTarget(Pointer inEvent, Pointer intarget);
int RemoveEventFromQueue(Pointer inQueue, Pointer inEvent);
void ReleaseEvent(Pointer inEvent);
Pointer AcquireFirstMatchingEventInQueue(Pointer inQueue,NativeLong inNumTypes,EventTypeSpec[] inList, NativeLong inOptions);
//... so on
}
Run Code Online (Sandbox Code Playgroud)
问题的解决方法是使用下面的函数来解决:
NativeLong ReceiveNextEvent(NativeLong inNumTypes, EventTypeSpec[] inList, double inTimeout, byte inPullEvent, Pointer outEvent);
Run Code Online (Sandbox Code Playgroud)
这样就可以完成工作了。根据文档 -
This routine tries to fetch the next event of a specified type.
If no events in the event queue match, this routine will run the
current event loop until an event that matches arrives, or the
timeout expires. Except for timers firing, your application is
blocked waiting for events to arrive when inside this function.
Run Code Online (Sandbox Code Playgroud)
另外,如果没有ReceiveNextEvent,那么上面类中提到的其他函数MCarbon也会很有用。
我认为Carbon框架文档将为解决问题提供更多见解和灵活性。除此之外Carbon,在论坛中人们提到过使用 解决问题Cocoa,但我不知道。
编辑:感谢technomarge,更多信息在这里
| 归档时间: |
|
| 查看次数: |
987 次 |
| 最近记录: |