Commit ab3c74b3 authored by Ryan Berkheimer's avatar Ryan Berkheimer

completed adding code for native session. now needs wrapper, build process,...

completed adding code for native session. now needs wrapper, build process, and tests before feature is complete
parent d28f6028
Pipeline #5776 failed with stages
in 0 seconds
......@@ -8,116 +8,116 @@
* @author Ryan Berkheimer
*/
struct map_val
typedef struct map_val
{
jobject jval;
};
} map_val;
struct val_map
typedef struct val_map
{
jobject jmap;
};
} val_map;
struct list_item
typedef struct list_item
{
jobject jitem;
};
} list_item;
struct val_list
typedef struct val_list
{
int count;
jobject jlist;
};
} val_list;
struct session
typedef struct session
{
jobject jsession;
};
jlong sessionLib;
} session;
struct transformation
typedef struct transformation
{
jobject jtransformation;
};
} transformation;
struct transformation_map
typedef struct transformation_map
{
jobject jtransformation_map;
};
} transformation_map;
struct response
typedef struct response
{
jobject jresponse;
};
} response;
struct request
typedef struct request
{
jobject jrequest;
};
} request;
struct condition
typedef struct condition
{
jobject jcondition;
};
} condition;
struct condition_list
typedef struct condition_list
{
int count;
struct condition **conditions;
};
struct val
} condition_list;
typedef struct val
{
jobject jvalue;
};
} val;
struct field
typedef struct field
{
jobject jfield;
};
} field;
struct field_list
typedef struct field_list
{
int count;
struct field **fields;
};
} field_list;
struct packet
typedef struct packet
{
jobject jpacket;
};
} packet;
struct record
typedef struct record
{
jobject jrecord;
};
} record;
struct rejection_list
typedef struct rejection_list
{
int count;
jobject jrejections;
};
struct rejection
} rejection_list;
typedef struct rejection
{
jobject jrejection;
};
} rejection;
struct record_list
typedef struct record_list
{
int count;
jobject jrecords;
};
} record_list;
struct string_list
typedef struct string_list
{
int count;
int max_length;
char **strings;
};
} string_list;
struct classifier
typedef struct classifier
{
char* key;
char* val;
};
} classifier;
#endif
\ No newline at end of file
......@@ -14,22 +14,22 @@ JNIEXPORT jobject JNICALL Java_gov_noaa_messageapi_endpoints_NativeEndpoint_proc
{
printf("In our test!\n");
printf("Hello, World\n");
struct record_list* default_record_list = getRecords(message);
record_list* default_record_list = getRecords(message);
//struct record_list* classifier_record_list = getRecordsByClassifier(message, "color", "blue");
//struct record_list* collection_record_list = getRecordsByCollection(message, "gold");
//struct record_list* transformation_record_list = getRecordsByTransformation(message, "combine-colors");
printf("Record count: %d\n", default_record_list->count);
struct string_list* default_field_name_list = getFieldIds(message, getRecord(message, default_record_list, 0));
string_list* default_field_name_list = getFieldIds(message, getRecord(message, default_record_list, 0));
printf("Field name count: %d\n", default_field_name_list->count);
printf("Length of longest field name: %d\n", default_field_name_list->max_length);
for (int i = 0; i < default_field_name_list->count; i++) {
printf("Field name: %s\n", default_field_name_list->strings[i]);
}
fflush(stdout);
struct field *testField = getField(message, getRecord(message, default_record_list, 0), "initial-value");
struct field *testField2 = getField(message, getRecord(message, default_record_list, 0), "string-test");
struct field *testField3 = getField(message, getRecord(message, default_record_list, 0), "int-list-test");
struct field *testField4 = getField(message, getRecord(message, default_record_list, 0), "null-test");
field *testField = getField(message, getRecord(message, default_record_list, 0), "initial-value");
field *testField2 = getField(message, getRecord(message, default_record_list, 0), "string-test");
field *testField3 = getField(message, getRecord(message, default_record_list, 0), "int-list-test");
field *testField4 = getField(message, getRecord(message, default_record_list, 0), "null-test");
const char *testFieldId = getFieldId(message, testField);
const char *testFieldId2 = getFieldId(message, testField2);
const char *testFieldId3 = getFieldId(message, testField3);
......@@ -53,10 +53,11 @@ JNIEXPORT jobject JNICALL Java_gov_noaa_messageapi_endpoints_NativeEndpoint_proc
printf("Field integer value is %d\n", integerFieldValue);
const char *stringFieldValue = getFieldStringVal(message, testField2);
printf("Field string value 2 is: %s\n", stringFieldValue);
struct val_list *val_list = getFieldListVal(message, testField3);
printf("Field value 3 (list) length is: %d\n", val_list->count);
for (int i = 0; i < val_list->count; i++) {
printf("Field value 3, element %d, is: %d\n", i, getIntItem(message, val_list, i));
val_list *fieldList = getFieldListVal(message, testField3);
printf("Field value 3 (list) length is: %d\n", fieldList->count);
for (int i = 0; i < fieldList->count; i++)
{
printf("Field value 3, element %d, is: %d\n", i, getIntItem(message, fieldList, i));
}
fflush(stdout);
if (getFieldIsNull(message, testField4)) {
......@@ -65,8 +66,8 @@ JNIEXPORT jobject JNICALL Java_gov_noaa_messageapi_endpoints_NativeEndpoint_proc
printf("Field val 4 has a value!\n");
}
fflush(stdout);
struct record *returnRecord = createRecord(message);
struct string_list *fieldIds = getFieldIds(message, returnRecord);
record *returnRecord = createRecord(message);
string_list *fieldIds = getFieldIds(message, returnRecord);
printf("field ids for return field follow. \n");
for (int i=0; i < fieldIds->count; i++) {
printf("Field name: %s\n", fieldIds->strings[i]);
......@@ -81,17 +82,17 @@ JNIEXPORT jobject JNICALL Java_gov_noaa_messageapi_endpoints_NativeEndpoint_proc
}
}
fflush(stdout);
printf("Creating a string list..\n");
struct val_list *return_val_list = createList(message);
addStringItem(message, return_val_list, "first element of our string!");
addStringItem(message, return_val_list, "second element of our string!!");
printf("Creating a value list to hold strings..\n");
val_list *returnList = createList(message);
addStringItem(message, returnList, "first element of our string!");
addStringItem(message, returnList, "second element of our string!!");
printf("Created a string list.\n");
setFieldListVal(message, getField(message, returnRecord, "return-list"), return_val_list);
printf("First value added to the return-list field: %s\n", getStringItem(message, return_val_list, 0));
printf("Second value added to the return-list field: %s\n", getStringItem(message, return_val_list, 1));
setFieldListVal(message, getField(message, returnRecord, "return-list"), returnList);
printf("First value added to the return-list field: %s\n", getStringItem(message, returnList, 0));
printf("Second value added to the return-list field: %s\n", getStringItem(message, returnList, 1));
printf("Added the string list to the return record. Should have two elements, see above.\n");
fflush(stdout);
struct packet* packet = createPacket(message);
packet* packet = createPacket(message);
addPacketRecord(message, packet, returnRecord);
printf("Leaving our C test!");
fflush(stdout);
......
......@@ -11,7 +11,7 @@ int main(int argc, char **argv)
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
//jstring jstr;
jobjectArray main_args;
//vm_args.version = JNI_V
......@@ -37,7 +37,7 @@ int main(int argc, char **argv)
return 1;
}
jstr = (*env)->NewStringUTF(env, "");
jstring jstr = (*env)->NewStringUTF(env, "");
main_args = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), jstr);
(*env)->CallStaticVoidMethod(env, cls, mid, main_args);
......
#include <jni.h>
#include <stdio.h>
//#include "messageapi_structs.h"
//#include "MessageApiSessionLib.h"
int main(int argc, char **argv)
{
printf("In our native session demo test!\n");
printf("Hello, World\n");
fflush(stdout);
return 0;
}
\ No newline at end of file
#!/bin/bash
gcc NativeSessionDemo.c -I$(/usr/libexec/java_home)/include/ -I$(/usr/libexec/java_home)/include/darwin -L$(/usr/libexec/java_home)/jre/lib/jli -L$(/usr/libexec/java_home)/jre/lib/server/ -ljli -ljvm
......@@ -15,7 +15,7 @@ JNIEXPORT jobject JNICALL Java_gov_noaa_messageapi_transformations_NativeTransfo
printf("In our transformation test!\n");
printf("Hello, World\n");
fflush(stdout);
struct record_list *records = getRecords(message, "test_key");
record_list *records = getRecords(message, "test_key");
printf("Record count: %d\n", records->count);
fflush(stdout);
return records->jrecords;
......
This diff is collapsed.
#include "MessageApiSession.h"
#include <iostream>
#include <string>
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
Constructor for the MessageApiEndpoint object. Takes a JNI environment pointer, an endpoint context (this refers to
the endpoint class that's instantiating the object), and a protocol record which holds containers of records.
*/
MessageApiSession::MessageApiSession(JNIEnv *env, jobject session)
{
this->jvm = env;
this->session = this->jvm->NewGlobalRef(session);
this->typeUtils = new TypeUtils(this->jvm);
this->listUtils = new ListUtils(this->jvm, typeUtils);
this->mapUtils = new MapUtils(this->jvm, typeUtils);
this->sessionUtils = new SessionUtils(this->jvm, this->session);
this->requestUtils = new RequestUtils(this->jvm, this->typeUtils, this->listUtils);
this->responseUtils = new ResponseUtils(this->jvm, this->typeUtils, this->listUtils);
this->recordUtils = new RecordUtils(this->jvm, this->typeUtils, this->listUtils);
this->rejectionUtils = new RejectionUtils(this->jvm, this->typeUtils, this->listUtils);
this->fieldUtils = new FieldUtils(this->jvm, this->typeUtils, this->listUtils, this->mapUtils);
this->conditionUtils = new ConditionUtils(this->jvm, this->typeUtils, this->listUtils, this->mapUtils);
this->packetUtils = new PacketUtils(this->jvm, this->listUtils);
}
MessageApiSession::~MessageApiSession()
{
try
{
delete this->sessionUtils;
delete this->requestUtils;
delete this->responseUtils;
delete this->recordUtils;
delete this->rejectionUtils;
delete this->fieldUtils;
delete this->conditionUtils;
delete this->packetUtils;
delete this->listUtils;
delete this->mapUtils;
delete this->typeUtils;
this->jvm->DeleteGlobalRef(this->session);
}
catch (const std::exception &e)
{
std::cout << e.what();
}
}
SessionUtils *MessageApiSession::getSessionUtils()
{
return this->sessionUtils;
}
RequestUtils *MessageApiSession::getRequestUtils()
{
return this->requestUtils;
}
ResponseUtils *MessageApiSession::getResponseUtils()
{
return this->responseUtils;
}
RecordUtils *MessageApiSession::getRecordUtils()
{
return this->recordUtils;
}
RejectionUtils *MessageApiSession::getRejectionUtils()
{
return this->rejectionUtils;
}
FieldUtils *MessageApiSession::getFieldUtils()
{
return this->fieldUtils;
}
ConditionUtils *MessageApiSession::getConditionUtils()
{
return this->conditionUtils;
}
PacketUtils *MessageApiSession::getPacketUtils()
{
return this->packetUtils;
}
ListUtils *MessageApiSession::getListUtils()
{
return this->listUtils;
}
MapUtils *MessageApiSession::getMapUtils()
{
return this->mapUtils;
}
TypeUtils *MessageApiSession::getTypeUtils()
{
return this->typeUtils;
}
#ifndef _Included_MessageApiSession
#define _Included_MessageApiSession
#include <jni.h>
#include <stdbool.h>
#include "messageapi_structs.h"
#ifdef __cplusplus
#include <iostream>
#include <string>
#include "JniUtils.h"
#include "MapUtils.h"
#include "ListUtils.h"
#include "SessionUtils.h"
#include "RequestUtils.h"
#include "ResponseUtils.h"
#include "RecordUtils.h"
#include "RejectionUtils.h"
#include "FieldUtils.h"
#include "ConditionUtils.h"
#include "PacketUtils.h"
/**
* @author Ryan Berkheimer
*/
class MessageApiSession
{
public:
/*Default constructor*/
MessageApiSession(JNIEnv *javaEnv, jobject jSession);
/*Default destructor*/
~MessageApiSession();
/*Utils Accessors*/
SessionUtils *getSessionUtils();
RequestUtils *getRequestUtils();
ResponseUtils *getResponseUtils();
RecordUtils *getRecordUtils();
RejectionUtils *getRejectionUtils();
FieldUtils *getFieldUtils();
ConditionUtils *getConditionUtils();
PacketUtils *getPacketUtils();
ListUtils *getListUtils();
MapUtils *getMapUtils();
TypeUtils *getTypeUtils();
private :
/*Global References*/
JNIEnv *jvm;
jobject session;
SessionUtils *sessionUtils;
RequestUtils *requestUtils;
ResponseUtils *responseUtils;
RecordUtils *recordUtils;
RejectionUtils *rejectionUtils;
FieldUtils *fieldUtils;
ConditionUtils *conditionUtils;
PacketUtils *packetUtils;
TypeUtils *typeUtils;
ListUtils *listUtils;
MapUtils *mapUtils;
};
extern "C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -11,9 +11,9 @@
*/
/* Default Constructor */
SessionUtils::SessionUtils(JNIEnv *jvm)
SessionUtils::SessionUtils(JNIEnv *jvm, jobject session)
{
this->loadGlobalRefs(jvm);
this->loadGlobalRefs(jvm, session);
this->loadMethodIds();
}
......@@ -30,9 +30,9 @@ SessionUtils::~SessionUtils()
/* Public API */
struct request *SessionUtils::createRequest(struct session *session)
struct request *SessionUtils::createRequest()
{
jobject jrequest = this->jvm->CallObjectMethod(session->jsession, this->createRequestMethodId);
jobject jrequest = this->jvm->CallObjectMethod(this->session, this->createRequestMethodId);
struct request *request = (struct request *)malloc(sizeof(struct request) + sizeof(jrequest));
request->jrequest = jrequest;
return request;
......@@ -40,9 +40,10 @@ struct request *SessionUtils::createRequest(struct session *session)
/* Private Methods */
void SessionUtils::loadGlobalRefs(JNIEnv *jvm)
void SessionUtils::loadGlobalRefs(JNIEnv *jvm, jobject session)
{
this->jvm = jvm;
this->session = session;
}
void SessionUtils::loadMethodIds()
......
......@@ -23,17 +23,18 @@ class SessionUtils
public:
/*Default constructor */
SessionUtils(JNIEnv *javaEnv);
SessionUtils(JNIEnv *javaEnv, jobject jSession);
/*Default Destructor */
~SessionUtils();
/* Session Methods */
struct request *createRequest(struct session *session);
struct request *createRequest();
private:
/*Vars*/
JNIEnv *jvm;
jobject session;
/*Request Methods*/
jmethodID createRequestMethodId;
......@@ -41,7 +42,7 @@ private:
/*Load method IDS for reuse. MethodIDS do not count against the jref count and do need to be released.*/
void loadMethodIds();
void loadGlobalRefs(JNIEnv *env);
void loadGlobalRefs(JNIEnv *env, jobject session);
/*Grouped methods for returning the matching method signature string for a given interface*/
const char *getMethodSignature(const char *methodName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment