/** * Delete an event, given the eventId */ int Cron::deleteEvent (int iEventId) { Event *pEvent; PtrLList<Cron::Event> *pEventList = (PtrLList<Cron::Event>*) _pEventList; pEventList->resetGet(); while ((pEvent = pEventList->getNext()) != NULL) { if (pEvent->_id == iEventId) { pEventList->remove (pEvent); return 1; } } return 0; }
/** * The run method. Sits in a while loop checking to * see if any of the events in the list are at a time * when they should fire */ int Cron::run (void) { while (1) { Event *pEvent; // temporary event PtrLList<Cron::Event> *pEventList = (PtrLList<Cron::Event>*) _pEventList; pEventList->resetGet(); // start at the beginning of the list // Go through the list while ((pEvent = pEventList->getNext()) != NULL) { ATime currentTime; // get the current time // check to see if the event should happen at this time if (pEvent->getStartTime() == currentTime) { // if the event should happen at this time, check to see whether // the event should happen on this day int dayOfMonth = currentTime.dayOfMonth(); int dayOfWeek = currentTime.dayOfWeek(); if ((pEvent->getDaysOfMonth() & ((0x00000001UL) << (dayOfMonth - 1))) > 0) { if ((pEvent->getDaysOfWeek() & ((0x01) << (dayOfWeek - 1))) > 0) { (*pEvent->getEventCallback()) (pEvent); // call the function // check the count if (pEvent->getCurrentCount() == pEvent->getCount()) { deleteEvent (pEvent->_id); } else { pEvent->incrCount(); } // update the time ATime tmpTime = pEvent->getStartTime() + pEvent->getPeriod(); pEvent->setTime(tmpTime); } } } } sleepForMilliseconds (60000); } }