Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / September 2005

Tip: Looking for answers? Try searching our database.

JNI two java classes makes same native call..will it affect the signature

Thread view: 
Neena - 21 Sep 2005 07:34 GMT
Hi,

I have two java classes, say client.java and server.java. both classes
make a call to my native method getName(long).
i made the .h file of client and wrote the function getName
accordingly, ie, i gave the function name as

JNIEXPORT jintArray JNICALL Java_Client_getName
 (JNIEnv *, jobject, jlong);

but i have server.h also.ie,

JNIEXPORT jintArray JNICALL Java_Server_getName
 (JNIEnv *, jobject, jlong);

what shall i do? write the native function twice???

Regards

Neena
Gordon Beaton - 21 Sep 2005 12:04 GMT
> I have two java classes, say client.java and server.java. both
> classes make a call to my native method getName(long). i made the .h
[quoted text clipped - 10 lines]
>
> what shall i do? write the native function twice???

This isn't really different than two classes needing a common Java
method, and some of the solutions are the same, regardless of the fact
that this is native code.

Here are some options:

- write separate, identical methods as you suggest.

- write a library method that contains the common code, and call it
 from each of the two methods.

- create a class containing utility methods for both Server and Client
 (or make Server and Client extend a common parent). Put the common
 native method there.

- use RegisterNatives() to associate the function pointer with both
 classes, avoiding the naming rules altogether. Note that you may
 have problems with visibility if the shared library is loaded by one
 of the classes, but it contains symbols that are needed by the other
 class.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Mike Amling - 21 Sep 2005 20:20 GMT
>>I have two java classes, say client.java and server.java. both
>>classes make a call to my native method getName(long). i made the .h
[quoted text clipped - 25 lines]
>   (or make Server and Client extend a common parent). Put the common
>   native method there.

Or have the server code call Client.getName() (or call new
Client().getName()). The client doesn't need a copy of the server code,
and it doesn't hurt the server at all to have a copy of the Client class.

> - use RegisterNatives() to associate the function pointer with both
>   classes, avoiding the naming rules altogether. Note that you may
>   have problems with visibility if the shared library is loaded by one
>   of the classes, but it contains symbols that are needed by the other
>   class.

--Mike Amling


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.