Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
JNI query
- From: venkatakrishnan.kan@xxxxxxxxx (K. P. Venkatakrishnan)
- Subject: JNI query
- Date: Mon, 28 Feb 2000 15:06:37 +0530
Hello everyone,
I have a class which has two string values as data members and two
functions corresponding to each to get their values.
class ValPair{
String vp_name;
String vp_value;
public ValPair(String name, String value){
vp_name = name;
vp_value = value;
}
public String getName(){
return vp_name;
}
public String getValue(){
return vp_value;
}
}
I want to create an array of this type, initialize it using elements of
a structure obtained from my C code(one object shall have the contents
of one structure) and give this array of objects to my Java program. I
proceeded in the following manner.
typedef struct sir_packet_count{
struct sir_packet_count *next;
char name[256];
long pkt_count;
}SIR_PACKET_COUNT;
(JNIEnv *env, jobject obj){
/* returns an array of object type NameValuePair */
SIR_PACKET_COUNTS sirPktCount;
/*SIR_PACKET_COUNTS* tempsirPktCount;*/
jint result = 0;
int numOfPacketCounts;
int numOfPackets;
jobjectArray pktInfo;
int tempCount;
int i;
jmethodID mid;
jstring str;
numOfPacketCounts = 0;
numOfPackets = 0;
if((sirPktCount =
(SIR_PACKET_COUNT*)malloc(sizeof(SIR_PACKET_COUNT))) == NULL){
result = 0;
}
else{
&sirPktCount = getPacketCounts(); /* getPacketCounts()
is a C function that returns a pointer to structure of type
SIR_NAS_RADIUS_CFG*/
while(&sirPktCount != NULL){
numOfPacketCounts++;
&sirPktCount = (&sirPktCount)->next;
}
pktInfo =
(jobjectArray)((*env)->NewObjectArray(numOfPacketCounts,
(*env)->FindClass(env, "ValPair"),NULL));
for(i = 0; i < numOfPacketCounts; i++){
cls = (*env)->GetObjectArrayElement(env,
pktInfo, i);
mid = (*env)->GetMethodID(cls, "ValPair",
"(Ljava/lang/String;Ljava/lang/String;)V"); /* getting the constructor
id */
str = (*env)->NewStringUTF(env,
&sirPktCount->name);
/*
Initialize each of pktInfo array elements with a string (name) and
another string (value of pkt_counts)
*/
&sirPktCount = (&sirPktCount)->next;
}
}
}
Questions:
1) What does NewObjectArray do ? Does it do the job of a constructor ?
If so, how can I pass the parameters for the constructor.
2) I have assumed in the above lines that the constructor can be called
like a method. Is that so correct ? I am doing so, because I don't know
how to pass the variables (required for the constructor) in
NewObjectArray call.
3) How can I convert the "long pkt_count" of the structure to a String ?
4) Its a wild guess though, but does "CallMethod" correspond to the
constructor ?
Please help me out,
Awaiting an early responses from the JNI buffs,
Venkat.
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Prev by Date: Java3D Textures
- Next by Date: What is garbage collection????
- Previous by thread: Java3D Textures
- Next by thread: ODBC-JDBC bridge, and ODBC configuration
- Index(es):