+ GtkTreeIter iter;
+ int i;
+ GtkTreeModel *model = GTK_TREE_MODEL(event_viewer_data->store_m);
+ GtkTreePath *tree_path;
+ RawTraceData * raw_data;
+ ScrollDirection direction = SCROLL_NONE;
+ GList * first;
+ int event_number;
+ double value = event_viewer_data->previous_value - time_value;
+ LttTime start, end, time;
+ LttEvent * ev;
+ unsigned backward_num, minNum, maxNum;
+ LttTracefile * tf;
+ unsigned block_num, event_num;
+ unsigned size = 1, count = 0;
+ gboolean need_backward_again, backward;
+ GdkWindow * win;
+ GdkCursor * new;
+ GtkWidget* widget = gtk_widget_get_parent(event_viewer_data->hbox_v);
+
+ if(widget){
+ new = gdk_cursor_new(GDK_X_CURSOR);
+ win = gtk_widget_get_parent_window(widget);
+ gdk_window_set_cursor(win, new);
+ gdk_cursor_unref(new);
+ gdk_window_stick(win);
+ gdk_window_unstick(win);
+ }
+
+
+ // if(event_number > event_viewer_data->last_event ||
+ // event_number + list_height-1 < event_viewer_data->first_event ||
+ // event_viewer_data->first_event == -1)
+ {
+ /* no event can be reused, clear and start from nothing */
+ if(value == -1.0) direction = SCROLL_STEP_DOWN;
+ else if(value == 1.0 ) direction = SCROLL_STEP_UP;
+ else if(value == -2.0) direction = SCROLL_PAGE_DOWN;
+ else if(value == 2.0 ) direction = SCROLL_PAGE_UP;
+ else if(value == 0.0 ) direction = SCROLL_NONE;
+ else direction = SCROLL_JUMP;
+
+ switch(direction){
+ case SCROLL_STEP_UP:
+ case SCROLL_PAGE_UP:
+ if(direction == SCROLL_PAGE_UP){
+ backward = list_height>event_viewer_data->start_event_index ? TRUE : FALSE;
+ }else{
+ backward = event_viewer_data->start_event_index == 0 ? TRUE : FALSE;
+ }
+ if(backward){
+ event_viewer_data->append = FALSE;
+ do{
+ if(direction == SCROLL_PAGE_UP){
+ minNum = list_height - event_viewer_data->start_event_index ;
+ }else{
+ minNum = 1;
+ }
+
+ first = event_viewer_data->raw_trace_data_queue->head;
+ if(!first)break;
+ raw_data = (RawTraceData*)g_list_nth_data(first,0);
+ end = raw_data->time;
+ end.tv_nsec--;
+ ltt_event_position_get(raw_data->ep, &block_num, &event_num, &tf);
+ if(size !=0){
+ if(event_num > minNum){
+ backward_num = event_num > RESERVE_SMALL_SIZE
+ ? event_num - RESERVE_SMALL_SIZE : 1;
+ ltt_event_position_set(raw_data->ep, block_num, backward_num);
+ ltt_tracefile_seek_position(tf, raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ maxNum = RESERVE_SMALL_SIZE_CUBE;
+ }else{
+ if(block_num > 1){
+ ltt_event_position_set(raw_data->ep, block_num-1, 1);
+ ltt_tracefile_seek_position(tf, raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ }else{
+ start.tv_sec = 0;
+ start.tv_nsec = 0;
+ }
+ maxNum = RESERVE_SMALL_SIZE_CUBE;
+ }
+ }else{
+ if(block_num > count){
+ ltt_event_position_set(raw_data->ep, block_num-count, 1);
+ ltt_tracefile_seek_position(tf, raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ }else{
+ start.tv_sec = 0;
+ start.tv_nsec = 0;
+ }
+ maxNum = RESERVE_SMALL_SIZE_CUBE;
+ }
+
+ event_viewer_data->current_event_index = event_viewer_data->start_event_index;
+ get_events(event_viewer_data, start, end, maxNum, &size);
+ event_viewer_data->start_event_index = event_viewer_data->current_event_index;
+
+ if(size < minNum && (start.tv_sec !=0 || start.tv_nsec !=0))
+ need_backward_again = TRUE;
+ else need_backward_again = FALSE;
+ if(size == 0){
+ count++;
+ }else{
+ count = 0;
+ }
+ }while(need_backward_again);
+ }
+ if(direction == SCROLL_STEP_UP)
+ event_number = event_viewer_data->start_event_index - 1;
+ else
+ event_number = event_viewer_data->start_event_index - list_height;
+ break;
+ case SCROLL_STEP_DOWN:
+ if(event_viewer_data->end_event_index == event_viewer_data->number_of_events - 1){
+ event_viewer_data->append = TRUE;
+ first = event_viewer_data->raw_trace_data_queue->head;
+ if(!first)break;
+ raw_data = (RawTraceData*)g_list_nth_data(first,event_viewer_data->number_of_events - 1);
+ start = raw_data->time;
+ start.tv_nsec++;
+ end.tv_sec = G_MAXULONG;
+ end.tv_nsec = G_MAXULONG;
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE, &size);
+ if(size == 0){
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_SQUARE,&size);
+ if(size == 0)
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_CUBE,&size);
+ }
+ }else size = 1;
+ if(size > 0) event_number = event_viewer_data->start_event_index + 1;
+ else event_number = event_viewer_data->start_event_index;
+ break;
+ case SCROLL_PAGE_DOWN:
+ i = event_viewer_data->number_of_events - 1 - list_height;
+ if((gint)(event_viewer_data->end_event_index) >= i){
+ event_viewer_data->append = TRUE;
+ first = event_viewer_data->raw_trace_data_queue->head;
+ if(!first)break;
+ raw_data = (RawTraceData*)g_list_nth_data(first,event_viewer_data->number_of_events - 1);
+ start = raw_data->time;
+ start.tv_nsec++;
+ end.tv_sec = G_MAXULONG;
+ end.tv_nsec = G_MAXULONG;
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE,&size);
+ if(size == 0){
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_SQUARE,&size);
+ if(size == 0)
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_CUBE,&size);
+ }
+ }
+ if(list_height <= event_viewer_data->number_of_events - 1 - event_viewer_data->end_event_index)
+ event_number = event_viewer_data->start_event_index + list_height - 1;
+ else
+ event_number = event_viewer_data->number_of_events - 1 - list_height;
+ break;
+ case SCROLL_JUMP:
+ event_viewer_data->append = TRUE;
+ remove_all_items_from_queue(event_viewer_data->raw_trace_data_queue);
+ end.tv_sec = G_MAXULONG;
+ end.tv_nsec = G_MAXULONG;
+ time = ltt_time_from_double(time_value / NANOSECONDS_PER_SECOND);
+ start = ltt_time_add(event_viewer_data->time_span.startTime, time);
+ event_viewer_data->previous_value = time_value;
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE,&size);
+ if(size < list_height && size > 0){
+ event_viewer_data->append = FALSE;
+ first = event_viewer_data->raw_trace_data_queue->head;
+ if(!first)break;
+ raw_data = (RawTraceData*)g_list_nth_data(first,0);
+ end = raw_data->time;
+ end.tv_nsec--;
+ ltt_event_position_get(raw_data->ep, &block_num, &event_num, &tf);
+
+ if(event_num > list_height - size){
+ backward_num = event_num > RESERVE_SMALL_SIZE
+ ? event_num - RESERVE_SMALL_SIZE : 1;
+ ltt_event_position_set(raw_data->ep, block_num, backward_num);
+ ltt_tracefile_seek_position(tf, raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ maxNum = RESERVE_SMALL_SIZE_CUBE;
+ event_viewer_data->current_event_index = 0;
+ get_events(event_viewer_data, start, end, maxNum, &size);
+ event_viewer_data->start_event_index = event_viewer_data->current_event_index;
+ }
+ event_number = event_viewer_data->raw_trace_data_queue->length - list_height;
+ }else if(size == 0){
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_SQUARE,&size);
+ if(size == 0)
+ get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_CUBE,&size);
+ event_number = 0;
+ }else{
+ event_number = 0;
+ }
+ break;
+ case SCROLL_NONE:
+ event_number = event_viewer_data->current_event_index;
+ break;
+ default:
+ break;
+ }
+
+ if(event_number < 0) event_number = 0;
+
+ //update the value of the scroll bar
+ if(direction != SCROLL_NONE && direction != SCROLL_JUMP){
+ first = event_viewer_data->raw_trace_data_queue->head;
+ if(first){
+ raw_data = (RawTraceData*)g_list_nth_data(first,event_number);
+ if(!raw_data) raw_data = (RawTraceData*)g_list_nth_data(first,0);
+ time = ltt_time_sub(raw_data->time, event_viewer_data->time_span.startTime);
+ event_viewer_data->vadjust_c->value = ltt_time_to_double(time) * NANOSECONDS_PER_SECOND;
+ g_signal_stop_emission_by_name(G_OBJECT(event_viewer_data->vadjust_c), "value-changed");
+ event_viewer_data->previous_value = event_viewer_data->vadjust_c->value;
+ }
+ }
+
+
+ event_viewer_data->start_event_index = event_number;
+ event_viewer_data->end_event_index = event_number + list_height - 1;
+ if(event_viewer_data->end_event_index > event_viewer_data->number_of_events - 1){
+ event_viewer_data->end_event_index = event_viewer_data->number_of_events - 1;
+ }
+
+ first = event_viewer_data->raw_trace_data_queue->head;
+ gtk_list_store_clear(event_viewer_data->store_m);
+ if(!first){
+ // event_viewer_data->previous_value = 0;
+ // event_viewer_data->vadjust_c->value = 0.0;
+ // gtk_widget_hide(event_viewer_data->vscroll_vc);
+ goto LAST;
+ }else gtk_widget_show(event_viewer_data->vscroll_vc);
+
+ for(i=event_number; i<event_number+list_height; i++)
+ {
+ guint64 real_data;
+
+ if(i>=event_viewer_data->number_of_events) break;
+
+ raw_data = (RawTraceData*)g_list_nth_data(first, i);
+
+ // Add a new row to the model
+ real_data = raw_data->time.tv_sec;
+ real_data *= NANOSECONDS_PER_SECOND;
+ real_data += raw_data->time.tv_nsec;
+ gtk_list_store_append (event_viewer_data->store_m, &iter);
+ gtk_list_store_set (event_viewer_data->store_m, &iter,
+ CPUID_COLUMN, raw_data->cpu_id,
+ EVENT_COLUMN, raw_data->event_name,
+ TIME_COLUMN, real_data,
+ PID_COLUMN, raw_data->pid,
+ ENTRY_LEN_COLUMN, raw_data->entry_length,
+ EVENT_DESCR_COLUMN, raw_data->event_description,
+ -1);
+/*
+ gtk_list_store_append (event_viewer_data->store_m, &iter);
+ gtk_list_store_set (event_viewer_data->store_m, &iter,
+ CPUID_COLUMN, 0,
+ EVENT_COLUMN, "event irq",
+ TIME_COLUMN, i,
+ PID_COLUMN, 100,
+ ENTRY_LEN_COLUMN, 17,
+ EVENT_DESCR_COLUMN, "Detailed information",
+ -1);
+*/
+ }
+ }
+#ifdef DEBUG //do not use this, it's slower and broken
+ // } else {
+ /* Some events will be reused */
+ if(event_number < event_viewer_data->first_event)
+ {
+ /* scrolling up, prepend events */
+ tree_path = gtk_tree_path_new_from_indices
+ (event_number+list_height-1 -
+ event_viewer_data->first_event + 1,
+ -1);
+ for(i=0; i<event_viewer_data->last_event-(event_number+list_height-1);
+ i++)
+ {
+ /* Remove the last events from the list */
+ if(gtk_tree_model_get_iter(model, &iter, tree_path))
+ gtk_list_store_remove(event_viewer_data->store_m, &iter);
+ }
+
+ for(i=event_viewer_data->first_event-1; i>=event_number; i--)