Esempio n. 1
0
static
cookie_t
scrumdemo_clock_recurring(int h, int m, int wd, int verbose)
{
  printf("\n----( recurring alarm %02d:%02d every %s )----\n\n",
         h,m, (wd < 0) ? "day" : scrumdemo_wday_name[wd]);

  alarm_event_t  *eve = 0;
  alarm_action_t *act = 0;
  alarm_recur_t  *rec = 0;
  cookie_t        aid = 0;

  // event
  eve = alarm_event_create();
  alarm_event_set_alarm_appid(eve, APPID);
  alarm_event_set_title(eve, "-- title --");
  alarm_event_set_message(eve, "-- message --");

  eve->flags |= ALARM_EVENT_BACK_RESCHEDULE;
  eve->flags |= ALARM_EVENT_BOOT;
  eve->flags |= ALARM_EVENT_SHOW_ICON;

  // STOP
  act = alarm_event_add_actions(eve, 1);
  act->flags |= ALARM_ACTION_WHEN_RESPONDED;
  alarm_action_set_label(act, "Stop");

  // action: SNOOZE
  act = alarm_event_add_actions(eve, 1);
  act->flags |= ALARM_ACTION_WHEN_RESPONDED;
  act->flags |= ALARM_ACTION_TYPE_SNOOZE;
  alarm_action_set_label(act, "Snooze");

  // action: recurrence
  rec = alarm_event_add_recurrences(eve, 1);
  rec->mask_hour = 1u   << h;
  rec->mask_min  = 1ull << m;
  rec->mask_wday = (wd < 0) ? ALARM_RECUR_WDAY_ALL : (1u << wd);
  eve->recur_count = -1;

  // send -> alarmd
  aid = alarmd_event_add(eve);
  printf("cookie = %d\n", (int)aid);
  alarm_event_delete(eve);

  if( (eve = alarmd_event_get(aid)) )
  {
    int d=0,h=0,m=0,s=0,t=0;
    t = scrumdemo_timediff(ticker_get_time(),eve->trigger, &d,&h,&m,&s);
    printf("Time left: %dd %dh %dm %ds (%d)\n", d,h,m,s, t);
    printf("\n");
    alarm_event_delete(eve);
  }

  return aid;
}
Esempio n. 2
0
void Maemo5Alarm::addSnoozeAction(const QString& text)
{
    alarm_action_t *action;

    action = alarm_event_add_actions(m_data, 1);
    alarm_action_set_label(action, text.toAscii().constData());
    action->flags = ALARM_ACTION_WHEN_RESPONDED | ALARM_ACTION_TYPE_SNOOZE;
}
Esempio n. 3
0
void Maemo5Alarm::addExecAction(const QString& text, const QString& command)
{
    alarm_action_t *action;

    action = alarm_event_add_actions(m_data, 1);
    alarm_action_set_label(action, text.toAscii().constData());
    action->flags = ALARM_ACTION_WHEN_RESPONDED | ALARM_ACTION_TYPE_EXEC;
    alarm_action_set_exec_command(action, command.toAscii().constData());
}
Esempio n. 4
0
void Maemo5Alarm::addDBusAction(const QString& text, const QString& service,
                                const QString& interface, const QString& path,
                                const QString& name)
{
    alarm_action_t *action;

    action = alarm_event_add_actions(m_data, 1);
    alarm_action_set_label(action, text.toAscii().constData());
    action->flags = ALARM_ACTION_WHEN_RESPONDED |
                    ALARM_ACTION_DBUS_USE_ACTIVATION | ALARM_ACTION_TYPE_DBUS;
    alarm_action_set_dbus_interface(action, interface.toAscii().constData());
    alarm_action_set_dbus_service(action, service.toAscii().constData());
    alarm_action_set_dbus_path(action, path.toAscii().constData());
    alarm_action_set_dbus_name(action, name.toAscii().constData());
}
Esempio n. 5
0
void Maemo5Alarm::copy(const Maemo5Alarm& other)
{
    alarm_event_set_alarm_appid(m_data, other.m_data->alarm_appid);
    alarm_event_set_message(m_data, other.m_data->message);
    m_data->alarm_time = other.m_data->alarm_time;

    alarm_action_t *act, *other_act;
    if (other.m_data->action_cnt > 0) {
         for (quint32 i = 0 ; i < other.m_data->action_cnt ; ++i) {
             act = alarm_event_add_actions(m_data, 1);
             other_act = alarm_event_get_action(other.m_data, i);
             act->flags = other_act->flags;
             alarm_action_set_label(act, other_act->label);
             alarm_action_set_exec_command(act, other_act->exec_command);
         }
    }
    m_set = other.m_set;
}
Esempio n. 6
0
int setFlipAlarmByIndex(int alarmIndex) {
	alarm_event_t *newEvent = 0;
	alarm_action_t *act = 0;
	


	//First make sure the alarm has a time defined
	if (userAlarmDObjects[alarmIndex]->alarmTime == 0) {
		return 0;
	}
	
	//Clear event if previously existing to be safe
	if (userAlarmDObjects[alarmIndex]->alarmCookie > 0) {
		if (clearFlipAlarm(userAlarmDObjects[alarmIndex]->alarmCookie) == 0) {
			//Couldn't clear out old alarm!
			return 0;
		} else {
			userAlarmDObjects[alarmIndex]->alarmCookie = 0;
		}
	}

	//Now we create the alarm event struct based on the settings given
	// Initialize alarm to 0s
    //memset (&newEvent, 0, sizeof(alarm_event_t));
	
	newEvent = alarm_event_create();	//Create the default alarm struct.
	//Set the APP ID
	alarm_event_set_alarm_appid(newEvent, APPID);
	
	alarm_event_set_title(newEvent, "FlipClockAlarm");
	
	//Create the alarm action
	act = alarm_event_add_actions(newEvent, 1);
	//Setup the action
	newEvent->flags = ALARM_EVENT_BOOT | ALARM_EVENT_SHOW_ICON;
	
	alarm_action_set_dbus_interface(act, DBUS_INTERFACE);
	alarm_action_set_dbus_service(act, DBUS_SERVICE);
	alarm_action_set_dbus_path(act, DBUS_PATH);
	alarm_action_set_dbus_name(act, "triggerAlarm");
	act->flags = ALARM_ACTION_WHEN_TRIGGERED | ALARM_ACTION_DBUS_USE_ACTIVATION | ALARM_ACTION_TYPE_DBUS;
	
	
	
	//Setup the alarm event members
	//createDefaultAlarm(&newEvent);
	
	
	
	//Now populate it with our actual values
	//if (userPreferences.userAlarms[alarmIndex]->title != NULL) {
		//printf("Alarm title: %s %s\n", userPreferences.userAlarms[alarmIndex]->title, newEvent.title);
		//if (newEvent.title != NULL) {
			//free(newEvent.title);
		//}
		//newEvent.title = calloc(strlen(userPreferences.userAlarms[alarmIndex]->title), sizeof(char));
		//sprintf(newEvent.title, "boo %s", userPreferences.userAlarms[alarmIndex]->title); 
	//}

	newEvent->recur_secs =userPreferences.userAlarms[alarmIndex]->recurrence * 60;  // The alarm function is now in seconds...
	newEvent->recur_count =userPreferences.userAlarms[alarmIndex]->recurrenceCount;
	newEvent->alarm_time = (time_t) userAlarmDObjects[alarmIndex]->alarmTime;
	
	printf("trying to make actual alarmD call with recurrence %i %i\n", newEvent->recur_secs,userPreferences.userAlarms[alarmIndex]->recurrence );
	//userPreferences.userAlarms[alarmIndex]->alarmCookie = alarm_event_add(&newEvent);
	
	//Okay all good, let's try to add it
	userAlarmDObjects[alarmIndex]->alarmCookie = alarmd_event_add_with_dbus_params(newEvent, DBUS_TYPE_INT64, &userAlarmDObjects[alarmIndex]->alarmTime, DBUS_TYPE_INT32, &alarmIndex, DBUS_TYPE_INVALID);
	
	
	
	alarm_event_delete(newEvent);

	
	printf("AlarmD update status: %ld\n",userAlarmDObjects[alarmIndex]->alarmCookie);
	
	
	
	return 1;
}
Esempio n. 7
0
static
cookie_t
scrumdemo_clock_oneshot(int h, int m, int wd, int verbose)
{
  /* - defined in local time
   * -> leave alarm_tz unset
   * -> re-evaluated if tz changes
   *
   * - do not add recurrence masks
   *
   * - set up trigger time via alarm_tm field
   * -> set tm_hour and tm_min fields as required
   * -> if specific weekday is requested set also tm_wday field
   *
   * - if alarm is missed it must be disabled
   * -> set event flag ALARM_EVENT_DISABLE_DELAYED
   *
   * - if user presses "stop", event must be disabled
   * -> set action flag ALARM_ACTION_TYPE_DISABLE
   */

  printf("\n----( oneshot alarm %02d:%02d %s )----\n\n",
         h,m, (wd < 0) ? "anyday" : scrumdemo_wday_name[wd]);

  alarm_event_t  *eve = 0;
  alarm_action_t *act = 0;
  cookie_t        aid = 0;

  // event
  eve = alarm_event_create();
  alarm_event_set_alarm_appid(eve, APPID);
  alarm_event_set_title(eve, "-- title --");
  alarm_event_set_message(eve, "-- message --");

  eve->flags |= ALARM_EVENT_DISABLE_DELAYED;
  eve->flags |= ALARM_EVENT_BOOT;
  eve->flags |= ALARM_EVENT_SHOW_ICON;

  // action: STOP
  act = alarm_event_add_actions(eve, 1);
  act->flags |= ALARM_ACTION_WHEN_RESPONDED;
  act->flags |= ALARM_ACTION_TYPE_DISABLE;
  alarm_action_set_label(act, "Stop");

  // action: SNOOZE
  act = alarm_event_add_actions(eve, 1);
  act->flags |= ALARM_ACTION_WHEN_RESPONDED;
  act->flags |= ALARM_ACTION_TYPE_SNOOZE;
  alarm_action_set_label(act, "Snooze");

  eve->alarm_tm.tm_hour = h;
  eve->alarm_tm.tm_min  = m;
  eve->alarm_tm.tm_wday = wd;

  // send -> alarmd
  aid = alarmd_event_add(eve);
  printf("cookie = %d\n", (int)aid);
  alarm_event_delete(eve);

  if( (eve = alarmd_event_get(aid)) )
  {
    int d=0,h=0,m=0,s=0,t=0;
    t = scrumdemo_timediff(ticker_get_time(),eve->trigger, &d,&h,&m,&s);
    printf("Time left: %dd %dh %dm %ds (%d)\n", d,h,m,s, t);
    printf("\n");
    alarm_event_delete(eve);
  }

  return aid;
}
Esempio n. 8
0
void
decode_event(DBusMessageIter *iter, int *err, alarm_event_t *eve)
{
  size_t action_cnt     = 0;
  size_t recurrence_cnt = 0;

  alarm_event_del_actions(eve);
  alarm_event_del_recurrences(eve);

  decode_cookie   (iter, err, &eve->ALARMD_PRIVATE(cookie));
  decode_time     (iter, err, &eve->ALARMD_PRIVATE(trigger));
  decode_dstring  (iter, err, &eve->title);
  decode_dstring  (iter, err, &eve->message);
  decode_dstring  (iter, err, &eve->sound);
  decode_dstring  (iter, err, &eve->icon);
  decode_unsigned (iter, err, &eve->flags);
  decode_dstring  (iter, err, &eve->alarm_appid);
  decode_time     (iter, err, &eve->alarm_time);
  decode_tm       (iter, err, &eve->alarm_tm);
  decode_dstring  (iter, err, &eve->alarm_tz);
  decode_time     (iter, err, &eve->recur_secs);
  decode_int      (iter, err, &eve->recur_count);
  decode_time     (iter, err, &eve->snooze_secs);
  decode_time     (iter, err, &eve->snooze_total);

  decode_size     (iter, err, &action_cnt);
  decode_int      (iter, err, &eve->response);

  /* - - - - - - - - - - - - - - - - - - - *
   * action table
   * - - - - - - - - - - - - - - - - - - - */

  alarm_action_t *act = alarm_event_add_actions(eve, action_cnt);
  for( size_t i = 0; i < action_cnt; ++i )
  {
    decode_action(iter, err, &act[i]);
  }

  /* - - - - - - - - - - - - - - - - - - - *
   * recurrence table
   * - - - - - - - - - - - - - - - - - - - */

  decode_size     (iter, err, &recurrence_cnt);
  alarm_recur_t *rec = alarm_event_add_recurrences(eve, recurrence_cnt);
  for( size_t i = 0; i < recurrence_cnt; ++i )
  {
    decode_recur(iter, err, &rec[i]);
  }
  /* - - - - - - - - - - - - - - - - - - - *
   * attribute table sent by libalarm >= 1.0.4
   * - - - - - - - - - - - - - - - - - - - */

  if( !decode_eom_p(iter, err) )
  {
    size_t count = 0;
    decode_size     (iter, err, &count);
    for( size_t i = 0; i < count; ++i )
    {
      alarm_attr_t *att = alarm_event_add_attr(eve, "\x7f");
      decode_attr(iter, err, att);
    }
  }
}