void SimpleTimer::run() { int i; unsigned long current_millis; // get current time current_millis = elapsed(); for (i = 0; i < MAX_TIMERS; i++) { toBeCalled[i] = DEFCALL_DONTRUN; // no callback == no timer, i.e. jump over empty slots if (callbacks[i]) { // is it time to process this timer ? if (current_millis - prev_millis[i] >= delays[i]) { // update time //prev_millis[i] = current_millis; prev_millis[i] += delays[i]; // check if the timer callback has to be executed if (enabled[i]) { // "run forever" timers must always be executed if (maxNumRuns[i] == RUN_FOREVER) { toBeCalled[i] = DEFCALL_RUNONLY; } // other timers get executed the specified number of times else if (numRuns[i] < maxNumRuns[i]) { toBeCalled[i] = DEFCALL_RUNONLY; numRuns[i]++; // after the last run, delete the timer if (numRuns[i] >= maxNumRuns[i]) { toBeCalled[i] = DEFCALL_RUNANDDEL; } } } } } } for (i = 0; i < MAX_TIMERS; i++) { switch(toBeCalled[i]) { case DEFCALL_DONTRUN: break; case DEFCALL_RUNONLY: (*callbacks[i])(); break; case DEFCALL_RUNANDDEL: (*callbacks[i])(); deleteTimer(i); break; } } }
void SimpleTimer::run() { int i; unsigned long current_millis; // get current time current_millis = elapsed(); for (i = 0; i < MAX_TIMERS; i++) { timer[i].toBeCalled = DEFCALL_DONTRUN; // no callback == no timer, i.e. jump over empty slots if (timer[i].callback != NULL) { // is it time to process this timer ? // see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592 if ((current_millis - timer[i].prev_millis) >= timer[i].delay) { unsigned long skipTimes = (current_millis - timer[i].prev_millis) / timer[i].delay; // update time timer[i].prev_millis += timer[i].delay * skipTimes; // check if the timer callback has to be executed if (timer[i].enabled) { // "run forever" timers must always be executed if (timer[i].maxNumRuns == RUN_FOREVER) { timer[i].toBeCalled = DEFCALL_RUNONLY; } // other timers get executed the specified number of times else if (timer[i].numRuns < timer[i].maxNumRuns) { timer[i].toBeCalled = DEFCALL_RUNONLY; timer[i].numRuns++; // after the last run, delete the timer if (timer[i].numRuns >= timer[i].maxNumRuns) { timer[i].toBeCalled = DEFCALL_RUNANDDEL; } } } } } } for (i = 0; i < MAX_TIMERS; i++) { if (timer[i].toBeCalled == DEFCALL_DONTRUN) continue; if (timer[i].hasParam) (*(timer_callback_p)timer[i].callback)(timer[i].param); else (*(timer_callback)timer[i].callback)(); if (timer[i].toBeCalled == DEFCALL_RUNANDDEL) deleteTimer(i); } }
void CdrCamera::stopAWMD() { db_msg("%s %d\n", __FUNCTION__, __LINE__); if (mHC && (mAWMDing)) { db_msg("%s %d\n", __FUNCTION__, __LINE__); mHC->stopAWMoveDetection(); if(mAwmdTimerID) { stopTimer(mAwmdTimerID); deleteTimer(mAwmdTimerID); mAwmdTimerID = 0; } mAWMDing = false; } }
void TimerList::deleteTimer(int timerId) { MyTimer *this_ptr; if (timerId == last_ptr->id) this_ptr=last_ptr; else if (timerId == first_ptr->id) this_ptr=first_ptr; else { this_ptr = last_ptr; while(this_ptr!=NULL&&timerId != this_ptr->id) this_ptr=this_ptr->prev_ptr; } deleteTimer(this_ptr); }
//according to the request this fuction composes //checks if the request is valid and construct //a response string to reply the client void getResponse(rtspd_t* rtspd, char response[]){ int status = BAD_REQUEST; printf("getting ----------- response\n"); if(strcmp(rtspd->request, "SETUP") == 0){ printf("send setup response\n"); rtspd->sessionid = getSessionId(); status = getVideo(); printf("video file ok: %d\n", status); //initMovie(rtspd->videoName, rtspd->client_fd); rtspd->data = send_frame_data_new(rtspd->videoName, rtspd->client_fd); composeResponse(rtspd, status, response); //setup complete change state to ready strcpy(rtspd->current_state, "READY"); }else if(strcmp(rtspd->request, "PLAY") == 0&& strcmp(rtspd->current_state,"READY")==0){ status = OK; composeResponse(rtspd, status, response); streamVideo(rtspd->data); strcpy(rtspd->current_state, "PLAYING"); }else if(strcmp(rtspd->request, "PLAY")==0 && strcmp(rtspd->current_state, "PLAYING")==0){ status = OK; printf("start playing, %s, %d\n\n", rtspd->videoName,rtspd->client_fd); composeResponse(rtspd, status, response); streamVideo(rtspd->data); strcpy(rtspd->current_state, "PLAYING"); }else if(strcmp(rtspd->request, "PAUSE")==0 && strcmp(rtspd->current_state, "PLAYING")==0){ status = OK; printf("pause video \n"); pauseVideo(rtspd->data); composeResponse(rtspd, status, response); strcpy(rtspd->current_state, "READY"); }else if(strcmp(rtspd->request, "TEARDOWN")==0 &&(strcmp(rtspd->current_state, "PLAYING")==0 || strcmp(rtspd->current_state, "READY")==0)){ status = OK; printf("TEARDOWN video \n"); deleteTimer(rtspd->data); composeResponse(rtspd, status, response); strcpy(rtspd->current_state, "INIT"); }else{ status = NOT_VALID; composeResponse(rtspd, status, response); } }
bool reset(unsigned dueTime, unsigned period, boost::function<void ()> fn) { if (timer_ != INVALID_HANDLE_VALUE) deleteTimer(); fn_ = fn; return (::CreateTimerQueueTimer( &timer_, NULL, &TimerProc, (LPVOID)this, dueTime, period, WT_EXECUTEINTIMERTHREAD) == TRUE); }
void SimpleTimer::run() { int i; unsigned long current_millis; current_millis = elapsed(); for (i = 0; i < MAX_TIMERS; i++) { toBeCalled[i] = DEFCALL_DONTRUN; if (callbacks[i]) { if (current_millis - prev_millis[i] >= delays[i]) { prev_millis[i] += delays[i]; if (enabled[i]) { if (maxNumRuns[i] == RUN_FOREVER) { toBeCalled[i] = DEFCALL_RUNONLY; } else if (numRuns[i] < maxNumRuns[i]) { toBeCalled[i] = DEFCALL_RUNONLY; numRuns[i]++; if (numRuns[i] >= maxNumRuns[i]) { toBeCalled[i] = DEFCALL_RUNANDDEL; } } } } } } for (i = 0; i < MAX_TIMERS; i++) { switch (toBeCalled[i]) { case DEFCALL_DONTRUN: break; case DEFCALL_RUNONLY: (*callbacks[i])(); break; case DEFCALL_RUNANDDEL: (*callbacks[i])(); deleteTimer(i); break; } } }
CdrCamera::~CdrCamera() { db_msg("CdrCamera Destructor\n"); if (mCD) { delete mCD; mCD = NULL; } if (mHC) { mHC->stopPreview(); release(); delete mHC; mHC = NULL; } if(mAwmdTimerID) { stopTimer(mAwmdTimerID); deleteTimer(mAwmdTimerID); mAwmdTimerID = 0; } }
void stopChopperDrop(ChopperDrop* game) { // unsubscribe devices unsubscribeKeyboard(); unsubscribeTimer(); unsubscribeMouse(); deleteBitmap(game->mouseCursor); deleteCurrentState(game); disableMouse(); cleanBuffer(); deleteMouse(); deleteTimer(game->timer); deleteDate(game->date); free(game); }
void SimpleTimer::run() { int i; long current_millis; // get current time current_millis = millis(); for (i = 0; i < MAX_TIMERS; i++) { // only process active timers if (calls[i].callback && calls[i].enabled) { // is it time to process this timer ? if (current_millis - calls[i].prev_millis >= calls[i].delay) { // update time calls[i].prev_millis = current_millis; // "run forever" timers must always be executed if (calls[i].maxRuns == RUN_FOREVER) { (calls[i].callback)(); } // other timers get executed the specified number of times //BUG take better care of your memory //if an earlier short timer gets deleted before an long later one, it gets overriden because //of the num_timers just stacks upwards and doesnt look down else if (calls[i].numRuns < calls[i].maxRuns) { (calls[i].callback)(); calls[i].numRuns++; // after the last run, delete the timer // to save some cycles if (calls[i].numRuns >= calls[i].maxRuns) { deleteTimer(i); } } } } } }
void TimerList::reset() { MyTimer *prev_ptr, *this_ptr = last_ptr; if (this_ptr == NULL) return; while (1) { prev_ptr = this_ptr->prev_ptr; deleteTimer(this_ptr); this_ptr = prev_ptr; if (this_ptr == NULL) break; } last_ptr=NULL; first_ptr=NULL; ID=0; return; }
void streamVideo(send_frame_data_t *data) { // The following snippet is used to create and start a new timer that runs // every 40 ms. deleteTimer(data); struct sigevent play_event; struct itimerspec play_interval; memset(&play_event, 0, sizeof(play_event)); play_event.sigev_notify = SIGEV_THREAD; play_event.sigev_value.sival_ptr = data; play_event.sigev_notify_function = send_frame; play_interval.it_interval.tv_sec = 0; play_interval.it_interval.tv_nsec = 40 * 1000000; // 40 ms in ns play_interval.it_value.tv_sec = 0; play_interval.it_value.tv_nsec = 1; // can't be zero timer_create(CLOCK_REALTIME, &play_event, &data->play_timer); timer_settime(data->play_timer, 0, &play_interval, NULL); }
~WinAPIWaitableTimer() { if (timer_ != INVALID_HANDLE_VALUE) deleteTimer(); }
void TimerList::run() { MyTimer *this_ptr, *next_ptr; this_ptr = first_ptr; if(this_ptr ==NULL) return; unsigned long current_millis = millis(); while (1) { this_ptr->toBeCalled = DEFCALL_DONTRUN; if (this_ptr->toBeDeleted) this_ptr->toBeCalled = DEFCALL_DEL; // no callback == no timer, i.e. jump over empty slots else if (this_ptr->callback) { // is it time to process this timer ? // see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592 if (current_millis - this_ptr->prev_millis >= this_ptr->delay) { // update time //prev_millis[i] = current_millis; this_ptr->prev_millis += this_ptr->delay; // check if the timer callback has to be executed if (this_ptr->enabled) { // "run forever" timers must always be executed if (this_ptr->maxNumRuns == RUN_FOREVER) { this_ptr->toBeCalled = DEFCALL_RUNONLY; } // other timers get executed the specified number of times else if (this_ptr->numRuns < this_ptr->maxNumRuns) { this_ptr->toBeCalled = DEFCALL_RUNONLY; this_ptr->numRuns++; // after the last run, delete the timer if (this_ptr->numRuns >= this_ptr->maxNumRuns) { this_ptr->toBeCalled = DEFCALL_RUNANDDEL; } } } } } this_ptr = this_ptr->next_ptr; if (this_ptr == NULL) break; } this_ptr = first_ptr; while (1) { next_ptr = this_ptr->next_ptr; switch(this_ptr->toBeCalled) { case DEFCALL_DONTRUN: break; case DEFCALL_RUNONLY: //Serial.print(this_ptr->id);Serial.println("calling"); (this_ptr->callback)(); break; case DEFCALL_RUNANDDEL: //Serial.print(this_ptr->id);Serial.println("calling"); (this_ptr->callback)(); deleteTimer(this_ptr); break; case DEFCALL_DEL: deleteTimer(this_ptr); break; } this_ptr = next_ptr; if (this_ptr == NULL) break; } return; }
void SimpleTimer::run() { Serial.println(F("SimpleTimer::run()")); Serial.flush(); int i; unsigned long current_millis; // get current time current_millis = elapsed(); for (i = 0; i < MAX_TIMERS; i++) { toBeCalled[i] = DEFCALL_DONTRUN; // no callback == no timer, i.e. jump over empty slots if (callbacks[i]) { // is it time to process this timer ? // see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592 if (current_millis - prev_millis[i] >= (unsigned long) delays[i]) { // update time //prev_millis[i] = current_millis; prev_millis[i] += delays[i]; // check if the timer callback has to be executed if (enabled[i]) { // "run forever" timers must always be executed if (maxNumRuns[i] == RUN_FOREVER) { toBeCalled[i] = DEFCALL_RUNONLY; } // other timers get executed the specified number of times else if (numRuns[i] < maxNumRuns[i]) { toBeCalled[i] = DEFCALL_RUNONLY; numRuns[i]++; // after the last run, delete the timer if (numRuns[i] >= maxNumRuns[i]) { toBeCalled[i] = DEFCALL_RUNANDDEL; } } } } } } for (i = 0; i < MAX_TIMERS; i++) { switch(toBeCalled[i]) { case DEFCALL_DONTRUN: continue; case DEFCALL_RUNONLY: (*callbacks[i])(i); //added timer num to callback continue; case DEFCALL_RUNANDDEL: (*callbacks[i])(i); //added timer num to callback deleteTimer(i); continue; } } }
void disconnect(rtspd_t *rtspd){ close(rtspd->client_fd); deleteTimer(rtspd->data); }
void MyTimerList::run() { int i; unsigned long current_millis; int *toBeCalled=new int[n]; // get current time current_millis = millis(); for (i = 0; i < n; i++) { toBeCalled[i] = DEFCALL_DONTRUN; // no callback == no timer, i.e. jump over empty slots if (timers[i]->callback) { // is it time to process this timer ? // see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592 if (current_millis - timers[i]->prev_millis >= timers[i]->delay) { // update time //prev_millis[i] = current_millis; timers[i]->prev_millis += timers[i]->delay; // check if the timer callback has to be executed if (timers[i]->enabled) { // "run forever" timers must always be executed if (timers[i]->maxNumRuns == RUN_FOREVER) { toBeCalled[i] = DEFCALL_RUNONLY; } // other timers get executed the specified number of times else if (timers[i]->numRuns < timers[i]->maxNumRuns) { toBeCalled[i] = DEFCALL_RUNONLY; timers[i]->numRuns++; // after the last run, delete the timer if (timers[i]->numRuns >= timers[i]->maxNumRuns) { toBeCalled[i] = DEFCALL_RUNANDDEL; } } } } } } for (i = 0; i < n; i++) { switch(toBeCalled[i]) { case DEFCALL_DONTRUN: break; case DEFCALL_RUNONLY: (*timers[i]->callback)(); break; case DEFCALL_RUNANDDEL: (*timers[i]->callback)(); deleteTimer(timers[i]); break; } } if(toBeCalled!=NULL) delete [] toBeCalled; toBeCalled=NULL; return; }