+static void print_result(int result)
+{
+ FILE *f;
+ pthread_mutex_lock(&client_mutex);
+ if (!client) {
+ pthread_mutex_unlock(&client_mutex);
+ return;
+ }
+ f = client;
+ fprintf(f, "Number of events: %d \n", event_no - init_events);
+ fprintf(f, "Duration: %lld \n\n", (long long) timestamp - event_init_poll_time);
+ if(!print_events){
+ if(result)
+ fprintf(f, "Test passed\n\n");
+ else
+ fprintf(f, "Test failed\n\n");
+ }
+ fflush(f);
+ pthread_mutex_unlock(&client_mutex);
+
+}
+
+static void process_event(struct sensors_event_t *e)
+{
+ int is_poll_duration_over = 0;
+ int is_event_number_reached = 0;
+
+ if (event_init_poll_time == 0) {
+ event_init_poll_time = (long long) e->timestamp;
+ init_events = event_no;
+ }
+ is_poll_duration_over = (long long) e->timestamp - event_init_poll_time <= poll_duration ? 0 : 1;
+ is_event_number_reached = (event_no - init_events) < number_of_events ? 0 : 1;
+
+ if ((!is_poll_duration_over && !is_event_number_reached) || non_param_poll)
+ {
+ timestamp = e -> timestamp;
+ event_no++;
+ if(print_events)
+ print_event(e);
+ } else {
+ ready_to_close = 1;
+ print_result(is_event_number_reached);
+ pthread_cond_signal(&cond);
+ }
+}
+