-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jrhea/feat-create_vm
jni working for ingress
- Loading branch information
Showing
23 changed files
with
204 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
**/.DS_Store | ||
*.code-workspace | ||
*.vscode | ||
jni.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include "mothra.h" | ||
|
||
void receive_gossip(char* message) { | ||
printf("C: received this message from another peer - %s\n",message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
bindings/java/mothra-jni.c → bindings/java/mothra-jni-egress.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <jni.h> | ||
#ifndef _MOTHRA_JNI_EGRESS_H_ | ||
#define _MOTHRA_JNI_EGRESS_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
JNIEXPORT void JNICALL Java_mothra_Start(JNIEnv *, jclass, jobjectArray); | ||
JNIEXPORT void JNICALL Java_mothra_SendGossip(JNIEnv *, jclass, jstring); | ||
|
||
extern void libp2p_start(char**, int); | ||
extern void libp2p_send_gossip(char*); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // _MOTHRA_JNI_EGRESS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <assert.h> | ||
#include "mothra-jni-ingress.h" | ||
|
||
static JavaVM *jvm; | ||
|
||
JNIEXPORT void JNICALL Java_mothra_Init(JNIEnv* jenv, jclass jcls) | ||
{ | ||
jint rs = (*jenv)->GetJavaVM(jenv, &jvm); | ||
assert (rs == JNI_OK); | ||
} | ||
|
||
void receive_gossip(char* message) { | ||
JNIEnv *jenv; | ||
jint rs = (*jvm)->AttachCurrentThread(jvm, (void**)&jenv, NULL); | ||
assert (rs == JNI_OK); | ||
if(jenv != NULL) { | ||
jclass mothra_class; | ||
jmethodID receivegossip_method; | ||
jstring jmessage; | ||
mothra_class = (*jenv)->FindClass(jenv, "mothra"); | ||
if(!mothra_class){ | ||
detach(jenv); | ||
} | ||
jmessage = (*jenv)->NewStringUTF(jenv, message); | ||
if(!jmessage){ | ||
detach(jenv); | ||
} | ||
receivegossip_method = (*jenv)->GetStaticMethodID(jenv, mothra_class, "ReceiveGossip", "(Ljava/lang/String;)V"); | ||
if(!receivegossip_method){ | ||
detach(jenv); | ||
} | ||
(*jenv)->CallStaticVoidMethod(jenv, mothra_class, receivegossip_method, jmessage); | ||
} | ||
} | ||
|
||
void detach(JNIEnv* jenv){ | ||
if((*jenv)->ExceptionOccurred(jenv)) { | ||
(*jenv)->ExceptionDescribe(jenv); | ||
} | ||
(*jvm)->DetachCurrentThread(jvm); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <jni.h> | ||
#ifndef _MOTHRA_JNI_INGRESS_H_ | ||
#define _MOTHRA_JNI_INGRESS_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
JNIEXPORT void JNICALL Java_mothra_Init(JNIEnv*,jclass); | ||
|
||
void receive_gossip(char*); | ||
|
||
void detach(JNIEnv* ); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // _MOTHRA_JNI_INGRESS_H_ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.