Commit 62490674 authored by Ryan Berkheimer's avatar Ryan Berkheimer

completed adding SessionUtils class

parent 6fa3b764
Pipeline #5769 failed with stages
in 0 seconds
......@@ -19,6 +19,11 @@ struct val_list
jobject jlist;
};
struct session
{
jobject jsession;
};
struct response
{
jobject jresponse;
......
#ifndef _CONDITIONUTILS_H
#define _CONDITIONUTILS_H
......
#ifndef _ENDPOINTUTILS_H
#define _ENDPOINTUTILS_H
......
#ifndef _FIELDUTILS_H
#define _FIELDUTILS_H
......
#ifndef _JNIUTILS_H
#define _JNIUTILS_H
......
#ifndef _LISTUTILS_H
#define _LISTUTILS_H
......
#ifndef _Included_MessageApiEndpoint
#define _Included_MessageApiEndpoint
......
#ifndef _PACKETUTILS_H
#define _PACKETUTILS_H
......
#ifndef _PROTOCOLRECORDUTILS_H
#define _PROTOCOLRECORDUTILS_H
......
#ifndef _RECORDUTILS_H
#define _RECORDUTILS_H
......
#ifndef _REJECTIONUTILS_H
#define _REJECTIONUTILS_H
......
#ifndef _REQUESTUTILS_H
#define _REQUESTUTILS_H
......
#ifndef _RESPONSEUTILS_H
#define _RESPONSEUTILS_H
......
#include "SessionUtils.h"
#include <jni.h>
/**
* Sessions are the top level API container of any given computation. Sessions
* bootstrap from a specification map and 'lock-in' a computation environment,
* allowing requests to be created.
*
* @author Ryan Berkheimer
*/
/* Default Constructor */
SessionUtils::SessionUtils(JNIEnv *jvm)
{
this->loadGlobalRefs(jvm);
this->loadMethodIds();
}
/* Default Destructor */
SessionUtils::~SessionUtils()
{
try
{}
catch (const std::exception &e)
{
std::cout << e.what();
}
}
/* Public API */
struct request *SessionUtils::createRequest(struct session *session)
{
jobject jrequest = this->jvm->CallObjectMethod(session->jsession, this->createRequestMethodId);
struct request *request = (struct request *)malloc(sizeof(struct request) + sizeof(jrequest));
request->jrequest = jrequest;
return request;
}
/* Private Methods */
void SessionUtils::loadGlobalRefs(JNIEnv *jvm)
{
this->jvm = jvm;
}
void SessionUtils::loadMethodIds()
{
jclass sessionClass = JniUtils::getNamedClass(this->jvm, "gov/noaa/messageapi/interfaces/ISession");
this->createRequestMethodId = JniUtils::getMethod(this->jvm, sessionClass, "createRequest", this->getMethodSignature("createRequest"), false);
jvm->DeleteLocalRef(sessionClass);
}
const char *SessionUtils::getMethodSignature(const char *methodName)
{
if (strcmp(methodName, "createRequest") == 0)
{
return "()Lgov/noaa/messageapi/interfaces/IRequest;";
}
return NULL;
}
\ No newline at end of file
#ifndef _SESSIONUTILS_H
#define _SESSIONUTILS_H
#include <jni.h>
#include <stdbool.h>
#include "messageapi_structs.h"
#ifdef __cplusplus
#include <iostream>
#include <string>
#include "JniUtils.h"
/**
* Sessions are the top level API container of any given computation. Sessions
* bootstrap from a specification map and 'lock-in' a computation environment,
* allowing requests to be created.
*
* @author Ryan Berkheimer
*/
class SessionUtils
{
public:
/*Default constructor */
SessionUtils(JNIEnv *javaEnv);
/*Default Destructor */
~SessionUtils();
/* Session Methods */
struct request *createRequest(struct session *session);
private:
/*Vars*/
JNIEnv *jvm;
/*Request Methods*/
jmethodID createRequestMethodId;
/*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);
/*Grouped methods for returning the matching method signature string for a given interface*/
const char *getMethodSignature(const char *methodName);
};
extern "C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif
#ifndef _TYPEUTILS_H
#define _TYPEUTILS_H
......
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