Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25236
| Path | csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Steven Simpson <ss@domain.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JNI and GetFieldID |
| Date | Fri, 06 Sep 2013 22:34:32 +0300 |
| Organization | A noiseless patient Spider |
| Lines | 53 |
| Message-ID | <8bnpfa-417.ln1@s.simpson148.btinternet.com> (permalink) |
| References | <l0a6jn$9t4$1@node1.news.atman.pl> <gb2pfa-s33.ln1@s.simpson148.btinternet.com> <l0d1ak$5s5$1@node1.news.atman.pl> <l0d7po$cqp$1@node1.news.atman.pl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Info | mx05.eternal-september.org; posting-host="567aef81bfffdf4c0a37048ecfe0090c"; logging-data="20882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+rKJPpPSWXTWWQ3o29PXLfgguyoiDA6U=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8 |
| In-Reply-To | <l0d7po$cqp$1@node1.news.atman.pl> |
| Cancel-Lock | sha1:8D1f40cYTz2f8NhvhpAkb2t9xqc= |
| Xref | csiph.com comp.lang.java.programmer:25236 |
Show key headers only | View raw
On 06/09/13 21:44, Borneq wrote:
> public interface ICallback {
> void OnPercent(int percent);
> void OnPercentEx(CmplxStruct cs);
> }
While in Java, you should use Java conventions, e.g. onPercent for a
method name. Can't say I'm a fan of prefixing "Callback" with "I" to
show it's an interface either.
> public class CmplxStruct {
> int fieldI;
> String str;
> }
CmplxStruct? Ky, 'll tk tht s jst n ex.
> How place number and string?
> jmethodID mid;
> mid = env->GetMethodID(cls, "OnPercentEx", "(LCmplxStruct;)V");
> env->CallVoidMethod(param1, mid, SOMETHING);
> how fill SOMETHING?
Never learned to do that - looks too error-prone. Instead of mucking
around in JNI, creating objects, accessing fields, etc, I prefer to do
as much as I can in Java, then declare the native methods as taking the
already dismantled fields as separate arguments.
You could do similar for a callback. Write a private static method to
do the fiddly stuff:
private static void callBack(ICallback dest, int i, String s) {
CmplxStruct obj = new CmplxStruct();
obj.fieldI = i;
obj.str = s;
dest.OnPercentEx(obj);
}
Now, in JNI, you use something like:
jobject dest = ...;
jint i = ...;
jstring s = ...;
mid = env->GetStaticMethodID(cls, "callBack", "(LICallback;ILjava/lang/String;)V");
env->CallStaticVoidMethod(dest, i, s);
--
ss at comp dot lancs dot ac dot uk
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next 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