summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksii Piskun <o.piskun@samsung.com>2017-12-29 21:57:06 +0200
committerMykyta Biliavskyi <m.biliavskyi@samsung.com>2017-12-29 21:57:06 +0200
commit5f81b8976e8a83b152749eb68f0c954400786ffb (patch)
treecf6cba83c3e0bbea0f02f2b95c54ca034dd88691
parent153970bed51a36b8233b970a0008bc9fac8690e7 (diff)
Remove useless file.
Summary: fix mistake in moving files Reviewers: NikaWhite Differential Revision: https://phab.enlightenment.org/D5717
-rw-r--r--src/lib/find.c1094
1 files changed, 0 insertions, 1094 deletions
diff --git a/src/lib/find.c b/src/lib/find.c
deleted file mode 100644
index 4b8bbb3..0000000
--- a/src/lib/find.c
+++ /dev/null
@@ -1,1094 +0,0 @@
1/*
2 * EFL Profiling Viewer
3 * Copyright (C) 2017 Samsung Electronics.
4 *
5 * This file is part of EFL Profiling Viewer.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; If not, see www.gnu.org/licenses/lgpl.html.
18 */
19
20#define _GNU_SOURCE
21
22#include "../helper.h"
23#include "tasks/tasks.h"
24#include "find.h"
25
26enum _Seek_Mode {
27 SEEK_FIND = 0,
28 SEEK_GO
29};
30typedef enum _Seek_Mode Seek_Mode;
31
32enum _Seek_Range {
33 SEEK_REGION = 0,
34 SEEK_ALL
35};
36typedef enum _Seek_Range Seek_Range;
37
38typedef struct _Find_UI
39{
40 double stored_length;
41
42 Evas_Object *win;
43 Evas_Object *combobox;
44 Evas_Object *box;
45
46 Evas_Object *find_layout;
47 Evas_Object *go_layout;
48
49 Elm_Genlist_Item_Class *combobox_itc;
50
51 Seek_Range seek_range;
52 Seek_Mode seek_mode;
53
54 Eina_Array *highlighted_cache;
55 Eina_Array *highlighted_active_cache;
56} Find_UI;
57
58typedef struct _Find_Data
59{
60 Evas_Object *content;
61 In_Thread_Data *thd;
62 double time;
63 Find_Mode mode;
64 char *name;
65
66 Find_UI ui;
67} Find_Data;
68
69static void _found_array_tasks_fill(Find_Data *find_data, Eina_Array *events);
70static void _found_event_task_fill(Find_Data *find_data, Event_Offsets *event);
71
72static inline Eina_Bool
73_event_compare(Event_Offsets *event1, Event_Offsets *event2)
74{
75 return event1->time_start > event2->time_start;
76}
77
78static Event_Offsets*
79_event_in_array_find(Find_Data *find_data, Eina_Array *events)
80{
81 Find_Mode mode = find_data->mode;
82 unsigned int i = 0;
83 Event_Offsets *event = NULL;
84
85 i = event_offsets_time_binary_search(events, find_data->time);
86 if (mode == FIND_MODE_NEXT)
87 {
88 event = eina_array_data_get(events, i);
89 if ((!i) && (event->time_start > find_data->time))
90 return event;
91 i++;
92 if (eina_array_count(events) == i) return NULL;
93 else return eina_array_data_get(events, i);
94 }
95 else
96 {
97 event = eina_array_data_get(events, i);
98 if ((!i) && (event->time_start >= find_data->time))
99 return NULL;
100 else if (event->time_start == find_data->time)
101 return eina_array_data_get(events, i - 1);
102 else return event;
103 }
104}
105
106static Event_Offsets*
107_event_state_name_find(Find_Data *find_data)
108{
109 Event_Info_State *event_info = NULL;
110 Event_Offsets *event = NULL;
111 eina_rwlock_take_read(&find_data->thd->state_events.lock);
112 event_info = eina_hash_find(find_data->thd->state_events.hash, find_data->name);
113 eina_rwlock_release(&find_data->thd->state_events.lock);
114 if (!event_info) return NULL;
115 if (event_info->common.filtered) return NULL;
116
117 eina_rwlock_take_read(&event_info->state_events.lock);
118 event = _event_in_array_find(find_data, event_info->state_events.data);
119 eina_rwlock_release(&event_info->state_events.lock);
120 return event;
121}
122
123static Event_Offsets *
124_event_thread_type_name_find(Find_Data *find_data, Eina_Bool threads_single)
125{
126 unsigned int index;
127
128 Eina_Array_Iterator it;
129 Event_Info *event_info;
130 Event_Offsets *event_optimal = NULL, *event_new = NULL;
131
132 Thread_Events *te;
133 if (threads_single)
134 {
135 eina_rwlock_take_read(&find_data->thd->single_events.lock);
136 event_info = eina_hash_find(find_data->thd->single_events.hash,
137 find_data->name);
138 eina_rwlock_release(&find_data->thd->single_events.lock);
139 }
140 else
141 {
142 eina_rwlock_take_read(&find_data->thd->thread_events.lock);
143 event_info = eina_hash_find(find_data->thd->thread_events.hash,
144 find_data->name);
145 eina_rwlock_release(&find_data->thd->thread_events.lock);
146 }
147 if (event_info && !event_info->common.filtered)
148 {
149 Eina_Array *data;
150 if (threads_single)
151 {
152 eina_rwlock_take_read(&((Event_Info_Single *)event_info)->threads.lock);
153 data = ((Event_Info_Single *)event_info)->threads.data;
154 }
155 else
156 {
157 eina_rwlock_take_read(&((Event_Info_Thread *)event_info)->threads.lock);
158 data = ((Event_Info_Thread *)event_info)->threads.data;
159 }
160
161 EINA_ARRAY_ITER_NEXT(data, index, te, it)
162 {
163 eina_rwlock_take_read(&te->thread_events.lock);
164 event_new = _event_in_array_find(find_data, te->thread_events.data);
165 eina_rwlock_release(&te->thread_events.lock);
166
167 if (find_data->mode == FIND_MODE_NEXT)
168 {
169 if ((!event_optimal) || ((event_new) && (_event_compare(event_optimal, event_new))))
170 event_optimal = event_new;
171 }
172 else
173 {
174 if ((!event_optimal) || ((event_new) && (_event_compare(event_new, event_optimal))))
175 event_optimal = event_new;
176 }
177 }
178 if (threads_single)
179 eina_rwlock_release(&((Event_Info_Single *)event_info)->threads.lock);
180 else
181 eina_rwlock_release(&((Event_Info_Thread *)event_info)->threads.lock);
182 }
183 return event_optimal;
184}
185
186static Event_Offsets*
187_next_event_find(Find_Data *find_data)
188{
189 Event_Offsets *event_new = NULL, *event_optimal = NULL;
190 event_optimal = _event_state_name_find(find_data);
191 event_new = _event_thread_type_name_find(find_data, EINA_FALSE);
192 if ((!event_optimal) || ((event_new) && (_event_compare(event_optimal, event_new))))
193 event_optimal = event_new;
194
195 event_new = _event_thread_type_name_find(find_data, EINA_TRUE);
196 if ((!event_optimal) || ((event_new) && (_event_compare(event_optimal, event_new))))
197 event_optimal = event_new;
198
199 if (event_optimal) find_data->time = event_optimal->time_start;
200 else find_data->time = find_data->thd->duration;
201 return event_optimal;
202}
203
204static Event_Offsets*
205_prev_event_find(Find_Data *find_data)
206{
207 Event_Offsets *event_new = NULL, *event_optimal = NULL;
208 event_optimal = _event_state_name_find(find_data);
209 event_new = _event_thread_type_name_find(find_data, EINA_FALSE);
210 if ((!event_optimal) || ((event_new) && (_event_compare(event_new, event_optimal))))
211 event_optimal = event_new;
212
213 event_new = _event_thread_type_name_find(find_data, EINA_TRUE);
214 if ((!event_optimal) || ((event_new) && (_event_compare(event_new, event_optimal))))
215 event_optimal = event_new;
216
217 if (event_optimal) find_data->time = event_optimal->time_start;
218 else find_data->time = 0;
219 return event_optimal;
220}
221
222//TODO: unify this func for usage here and in interval_fill module.
223static Pointer_To_Time *
224_find_ptt_get(In_Thread_Data *thd, double time)
225{
226 Eina_List *start_list;
227 Pointer_To_Time *ptt;
228 EINA_LIST_FOREACH(thd->blocks, start_list, ptt)
229 {
230 if (ptt->time > time)
231 {
232 start_list = eina_list_prev(start_list);
233 break;
234 }
235 }
236
237 if (!(start_list = eina_list_prev(start_list)))
238 {
239 return NULL;
240 }
241 return (Pointer_To_Time*)start_list->data;
242}
243
244static Event_Offsets *
245_active_events_list_search(Find_Data *find_data, Eina_List *active)
246{
247 Eina_List *l;
248 Event_Offsets *event_new = NULL, *event_optimal = NULL;
249 EINA_LIST_FOREACH(active, l, event_new)
250 {
251 if (!strcmp(event_new->event_info->common.name, find_data->name)) continue;
252
253 if (find_data->mode == FIND_MODE_NEXT)
254 {
255 if (event_new->time_start < find_data->time) continue;
256 if ((!event_optimal) || (_event_compare(event_optimal, event_new)))
257 event_optimal = event_new;
258 }
259 else
260 {
261 if (event_new->time_start > find_data->time) continue;
262 if ((!event_optimal) || (_event_compare(event_new, event_optimal)))
263 event_optimal = event_new;
264 }
265 }
266 return event_optimal;
267}
268
269static Event_Offsets *
270_event_find_retry(Find_Data *find_data)
271{
272 Event_Offsets *event = NULL;
273 Time_Range interval = find_data->thd->stored_data->interval;
274 if (find_data->mode == FIND_MODE_NEXT)
275 {
276 while ((event = _next_event_find(find_data)) &&
277 (event->time_end < interval.start))
278 {
279 ; /* NULL */
280 }
281 if ((event) && (event->time_start > interval.start + interval.length))
282 event = NULL;
283 }
284 else
285 {
286 if (find_data->time > interval.start + interval.length)
287 find_data->time = interval.start + interval.length;
288 Pointer_To_Time *ptt = _find_ptt_get(find_data->thd, find_data->time);
289 if ((ptt) && (find_data->time < ptt->last_event_time))
290 {
291 event = _active_events_list_search(find_data, ptt->active_events);
292 if (event) find_data->time = event->time_start;
293 }
294 else
295 {
296 event = _prev_event_find(find_data);
297 }
298 }
299
300 return event;
301}
302
303static void
304_event_name_not_found_cb(Find_Data *find_data)
305{
306 const char *name;
307 char failure[STRING_LENGTH];
308 name = elm_object_text_get(find_data->ui.combobox);
309 if (!name)
310 return;
311
312 if (eina_str_has_prefix(name, "<failure>"))
313 if (eina_str_has_suffix(name, "</failure>"))
314 return;
315
316 snprintf(failure, STRING_LENGTH, "<failure>%s</failure>", name);
317 elm_object_text_set(find_data->ui.combobox, failure);
318}
319
320static void
321_event_name_next_find_cb(Find_Data *find_data)
322{
323 Time_Range interval = find_data->thd->stored_data->interval;
324 Event_Offsets *event = NULL;
325
326 if (!interval_cross(find_data->time, find_data->time, interval))
327 {
328 Pointer_To_Time *ptt = _find_ptt_get(find_data->thd, find_data->time);
329 if ((ptt) && (find_data->time < ptt->last_event_time))
330 {
331 event = _active_events_list_search(find_data, ptt->active_events);
332 if (event) find_data->time = event->time_start;
333 else find_data->time = ptt->last_event_time;
334 }
335 }
336
337 if (!event) event = _next_event_find(find_data);
338
339 if (!event)
340 _event_name_not_found_cb(find_data);
341 else
342 _found_event_task_fill(find_data, event);
343}
344
345static void
346_event_name_previous_find_cb(Find_Data *find_data)
347{
348 Event_Offsets *event = _prev_event_find(find_data);
349
350 if (!event)
351 _event_name_not_found_cb(find_data);
352 else
353 _found_event_task_fill(find_data, event);
354}
355
356/* Highlight all */
357static void
358_event_name_state_array_find(Find_Data *find_data)
359{
360 Event_Info_State *ev_inf_st;
361
362 eina_rwlock_take_read(&find_data->thd->state_events.lock);
363 ev_inf_st = eina_hash_find(find_data->thd->state_events.hash, find_data->name);
364 eina_rwlock_release(&find_data->thd->state_events.lock);
365
366 if (ev_inf_st && !ev_inf_st->common.filtered)
367 {
368 eina_rwlock_take_read(&ev_inf_st->state_events.lock);
369
370 _found_array_tasks_fill(find_data, ev_inf_st->state_events.data);
371
372 eina_rwlock_release(&ev_inf_st->state_events.lock);
373 }
374}
375
376static void
377_event_name_thread_type_array_find(Find_Data *find_data, Eina_Bool threads_single)
378{
379 Eina_Array_Iterator it;
380 Event_Info_Thread *event_info;
381 unsigned int index;
382 Thread_Events *te;
383 Eina_Array *data;
384
385 if (threads_single)
386 {
387 eina_rwlock_take_read(&find_data->thd->single_events.lock);
388 event_info = eina_hash_find(find_data->thd->single_events.hash,
389 find_data->name);
390 eina_rwlock_release(&find_data->thd->single_events.lock);
391 }
392 else
393 {
394 eina_rwlock_take_read(&find_data->thd->thread_events.lock);
395 event_info = eina_hash_find(find_data->thd->thread_events.hash,
396 find_data->name);
397 eina_rwlock_release(&find_data->thd->thread_events.lock);
398 }
399
400 if (event_info && !event_info->common.filtered)
401 {
402 if (threads_single)
403 {
404 eina_rwlock_take_read(&((Event_Info_Single *)event_info)->threads.lock);
405 data = ((Event_Info_Single *)event_info)->threads.data;
406 }
407 else
408 {
409 eina_rwlock_take_read(&((Event_Info_Thread *)event_info)->threads.lock);
410 data = ((Event_Info_Thread *)event_info)->threads.data;
411 }
412
413 EINA_ARRAY_ITER_NEXT(data, index, te, it)
414 {
415 eina_rwlock_take_read(&te->thread_events.lock);
416 _found_array_tasks_fill(find_data, te->thread_events.data);
417 eina_rwlock_release(&te->thread_events.lock);
418 }
419 if (threads_single)
420 eina_rwlock_release(&((Event_Info_Single *)event_info)->threads.lock);
421 else
422 eina_rwlock_release(&((Event_Info_Thread *)event_info)->threads.lock);
423 }
424}
425
426static void
427_event_name_array_find_cb(Find_Data *find_data)
428{
429 _event_name_state_array_find(find_data);
430 _event_name_thread_type_array_find(find_data, EINA_FALSE);
431 _event_name_thread_type_array_find(find_data, EINA_TRUE);
432}
433/* end of Highlight all*/
434
435static void
436_event_time_select_set_cb(void *data, Evas_Object *obj EINA_UNUSED, void *time)
437{
438 Find_Data *find_data = data;
439 find_data->time = *(double *)time;
440}
441
442static void
443_event_data_free_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
444{
445 Find_Data *find_data = data;
446 if (find_data->ui.win)
447 {
448 evas_object_del(find_data->ui.win);
449 elm_genlist_item_class_free(find_data->ui.combobox_itc);
450 }
451 free(find_data);
452}
453
454/* UI */
455static void
456_find_win_del(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
457{
458 evas_object_hide(obj);
459}
460
461static int
462_list_str_cmp_cb(const void *d1, const void *d2)
463{
464 const char *txt = d1;
465 const char *txt2 = d2;
466
467 if (!txt) return(1);
468 if (!txt2) return(-1);
469
470 return strcmp(txt, txt2);
471}
472
473static char *
474_gl_text_get_cb(void *data,
475 Evas_Object *obj EINA_UNUSED,
476 const char *part EINA_UNUSED)
477{
478 if (!data)
479 return NULL;
480 return strdup(data);
481}
482
483static Eina_Bool
484_gl_filter_get_cb(void *data, Evas_Object *obj EINA_UNUSED, void *key)
485{
486 if (key && data && strcasestr(data, (char *)key))
487 return EINA_TRUE;
488 return EINA_FALSE;
489}
490
491static Eina_Bool
492_name_uniq_save_cb(const Eina_Hash *hash EINA_UNUSED,
493 const void *key,
494 void *data EINA_UNUSED,
495 void *fdata)
496{
497 Eina_List **names = fdata;
498 if (!eina_list_search_sorted(*names, _list_str_cmp_cb, key))
499 *names = eina_list_sorted_insert(*names ,_list_str_cmp_cb, key);
500
501 return EINA_TRUE;
502}
503
504static void
505_find_combobox_update_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
506{
507 Find_Data *find_data = data;
508 Find_UI *ui = &find_data->ui;
509
510 if (event_info)
511 find_data->thd = event_info;
512 if (!ui->combobox) return;
513
514 In_Thread_Data *thd = find_data->thd;
515 Eina_List *names_list = NULL;
516 char *key = NULL;
517 if (!ui->combobox_itc)
518 {
519 ui->combobox_itc = elm_genlist_item_class_new();
520 ui->combobox_itc->item_style = "default";
521 ui->combobox_itc->func.text_get = _gl_text_get_cb;
522 ui->combobox_itc->func.content_get = NULL;
523 ui->combobox_itc->func.state_get = NULL;
524 ui->combobox_itc->func.filter_get = _gl_filter_get_cb;
525 ui->combobox_itc->func.del = NULL;
526 }
527
528 eina_rwlock_take_read(&thd->thread_events.lock);
529 eina_hash_foreach(thd->thread_events.hash, _name_uniq_save_cb, &names_list);
530 eina_rwlock_release(&thd->thread_events.lock);
531 eina_rwlock_take_read(&thd->state_events.lock);
532 eina_hash_foreach(thd->state_events.hash, _name_uniq_save_cb, &names_list);
533 eina_rwlock_release(&thd->state_events.lock);
534 eina_rwlock_take_read(&thd->single_events.lock);
535 eina_hash_foreach(thd->single_events.hash, _name_uniq_save_cb, &names_list);
536 eina_rwlock_release(&thd->single_events.lock);
537 elm_combobox_hover_end(ui->combobox);
538 elm_genlist_clear(ui->combobox);
539
540 EINA_LIST_FREE(names_list, key)
541 {
542 elm_genlist_item_append(ui->combobox, ui->combobox_itc, key, NULL,
543 ELM_GENLIST_ITEM_NONE, NULL, key);
544 }
545}
546
547static void
548_event_name_find_reset_color_cb(void *data EINA_UNUSED,
549 Evas_Object *obj,
550 void *event_info EINA_UNUSED)
551{
552 char *name = elm_entry_markup_to_utf8(elm_object_text_get(obj));
553 elm_object_text_set(obj, name);
554 free(name);
555}
556
557static void
558_gl_filter_restart_cb(void *data EINA_UNUSED,
559 Evas_Object *obj,
560 void *event_info EINA_UNUSED)
561{
562 elm_genlist_filter_set(obj, (void *)elm_object_text_get(obj));
563}
564
565static void
566_combobox_item_pressed_cb(void *data EINA_UNUSED, Evas_Object *obj,
567 void *event_info)
568{
569 const char *txt = elm_object_item_text_get(event_info);
570 elm_object_text_set(obj, txt);
571 elm_combobox_hover_end(obj);
572 elm_entry_cursor_end_set(obj);
573}
574
575static Evas_Object *
576_find_combobox_create(Find_UI *ui)
577{
578 Evas_Object *combobox = NULL;
579
580 combobox = elm_combobox_add(ui->win);
581 evas_object_size_hint_weight_set(combobox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
582 evas_object_size_hint_align_set(combobox, EVAS_HINT_FILL, EVAS_HINT_FILL);
583 elm_object_part_text_set(combobox, "guide", _("Enter event name"));
584 evas_object_show(combobox);
585
586 evas_object_smart_callback_add(combobox, "changed,user", _event_name_find_reset_color_cb, NULL);
587 evas_object_smart_callback_add(combobox, "changed", _gl_filter_restart_cb, NULL);
588 evas_object_smart_callback_add(combobox, "item,pressed", _combobox_item_pressed_cb, NULL);
589 return combobox;
590}
591
592static void
593_seek_current_range_mode_cb(void *data,
594 Evas_Object *obj EINA_UNUSED,
595 void *event_info EINA_UNUSED)
596{
597 Find_UI *ui = (Find_UI *) data;
598 ui->seek_range = SEEK_REGION;
599}
600
601static void
602_seek_all_data_mode_cb(void *data,
603 Evas_Object *obj EINA_UNUSED,
604 void *event_info EINA_UNUSED)
605{
606 Find_UI *ui = (Find_UI *) data;
607 ui->seek_range = SEEK_ALL;
608}
609
610static void
611_event_name_find_show(void *data, Find_Mode mode)
612{
613 Evas_Object *combobox;
614 Find_Data *find_data = data;
615 combobox = find_data->ui.combobox;
616 evas_object_smart_callback_call(combobox, "changed,user", NULL);
617 evas_object_smart_callback_call(find_data->content, "unfollow", NULL);
618
619 find_data->name = elm_entry_markup_to_utf8(elm_object_text_get(combobox));
620 evas_object_smart_callback_call(find_data->content, "event,unselect", NULL);
621
622 find_data->mode = mode;
623
624 if (mode == FIND_MODE_NEXT)
625 _event_name_next_find_cb(find_data);
626
627 if (mode == FIND_MODE_PREVIOUS)
628 _event_name_previous_find_cb(find_data);
629}
630
631static void
632_event_name_find_previous_cb(void *data,
633 Evas_Object *obj EINA_UNUSED,
634 void *event_info EINA_UNUSED)
635{
636 _event_name_find_show(data, FIND_MODE_PREVIOUS);
637}
638
639static void
640_event_name_find_next_cb(void *data,
641 Evas_Object *obj EINA_UNUSED,
642 void *event_info EINA_UNUSED)
643{
644 _event_name_find_show(data, FIND_MODE_NEXT);
645}
646
647static void
648_find_dialog_buttons_add(Evas_Object *layout, Find_Data *find_data)
649{
650 Evas_Object *button = NULL;
651
652 button = elm_button_add(layout);
653 elm_object_text_set(button, _("Previous"));
654 evas_object_smart_callback_add(button, "clicked", _event_name_find_previous_cb, find_data);
655 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
656 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
657 elm_object_part_content_set(layout, "find_prev_btn", button);
658 evas_object_show(button);
659
660 button = elm_button_add(layout);
661 elm_object_text_set(button, _("Next"));
662 evas_object_smart_callback_add(button, "clicked", _event_name_find_next_cb, find_data);
663 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
664 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
665 elm_object_part_content_set(layout, "find_next_btn", button);
666 evas_object_show(button);
667}
668
669static void
670_find_layout_update(Evas_Object *layout, Find_UI *ui)
671{
672 Evas_Object *hoversel = elm_object_part_content_get(layout,
673 "find_in_cmbbx");
674 switch (ui->seek_range)
675 {
676 case SEEK_REGION:
677 {
678 elm_object_text_set(hoversel, _("Current range"));
679 break;
680 }
681 case SEEK_ALL:
682 {
683 elm_object_text_set(hoversel, _("Full time"));
684 break;
685 }
686 }
687}
688
689static void
690_switch_find_ui_mode(Find_UI *ui)
691{
692 Evas_Object *active_layout = NULL;
693 Evas_Object *inactive_layout = NULL;
694
695 switch (ui->seek_mode)
696 {
697 case SEEK_FIND:
698 {
699 active_layout = ui->find_layout;
700 inactive_layout = ui->go_layout;
701 _find_layout_update(active_layout, ui);
702 break;
703 }
704 case SEEK_GO:
705 {
706 active_layout = ui->go_layout;
707 inactive_layout = ui->find_layout;
708 ui->seek_range = SEEK_ALL;
709 break;
710 }
711 }
712
713 elm_box_unpack(ui->box, inactive_layout);
714 evas_object_hide(inactive_layout);
715 elm_box_pack_end(ui->box, active_layout);
716 evas_object_show(active_layout);
717
718 elm_object_part_content_set(active_layout, "combobox", ui->combobox);
719}
720
721static void
722_event_name_find_all_cb(void *data, Evas_Object *obj EINA_UNUSED,
723 void *event_info EINA_UNUSED)
724{
725 char *name;
726 Find_Data *find_data = data;
727 Find_UI *ui = &find_data->ui;
728
729 evas_object_smart_callback_call(ui->combobox, "changed,user", NULL);
730 evas_object_smart_callback_call(find_data->content, "unfollow", NULL);
731 evas_object_smart_callback_call(find_data->content, "event,unselect", NULL);
732 name = elm_entry_markup_to_utf8(elm_object_text_get(ui->combobox));
733 find_data->name = name;
734 _event_name_array_find_cb(find_data);
735}
736
737static Evas_Object *
738_find_layout_create(Find_Data *find_data)
739{
740 Find_UI *ui = &find_data->ui;
741 Evas_Object *layout = NULL;
742 Evas_Object *hoversel = NULL;
743
744 if (!ui->combobox)
745 {
746 ERR("Failed create find layout: combobox isn't created");
747 return NULL;
748 }
749
750 layout = layout_create(ui->win, "efl_profiling_viewer", "find");
751 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
752 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
753 evas_object_show(layout);
754
755 elm_object_part_content_set(layout, "combobox", ui->combobox);
756
757 hoversel = elm_hoversel_add(layout);
758 elm_hoversel_auto_update_set(hoversel, EINA_TRUE);
759 evas_object_size_hint_weight_set(hoversel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
760 evas_object_size_hint_align_set(hoversel, EVAS_HINT_FILL, EVAS_HINT_FILL);
761 elm_hoversel_item_add(hoversel, _("Current range"), NULL, ELM_ICON_NONE,
762 _seek_current_range_mode_cb, ui);
763 elm_hoversel_item_add(hoversel, _("Full time"), NULL, ELM_ICON_NONE,
764 _seek_all_data_mode_cb, ui);
765 elm_object_part_content_set(layout, "find_in_cmbbx", hoversel);
766 evas_object_show(hoversel);
767
768 Evas_Object *button = elm_button_add(layout);
769 elm_object_text_set(button, _("Highlight all"));
770 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
771 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
772 elm_object_part_content_set(layout, "highlight", button);
773 evas_object_show(button);
774 evas_object_smart_callback_add(button, "clicked", _event_name_find_all_cb, find_data);
775
776 _find_layout_update(layout, ui);
777 _find_dialog_buttons_add(layout, find_data);
778
779 return layout;
780}
781
782static Evas_Object *
783_go_layout_create(Find_Data *find_data)
784{
785 Find_UI *ui = &find_data->ui;
786 Evas_Object *layout = NULL;
787
788 if (!ui->combobox)
789 {
790 ERR("Failed create go layout: combobox isn't created");
791 return NULL;
792 }
793
794 layout = layout_create(ui->win, "efl_profiling_viewer", "find");
795 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
796 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
797 evas_object_show(layout);
798 elm_object_part_content_set(layout, "combobox", ui->combobox);
799
800 _find_dialog_buttons_add(layout, find_data);
801 return layout;
802}
803
804static void
805_find_toolbar_item_clicked_cb(void *data,
806 Evas_Object *obj EINA_UNUSED,
807 void *event_info EINA_UNUSED)
808{
809 Find_Data *find_data = data;
810 Find_UI *ui = &find_data->ui;
811 ui->seek_mode = SEEK_FIND;
812 _switch_find_ui_mode(ui);
813}
814
815static void
816_go_toolbar_item_clicked_cb(void *data,
817 Evas_Object *obj EINA_UNUSED,
818 void *event_info EINA_UNUSED)
819{
820 Find_Data *find_data = data;
821 Find_UI *ui = &find_data->ui;
822 ui->seek_mode = SEEK_GO;
823 _switch_find_ui_mode(ui);
824}
825
826static void
827_menu_find_dialog_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
828{
829 Find_Data *find_data = data;
830 Evas_Object *box = NULL;
831 Evas_Object *toolbar = NULL;
832 Find_UI *ui = &find_data->ui;
833
834 if (ui->win)
835 {
836 evas_object_show(ui->win);
837 elm_win_activate(ui->win);
838 return;
839 }
840
841 ui->win = elm_win_util_dialog_add(obj, "find", _("Find event"));
842 elm_win_autodel_set(ui->win, EINA_FALSE);
843 evas_object_smart_callback_add(ui->win, "delete,request", _find_win_del, NULL);
844 evas_object_show(ui->win);
845
846 box = elm_box_add(ui->win);
847 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
848 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
849 elm_box_padding_set(box, 0, 10);
850 ui->box = box;
851 evas_object_show(box);
852 elm_win_resize_object_add(ui->win, box);
853
854 toolbar = elm_toolbar_add(ui->win);
855 elm_toolbar_homogeneous_set(toolbar, EINA_FALSE);
856 elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_SCROLL);
857 elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
858 elm_toolbar_align_set(toolbar, 0.0);
859 elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
860 evas_object_size_hint_weight_set(toolbar, 0.0, 0.0);
861 evas_object_size_hint_align_set(toolbar, EVAS_HINT_FILL, 0.0);
862 evas_object_show(toolbar);
863 elm_box_pack_end(box, toolbar);
864
865 ui->seek_range = SEEK_ALL;
866 ui->seek_mode = SEEK_FIND;
867 ui->combobox = _find_combobox_create(ui);
868 evas_object_smart_callback_call(find_data->content, "find,combobox,update", NULL);
869
870 ui->find_layout = _find_layout_create(find_data);
871 ui->go_layout = _go_layout_create(find_data);
872 elm_toolbar_item_append(toolbar, NULL, _("Find"), _find_toolbar_item_clicked_cb, find_data);
873 elm_toolbar_item_append(toolbar, NULL, _("Go"), _go_toolbar_item_clicked_cb, find_data);
874 _switch_find_ui_mode(ui);
875}
876/* UI */
877
878/* Event draw */
879static Event_Offsets *
880_found_event_process(Find_Data *find_data, Event_Offsets *event)
881{
882 Time_Range interval = find_data->thd->stored_data->interval;
883 double time_start;
884 double time_end;
885 double length = find_data->ui.stored_length;
886 if (!length) length = interval.length;
887
888 time_start = event->time_start;
889
890 if (event->event_info->common.type != SINGLE_EVENT)
891 time_end = event->time_end;
892 else
893 time_end = time_start;
894
895 double delta = 0.0;
896 Eina_Bool redraw = EINA_FALSE;
897
898 switch (find_data->ui.seek_mode)
899 {
900 case SEEK_FIND:
901 if (find_data->ui.seek_range == SEEK_ALL)
902 {
903 if (!interval_cross(time_start, time_end, interval))
904 {
905 redraw = EINA_TRUE;
906 }
907 if (find_data->ui.stored_length)
908 interval.length = find_data->ui.stored_length;
909 interval.start = (time_end + time_start) / 2.0;
910 interval.start -= interval.length / 2.0;
911 }
912 else
913 {
914 while (!interval_cross(time_start, time_end, interval))
915 {
916 event = _event_find_retry(find_data);
917 if (!event)
918 {
919 _event_name_not_found_cb(find_data);
920 return NULL;
921 }
922 time_start = event->time_start;
923 if (event->event_info->common.type != SINGLE_EVENT)
924 time_end = event->time_end;
925 else
926 time_end = time_start;
927 }
928 }
929 break;
930 case SEEK_GO:
931 if (event->event_info->common.type != SINGLE_EVENT)
932 {
933 interval.length = (time_end - time_start) * 1.03;
934 delta = interval.length * 0.03;
935 }
936 else
937 {
938 interval.length = 0;
939 delta = 0.000001;
940 }
941 interval.start = time_start - delta;
942 interval.length += delta * 2.0;
943
944 if (!((interval.start == find_data->thd->stored_data->interval.start) &&
945 (interval.length == find_data->thd->stored_data->interval.length)))
946 redraw = EINA_TRUE;
947 break;
948 }
949
950 if (redraw)
951 {
952 find_data->thd->selected_start_offset = event->offset_start;
953 event = NULL;
954 evas_object_smart_callback_call(find_data->content,
955 "display,interval",
956 &interval);
957 if (find_data->ui.seek_mode == SEEK_GO)
958 find_data->ui.stored_length = length;
959
960 }
961 return event;
962}
963
964static inline void
965_highlight_task_coords_fill(Time_Range interval,
966 Event_Offsets *event,
967 Task_Highlight *task)
968{
969 double time_start, time_end;
970 time_start = event->time_start;
971 double interval_end = interval.start + interval.length;
972
973 time_end = (event->time_end > interval_end) ? interval_end : event->time_end;
974 task->common.grid.x = time_to_grid_interval_convert(time_start, interval);
975 if (task->common.grid.x < 0) task->common.grid.x = 0;
976 task->common.grid.w = time_to_grid_interval_convert(time_end, interval) - task->common.grid.x;
977 task->common.grid.y = event->grid_slot;
978 task->common.grid.h = 2;
979
980 if (task->common.grid.w <= 0) task->common.grid.w = 1;
981
982 DBG("Selected coords: \tx: %i\tw: %i\ty: %i\th:%i", task->common.grid.x,
983 task->common.grid.w, task->common.grid.y, task->common.grid.h);
984}
985
986static void
987_found_event_task_fill(Find_Data *find_data, Event_Offsets *event)
988{
989 Task_Highlight *task = NULL;
990
991 event = _found_event_process(find_data, event);
992 if (!event) return;
993
994 evas_object_smart_callback_call(find_data->content, "task,highlight,register", &task);
995 _highlight_task_coords_fill(find_data->thd->stored_data->interval, event, task);
996 task->type = event->event_info->common.type;
997 task->grid_num = event->thread_slot;
998 evas_object_smart_callback_call(find_data->content, "task,highlight,grid,set", task);
999 task->offset_start = event->offset_start;
1000 task->offset_finish = event->offset_finish;
1001 task->standalone = EINA_TRUE;
1002}
1003
1004static inline Eina_Bool
1005_highlight_filling_hash_check(Eina_Hash *hash, Task_Highlight *task)
1006{
1007 long long int key;
1008 key = ((long long int)task->common.grid.x << 48) |
1009 ((long long int)task->common.grid.y << 32) |
1010 ((long long int)task->common.grid.w << 16) |
1011 (long long int)task->common.grid.h;
1012
1013 if (eina_hash_find(hash, &key))
1014 return EINA_FALSE;
1015
1016 eina_hash_add(hash, &key, &key);
1017 return EINA_TRUE;
1018}
1019
1020static void
1021_found_array_tasks_fill(Find_Data *find_data, Eina_Array *events)
1022{
1023 //Evas_Object *grid = NULL;
1024 double time_start, time_end;
1025 Time_Range interval = find_data->thd->stored_data->interval;
1026 Eina_Hash *grid_position_unique_highlight = eina_hash_int64_new(NULL);
1027 Task_Highlight *task = NULL;
1028
1029 unsigned int index;
1030 Event_Offsets *event;
1031 Eina_Array_Iterator it;
1032 EINA_ARRAY_ITER_NEXT(events, index, event, it)
1033 {
1034 time_start = event->time_start;
1035 time_end = event->time_end;
1036
1037 if (!interval_cross(time_start, time_end, interval))
1038 continue;
1039 if (!task)
1040 evas_object_smart_callback_call(find_data->content, "task,highlight,register", &task);
1041 _highlight_task_coords_fill(find_data->thd->stored_data->interval, event, task);
1042
1043 if (!_highlight_filling_hash_check(grid_position_unique_highlight, task))
1044 continue;
1045
1046 task->type = event->event_info->common.type;
1047 task->grid_num = event->thread_slot;
1048 evas_object_smart_callback_call(find_data->content, "task,highlight,grid,set", task);
1049 task->offset_start = event->offset_start;
1050 task->offset_finish = event->offset_finish;
1051 task = NULL;
1052 }
1053 eina_hash_free(grid_position_unique_highlight);
1054}
1055/* Event draw */
1056
1057static void
1058_interval_display_cb(void *data,
1059 Evas_Object *obj EINA_UNUSED,
1060 void *event_info EINA_UNUSED)
1061{
1062 Find_Data *find_data = data;
1063 find_data->ui.stored_length = 0;
1064}
1065
1066Eina_Bool
1067find_init(Evas_Object* content)
1068{
1069 Find_Data *find_data = (Find_Data *)calloc(1, sizeof(Find_Data));
1070 find_data->content = content;
1071 evas_object_smart_callback_add(content, "find,combobox,update", _find_combobox_update_cb, find_data);
1072 evas_object_smart_callback_add(content, "event,time,current", _event_time_select_set_cb, find_data);
1073 evas_object_smart_callback_add(content, "event,data,free", _event_data_free_cb, find_data);
1074 evas_object_smart_callback_add(content, "display,interval", _interval_display_cb, find_data);
1075
1076 evas_object_smart_callback_add(content, "find,show", _menu_find_dialog_cb, find_data);
1077
1078 return EINA_TRUE;
1079}
1080
1081Eina_Bool
1082find_shutdown(Evas_Object* content)
1083{
1084 evas_object_smart_callback_call(content, "event,data,free", NULL);
1085
1086 evas_object_smart_callback_del(content, "find,combobox,update", _find_combobox_update_cb);
1087 evas_object_smart_callback_del(content, "event,time,current", _event_time_select_set_cb);
1088 evas_object_smart_callback_del(content, "event,data,free", _event_data_free_cb);
1089 evas_object_smart_callback_del(content, "display,interval", _interval_display_cb);
1090
1091 evas_object_smart_callback_del(content, "find,show", _menu_find_dialog_cb);
1092
1093 return EINA_TRUE;
1094}