You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

331 lines
11 KiB

#include <Ecore.h>
#include <Ecore_Getopt.h>
#include "tsuite_file_data.h"
static const char *
_event_name_get(const Variant_st *v)
{
switch(tsuite_event_mapping_type_get(v->t.type))
{
case TSUITE_EVENT_MOUSE_IN: return "Mouse In";
case TSUITE_EVENT_MOUSE_OUT: return "Mouse Out";
case TSUITE_EVENT_MOUSE_DOWN: return "Mouse Down";
case TSUITE_EVENT_MOUSE_UP: return "Mouse Up";
case TSUITE_EVENT_MOUSE_MOVE: return "Mouse Move";
case TSUITE_EVENT_MOUSE_WHEEL: return "Mouse Wheel";
case TSUITE_EVENT_MULTI_DOWN: return "Multi Down";
case TSUITE_EVENT_MULTI_UP: return "Multi Up";
case TSUITE_EVENT_MULTI_MOVE: return "Multi Move";
case TSUITE_EVENT_KEY_DOWN: return "Key Down";
case TSUITE_EVENT_KEY_UP: return "Key Up";
case TSUITE_EVENT_KEY_DOWN_WITH_KEYCODE: return "Key Down with Keycode";
case TSUITE_EVENT_KEY_UP_WITH_KEYCODE: return "Key Up with Keycode";
case TSUITE_EVENT_TAKE_SHOT: return "Take shot";
default: return NULL;
}
}
static int
_event_struct_len_get(Tsuite_Event_Type type)
{
switch(type)
{
case TSUITE_EVENT_MOUSE_IN: case TSUITE_EVENT_MOUSE_OUT: return sizeof(mouse_in_mouse_out);
case TSUITE_EVENT_MOUSE_DOWN: case TSUITE_EVENT_MOUSE_UP: return sizeof(mouse_down_mouse_up);
case TSUITE_EVENT_MOUSE_MOVE: return sizeof(mouse_move);
case TSUITE_EVENT_MOUSE_WHEEL: return sizeof(mouse_wheel);
case TSUITE_EVENT_MULTI_DOWN: case TSUITE_EVENT_MULTI_UP: return sizeof(multi_move);
case TSUITE_EVENT_MULTI_MOVE: return sizeof(multi_event);
case TSUITE_EVENT_KEY_DOWN: case TSUITE_EVENT_KEY_UP: return sizeof(key_down_key_up);
case TSUITE_EVENT_KEY_DOWN_WITH_KEYCODE: case TSUITE_EVENT_KEY_UP_WITH_KEYCODE: return sizeof(key_down_key_up_with_keycode);
case TSUITE_EVENT_TAKE_SHOT: return sizeof(take_screenshot);
default: return 0;
}
}
static void
_event_specific_info_get(const Variant_st *v, char output[1024])
{
switch(tsuite_event_mapping_type_get(v->t.type))
{
case TSUITE_EVENT_MOUSE_DOWN:
{
mouse_down_mouse_up *t = v->data;
sprintf(output, "Button %d Flags %d", t->b, t->flags);
break;
}
case TSUITE_EVENT_MOUSE_UP:
{
mouse_down_mouse_up *t = v->data;
sprintf(output, "Button %d Flags %d", t->b, t->flags);
break;
}
case TSUITE_EVENT_MOUSE_MOVE:
{
mouse_move *t = v->data;
sprintf(output, "X %d Y %d", t->x, t->y);
break;
}
case TSUITE_EVENT_MOUSE_WHEEL:
{
mouse_wheel *t = v->data;
sprintf(output, "Direction %d Z %d", t->direction, t->z);
break;
}
case TSUITE_EVENT_MULTI_DOWN: case TSUITE_EVENT_MULTI_UP:
{
multi_event *t = v->data;
if (!t->d)
sprintf(output, "Button %d Flags %d", t->b, t->flags);
else
sprintf(output, "D %d X %d Y %d Rad %f RadX %f RadY %f Pres %f Ang %f FX %f FY %f Flags %d",
t->d, t->x, t->y, t->rad, t->radx, t->rady, t->pres, t->ang, t->fx, t->fy, t->flags);
break;
}
case TSUITE_EVENT_MULTI_MOVE:
{
multi_move *t = v->data;
if (!t->d)
sprintf(output, "X %d Y %d", t->x, t->y);
else
sprintf(output, "D %d X %d Y %d Rad %f RadX %f RadY %f Pres %f Ang %f FX %f FY %f",
t->d, t->x, t->y, t->rad, t->radx, t->rady, t->pres, t->ang, t->fx, t->fy);
break;
}
case TSUITE_EVENT_KEY_UP: case TSUITE_EVENT_KEY_DOWN:
{
key_down_key_up *t = v->data;
sprintf(output, "Keyname %s Key %s String %s Compose %s",
t->keyname, t->key, t->string, t->compose);
break;
}
case TSUITE_EVENT_KEY_DOWN_WITH_KEYCODE: case TSUITE_EVENT_KEY_UP_WITH_KEYCODE:
{
key_down_key_up_with_keycode *t = v->data;
sprintf(output, "Keyname %s Key %s String %s Compose %s Keycode %d",
t->keyname, t->key, t->string, t->compose, t->keycode);
break;
}
default:
{
output[0] = '\0';
break;
}
}
}
static const Ecore_Getopt optdesc = {
"exactness_helper",
"%prog [options] [<rec file> | <file1 file2>]",
NULL,
"(C) 2016 Enlightenment",
"BSD",
"Helper for Exactness",
0,
{
ECORE_GETOPT_STORE_USHORT('d', "delay", "Delay the given recording by a given time (in milliseconds)."),
ECORE_GETOPT_STORE_TRUE('c', "clean", "Clean the given recording from wrong events."),
ECORE_GETOPT_STORE_TRUE('l', "list", "List the events of the given recording."),
ECORE_GETOPT_STORE_TRUE('C', "compare", "Compare two given files (images files or objects eet files)."),
ECORE_GETOPT_STORE_USHORT('s', "shot", "Select a specific shot (1 = 1st shot...)."),
ECORE_GETOPT_LICENSE('L', "license"),
ECORE_GETOPT_COPYRIGHT('C', "copyright"),
ECORE_GETOPT_VERSION('V', "version"),
ECORE_GETOPT_HELP('h', "help"),
ECORE_GETOPT_SENTINEL
}
};
static Eina_Bool
_is_hook_duplicate(const Variant_st *cur_v, const Variant_st *prev_v)
{
if (!prev_v) return EINA_FALSE;
Tsuite_Event_Type cur_type = tsuite_event_mapping_type_get(cur_v->t.type);
Tsuite_Event_Type prev_type = tsuite_event_mapping_type_get(prev_v->t.type);
if (cur_type == prev_type &&
!memcmp(cur_v->data, prev_v->data, _event_struct_len_get(cur_type))) return EINA_TRUE;
return EINA_FALSE;
}
int
main(int argc, char *argv[])
{
const char *rec_file = NULL, *comp1 = NULL, *comp2 = NULL;
int ret = 0, args = 0;
unsigned short delay = 0, shot = 0;
Eina_Bool write_file = EINA_FALSE;
Eina_Bool want_quit, clean = EINA_FALSE, list_get = EINA_FALSE, compare_files = EINA_FALSE;
Ecore_Getopt_Value values[] = {
ECORE_GETOPT_VALUE_USHORT(delay),
ECORE_GETOPT_VALUE_BOOL(clean),
ECORE_GETOPT_VALUE_BOOL(list_get),
ECORE_GETOPT_VALUE_BOOL(compare_files),
ECORE_GETOPT_VALUE_USHORT(shot),
ECORE_GETOPT_VALUE_BOOL(want_quit),
ECORE_GETOPT_VALUE_BOOL(want_quit),
ECORE_GETOPT_VALUE_BOOL(want_quit),
ECORE_GETOPT_VALUE_BOOL(want_quit),
ECORE_GETOPT_VALUE_NONE
};
ecore_init();
want_quit = EINA_FALSE;
args = ecore_getopt_parse(&optdesc, values, argc, argv);
if (args < 0)
{
fprintf(stderr, "Failed parsing arguments.\n");
ret = 1;
goto end;
}
else if (want_quit)
{
ret = 1;
goto end;
}
else if ((clean || delay || shot || list_get) && args == argc)
{
fprintf(stderr, "Expected rec file as the last argument..\n");
ecore_getopt_help(stderr, &optdesc);
ret = 1;
goto end;
}
else if (shot && !delay)
{
fprintf(stderr, "shot option can only be used with delay option\n");
ret = 1;
goto end;
}
else if (compare_files && argc - args != 2)
{
fprintf(stderr, "Expected two files to compare as last arguments..\n");
ecore_getopt_help(stderr, &optdesc);
ret = 1;
goto end;
}
Lists_st *list = NULL;
if (clean || delay || list_get)
{
rec_file = argv[args];
Timer_Data td;
list = read_events(rec_file, &td);
}
if (compare_files)
{
comp1 = argv[args];
comp2 = argv[args+1];
}
if (clean)
{
Variant_st *v;
Eina_List *itr, *itr2;
EINA_LIST_FOREACH_SAFE(list->variant_list, itr, itr2, v)
{
if (!evt_time_get(0, v))
list->variant_list = eina_list_remove_list(list->variant_list, itr);
else
{
if (_is_hook_duplicate(v, eina_list_data_get(eina_list_prev(itr))))
list->variant_list = eina_list_remove_list(list->variant_list, itr);
}
}
if (!list->first_timestamp)
{
list->first_timestamp = evt_time_get(0, eina_list_data_get(list->variant_list));
}
write_file = EINA_TRUE;
}
if (delay)
{
if (!shot)
{
if (!list->first_timestamp)
{
list->first_timestamp = evt_time_get(0, eina_list_data_get(list->variant_list));
}
list->first_timestamp -= delay;
}
else
{
Variant_st *v;
Eina_List *itr;
unsigned int cur_shot = 0;
EINA_LIST_FOREACH(list->variant_list, itr, v)
{
if (tsuite_event_mapping_type_get(v->t.type) == TSUITE_EVENT_TAKE_SHOT)
{
cur_shot++;
if (cur_shot == shot)
{
take_screenshot *t = v->data;
t->timestamp += delay;
break;
}
}
}
}
write_file = EINA_TRUE;
}
if (list_get)
{
Variant_st *v;
Eina_List *itr;
printf("First timestamp: ");
if (list->first_timestamp) printf("%u\n", list->first_timestamp);
else printf("undefined\n");
EINA_LIST_FOREACH(list->variant_list, itr, v)
{
char specific_output[1024];
unsigned int timestamp = evt_time_get(0, v);
if (!timestamp) printf("BAD_TIME: ");
else printf("%.3f: ", (list->first_timestamp ? timestamp - list->first_timestamp : timestamp) / 1000.0);
printf("%s", _event_name_get(v));
_event_specific_info_get(v, specific_output);
if (*specific_output) printf(" - %s", specific_output);
printf("\n");
}
}
if (compare_files)
{
const char *ext = strrchr(comp1, '.');
if (!ext)
{
fprintf(stderr, "Extension required\n");
goto end;
}
if (!strcmp(ext, ".eet"))
{
if (!objects_files_compare(comp1, comp2, EINA_TRUE))
{
fprintf(stderr, "Failed objects comparing\n");
}
}
else
{
char buf[1024];
/* FIXME: Clean up. */
snprintf(buf, sizeof(buf),
"compare '%s' '%s' 'comp_file%s'",
comp1, comp2, ext);
if (system(buf))
{
fprintf(stderr, "Failed image comparing '%s' and '%s'\n", comp1, comp2);
}
}
}
if (rec_file && write_file) write_events(rec_file, list);
end:
ecore_shutdown();
return ret;
}