> 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