Basic class question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joe

    #1

    Basic class question

    I have the following header file generated by Java JNI's header file
    generator (see bottom).

    Obviously I will write a source file which will provide an implementation of
    these methods.

    I have a few questions regarding this:

    1) Where is the class name defined? Is this a C++ class? It says "class
    TestAPIMsg" in a generated comment but I can't see where this is set in the
    header file.

    2) How do I set global variables in this class (baring in mind it tells me
    not to edit the header file)?

    3) How do I add additional methods to this class i.e. ones not set in the
    header file (again baring in mind I can't edit the header)?


    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class TestAPIMsg */

    #ifndef _Included_TestA PIMsg
    #define _Included_TestA PIMsg
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    * Class: TestAPIMsg
    * Method: SendMessageTest
    * Signature: (Ljava/lang/String;)Z
    */
    JNIEXPORT jboolean JNICALL Java_TestAPIMsg _SendMessageTes t
    (JNIEnv *, jobject, jstring);

    /*
    * Class: TestAPIMsg
    * Method: IncomingMessage
    * Signature: (Ljava/lang/String;)V
    */
    JNIEXPORT void JNICALL Java_TestAPIMsg _IncomingMessag e
    (JNIEnv *, jobject, jstring);

    /*
    * Class: TestAPIMsg
    * Method: DoConnect
    * Signature: ()V
    */
    JNIEXPORT void JNICALL Java_TestAPIMsg _DoConnect
    (JNIEnv *, jobject);

    /*
    * Class: TestAPIMsg
    * Method: DoDisconnect
    * Signature: ()V
    */
    JNIEXPORT void JNICALL Java_TestAPIMsg _DoDisconnect
    (JNIEnv *, jobject);

    #ifdef __cplusplus
    }
    #endif
    #endif



  • TB

    #2
    Re: Basic class question

    joe skrev:[color=blue]
    > I have the following header file generated by Java JNI's header file
    > generator (see bottom).
    >
    > Obviously I will write a source file which will provide an implementation of
    > these methods.
    >
    > I have a few questions regarding this:
    >
    > 1) Where is the class name defined? Is this a C++ class? It says "class
    > TestAPIMsg" in a generated comment but I can't see where this is set in the
    > header file.[/color]

    The generated functions combined form a class interface even though
    there isn't a formal class definition available. Most likely "jobject"
    is a pointer to a structure of some sort that contains necessary
    instance variables.
    [color=blue]
    >
    > 2) How do I set global variables in this class (baring in mind it tells me
    > not to edit the header file)?[/color]

    What "global variables in this class"?
    [color=blue]
    >
    > 3) How do I add additional methods to this class i.e. ones not set in the
    > header file (again baring in mind I can't edit the header)?
    >[/color]

    Just add them.
    [color=blue]
    >
    > /* DO NOT EDIT THIS FILE - it is machine generated */
    > #include <jni.h>
    > /* Header for class TestAPIMsg */
    >
    > #ifndef _Included_TestA PIMsg
    > #define _Included_TestA PIMsg
    > #ifdef __cplusplus
    > extern "C" {
    > #endif
    > /*
    > * Class: TestAPIMsg
    > * Method: SendMessageTest
    > * Signature: (Ljava/lang/String;)Z
    > */
    > JNIEXPORT jboolean JNICALL Java_TestAPIMsg _SendMessageTes t
    > (JNIEnv *, jobject, jstring);
    >
    > /*
    > * Class: TestAPIMsg
    > * Method: IncomingMessage
    > * Signature: (Ljava/lang/String;)V
    > */
    > JNIEXPORT void JNICALL Java_TestAPIMsg _IncomingMessag e
    > (JNIEnv *, jobject, jstring);
    >
    > /*
    > * Class: TestAPIMsg
    > * Method: DoConnect
    > * Signature: ()V
    > */
    > JNIEXPORT void JNICALL Java_TestAPIMsg _DoConnect
    > (JNIEnv *, jobject);
    >
    > /*
    > * Class: TestAPIMsg
    > * Method: DoDisconnect
    > * Signature: ()V
    > */
    > JNIEXPORT void JNICALL Java_TestAPIMsg _DoDisconnect
    > (JNIEnv *, jobject);
    >
    > #ifdef __cplusplus
    > }
    > #endif
    > #endif
    >
    >
    >[/color]

    --
    TB @ SWEDEN

    Comment

    • Bob Hairgrove

      #3
      Re: Basic class question

      On Sat, 04 Mar 2006 13:22:19 GMT, "joe" <joe@gmailNOSPA M.com> wrote:
      [color=blue]
      >I have the following header file generated by Java JNI's header file
      >generator (see bottom).
      >
      >Obviously I will write a source file which will provide an implementation of
      >these methods.
      >
      >I have a few questions regarding this:
      >
      >1) Where is the class name defined? Is this a C++ class? It says "class
      >TestAPIMsg" in a generated comment but I can't see where this is set in the
      >header file.[/color]

      It appears to be a Java class. The header is there so that a C or C++
      program can call exported methods in the Java unit containing the
      implementation of TestAPIMsg.
      [color=blue]
      >2) How do I set global variables in this class (baring in mind it tells me
      >not to edit the header file)?[/color]

      If it is a Java class, you need to edit the Java program's source code
      so that the methods to set them are exported, then regenerate the
      header file.
      [color=blue]
      >3) How do I add additional methods to this class i.e. ones not set in the
      >header file (again baring in mind I can't edit the header)?[/color]

      Again, in the Java program's source code, then regenerate the header.
      [color=blue]
      >/* DO NOT EDIT THIS FILE - it is machine generated */
      >#include <jni.h>
      >/* Header for class TestAPIMsg */
      >
      >#ifndef _Included_TestA PIMsg
      >#define _Included_TestA PIMsg
      >#ifdef __cplusplus
      >extern "C" {
      >#endif
      >/*
      > * Class: TestAPIMsg
      > * Method: SendMessageTest
      > * Signature: (Ljava/lang/String;)Z
      > */
      >JNIEXPORT jboolean JNICALL Java_TestAPIMsg _SendMessageTes t
      > (JNIEnv *, jobject, jstring);
      >
      >/*
      > * Class: TestAPIMsg
      > * Method: IncomingMessage
      > * Signature: (Ljava/lang/String;)V
      > */
      >JNIEXPORT void JNICALL Java_TestAPIMsg _IncomingMessag e
      > (JNIEnv *, jobject, jstring);
      >
      >/*
      > * Class: TestAPIMsg
      > * Method: DoConnect
      > * Signature: ()V
      > */
      >JNIEXPORT void JNICALL Java_TestAPIMsg _DoConnect
      > (JNIEnv *, jobject);
      >
      >/*
      > * Class: TestAPIMsg
      > * Method: DoDisconnect
      > * Signature: ()V
      > */
      >JNIEXPORT void JNICALL Java_TestAPIMsg _DoDisconnect
      > (JNIEnv *, jobject);
      >
      >#ifdef __cplusplus
      >}
      >#endif
      >#endif
      >
      >[/color]

      --
      Bob Hairgrove
      NoSpamPlease@Ho me.com

      Comment

      • Alf P. Steinbach

        #4
        Re: Basic class question

        * joe:[color=blue]
        > I have the following header file generated by Java JNI's header file
        > generator (see bottom).
        >
        > Obviously I will write a source file which will provide an implementation of
        > these methods.[/color]

        Goodie.

        [color=blue]
        > I have a few questions regarding this:[/color]

        I have moved to after the code.

        [color=blue]
        > /* DO NOT EDIT THIS FILE - it is machine generated */
        > #include <jni.h>
        > /* Header for class TestAPIMsg */
        >
        > #ifndef _Included_TestA PIMsg
        > #define _Included_TestA PIMsg
        > #ifdef __cplusplus
        > extern "C" {
        > #endif
        > /*
        > * Class: TestAPIMsg
        > * Method: SendMessageTest
        > * Signature: (Ljava/lang/String;)Z
        > */
        > JNIEXPORT jboolean JNICALL Java_TestAPIMsg _SendMessageTes t
        > (JNIEnv *, jobject, jstring);
        >
        > /*
        > * Class: TestAPIMsg
        > * Method: IncomingMessage
        > * Signature: (Ljava/lang/String;)V
        > */
        > JNIEXPORT void JNICALL Java_TestAPIMsg _IncomingMessag e
        > (JNIEnv *, jobject, jstring);
        >
        > /*
        > * Class: TestAPIMsg
        > * Method: DoConnect
        > * Signature: ()V
        > */
        > JNIEXPORT void JNICALL Java_TestAPIMsg _DoConnect
        > (JNIEnv *, jobject);
        >
        > /*
        > * Class: TestAPIMsg
        > * Method: DoDisconnect
        > * Signature: ()V
        > */
        > JNIEXPORT void JNICALL Java_TestAPIMsg _DoDisconnect
        > (JNIEnv *, jobject);
        >
        > #ifdef __cplusplus
        > }
        > #endif
        > #endif[/color]

        [color=blue]
        > 1) Where is the class name defined?[/color]

        This header file does not define a class.

        [color=blue]
        > Is this a C++ class?[/color]

        Is what a C++ class? You have generated this header from Java source
        code. Presumably you have /some/ understanding of that.

        [color=blue]
        > It says "class TestAPIMsg" in a generated comment but I can't see
        > where this is set in the header file.[/color]

        What /what/ is "set"?


        [color=blue]
        > 2) How do I set global variables in this class (baring in mind it
        > tells me not to edit the header file)?[/color]

        In which class?

        [color=blue]
        > 3) How do I add additional methods to this class i.e. ones not set in[/color]
        the[color=blue]
        > header file (again baring in mind I can't edit the header)?[/color]

        Which class?


        --
        A: Because it messes up the order in which people normally read text.
        Q: Why is it such a bad thing?
        A: Top-posting.
        Q: What is the most annoying thing on usenet and in e-mail?

        Comment

        • Dave Townsend

          #5
          Re: Basic class question


          JNI doesn't generate a class or any C++ code, only the header file. The
          header file
          provides the declarations of extern "C" functions which you will have to
          implement in a shared library or DLL. If you implement things correctly,
          your java code can load the library
          at run time and call the interface functions you have written. You must
          understand that
          the functions in the interface are "free" functions (ie, not members of a
          class), but you can
          implement their functionality using classes and member functions if you
          wish. The "class"
          name appearing in the generated file is the original Java class which you
          used to generate
          the JNI interface.



          For instance, in your C/C++ you will have to implement this function:
          JNIEXPORT jboolean JNICALL Java_TestAPIMsg _SendMessageTes t
          (JNIEnv *, jobject, jstring);

          which might look something like:
          JNIEXPORT jboolean JNICALL Java_TestAPIMsg _SendMessageTes t
          (JNIEnv *, jobject, jstring)
          {
          // convert jstring into string object.....

          cout << "Received test message.....\n" ;
          }

          If you want to generate a class on the C/C++ side, you will need to add more
          functions to
          the Java JNI interface, such as createMyClass() , destroyMyClass( ), etc.

          You will not get very far unless with JNI you read the documentation for
          JNI, I'd recommend getting one of the two main books on the subject, JNI is
          a very complicated system, more complex than I could explain in an email.

          dave




          "joe" <joe@gmailNOSPA M.com> wrote in message
          news:fwgOf.2683 6$bw1.11963@new sfe2-win.ntli.net...[color=blue]
          > I have the following header file generated by Java JNI's header file
          > generator (see bottom).
          >
          > Obviously I will write a source file which will provide an implementation[/color]
          of[color=blue]
          > these methods.
          >
          > I have a few questions regarding this:
          >
          > 1) Where is the class name defined? Is this a C++ class? It says "class
          > TestAPIMsg" in a generated comment but I can't see where this is set in[/color]
          the[color=blue]
          > header file.
          >
          > 2) How do I set global variables in this class (baring in mind it tells me
          > not to edit the header file)?
          >
          > 3) How do I add additional methods to this class i.e. ones not set in the
          > header file (again baring in mind I can't edit the header)?
          >
          >
          > /* DO NOT EDIT THIS FILE - it is machine generated */
          > #include <jni.h>
          > /* Header for class TestAPIMsg */
          >
          > #ifndef _Included_TestA PIMsg
          > #define _Included_TestA PIMsg
          > #ifdef __cplusplus
          > extern "C" {
          > #endif
          > /*
          > * Class: TestAPIMsg
          > * Method: SendMessageTest
          > * Signature: (Ljava/lang/String;)Z
          > */
          > JNIEXPORT jboolean JNICALL Java_TestAPIMsg _SendMessageTes t
          > (JNIEnv *, jobject, jstring);
          >
          > /*
          > * Class: TestAPIMsg
          > * Method: IncomingMessage
          > * Signature: (Ljava/lang/String;)V
          > */
          > JNIEXPORT void JNICALL Java_TestAPIMsg _IncomingMessag e
          > (JNIEnv *, jobject, jstring);
          >
          > /*
          > * Class: TestAPIMsg
          > * Method: DoConnect
          > * Signature: ()V
          > */
          > JNIEXPORT void JNICALL Java_TestAPIMsg _DoConnect
          > (JNIEnv *, jobject);
          >
          > /*
          > * Class: TestAPIMsg
          > * Method: DoDisconnect
          > * Signature: ()V
          > */
          > JNIEXPORT void JNICALL Java_TestAPIMsg _DoDisconnect
          > (JNIEnv *, jobject);
          >
          > #ifdef __cplusplus
          > }
          > #endif
          > #endif
          >
          >
          >[/color]


          Comment

          Working...