FD.io VPP  v19.01.1-17-ge106252
Vector Packet Processing
jvpp_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __included_jvpp_common_h__
16 #define __included_jvpp_common_h__
17 //
18 #include <vppinfra/types.h>
19 #include <vlibapi/api.h>
20 #include <vlibapi/api_types.h>
21 #include <vlibmemory/api.h>
22 #include <jni.h>
23 
24 typedef struct {
25  /* Unique identifier used for matching replays with requests */
26  volatile u32 context_id;
27 
28  /* Spinlock */
29  volatile u32 lock;
31 
32  /* JNI Native Method Interface pointer for message handlers */
33  JNIEnv *jenv;
34 
35  /* JNI Invoke Interface pointer for attachment of rx thread to java thread */
36  JavaVM *jvm;
37 
38  /* Convenience */
42 } jvpp_main_t;
43 
44 extern jvpp_main_t jvpp_main __attribute__((aligned (64)));
45 
47  return clib_atomic_add_fetch(&jm->context_id, 1);
48 }
49 
51  while (clib_atomic_test_and_set(&jm->lock))
52  ;
53  jm->tag = tag;
54 }
55 
57  jm->tag = 0;
59  jm->lock = 0;
60 }
61 
62 /**
63  * Calls onError callback on callbackObject reference. Passes instance of callbackExceptionClass as parameter.
64  */
65 void call_on_error(const char* callName, int contextId, int retval,
66  jclass callbackClass, jobject callbackObject,
67  jclass callbackExceptionClass);
68 
69 /**
70  * Retrieves message id based on message name and crc (key format: name_crc).
71  * Throws java/lang/IllegalStateException on failure.
72  */
73 u32 get_message_id(JNIEnv *env, const char* key);
74 
75 #endif /* __included_jvpp_common_h__ */
#define clib_atomic_add_fetch(a, b)
Definition: atomics.h:30
static_always_inline u32 vppjni_get_context_id(jvpp_main_t *jm)
Definition: jvpp_common.h:46
volatile u32 lock
Definition: jvpp_common.h:29
#define static_always_inline
Definition: clib.h:99
jvpp_main_t jvpp_main
Definition: jvpp_common.c:41
unsigned int u32
Definition: types.h:88
#define clib_atomic_test_and_set(a)
Definition: atomics.h:40
u32 get_message_id(JNIEnv *env, const char *key)
Retrieves message id based on message name and crc (key format: name_crc).
Definition: jvpp_common.c:82
void call_on_error(const char *callName, int contextId, int retval, jclass callbackClass, jobject callbackObject, jclass callbackExceptionClass)
Calls onError callback on callbackObject reference.
Definition: jvpp_common.c:43
JavaVM * jvm
Definition: jvpp_common.h:36
JNIEnv * jenv
Definition: jvpp_common.h:33
static_always_inline void vppjni_lock(jvpp_main_t *jm, u32 tag)
Definition: jvpp_common.h:50
static_always_inline void vppjni_unlock(jvpp_main_t *jm)
Definition: jvpp_common.h:56
u64 uword
Definition: types.h:112
struct _svm_queue svm_queue_t
u32 my_client_index
Definition: jvpp_common.h:40
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:115
uword * messages_hash
Definition: jvpp_common.h:41
volatile u32 context_id
Definition: jvpp_common.h:26
svm_queue_t * vl_input_queue
Definition: jvpp_common.h:39