Example #1
0
int replace(int ac, char **av)
{
  int cookie ;
  if(!pcrecpp::RE("([0-9]+)").FullMatch(av[0], &cookie))
  {
    qDebug() << "invalid integer:" << av[0] ;
    return 1 ;
  }
  QString title = QString("replacement_of_%1").arg(cookie) ;
  Maemo::Timed::Event e ;
  Maemo::Timed::Event::Action &a = e.addAction() ;
  a.whenTriggered() ;
  a.setSendCookieFlag() ;
  a.runCommand(QString("echo cookie=[COOKIE] (%1) TRIGGERED $(date) >> /tmp/aa").arg(title)) ;

  e.setAttribute("TITLE", title) ;
  e.setTicker(time(NULL)+10) ;

  Maemo::Timed::Interface timed ;
  if(!timed.isValid())
  {
    qDebug() << "not valid interface:" << timed.lastError() ;
    return 1 ;
  }

  QDBusReply<uint> res = timed.replace_event_sync(e, cookie) ;
  if(!res.isValid())
  {
    qDebug() << "replace_event call failed:" << res.error().message() ;
    return 1 ;
  }

  qDebug() << "new event cookie:" << res.value() ;
  return 0 ;
}
Example #2
0
bool tst_Events::replaceEvent(const uint oldCookie, const qint64 timestamp,
                              const int dueInSeconds, uint &cookie)
{
    Maemo::Timed::Event event = createEvent(timestamp, dueInSeconds);

    // Open a connection to timed and replace the event
    Maemo::Timed::Interface timedIface;
    if (!timedIface.isValid()) {
        qWarning() << "Invalid timed interface:" << timedIface.lastError().message();
        return false;
    }

    QDBusReply<uint> reply = timedIface.replace_event_sync(event, oldCookie);
    if (!reply.isValid()) {
        qWarning() << "Replace event failed: %1" << reply.error().message();
        return false;
    }
    cookie = reply.value();
    return true;
}