Add live trace reading support to lttvtraceread lib
[lttv.git] / ltt / jni_interface.c
index d1bd993740cbab25be544648a93c73ff31384dae..52c9993c5e035f3319a838d858e7f2cab2c8ac6e 100644 (file)
@@ -30,7 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
-
+#include <errno.h>
 /* 
 ***FIXME***
 ***HACK***
@@ -142,7 +142,24 @@ JNIEXPORT jlong JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1open
         }
         
         const char *c_pathname = (*env)->GetStringUTFChars(env, pathname, 0);
-        LttTrace *newPtr = ltt_trace_open( c_pathname );
+        LttTrace *newPtr = ltt_trace_open(c_pathname);
+        
+        (*env)->ReleaseStringUTFChars(env, pathname, c_pathname);
+        
+        return CONVERT_PTR_TO_JLONG(newPtr); 
+}
+
+/* JNI mapping of   < LttTrace *ltt_trace_open_live(const gchar *pathname)  > (trace.h) */
+JNIEXPORT jlong JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1openTraceLive(JNIEnv *env, jobject jobj, jstring pathname, jboolean show_debug) {
+        
+        if ( !show_debug) {
+                /* Make sure we don't use any debug (speed up the read) */
+                g_log_set_handler(NULL, G_LOG_LEVEL_INFO, ignore_and_drop_message, NULL);
+                g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, ignore_and_drop_message, NULL);
+        }
+        
+        const char *c_pathname = (*env)->GetStringUTFChars(env, pathname, 0);
+        LttTrace *newPtr = ltt_trace_open_live(c_pathname);
         
         (*env)->ReleaseStringUTFChars(env, pathname, c_pathname);
         
@@ -242,6 +259,14 @@ JNIEXPORT jlong JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getS
         return CONVERT_UINT64_TO_JLONG(newPtr->start_monotonic);
 }
 
+/* JNI mapping of  < int ltt_trace_update(LttTrace *t)  > (trace.h) */
+JNIEXPORT jint JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1updateTrace(JNIEnv *env, jobject jobj, jlong trace_ptr){
+        
+        LttTrace *newPtr = (LttTrace*)CONVERT_JLONG_TO_PTR(trace_ptr);
+        
+        return (jint)ltt_trace_update(newPtr);
+}
+
 /* Access to start_time */
 /* Note that we are calling the setTimeFromC function in Jaf_Time from here */
 JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedStartTime(JNIEnv *env, jobject jobj, jlong trace_ptr, jobject time_jobj) {
@@ -671,6 +696,9 @@ JNIEXPORT jint JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1posit
             ERANGE  = 34    out of range, back to last event (might be system dependent?)
             EPERM   = 1     error while reading              (might be system dependent?)  */
         
+        if (tracefilePtr->trace == NULL) {
+            return (jint) EPERM;
+        }
         
         /* Seek to the start time... this will also read the first event, as we want. */
         int returnedValue = ltt_tracefile_seek_time(tracefilePtr, ((struct LttTrace)*(tracefilePtr->trace)).start_time_from_tsc);
This page took 0.02285 seconds and 4 git commands to generate.