5 if [ "$JNI_PATH" = "" ]; then
6 echo "No jni path given!"
13 echo -e "/* Important to get consistent size_t type */"
14 echo -e "#define _FILE_OFFSET_BITS 64"
16 echo -e "#include <jni.h>"
17 echo -e "#include <ltt/trace.h>"
18 echo -e "#include <ltt/time.h>"
19 echo -e "#include <ltt/marker.h>"
20 echo -e "#include <glib.h>"
22 echo -e "#include <stdlib.h>"
23 echo -e "#include <stdio.h>"
24 echo -e "#include <string.h>"
25 echo -e "#include <stdint.h>"
26 echo -e "#include <dlfcn.h>"
28 echo -e "int nb_id = 0;"
30 echo -e "struct version_correlation {"
32 echo -e " char *libname;"
33 echo -e " void *static_handle;"
36 echo -e "struct version_correlation *version_table = NULL;"
38 echo -e "struct function_tables {"
39 for x
in `grep JNIEXPORT $JNI_PATH | grep -v getTraceVersion | sed -e "s/{//g" | sed -e "s/ /#/g"`; do
40 echo -e " `echo $x | sed -e "s
/#/ /g" | sed -e "s/JNICALL.*/JNICALL/g"` (*`echo $x | sed -e "s/#/ /g" | sed -e "s/.*JNICALL //g" | cut -d\( -f1 | sed -e "s/ / /g"`)(`echo $x | sed -e "s/#/ /g" | cut -d\( -f2 | sed -e "s/ / /g" | sed -e "s/) /)/g"`;"
44 echo -e "struct function_tables *version_functions_table = NULL;"
46 echo -e "void ignore_and_drop_message(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) {"
49 echo -e "JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_factory_JniTraceVersion_ltt_1getTraceVersion(JNIEnv *env, jobject jobj, jstring tracepath) {"
51 echo -e " void *handle = dlopen(\"liblttvtraceread.so\", RTLD_LAZY );"
53 echo -e " if (!handle ) {"
54 echo -e " printf (\"WARNING : Failed to initialize library handle from %s!\\\n\", \"liblttvtraceread.so\");"
56 echo -e " JNIEXPORT void JNICALL (*functor)(JNIEnv *env, jobject jobj, jstring tracepath);"
57 echo -e " functor=dlsym(handle, \"Java_org_eclipse_linuxtools_lttng_jni_factory_JniTraceVersion_ltt_1getTraceVersion\");"
59 echo -e " char *error = dlerror();"
60 echo -e " if ( error != NULL) {"
61 echo -e " printf (\"Call failed with : %s\\\n\", error);"
64 echo -e " (*functor)(env, jobj, tracepath);"
68 echo -e "void freeAllHandle() {"
69 echo -e " if ( version_table != NULL ) {"
70 echo -e " free(version_table);"
71 echo -e " version_table = NULL;"
74 echo -e " if ( version_functions_table != NULL ) {"
75 echo -e " free(version_functions_table);"
76 echo -e " version_functions_table = NULL;"
80 echo -e "void freeHandle(int handle_id) {"
81 echo -e " if ( handle_id >= nb_id ) {"
82 echo -e " if (version_table[handle_id].static_handle != NULL) {"
83 echo -e " /* Memory will be freed by dlclose as well */"
84 echo -e " dlclose(version_table[handle_id].static_handle);"
85 echo -e " version_table[handle_id].static_handle = NULL;"
86 echo -e " free(version_table[handle_id].libname);"
87 echo -e " version_table[handle_id].libname = NULL;"
91 echo -e " int isEmpty = 1;"
93 echo -e " for ( n=0; n<nb_id; n++) {"
94 echo -e " if ( version_table[n].static_handle != NULL ) {"
95 echo -e " isEmpty = 0;"
99 echo -e " if ( isEmpty == 1 ) {"
100 echo -e " freeAllHandle();"
104 echo -e "JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1freeHandle(JNIEnv *env, jobject jobj, jint lib_id) {"
105 echo -e " /* Call function to free the memory */"
106 echo -e " freeHandle(lib_id);"
109 echo -e "JNIEXPORT jint JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1initializeHandle(JNIEnv *env, jobject jobj, jstring libname) {"
111 echo -e " jint lib_id = -1;"
112 echo -e " const char* c_path = (*env)->GetStringUTFChars(env, libname, 0);"
114 echo -e " int isLoaded = 0;"
116 echo -e " for ( n=0; n<nb_id; n++) {"
117 echo -e " if ( strncmp(version_table[n].libname, c_path, strlen(version_table[n].libname) ) == 0 ) {"
118 echo -e " isLoaded = 1;"
119 echo -e " lib_id = version_table[n].id;"
123 echo -e " if ( isLoaded == 0 ) {"
124 echo -e " void *new_handle = dlopen(c_path, RTLD_LAZY );"
126 echo -e " if (!new_handle ) {"
127 echo -e " printf (\"WARNING : Failed to initialize library handle from %s!\\\n\", c_path);"
130 echo -e " lib_id = nb_id;"
133 echo -e " void* new_version_table = malloc(sizeof(struct version_correlation)*(nb_id) );"
134 echo -e " void* new_function_tables = malloc(sizeof(struct function_tables)*(nb_id) );"
136 echo -e " if ( nb_id > 1) {"
137 echo -e " memcpy(new_version_table,version_table, sizeof(struct version_correlation)*(nb_id-1) );"
138 echo -e " free( version_table );"
140 echo -e " memcpy(new_function_tables,version_functions_table, sizeof(struct function_tables)*(nb_id-1) );"
141 echo -e " free( version_functions_table);"
144 echo -e " version_table = (struct version_correlation *)new_version_table;"
145 echo -e " version_table[lib_id].id = lib_id;"
146 echo -e " version_table[lib_id].libname = (char*)malloc( strlen(c_path) );"
147 echo -e " strncpy(version_table[lib_id].libname, c_path, strlen(c_path));"
148 echo -e " version_table[lib_id].static_handle = new_handle;"
150 echo -e " version_functions_table = (struct function_tables*)new_function_tables;"
152 for x
in `grep JNIEXPORT $JNI_PATH | grep -v getTraceVersion |sed -e "s/{//g" | sed -e "s/ /#/g"`; do
153 echo -e " version_functions_table[lib_id].`echo $x | sed -e "s
/#/ /g" | sed -e "s/.*JNICALL //g" | cut -d\( -f1 | sed -e "s/ / /g"` = dlsym(version_table[lib_id].static_handle, \"`echo $x | sed -e "s/#/ /g" | sed -e "s/.*JNICALL //g" | cut -d\( -f1 | sed -e "s/ / /g"`\");"
158 echo -e " return lib_id;"
162 for x
in `grep JNIEXPORT $JNI_PATH | grep -v getTraceVersion | sed -e "s/{//g" | sed -e "s/ /#/g"`; do
163 echo -e "` echo $x | sed -e "s
/#/ /g" | sed -e "s/ / /g" | sed -e "s/env, jobject jobj,/env, jobject jobj, jint lib_id,/g" | sed -e "s/env, jclass accessClass,/env, jclass accessClass, jint lib_id,/g"`{";
165 TEST
=`echo $x | sed -e "s/#/ /g" | awk {print'$2'}`
167 ARG
=`echo $x | sed -e "s/#/ /g" | cut -d\( -f2 | sed -e "s/JNIEnv \*//g" | sed -e "s/jobject//g" | sed -e "s/jstring//g" | sed -e "s/jlong//g" | sed -e "s/jint//g" | sed -e "s/jclass//g" | sed -e "s/jboolean//g" | sed -e "s/jbyteArray//g" | sed -e "s/ / /g" | sed -e "s/) /)/g"`
169 if [ "$TEST" = "void" ]; then
170 echo -e " (version_functions_table[lib_id].`echo $x | sed -e "s
/#/ /g" | sed -e "s/.*JNICALL //g" | cut -d\( -f1 | sed -e "s/ / /g"`)($ARG;"
172 echo -e " return (version_functions_table[lib_id].`echo $x | sed -e "s
/#/ /g" | sed -e "s/.*JNICALL //g" | cut -d\( -f1 | sed -e "s/ / /g"`)($ARG;"
This page took 0.044795 seconds and 4 git commands to generate.