Exemplo n.º 1
0
/**
 * Adjust timeout value to not miss new comming timer
 * alarms while the system is blocked
 */
static void adjustTimeout(jlong currentTime, jlong *timeout) {
    TimerHandle* timer = peek_timer();
    if (timer != NULL) {
        jlong wakeupTime = get_timer_wakeup(timer);
        if (wakeupTime > currentTime) {
            jlong delta = wakeupTime - currentTime;
            if (*timeout < 0 || *timeout > delta) {
                REPORT_INFO2(LC_PUSH, "[adjustTimeout] timeout=%lu adjusted to %lu",
                    (long)*timeout, (long)delta);

                *timeout = delta;
            }
        }
    }
}
/** Handle key repeat timer alarm on timer wakeup */
static void handle_repeat_key_timer_alarm(TimerHandle *timer) {
    static MidpEvent newMidpEvent;
    static int midp_keycode;
    if (timer != NULL) {
        midp_keycode = (int)(get_timer_data(timer));

        newMidpEvent.type = MIDP_KEY_EVENT;
        newMidpEvent.CHR = midp_keycode;
        newMidpEvent.ACTION = KEYMAP_STATE_REPEATED;

        midpStoreEventAndSignalForeground(newMidpEvent);

        timer = remove_timer(timer);
        set_timer_wakeup(timer, get_timer_wakeup(timer) + REPEAT_PERIOD);
        add_timer(timer);
    }
}