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 / General / July 2007

Tip: Looking for answers? Try searching our database.

JNIWrapper Help

Thread view: 
paul.h.burns - 23 Jul 2007 13:48 GMT
Hopefully someone can help me with this problem.
I am trying to write a wrapper class for a C library, using the
JNIWrapper library.
I understand how to use the Pointer class, but what I'm not sure about
is how to wrap funciton pointers.
Specifically, in the C library there are several structures defined as
follows

struct vtable {
   getValue_proto getValue;  /* A function to get the current value
*/
   ...
   ...                                   /* Similar functions */
   ...
};

struct quantity {
   Quantity_getVTable getVTable  /* a function to get the vtable */
   ...
   ...           /* Misc. items related to the quantity  */
};

Then there are several type definitions:
typedef vtable * (*Quantity_getVTable)();
typedef double (*getValue_proto) (quantity *quant, ...);

I've set up four seperate classes using JNIWrapper.  Two to extend the
Structure class, and two extending Callback (which is what I assume
one is supposed to do with function pointers, though I'm not really
sure.)
Thus:
public class vtable extends Structure
{
   public Pointer getValue = new Pointer(new getValue_proto());
   ...
}
public class quantity extends Structure
{
   public Pointer getVTable = new Pointer(new Quantity_getVTable());
   ...
}
public class Quantity_getVTable extends Callback
{
   public Pointer retVal = new Pointer(new vtable());
   ...
}
public class getValue_proto extends Callback
{
   public Pointer quant = new Pointer(new quantity());
   ...
}

Doing things this way introduces a stack overflow as the classes are
now circularly dependent.  So, my question is, how are virtual
functions supposed to be implemented within JNIWrapper in order to
solve this problem?
If this is the wrong forum to post, please let me know where I should
redirect this to.

Thanks,
Paul
Roedy Green - 23 Jul 2007 19:36 GMT
On Mon, 23 Jul 2007 05:48:29 -0700, "paul.h.burns"
<paul.h.burns@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>Doing things this way introduces a stack overflow as the classes are
>now circularly dependent.  So, my question is, how are virtual
>functions supposed to be implemented within JNIWrapper in order to
>solve this problem?

The equivalent animal in Java is a Delegate class with a single
method.  Perhaps you can wrap the C method into a Delegate C++ class.

see http://mindprod.com/jgloss/delegate.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

paul.h.burns - 23 Jul 2007 20:23 GMT
On Jul 23, 2:36 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Mon, 23 Jul 2007 05:48:29 -0700, "paul.h.burns"
> <paul.h.bu...@gmail.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 12 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

Thanks for the reply.  I might have to give that a shot if what I've
managed to hack together doesn't work.

-Paul


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.