Terminal command line events and application events
Terminal command line events and application events
- Subject: Terminal command line events and application events
- From: Michael Hall <email@hidden>
- Date: Tue, 13 Apr 2004 08:49:20 -0500
Hello,
New to the list, so I think maybe some background may be necessary here.
I normally do java or native, that mostly Carbon up to now, the native
meant to run from java.
I used to do the native using the Apple JDirect technoligy. This
provides a way to bind to native methods without using the normal Java
JNI native interface.
JDirect was eliminated at 1.4 when the underlying jvm code went Cocoa
instead of Carbon.
At some point I switched to using a JDirect like technology -
http://homepage.mac.com/pcbeard/JNIDirect/
http://sourceforge.net/projects/jnidirect/
One thing I did was split up my application to run a couple different
ways as Client/Server. One using native as AppleEvent client server.
The other way for cross-platform as Java RMI client server. The
required method closure or callback for the AppleEvent server to work
wouldn't function JNIDirect. This became the last piece of JDirect code
I needed to keep this working 1.3 and the one piece that kept it from
working 1.4 at all. So I ended up carrying both 1.3 and 1.4 version of
my application for some period of time.
Recently I decided to look at this again to see if it could be
corrected. The callback problem turned out to be a JNIDirect problem
that was fixed over night once I reported it directly instead of to the
SourceForge project.
But, I had come up with what I thought was some interesting related
things to look at in some searching I had done at the time. I decided
to look into these.
First I JNIDirect coded up QA1123 which I had seen mentioned.
Then I started coding up and looking at the various samples included in
TN2050. I did the mach more Unix-like version first. I sort of assumed
Carbon would present no special challenges as I've done a fair amount
of JNIDirect with that so I looked at the Cocoa.
We're getting to where this is hopefully somewhat appropriate to this
list. The Cocoa Java example didn't work. My guess now would be that
this is because of the awakeFromNib it tries to use in Terminal command
line testing when there is no nib to wake up from? Anyhow, the really
interesting question for me was more could JNIDirect be used to do the
ObjectiveC version. Patrick Beard, the JNIDirect originator had
included a NSString/NSLog example that showed it could be used with
existing Cocoa features. But could you come up with new features?
About here I feel like I should try a little to shorten this so long
story not quite so long I coded this up and have it working and am
gratuitously claiming it over on the java-dev list as a alternative
java bridge. But it would in fact have a ways to go before it could
really be claimed to be that. Making it that will probably require more
knowledge than I have but I'm sure is present on this list so I have
signed up here.
Anyhow the first actual question, when I got the TN2050 version working
I used NSApplication's sharedApplication to try and get events rolling.
From terminal command line this did not get anything rolling where if I
ran it from my actual java application it already seemed rolling and
nothing was required. So the JNIDirect including java code ended up...
final NSApplication currentApplication =
NSApplication.sharedApplication();
...
new CocoaNotifications();
...
/* Running the current applications main event loop. This will allow
us
* to receive the launch/terminate notifications
*/
if (!currentApplication.isActive()) {
currentApplication.activateIgnoringOtherApps(true);
new Thread("NSRunner") {
public void run() { currentApplication.run(); }
}.start();
Object o = new Object();
for (int i=0;i<10;i++) {
System.out.println("current application is active is " +
currentApplication.isActive());
System.out.println("current application is running is " +
currentApplication.isRunning());
synchronized(o) {
try { o.wait(1000); }
catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
// No more need for autorelease pool so release
pool.release();
The println's show the application as running but not active? The
activateIgnoringOtherApps did not seem a fix.
So basically running as an application the isActive check skips all of
this and things run fine. From terminal this code runs but does no good.
As I indicated on the Java list if anyone has any interest or thoughts
on a 'possible' alternative java bridge let me know I'm fairly open to
suggestions at this point as to where it should go but if there isn't
interest it I probably won't put a lot more time into it immediately.
Mike Hall <mikehall at spacestar dot net>
<
http://www.spacestar.net/users/mikehall>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.