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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef __included_vppjni_h__
16 #define __included_vppjni_h__
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/api_errno.h>
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
26 /* Unique identifier used for matching replays with requests */
27 volatile u32 context_id;
33 /* Used for first control ping */
35 volatile u32 result_ready;
38 /* JNI Native Method Interface pointer for message handlers */
42 pthread_key_t cleanup_rx_thread_key;
44 /* JNI Invoke Interface pointer for attachment of rx thread to java thread */
47 /* Callback object and class references enabling asynchronous Java calls */
51 /* Connected indication */
52 volatile u8 is_connected;
55 unix_shared_memory_queue_t * vl_input_queue;
60 vppjni_main_t vppjni_main __attribute__((aligned (64)));
62 static inline u32 vppjni_get_context_id (vppjni_main_t * jm)
64 return __sync_add_and_fetch (&jm->context_id, 1);
67 static inline void vppjni_lock (vppjni_main_t * jm, u32 tag)
69 while (__sync_lock_test_and_set (&jm->lock, 1))
74 static inline void vppjni_unlock (vppjni_main_t * jm)
77 CLIB_MEMORY_BARRIER();
81 static inline int vppjni_sanity_check (vppjni_main_t * jm)
83 if (!jm->is_connected)
84 return VNET_API_ERROR_NOT_CONNECTED;
88 // TODO remove macros (code is now fully autogenerated)
90 /* M: construct, but don't yet send a message */
93 jm->result_ready = 0; \
94 mp = vl_msg_api_alloc(sizeof(*mp)); \
95 memset (mp, 0, sizeof (*mp)); \
96 mp->_vl_msg_id = ntohs (VL_API_##T); \
97 mp->client_index = jm->my_client_index; \
102 jm->result_ready = 0; \
103 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
104 memset (mp, 0, sizeof (*mp)); \
105 mp->_vl_msg_id = ntohs (VL_API_##T); \
106 mp->client_index = jm->my_client_index; \
109 /* S: send a message */
110 #define S (vl_msg_api_send_shmem (jm->vl_input_queue, (u8 *)&mp))
112 #endif /* __included_vppjni_h__ */