18 #define vl_api_version(n,v) static u32 vpe_api_version = (v); 19 #include <api/vpe.api.h> 24 #include <jvpp/org_openvpp_jvpp_VppJNIConnection.h> 25 #include <jvpp/org_openvpp_jvpp_JVppImpl.h> 37 #define vl_print(handle, ...) 42 #define VPPJNI_DEBUG 0 45 #define DEBUG_LOG(...) clib_warning(__VA_ARGS__) 47 #define DEBUG_LOG(...) 50 #include "gen/target/jvpp_gen.h" 60 void __stack_chk_guard (
void) __attribute__((weak));
61 void __stack_chk_guard (
void) { }
69 mp->
api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
79 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **)&(jm->
jenv), JNI_VERSION_1_8);
80 if (getEnvStat == JNI_EVERSION) {
82 jm->
retval = VNET_API_ERROR_UNSUPPORTED_JNI_VERSION;
84 }
else if (getEnvStat != JNI_EDETACHED) {
85 (*jm->
jvm)->DetachCurrentThread(jm->
jvm);
92 (JNIEnv *env, jclass obj, jstring clientName, jobject callback)
95 const char *client_name;
96 void vl_msg_reply_handler_hookup(
void);
103 return VNET_API_ERROR_NOT_RUNNING_AS_ROOT;
106 return VNET_API_ERROR_ALREADY_CONNECTED;
108 client_name = (*env)->GetStringUTFChars(env, clientName, 0);
110 return VNET_API_ERROR_INVALID_VALUE;
117 (*env)->ReleaseStringUTFChars (env, clientName, client_name);
127 jm->
callback = (*env)->NewGlobalRef(env, callback);
128 jm->
callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
133 M(CONTROL_PING, control_ping);
138 rv = VNET_API_ERROR_RESPONSE_NOT_READY;
151 DEBUG_LOG (
"clientConnect result: %d", rv);
156 (JNIEnv *env, jclass clazz)
170 char was_thread_connected = 0;
173 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **)&(jm->
jenv), JNI_VERSION_1_8);
174 if (getEnvStat == JNI_EDETACHED) {
175 if ((*jm->
jvm)->AttachCurrentThread(jm->
jvm, (
void **)&(jm->
jenv),
NULL) != 0) {
177 jm->
retval = VNET_API_ERROR_FAILED_TO_ATTACH_TO_JAVA_THREAD;
185 was_thread_connected = 1;
186 }
else if (getEnvStat == JNI_EVERSION) {
188 jm->
retval = VNET_API_ERROR_UNSUPPORTED_JNI_VERSION;
192 if (was_thread_connected == 0) {
193 JNIEnv *env = jm->
jenv;
195 jmethodID constructor = (*env)->GetMethodID(env, controlPingReplyClass,
"<init>",
"()V");
196 jmethodID callbackMethod = (*env)->GetMethodID(env, jm->
callbackClass,
"onControlPingReply",
"(Lorg/openvpp/jvpp/dto/ControlPingReply;)V");
198 jobject dto = (*env)->NewObject(env, controlPingReplyClass, constructor);
200 jfieldID contextFieldId = (*env)->GetFieldID(env, controlPingReplyClass,
"context",
"I");
201 (*env)->SetIntField(env, dto, contextFieldId, clib_net_to_host_u32(mp->
context));
203 jfieldID retvalFieldId = (*env)->GetFieldID(env, controlPingReplyClass,
"retval",
"I");
204 (*env)->SetIntField(env, dto, retvalFieldId, clib_net_to_host_u32(mp->
retval));
206 jfieldID clientIndexFieldId = (*env)->GetFieldID(env, controlPingReplyClass,
"clientIndex",
"I");
207 (*env)->SetIntField(env, dto, clientIndexFieldId, clib_net_to_host_u32(mp->
client_index));
209 jfieldID vpePidFieldId = (*env)->GetFieldID(env, controlPingReplyClass,
"vpePid",
"I");
210 (*env)->SetIntField(env, dto, vpePidFieldId, clib_net_to_host_u32(mp->
vpe_pid));
212 (*env)->CallVoidMethod(env, jm->
callback, callbackMethod, dto);
222 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
226 if (cache_class_references(env) != 0) {
231 return JNI_VERSION_1_8;
237 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
243 (*env)->DeleteGlobalRef(env, jm->
callback);
263 vl_msg_api_set_handlers(VL_API_##N, #n, \ 264 vl_api_##n##_t_handler, \ 266 vl_api_##n##_t_endian, \ 267 vl_api_##n##_t_print, \ 268 sizeof(vl_api_##n##_t), 1); int vl_client_connect_to_vlib(char *svm_name, char *client_name, int rx_queue_size)
pthread_key_t cleanup_rx_thread_key
Control ping from client to api server request.
static int connect_to_vpe(char *name)
void vl_client_disconnect_from_vlib(void)
vppjni_main_t vppjni_main
unix_shared_memory_queue_t * vl_input_queue
static void vppjni_unlock(vppjni_main_t *jm)
#define clib_warning(format, args...)
struct vl_shmem_hdr_ * shmem_hdr
always_inline f64 clib_time_now(clib_time_t *c)
static void vppjni_lock(vppjni_main_t *jm, u32 tag)
jint JNI_OnLoad(JavaVM *vm, void *reserved)
volatile u32 result_ready
void clib_time_init(clib_time_t *c)
static void cleanup_rx_thread(void *arg)
#define foreach_vpe_api_msg
void JNI_OnUnload(JavaVM *vm, void *reserved)
Control ping from the client to the server response.
JNIEXPORT jint JNICALL Java_org_openvpp_jvpp_VppJNIConnection_clientConnect(JNIEnv *env, jclass obj, jstring clientName, jobject callback)
JNIEXPORT void JNICALL Java_org_openvpp_jvpp_VppJNIConnection_clientDisconnect(JNIEnv *env, jclass clazz)
unix_shared_memory_queue_t * vl_input_queue
static void vl_api_control_ping_reply_t_handler(vl_api_control_ping_reply_t *mp)
void vl_client_add_api_signatures(vl_api_memclnt_create_t *mp)