bool Timer::update(const Milliseconds& now) { if(_active == false) return false; bool hasElapsed = now >= _finished; Timer::Sentry sentry(_sentry); DateTime ts; while( _active && now >= _finished ) { Milliseconds currentTs = _finished; // We add another interval before sending the signal // since sending might throw an exception. We would // skip recalculating the new time then and may loop. _finished += _interval; if( ! sentry ) return hasElapsed; timeout.send(); // We send the signal with datetime only, when someone is // connected since it will take some time to calculate a // DateTime object from milliseconds. if (timeoutts.connectionCount() > 0) { struct tm tim; time_t sec = static_cast<time_t>(currentTs.totalSeconds()); localtime_r(&sec, &tim); DateTime dueTime(tim.tm_year + 1900, tim.tm_mon + 1, tim.tm_mday, tim.tm_hour, tim.tm_min, tim.tm_sec, 0, currentTs.totalUSecs() % 1000000); timeoutts.send(dueTime); } if (_once) stop(); } return hasElapsed; }
TVerdict CInitialiseStep::doTestStepL() { SetTestStepResult(EFail); INFO_PRINTF1(_L("Scheduler BUR test Init")); TSchedulerItemRef ref,ref2; _LIT(KBackupCondition, "AddCondition"); TPtrC data; if (!GetStringFromConfig(ConfigSection(), KBackupCondition, data)) { ERR_PRINTF1(KMissingInputParam); SetTestStepResult(EFail); User::Leave(KErrCorrupt); } _LIT(KTimeStr, "Time"); _LIT(KTestStr, "Test"); _LIT(KBackupStr, "Backup"); _LIT(KRestoreStr, "Restore"); _LIT(KRestoreStr1, "Restore1"); if (data == KTimeStr) { // Creates a time based schedule _LIT(KSchTestName, "Persistent Schedule Test (Time)"); // This is the time when we want the time-based schedule to fire TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0); TTsTime dueTime(datetime1, EFalse); AddTimeScheduleL(KSchTestName, dueTime, ref); _LIT(KSchTestName2, "Transient Time Schedule Test"); AddTransientTimeScheduleL(KSchTestName2, dueTime, ref2); } else { // Creates a condition based schedule _LIT(KSchTestName, "Persistent Schedule Test (Condition)"); // If condition not met, task is run one year from now. TDateTime datetime1(2001, EJanuary, 1, 10, 0, 0, 0); TTsTime dueTime(datetime1, EFalse); CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(2); CleanupStack::PushL(conditionList); if (data == KTestStr) { CreatePSKeyL(KTestKey1); AddTestConditionL(*conditionList, KTestKey1); AddConditionScheduleL(KSchTestName, dueTime, ref, *conditionList); } else if (data == KBackupStr) { // Only create sema if condition not triggered by test but by SBE iSem.CreateL(); CreatePSKeyL(conn::KUidBackupRestoreKey); AddBackupConditionL(*conditionList); AddConditionScheduleL(KSchTestName, dueTime, ref, *conditionList); } else if (data == KRestoreStr || data == KRestoreStr1) { // Only create sema if condition not triggered by test but by SBE TRAPD(ignoreifalreadycreated, iSem.CreateL()); if (ignoreifalreadycreated != KErrNone && ignoreifalreadycreated != KErrAlreadyExists) { User::Leave(ignoreifalreadycreated); } CreatePSKeyL(conn::KUidBackupRestoreKey); AddRestoreConditionL(*conditionList); if (data==KRestoreStr1) { AddTransientConditionScheduleL(KSchTestName, dueTime,*conditionList); } else { AddConditionScheduleL(KSchTestName, dueTime, ref, *conditionList); } } else { SetTestStepResult(EFail); User::Leave(KErrCorrupt); } CleanupStack::PopAndDestroy(conditionList); } SetTestStepResult(EPass); return TestStepResult(); }