Ejemplo 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;
}
Ejemplo n.º 2
0
static
void
alarm_state_delete(alarm_state_t *self)
{
  if( self != 0 )
  {
    alarm_event_delete(self->event);
    free(self);
  }
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
int clearAllFlipAlarms() {

	cookie_t *setAlarms, *iter;	//Container for alarm ID's
	alarm_event_t *thisAlarm;	//All alarm events
	alarm_action_t *act = 0;	//Action for this alarm event
	int i = 0;
	
	const char *dbusInterface = NULL;
	const char *dbusPath = NULL;
	
	int matchedAlarm =0;	//Does alarm match criteria?
	
	setAlarms = NULL;
	
	setAlarms = alarmd_event_query((time_t) 0, (time_t) INT_MAX, 0, 0, APPID);
	if (setAlarms == NULL) {
		printf("No alarms!\n");
		return 0;
	}
	
	if (setAlarms[0] == (cookie_t) 0) {
		printf("No alarms!\n");
	} else {
		//Alarms found!
		for (iter = setAlarms; *iter != (cookie_t) 0; iter++) {
			thisAlarm = alarmd_event_get(*iter);
			
			matchedAlarm = 0;
			
			//Shouldn't need to do this thanks to that APPID thing, but might as well just to be safe... never hurts!
			//Libalarm2 introduces multiple actions per alarm event, so we have to check them all
			for(i = 0; (act = alarm_event_get_action(thisAlarm, i)) != 0; ++i )
			{
				//printf("action%d.label = %s\n", i, alarm_action_get_label(act));

				dbusInterface = alarm_action_get_dbus_interface(act);
				dbusPath = alarm_action_get_dbus_path(act);

				if ((dbusInterface != NULL)  && (dbusPath != NULL)) {
					if (!strcmp(dbusInterface, DBUS_INTERFACE)) { 
						if (!strcmp(dbusPath, DBUS_PATH)) {	
							matchedAlarm = 1;
						}
					}
					//Should I be freeing these? guess so..
					//free(dbusInterface);
					//free(dbusPath);
				}
			}
			
			
			if (matchedAlarm) {
				clearFlipAlarm(*iter);
				printf("Cleared flip alarm %s\n", alarm_event_get_title(thisAlarm));
			}
			
			
			alarm_event_delete(thisAlarm);
		}
		

	}
	
	if (setAlarms != NULL) {
		free(setAlarms);
	}
	
	return 1;
	

}
Ejemplo n.º 5
0
Maemo5Alarm::~Maemo5Alarm()
{
    alarm_event_delete(m_data);
}
void OrganizerItemTransform::fillInCommonCComponentDetails(QOrganizerItem *item, CComponent *component, bool setId)
{
    if (item) {
        // Summary
        QString tempstr = QString::fromStdString(component->getSummary());
        if (!tempstr.isEmpty())
            item->setDisplayLabel(tempstr);

        // Description
        tempstr = QString::fromStdString(component->getDescription());
        if (!tempstr.isEmpty())
            item->setDescription(tempstr);

        // Location
        tempstr = QString::fromStdString(component->getLocation());
        if(!tempstr.isEmpty()) {
            QOrganizerItemLocation il = item->detail<QOrganizerItemLocation>();
            il.setLabel(tempstr);
            item->saveDetail(&il);
        }

        // Timestamps
        time_t createdTime = component->getCreatedTime();
        time_t lastModifiedTime = component->getLastModified();

        if (createdTime || lastModifiedTime) {
            QOrganizerItemTimestamp timeStamps = item->detail<QOrganizerItemTimestamp>();
            timeStamps.setCreated(QDateTime::fromTime_t(createdTime));
            timeStamps.setLastModified(QDateTime::fromTime_t(lastModifiedTime));
            item->saveDetail(&timeStamps);
        }

        // GUid
        QOrganizerItemGuid ig = item->detail<QOrganizerItemGuid>();
        tempstr = QString::fromStdString(component->getGUid());
        if(!tempstr.isEmpty())
            ig.setGuid(tempstr);
        item->saveDetail(&ig);

        // Set component ID
        if (setId) {
            QString idString = QString::fromStdString(component->getId());
            item->setId(QOrganizerItemId(new QOrganizerItemMaemo5EngineId(idString.toUInt())));
        } else {
            item->setId(QOrganizerItemId());
        }

        // Set comments
        CComponentDetails *componentDetails = dynamic_cast<CComponentDetails*>(component);
        if (componentDetails) {
            string comments = componentDetails->getComments();
            if (!comments.empty()) {
                QStringList commentList = QString::fromStdString(comments).split('\n', QString::SkipEmptyParts);
                foreach(const QString comment, commentList)
                    item->addComment(comment);
            }
        }

        // Reminder (alarm)
        CAlarm *alarm = component->getAlarm();
        if (alarm) {
            // TODO: Only visual remainders are supported
            QOrganizerItemVisualReminder reminder = item->detail<QOrganizerItemVisualReminder>();
            reminder.setRepetition(alarm->getRepeat(), reminder.repetitionDelay());

            // Alarm time and messages can't be read with CAlarm,
            // read them straight from the alarm framework:

            // Get the cookie
            std::vector<long> cookies = alarm->getCookie();
            if (cookies.size() > 0) {
                cookie_t cookie = static_cast<cookie_t>(cookies[0]); // only one alarm supported

                alarm_event_t *eve = 0;
                if ((eve = alarmd_event_get(cookie)) != 0) {
                    QString message = QString::fromStdString(alarm_event_get_title(eve));
                    reminder.setMessage(message);
                    time_t alarmTime = alarm_event_get_trigger(eve);
                    alarm_event_delete(eve);

                    QDateTime sTime = QDateTime::fromTime_t(component->getDateStart());
                    QDateTime aTime = QDateTime::fromTime_t(alarmTime);
                    reminder.setSecondsBeforeStart(aTime.secsTo(sTime));
                }
            }

            item->saveDetail(&reminder);
        }
    }
Ejemplo n.º 7
0
static gboolean queue_rescan_callback(void *data)
{
  //log_append("@ %s()\n", __FUNCTION__);

  cookie_t *vec = 0;
  alarm_event_t *eve = 0;

  queue_clear();

  if( (vec = alarmd_event_query(0,0, 0,0, 0)) )
  {
    for( int i = 0; vec[i] > 0; ++i )
    {
      if( (eve = alarmd_event_get(vec[i])) )
      {
        char tdate[256];
        char adate[256];
        char tz[256];
        char trigger[256];

        struct tm tm;
        time_t t = local_get_time();

        *adate = *tz = 0;

        ticker_get_timezone(tz, sizeof tz);
        ticker_get_remote(eve->trigger, tz, &tm);
        snprintf(tdate, sizeof tdate,
                 //"%04d-%02d-%02d %02d:%02d:%02d %s (%s)",
                 //tm.tm_year + 1900,
                 "%02d-%02d-%02d %02d:%02d:%02d %s (%s)",
                 tm.tm_year % 100,
                 tm.tm_mon + 1,
                 tm.tm_mday,
                 tm.tm_hour,
                 tm.tm_min,
                 tm.tm_sec,
                 tz,
                 timeto(eve->trigger, t));

        if( *eve->alarm_tz != 0 )
        {
          ticker_get_remote(eve->trigger, eve->alarm_tz, &tm);
          snprintf(adate, sizeof adate,
                   "\n"
                   //"%04d-%02d-%02d %02d:%02d:%02d %s",
                   //tm.tm_year + 1900,
                   "%02d-%02d-%02d %02d:%02d:%02d %s",
                   tm.tm_year % 100,
                   tm.tm_mon + 1,
                   tm.tm_mday,
                   tm.tm_hour,
                   tm.tm_min,
                   tm.tm_sec,
                   eve->alarm_tz);
        }

        snprintf(trigger, sizeof trigger, "%c %s%s",
                 (eve->flags & ALARM_EVENT_DISABLED) ? 'D' : 'E',
                 tdate, adate);

        queue_append(eve->cookie,
                     trigger,
                     eve->recur_count,
                     eve->title,
                     eve->message);
        alarm_event_delete(eve);
      }

    }
    free(vec);
  }

  rescan_id = 0;
  return FALSE;
}
Ejemplo n.º 8
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;
}