summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/java/jvpp-common
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-01-27 08:57:40 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2017-01-27 19:53:59 +0000
commit4746a5d75ebb080d15d5d743dca3a85d0265176f (patch)
tree1b3d9f6ddbeed9a9b561cb688afbf67c73c9f34c /src/vpp-api/java/jvpp-common
parent32e1c010b0c34fd0984f7fc45fae648a182025c5 (diff)
jvpp: utilize per-message CRCs (VPP-544)
Since messages ids are no longer statically referenced, fixes also VPP-611. Change-Id: Ic8e6ee2b7f1142c185595347984d69350be25ac3 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'src/vpp-api/java/jvpp-common')
-rw-r--r--src/vpp-api/java/jvpp-common/jvpp_common.c16
-rw-r--r--src/vpp-api/java/jvpp-common/jvpp_common.h7
2 files changed, 23 insertions, 0 deletions
diff --git a/src/vpp-api/java/jvpp-common/jvpp_common.c b/src/vpp-api/java/jvpp-common/jvpp_common.c
index a161c09c95b..b88c0ea2197 100644
--- a/src/vpp-api/java/jvpp-common/jvpp_common.c
+++ b/src/vpp-api/java/jvpp-common/jvpp_common.c
@@ -63,3 +63,19 @@ void call_on_error(const char* callName, int contextId, int retval,
(*env)->CallVoidMethod(env, callbackObject, callbackExcMethod, excObject);
DEBUG_LOG("CallOnError : Response sent\n");
}
+
+u32 get_message_id(JNIEnv *env, const char *key) {
+ uword *p = hash_get(jvpp_main.messages_hash, key);
+ if (!p) {
+ jclass exClass = (*env)->FindClass(env, "java/lang/IllegalStateException");
+ char *msgBuf = clib_mem_alloc(strlen(key) + 40);
+ strcpy(msgBuf, "API mismatch detected: ");
+ strcat(msgBuf, key);
+ strcat(msgBuf, " is missing");
+ DEBUG_LOG("get_message_id : %s\n", msgBuf);
+ (*env)->ThrowNew(env, exClass, msgBuf);
+ clib_mem_free(msgBuf);
+ return 0;
+ }
+ return (u32) p[0];
+}
diff --git a/src/vpp-api/java/jvpp-common/jvpp_common.h b/src/vpp-api/java/jvpp-common/jvpp_common.h
index bbb203edcb4..34502d04ab8 100644
--- a/src/vpp-api/java/jvpp-common/jvpp_common.h
+++ b/src/vpp-api/java/jvpp-common/jvpp_common.h
@@ -37,6 +37,7 @@ typedef struct {
/* Convenience */
unix_shared_memory_queue_t * vl_input_queue;
u32 my_client_index;
+ uword *messages_hash;
} jvpp_main_t;
extern jvpp_main_t jvpp_main __attribute__((aligned (64)));
@@ -64,4 +65,10 @@ void call_on_error(const char* callName, int contextId, int retval,
jclass callbackClass, jobject callbackObject,
jclass callbackExceptionClass);
+/**
+ * Retrieves message id based on message name and crc (key format: name_crc).
+ * Throws java/lang/IllegalStateException on failure.
+ */
+u32 get_message_id(JNIEnv *env, const char* key);
+
#endif /* __included_jvpp_common_h__ */