// cancel current running wakeup (if any) and setup the next wakeup
void prepare_next_wakeup(void){
	WakeupId id;
	time_t scheduled_time;

	if(reminder_data.num_of_reminders == 0)
		return;

	scheduled_time = reminder_data.wakeup_data[reminder_data.sorted_index[0]].time;

	// cancel existing wakeup
	if(reminder_data.wakeup_id > 0){
		APP_LOG(APP_LOG_LEVEL_DEBUG, "Going to cancel wakeup %d", (int)reminder_data.wakeup_id);
		wakeup_cancel(reminder_data.wakeup_id);
	}

	APP_LOG(APP_LOG_LEVEL_DEBUG, "Next wakeup data: todo:%s time:%lu current_time=%lu", 
		reminder_data.wakeup_data[reminder_data.sorted_index[0]].todo, scheduled_time, time(NULL));
	id = wakeup_schedule(scheduled_time, 0, true);
	if(id > 0){
		APP_LOG(APP_LOG_LEVEL_DEBUG, "Next wakeup id=%d, todo=%s", (int)id, reminder_data.wakeup_data[reminder_data.sorted_index[0]].todo);
		reminder_data.wakeup_id = id;
	}
	else{
		// TODO: error handling
		APP_LOG(APP_LOG_LEVEL_ERROR, "Cannot prepare next wakeup. Id=%d", (int)id);
		reminder_data.wakeup_id = id;
	}
}
Beispiel #2
0
static void timer_cancel_wakeup(Timer* timer) {
  if (! timer) {
    return;
  }
  if (timer->wakeup_id <= 0) {
    return;
  }
  wakeup_cancel(timer->wakeup_id);
  timer->wakeup_id = -1;
}
Beispiel #3
0
static void reset_wakeup() {
  wakeup_cancel(s_wakeup_id);
  s_wakeup_id = -1;
  s_wakeup_timestamp = 0;
  persist_delete(PERSIST_WAKEUP);
}