25

I work on windows but I am stuck here on Mac. I have the Canon SDK and have built a JNA wrapper over it. It works well on windows and need some help with Mac. In the sdk, there is a function where one can register a callback function. Basically when an event occurs in camera, it calls the callback function.

On windows, after registering, I need to use User32 to get the event and to dispatch the event by:

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
}

In the api, I do not find a similar class in Mac. How do I go about this one??

PS: The JNA api for unix is extensive and I could not figure out what to look for. The reference might help

Jatin
  • 31,116
  • 15
  • 98
  • 163
  • You will probably want to check out GCEventRef, https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html – Grady Player Mar 08 '13 at 05:53
  • Most of JNA's platform mappings for unix are for X11, and there isn't much specifically for OS X. [Rococoa](http://code.google.com/p/rococoa/) has a lot more by way of OS X mappings. – technomage Mar 08 '13 at 16:35
  • @technomage I cannot now shift to Rococoa because then I will have to rewrite the code. Windows one already works fine. I just need some technique to get the message – Jatin Mar 09 '13 at 08:32
  • 2
    You should read a little more about what rococoa does. It's a library on top of JNA to facilitate access to OS X libraries which make use of ObjectiveC. That project also has more community specifically involved in using OS X libraries from Java. Ultimately, though, you need some OSX expertise to identify the appropriate OS X event APIs (unless your Canon SDK provides examples). – technomage Mar 09 '13 at 15:36
  • 2
    If you were to provide the native code example for OSX that comes with the Canon SDK, you'd be more likely to get a complete response. – technomage Mar 10 '13 at 12:49

1 Answers1

3

This solution is using the Cocoa framework. Cocoa is deprecated and I am not aware of any other alternative solution. But the below works like charm.

Finally I found the solution using Carbon framework. Here is my MCarbon interface which defines calls I need.

  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
  }

The solution to the problem is solved using the below function:

 NativeLong ReceiveNextEvent(NativeLong inNumTypes, EventTypeSpec[] inList, double inTimeout, byte inPullEvent, Pointer outEvent);

This does the job. As per documentation -

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.

Also if not ReceiveNextEvent, then other functions as mentioned in MCarbon class above would be useful.

I think Carbon framework documentation would give more insights and flexibilities to solve the problem. Apart from Carbon, in forums people have mentioned about solving using Cocoa, but none I am aware of.

Edit: Thanks to technomarge, more information here

Community
  • 1
  • 1
Jatin
  • 31,116
  • 15
  • 98
  • 163