Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25305
| From | "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| References | (2 earlier) <l0d1ak$5s5$1@node1.news.atman.pl> <l0g277$75f$1@node1.news.atman.pl> <7cstfa-3nc.ln1@s.simpson148.btinternet.com> <l0hjht$nvr$1@node1.news.atman.pl> <d5dbga-em5.ln1@s.simpson148.btinternet.com> |
| Subject | Re: JNI and GetFieldID |
| Date | 2013-09-19 15:02 +0100 |
| Message-ID | <ptqdnfE0Qp55nqbPnZ2dnUVZ7tSdnZ2d@bt.com> (permalink) |
Steven Simpson wrote:
> On 08/09/13 11:29, Borneq wrote:
> > Inside StateProc I can call my_callback function, and ACEListProc will
> > be called inside native function. Native function can store env and
> > others parameters. But how within StateProc refer to this env and
> > other parameters?
>
> It's a bugger, isn't it?!
I think what you (plural) are looking for is the GetEnv() function, or the
(JavaVM::GetEnv() method). That will return the correct JNIEnv to use in
whatever context you call it. If there already is a JNIEnv that can be validly
used in that context then the operation is cheap. If not then the operation is
a bit more expensive, but necessary and so unavoidable.
If you are dealing with callbacks that might not happen on a thread that's
known to Java (improbable in this case) then you'd better look into
AttachCurrentThread() and DetachCurrentThread() too.
If the main program is a Java program (rather than a C/C++/whatever program
that uses Java via JNI) then you won't naturally have a reference to a JavaVM.
You can find that from any handy JNIEnv with GetJavaVM(). The JavaVM is a
globally shared, and unique, object, so it can be treated as threadsafe (there
may be documented exceptions to that -- I no longer remember clearly), and so
it's OK to put a reference to it into some shared global variable at the C/C++
level.
-- chris
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-05 17:05 +0200
Re: JNI and GetFieldID Mark <i@dontgetlotsofspamanymore.invalid> - 2013-09-06 10:25 +0100
Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-06 16:36 +0300
Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-06 18:53 +0200
Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-06 20:44 +0200
Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-06 22:34 +0300
Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-06 23:06 +0200
Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-07 22:27 +0200
Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-08 10:24 +0100
Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-08 12:29 +0200
Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-08 22:45 +0200
Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-13 13:31 +0100
Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-14 18:50 +0200
Re: JNI and GetFieldID "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-09-19 15:02 +0100
csiph-web