468,247 Members | 1,328 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

Basic class question

joe
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_TestAPIMsg
#define _Included_TestAPIMsg
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestAPIMsg
* Method: SendMessageTest
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_TestAPIMsg_SendMessageTest
(JNIEnv *, jobject, jstring);

/*
* Class: TestAPIMsg
* Method: IncomingMessage
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_TestAPIMsg_IncomingMessage
(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

Mar 4 '06 #1
4 1680
TB
joe skrev:
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.
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.

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

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)?

Just add them.

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

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

/*
* Class: TestAPIMsg
* Method: IncomingMessage
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_TestAPIMsg_IncomingMessage
(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 @ SWEDEN
Mar 4 '06 #2
On Sat, 04 Mar 2006 13:22:19 GMT, "joe" <jo*@gmailNOSPAM.com> wrote:
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.
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.
2) How do I set global variables in this class (baring in mind it tells me
not to edit the header file)?
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.
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)?
Again, in the Java program's source code, then regenerate the header.
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class TestAPIMsg */

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

/*
* Class: TestAPIMsg
* Method: IncomingMessage
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_TestAPIMsg_IncomingMessage
(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


--
Bob Hairgrove
No**********@Home.com
Mar 4 '06 #3
* joe:
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.
Goodie.

I have a few questions regarding this:
I have moved to after the code.

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

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

/*
* Class: TestAPIMsg
* Method: IncomingMessage
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_TestAPIMsg_IncomingMessage
(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
1) Where is the class name defined?
This header file does not define a class.

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

It says "class TestAPIMsg" in a generated comment but I can't see
where this is set in the header file.
What /what/ is "set"?
2) How do I set global variables in this class (baring in mind it
tells me not to edit the header file)?
In which class?

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)?


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?
Mar 4 '06 #4

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_SendMessageTest
(JNIEnv *, jobject, jstring);

which might look something like:
JNIEXPORT jboolean JNICALL Java_TestAPIMsg_SendMessageTest
(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" <jo*@gmailNOSPAM.com> wrote in message
news:fw*******************@newsfe2-win.ntli.net...
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_TestAPIMsg
#define _Included_TestAPIMsg
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestAPIMsg
* Method: SendMessageTest
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_TestAPIMsg_SendMessageTest
(JNIEnv *, jobject, jstring);

/*
* Class: TestAPIMsg
* Method: IncomingMessage
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_TestAPIMsg_IncomingMessage
(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

Mar 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ramesh | last post: by
5 posts views Thread by Aussie Rules | last post: by
18 posts views Thread by Ann Scharpf via AccessMonster.com | last post: by
4 posts views Thread by MikeB | last post: by
14 posts views Thread by MartinRinehart | last post: by
9 posts views Thread by Peskov Dmitry | last post: by
3 posts views Thread by Scott Stark | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.