Update the README file to mark the project as unmaintained
[lttv.git] / scripts / autogen_lttvtraceread_loader.sh
CommitLineData
f75974d3
PMF
1#!/bin/bash
2
3JNI_PATH="$1"
4
5if [ "$JNI_PATH" = "" ]; then
6 echo "No jni path given!"
7 exit 1
8fi
9
10
11
12echo -e ""
13echo -e "/* Important to get consistent size_t type */"
14echo -e "#define _FILE_OFFSET_BITS 64"
15echo -e ""
16echo -e "#include <jni.h>"
17echo -e "#include <ltt/trace.h>"
18echo -e "#include <ltt/time.h>"
19echo -e "#include <ltt/marker.h>"
20echo -e "#include <glib.h>"
21echo -e ""
22echo -e "#include <stdlib.h>"
23echo -e "#include <stdio.h>"
24echo -e "#include <string.h>"
25echo -e "#include <stdint.h>"
26echo -e "#include <dlfcn.h>"
27echo -e ""
28echo -e "int nb_id = 0;"
29echo -e ""
30echo -e "struct version_correlation {"
31echo -e " int id;"
32echo -e " char *libname;"
33echo -e " void *static_handle;"
34echo -e "};"
35echo -e ""
36echo -e "struct version_correlation *version_table = NULL;"
37echo -e ""
38echo -e "struct function_tables {"
39for 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"`;"
41done
42echo -e "};"
43echo -e ""
44echo -e "struct function_tables *version_functions_table = NULL;"
45echo -e ""
46echo -e "void ignore_and_drop_message(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) {"
47echo -e "}"
48echo -e ""
49echo -e "JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_factory_JniTraceVersion_ltt_1getTraceVersion(JNIEnv *env, jobject jobj, jstring tracepath) {"
50echo -e ""
51echo -e " void *handle = dlopen(\"liblttvtraceread.so\", RTLD_LAZY );"
52echo -e ""
53echo -e " if (!handle ) {"
54echo -e " printf (\"WARNING : Failed to initialize library handle from %s!\\\n\", \"liblttvtraceread.so\");"
55echo -e " }"
56echo -e " JNIEXPORT void JNICALL (*functor)(JNIEnv *env, jobject jobj, jstring tracepath);"
57echo -e " functor=dlsym(handle, \"Java_org_eclipse_linuxtools_lttng_jni_factory_JniTraceVersion_ltt_1getTraceVersion\");"
58echo -e ""
59echo -e " char *error = dlerror();"
60echo -e " if ( error != NULL) {"
61echo -e " printf (\"Call failed with : %s\\\n\", error);"
62echo -e " }"
63echo -e " else {"
64echo -e " (*functor)(env, jobj, tracepath);"
65echo -e " }"
66echo -e "}"
67echo -e ""
68echo -e "void freeAllHandle() {"
69echo -e " if ( version_table != NULL ) {"
70echo -e " free(version_table);"
71echo -e " version_table = NULL;"
72echo -e " }"
73echo -e ""
74echo -e " if ( version_functions_table != NULL ) {"
75echo -e " free(version_functions_table);"
76echo -e " version_functions_table = NULL;"
77echo -e " }"
78echo -e "}"
79echo -e ""
80echo -e "void freeHandle(int handle_id) {"
81echo -e " if ( handle_id >= nb_id ) {"
82echo -e " if (version_table[handle_id].static_handle != NULL) {"
83echo -e " /* Memory will be freed by dlclose as well */"
84echo -e " dlclose(version_table[handle_id].static_handle);"
85echo -e " version_table[handle_id].static_handle = NULL;"
86echo -e " free(version_table[handle_id].libname);"
87echo -e " version_table[handle_id].libname = NULL;"
88echo -e " }"
89echo -e " }"
90echo -e ""
91echo -e " int isEmpty = 1;"
92echo -e " int n;"
93echo -e " for ( n=0; n<nb_id; n++) {"
94echo -e " if ( version_table[n].static_handle != NULL ) {"
95echo -e " isEmpty = 0;"
96echo -e " }"
97echo -e " }"
98echo -e ""
99echo -e " if ( isEmpty == 1 ) {"
100echo -e " freeAllHandle();"
101echo -e " }"
102echo -e "}"
103echo -e ""
104echo -e "JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1freeHandle(JNIEnv *env, jobject jobj, jint lib_id) {"
105echo -e " /* Call function to free the memory */"
106echo -e " freeHandle(lib_id);"
107echo -e "}"
108echo -e ""
109echo -e "JNIEXPORT jint JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1initializeHandle(JNIEnv *env, jobject jobj, jstring libname) {"
110echo -e ""
111echo -e " jint lib_id = -1;"
112echo -e " const char* c_path = (*env)->GetStringUTFChars(env, libname, 0);"
113echo -e ""
114echo -e " int isLoaded = 0;"
115echo -e " int n;"
116echo -e " for ( n=0; n<nb_id; n++) {"
117echo -e " if ( strncmp(version_table[n].libname, c_path, strlen(version_table[n].libname) ) == 0 ) {"
118echo -e " isLoaded = 1;"
119echo -e " lib_id = version_table[n].id;"
120echo -e " }"
121echo -e " }"
122echo -e ""
123echo -e " if ( isLoaded == 0 ) {"
124echo -e " void *new_handle = dlopen(c_path, RTLD_LAZY );"
125echo -e ""
126echo -e " if (!new_handle ) {"
127echo -e " printf (\"WARNING : Failed to initialize library handle from %s!\\\n\", c_path);"
128echo -e " }"
129echo -e " else {"
130echo -e " lib_id = nb_id;"
131echo -e " nb_id++;"
132echo -e ""
133echo -e " void* new_version_table = malloc(sizeof(struct version_correlation)*(nb_id) );"
134echo -e " void* new_function_tables = malloc(sizeof(struct function_tables)*(nb_id) );"
135echo -e ""
136echo -e " if ( nb_id > 1) {"
137echo -e " memcpy(new_version_table,version_table, sizeof(struct version_correlation)*(nb_id-1) );"
138echo -e " free( version_table );"
139echo -e ""
140echo -e " memcpy(new_function_tables,version_functions_table, sizeof(struct function_tables)*(nb_id-1) );"
141echo -e " free( version_functions_table);"
142echo -e " }"
143echo -e ""
144echo -e " version_table = (struct version_correlation *)new_version_table;"
145echo -e " version_table[lib_id].id = lib_id;"
146echo -e " version_table[lib_id].libname = (char*)malloc( strlen(c_path) );"
147echo -e " strncpy(version_table[lib_id].libname, c_path, strlen(c_path));"
148echo -e " version_table[lib_id].static_handle = new_handle;"
149echo -e ""
150echo -e " version_functions_table = (struct function_tables*)new_function_tables;"
151echo -e ""
152for 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"`\");"
154done
155echo -e " }"
156echo -e " }"
157echo -e ""
158echo -e " return lib_id;"
159echo -e "}"
160echo -e ""
161
162for 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"`{";
164
165 TEST=`echo $x | sed -e "s/#/ /g" | awk {print'$2'}`
166
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"`
168
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;"
171 else
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;"
173 fi
174
175 echo -e "}\n\n"
176
177done
This page took 0.031938 seconds and 4 git commands to generate.