//--------------------------------------------------------------------------- void CXMMRCtrl::OnTimer(UINT nIDEvent) { if( nIDEvent == m_nTimerID ){ switch(m_TimerMode){ case 0: if( m_TimerCount ){ m_TimerCount--; break; } if( m_pCom ){ m_pCom->smpFFT = m_smpFFT; STRNCPY(m_pCom->title, m_Title, sizeof(m_pCom->title)); if( m_ComName.IsEmpty() ){ m_ComName = m_pCom->comName; } else { STRNCPY(m_pCom->comName, m_ComName, sizeof(m_pCom->comName)); } if( m_RadioName.IsEmpty() ){ m_RadioName = m_pCom->comRadio; } else { STRNCPY(m_pCom->comRadio, m_RadioName, sizeof(m_pCom->comRadio)); } } VERIFY(m_hWnd == (HWND)GetHwnd()); if( !m_hWnd ){ AfxMessageBox(IDS_XMMR_NO_WINDOW); return; } { TCHAR bf[512]; wsprintf(bf, _T("%s -h%X"), m_InvokeCommand, (DWORD)m_hWnd); #ifdef _UNICODE char bbf[512]; STRNCPY(bbf, bf, sizeof(bbf)); UINT r = ::WinExec(bbf, SW_SHOW); #else UINT r = ::WinExec(bf, SW_SHOW); #endif m_TimerMode++; m_TimerCount = (r > 31) ? m_Timeup : 1; } //break; case 1: m_TimerCount--; if( !m_TimerCount ){ DeleteTimer(); FireOnDisconnected(2); } else if( !m_bConnected && m_bInitialClose && (m_TimerCount < (m_Timeup-50)) ){ // For insurance HWND hWnd = ::FindWindow(_T("TMmttyWd"), NULL); if( hWnd ){ ::PostMessage(hWnd, gMsgMmtty, RXM_HANDLE, (DWORD)m_hWnd); ::PostMessage(hWnd, gMsgMmtty, RXM_REQHANDLE, 0); } } break; } } else { COleControl::OnTimer(nIDEvent); } }
////////////////////////////////////////////////////////////////////////// // Delete a timer from the list. void CScriptTimerMgr::RemoveTimer(int nTimerID) { if (nTimerID == m_nTimerIDCurrentlyBeingCalled) { ScriptWarning("[CScriptTimerMgr::RemoveTimer] Trying to remove the timer (ID = %d, Lua function = %s) currently being called.", nTimerID, m_mapTimers.find(nTimerID)->second->sFuncName); return; } ScriptTimerMapItor it = m_mapTimers.find(nTimerID); if (it != m_mapTimers.end()) { ScriptTimer* timer = it->second; DeleteTimer(timer); m_mapTimers.erase(it); } else { it = m_mapTempTimers.find(nTimerID); if (it != m_mapTempTimers.end()) { ScriptTimer* timer = it->second; DeleteTimer(timer); m_mapTempTimers.erase(it); } } }
////////////////////////////////////////////////////////////////////////// // Remove all timers. void CScriptTimerMgr::Reset() { m_nLastTimerID = 1; ScriptTimerMapItor itor; itor=m_mapTimers.begin(); while(itor!=m_mapTimers.end()) { if(itor->second) { DeleteTimer(itor->second); } ++itor; } m_mapTimers.clear(); itor=m_mapTempTimers.begin(); while(itor!=m_mapTempTimers.end()) { if(itor->second) { DeleteTimer(itor->second); } ++itor; } m_mapTempTimers.clear(); }
int CBaseVision::Deactive() { if (!m_ppname.empty()) { // 删除消息发送定时器 DeleteTimer(m_sTimerid); } if (m_vProcInfo.size() > 0) { // 注销消息模块 CMt::mt_destory(m_rkey); // 删除消息接收定时器 DeleteTimer(m_rTimerid); char szCmd[256] = {0}; vector<PROC_INFO>::iterator itrProc = m_vProcInfo.begin(); for (; itrProc != m_vProcInfo.end(); ++itrProc) { sprintf(szCmd, "kill -2 %d", itrProc->pid); FILE* fp = popen(szCmd, "r"); if (NULL != fp) { pclose(fp); } } } // 注销通信模块 map<string, key_t>::iterator itr = m_mapShmKey.begin(); for (; itr != m_mapShmKey.end(); ++itr) { CMt::mt_destory(itr->second); } vector<PTHREAD_PFUNC*>::iterator it = m_vPthread.begin(); for (; it != m_vPthread.end(); ++it) { // 停止线程 delete *it; *it = NULL; } LOGW("%s deactived. %s : %d\n", m_pname.c_str(), __FILE__, __LINE__); NotifyExit(PROC_EXIT); return 0; }
void rr::on_ResetSim_clicked() { DisableWidgetsBeforeProcessCreation(); EnableWidgetWhenStop(); DeleteTimer(); ResetSimulator(); }
//--------------------------------------------------------------------------- void CXMMRCtrl::CloseMmtty(BOOL bWait) { DeleteTimer(); HWND hWnd = NULL; if( m_bInitialClose ){ hWnd = (m_hMMWnd != HWND_BROADCAST) ? m_hMMWnd : ::FindWindow(_T("TMmttyWd"), NULL); } else { hWnd = (m_hMMWnd != HWND_BROADCAST) ? m_hMMWnd : NULL; } m_hMMWnd = HWND_BROADCAST; m_bConnected = FALSE; m_ptt = FALSE; if( hWnd ){ // スタンドアローンで起動されているかもしれないので、 // WM_CLOSEを送って終了させます。 ::SendMessage(hWnd, WM_CLOSE, 0, 0); if( bWait ){ int i = 0; if( m_bConfirmClose ){ // MMTTYが完全に終了するまで待ちます。 for( i = 0; (i < 500) && IsWindow(hWnd); i++ ){ ::Sleep(10); } } FireOnDisconnected(i >= 500 ? 0 : 1); } } }
bool CPVRGUIActions::StopRecording(const CFileItemPtr &item) const { if (!DeleteTimer(item, true, false)) return false; g_PVRManager.TriggerRecordingsUpdate(); return true; }
void rr::closeEvent(QCloseEvent *event) { event->ignore(); event->accept(); ClearFCFSAll(); DeleteTimer(); delete pRr; }
virtual void Tick(dword time, bool &redraw){ if((reset_counter -= time) <= 0 || !app.IsFocused()){ DeleteTimer(); if(system::CanRebootDevice()) system::RebootDevice(); #ifdef _DEBUG Fatal("reset"); #endif } }
bool CPVRTimers::DeleteTimer(const CFileItem &item, bool bForce /* = false */) { /* Check if a CPVRTimerInfoTag is inside file item */ if (!item.IsPVRTimer()) { CLog::Log(LOGERROR, "cPVRTimers: DeleteTimer no TimerInfoTag given!"); return false; } const CPVRTimerInfoTag* tag = item.GetPVRTimerInfoTag(); if (!tag) return false; return DeleteTimer(*tag, bForce); }
bool CPVRGUIActions::ToggleTimer(const CFileItemPtr &item) const { if (!item->HasEPGInfoTag()) return false; const CPVRTimerInfoTagPtr timer(CPVRItem(item).GetTimerInfoTag()); if (timer) { if (timer->IsRecording()) return StopRecording(item); else return DeleteTimer(item); } else return AddTimer(item, false); }
void TimerManager::CancelAllTimers() { Timer *timer_ptr; while( timer_list != NULL ) { timer_ptr = timer_list; timer_list = timer_list->next; if( in_timeout == timer_ptr ) { // We get here if somebody calls exit from inside a timer. did_cancel = true; } else { DeleteTimer( timer_ptr ); } } timer_list = NULL; list_tail = NULL; }
void rr::on_StartSim_clicked() { if(CheckQValueBeforeStart()) { if(!bRRStart) { DisableWidgetsWhenStart(); int i = 0; for(i=0;i<MAXIMUM_PROC;i++) { memcpy(&RrProcessInfo[i],&RrProcStructInUse[i],sizeof(ProcessDef)); } CreateTimer(); gUi->StartSim->setText("Stop"); bRRStart= true; gUi->PauseSim->setText("Pause"); gUi->PauseSim->setEnabled(true); } else { EnableWidgetWhenStop(); DeleteTimer(); ClearLabelColour(); ClearRQLabels(); ClearCPULabels(); ClearBTTimeLabel(); ClearStructureForStop(); bRRStart = false; gUi->StartSim->setText("Start"); ProcessDisplayOnHMi(RrProcStructInUse); gUi->PauseSim->setEnabled(false); } } else { return; } }
int TimerManager::CancelTimer(int id) { Timer* timer_ptr; Timer* trail_ptr; dprintf( D_DAEMONCORE, "In cancel_timer(), id=%d\n",id); if (timer_list == NULL) { dprintf( D_DAEMONCORE, "Removing Timer from empty list!\n"); return -1; } timer_ptr = timer_list; trail_ptr = NULL; while ( timer_ptr && timer_ptr->id != id ) { trail_ptr = timer_ptr; timer_ptr = timer_ptr->next; } if ( timer_ptr == NULL ) { dprintf( D_ALWAYS, "Timer %d not found\n",id ); return -1; } RemoveTimer( timer_ptr, trail_ptr ); if ( in_timeout == timer_ptr ) { // We're inside the handler for this timer. Don't delete it, // since Timeout() still needs it. Timeout() will delete it once // it's done with it. did_cancel = true; } else { DeleteTimer( timer_ptr ); } return 0; }
~Counter() { if (timer_valid) { DeleteTimer(); } }
////////////////////////////////////////////////////////////////////////// // Update all managed timers. void CScriptTimerMgr::Update(int64 nCurrentTime) { FUNCTION_PROFILER(gEnv->pSystem, PROFILE_SCRIPT); ScriptTimerMapItor itor; // Loop through all timers. itor = m_mapTimers.begin(); while (itor != m_mapTimers.end()) { ScriptTimer *pST = itor->second; if (m_bPause && !pST->bUpdateDuringPause) { ++itor; continue; } // if it is time send a timer-event if(nCurrentTime >= pST->nEndTime) { ScriptHandle timerIdHandle; timerIdHandle.n = pST->nTimerID; // Call function specified by the script. m_nTimerIDCurrentlyBeingCalled = pST->nTimerID; if (pST->pScriptFunction) { if (!pST->pUserData) Script::Call( m_pScriptSystem,pST->pScriptFunction,timerIdHandle ); else Script::Call( m_pScriptSystem,pST->pScriptFunction,pST->pUserData,timerIdHandle ); } else if (*pST->sFuncName) { HSCRIPTFUNCTION hFunc = 0; if (gEnv->pScriptSystem->GetGlobalValue(pST->sFuncName,hFunc)) { if (!pST->pUserData) Script::Call( m_pScriptSystem,hFunc,timerIdHandle ); else Script::Call( m_pScriptSystem,hFunc,pST->pUserData,timerIdHandle ); gEnv->pScriptSystem->ReleaseFunc(hFunc); } } m_nTimerIDCurrentlyBeingCalled = -1; // After sending the event we can remove the timer. ScriptTimerMapItor tempItor=itor; ++itor; m_mapTimers.erase(tempItor); DeleteTimer(pST); } else { ++itor; } } // lets move all new created timers in the map. this is done at this point to avoid recursion, while trying to create a timer on a timer-event. if(!m_mapTempTimers.empty()) { ScriptTimerMapItor timer_it; timer_it=m_mapTempTimers.begin(); while(timer_it!=m_mapTempTimers.end()) { m_mapTimers.insert(ScriptTimerMapItor::value_type(timer_it->first,timer_it->second)); ++timer_it; } m_mapTempTimers.clear(); } }
bool CPVRGUIActions::DeleteTimerRule(const CFileItemPtr &item) const { return DeleteTimer(item, false, true); }
void __fastcall TriggerPortraitFinished_Hook(Control *ctrl, int timer_id) { DeleteTimer(ctrl, timer_id); *bw::trigger_portrait_active = 0; // Not including the code which clears waits in singleplayer, as it causes replays to desync }
// Timeout() is called when a select() time out. Returns number of seconds // until next timeout event, a 0 if there are no more events, or a -1 if // called while a handler is active (i.e. handler calls Timeout; // Timeout is not re-entrant). int TimerManager::Timeout(int * pNumFired /*= NULL*/, double * pruntime /*=NULL*/) { int result, timer_check_cntr; time_t now, time_sample; int num_fires = 0; // num of handlers called in this timeout if (pNumFired) *pNumFired = 0; if ( in_timeout != NULL ) { dprintf(D_DAEMONCORE,"DaemonCore Timeout() called and in_timeout is non-NULL\n"); if ( timer_list == NULL ) { result = 0; } else { result = (timer_list->when) - time(NULL); } if ( result < 0 ) { result = 0; } return(result); } dprintf( D_DAEMONCORE, "In DaemonCore Timeout()\n"); if (timer_list == NULL) { dprintf( D_DAEMONCORE, "Empty timer list, nothing to do\n" ); } time(&now); timer_check_cntr = 0; DumpTimerList(D_DAEMONCORE | D_FULLDEBUG); // loop until all handlers that should have been called by now or before // are invoked and renewed if periodic. Remember that NewTimer and CancelTimer // keep the timer_list happily sorted on "when" for us. We use "now" as a // variable so that if some of these handler functions run for a long time, // we do not sit in this loop forever. // we make certain we do not call more than "max_fires" handlers in a // single timeout --- this ensures that timers don't starve out the rest // of daemonCore if a timer handler resets itself to 0. while( (timer_list != NULL) && (timer_list->when <= now ) && (num_fires++ < MAX_FIRES_PER_TIMEOUT)) { // DumpTimerList(D_DAEMONCORE | D_FULLDEBUG); in_timeout = timer_list; // In some cases, resuming from a suspend can cause the system // clock to become temporarily skewed, causing crazy things to // happen with our timers (particularly for sending updates to // the collector). So, to correct for such skews, we routinely // check to make sure that 'now' is not in the future. timer_check_cntr++; // since time() is somewhat expensive, we // only check every 10 times we loop if ( timer_check_cntr > 10 ) { timer_check_cntr = 0; time(&time_sample); if (now > time_sample) { dprintf(D_ALWAYS, "DaemonCore: Clock skew detected " "(time=%ld; now=%ld). Resetting TimerManager's " "notion of 'now'\n", (long) time_sample, (long) now); now = time_sample; } } // Update curr_dataptr for GetDataPtr() curr_dataptr = &(in_timeout->data_ptr); // Initialize our flag so we know if ResetTimer was called. did_reset = false; did_cancel = false; // Log a message before calling handler, but only if // D_FULLDEBUG is also enabled. if (IsDebugVerbose(D_COMMAND)) { dprintf(D_COMMAND, "Calling Timer handler %d (%s)\n", in_timeout->id, in_timeout->event_descrip); } if( in_timeout->timeslice ) { in_timeout->timeslice->setStartTimeNow(); } // Now we call the registered handler. If we were told that the handler // is a c++ method, we call the handler from the c++ object referenced // by service*. If we were told the handler is a c function, we call // it and pass the service* as a parameter. if ( in_timeout->handlercpp ) { // typedef int (*TimerHandlercpp)() ((in_timeout->service)->*(in_timeout->handlercpp))(); } else { // typedef int (*TimerHandler)() (*(in_timeout->handler))(); } if( in_timeout->timeslice ) { in_timeout->timeslice->setFinishTimeNow(); } if (IsDebugVerbose(D_COMMAND)) { if( in_timeout->timeslice ) { dprintf(D_COMMAND, "Return from Timer handler %d (%s) - took %.3fs\n", in_timeout->id, in_timeout->event_descrip, in_timeout->timeslice->getLastDuration() ); } else { dprintf(D_COMMAND, "Return from Timer handler %d (%s)\n", in_timeout->id, in_timeout->event_descrip); } } if (pruntime) { *pruntime = daemonCore->dc_stats.AddRuntime(in_timeout->event_descrip, *pruntime); } // Make sure we didn't leak our priv state daemonCore->CheckPrivState(); // Clear curr_dataptr curr_dataptr = NULL; if ( did_cancel ) { // Timer was canceled inside its handler. All we need to do // is delete it. DeleteTimer( in_timeout ); } else if ( !did_reset ) { // here we remove the timer we just serviced, or renew it if it is // periodic. // If a new timer was added at a time in the past // (possible when resetting a timeslice timer), then // it may have landed before the timer we just processed, // meaning that we cannot assume prev==NULL in the call // to RemoveTimer() below. Timer *prev = NULL; ASSERT( GetTimer(in_timeout->id,&prev) == in_timeout ); RemoveTimer( in_timeout, prev ); if ( in_timeout->period > 0 || in_timeout->timeslice ) { in_timeout->period_started = time(NULL); in_timeout->when = in_timeout->period_started; if ( in_timeout->timeslice ) { in_timeout->when += in_timeout->timeslice->getTimeToNextRun(); } else { if( in_timeout->period == TIMER_NEVER ) { in_timeout->when = TIME_T_NEVER; } else { in_timeout->when += in_timeout->period; } } InsertTimer( in_timeout ); } else { // timer is not perodic; it is just a one-time event. we just called // the handler, so now just delete it. DeleteTimer( in_timeout ); } } } // end of while loop // set result to number of seconds until next event. get an update on the // time from time() in case the handlers we called above took significant time. if ( timer_list == NULL ) { // we set result to be -1 so that we do not busy poll. // a -1 return value will tell the DaemonCore:Driver to use select with // no timeout. result = -1; } else { result = (timer_list->when) - time(NULL); if (result < 0) result = 0; } dprintf( D_DAEMONCORE, "DaemonCore Timeout() Complete, returning %d \n",result); if (pNumFired) *pNumFired = num_fires; in_timeout = NULL; return(result); }
//--------------------------------------------------------------------------- LRESULT CXMMRCtrl::OnMmttyMessage(WPARAM wParam, LPARAM lParam) { switch(wParam){ case TXM_HANDLE: m_hMMWnd = (HWND)lParam; InternalPostMmttyMessage(RXM_HANDLE, (DWORD)m_hWnd); if( !m_bConnected ){ DeleteTimer(); InternalPostMmttyMessage(RXM_ENBFOCUS, FALSE); m_bConnected = TRUE; FireOnConnected(); } break; case TXM_REQHANDLE: InternalPostMmttyMessage(RXM_HANDLE, (DWORD)m_hWnd); break; case TXM_START: VERIFY(m_hMMWnd != HWND_BROADCAST); break; case TXM_PTTEVENT: m_ptt = lParam; if( !m_bTranslateAllMessages ) FireOnPttEvent(SHORT(lParam)); break; case TXM_CHAR: if( !m_bTranslateAllMessages ) FireOnCharRcvd(SHORT(lParam)); break; case TXM_BAUD: m_NMMR.m_baud = lParam; if( !m_bTranslateAllMessages ) FireOnBaudChanged(SHORT(lParam)); break; case TXM_MARK: m_NMMR.m_markfreq = lParam; break; case TXM_SPACE: m_NMMR.m_spacefreq = lParam; if( !m_bTranslateAllMessages ) FireOnFreqChanged(SHORT(m_NMMR.m_markfreq), SHORT(m_NMMR.m_spacefreq)); break; case TXM_SWITCH: m_NMMR.m_codeswitch = lParam; if( !m_bTranslateAllMessages ) FireOnSwitchChanged(lParam); break; case TXM_VIEW: m_NMMR.m_codeview = lParam; if( !m_bTranslateAllMessages ) FireOnViewChanged(lParam); break; case TXM_LEVEL: if( m_bRemoveUselessMessage ) RemoveUselessMessage(); m_NMMR.m_siglevel = LOWORD(lParam); m_NMMR.m_sqlevel = HIWORD(lParam); if( !m_bTranslateAllMessages ) FireOnNotifyNMMR((LONG *)&m_NMMR); if( m_pCom ){ if( m_bNotifyFFT && m_pCom->flagFFT ){ SHORT *pw = m_fft; LPLONG pl = m_pCom->arrayFFT; int size = (m_pCom->smpFreq >= 10000) ? 2048 : 1024; if( m_pCom->smpFFT ) size = 2048; for( int i = 0; i < size; i++ ) *pw++ = SHORT(*pl++); m_pCom->flagFFT = 0; FireOnNotifyFFT(m_fft, SHORT(size), SHORT(m_pCom->smpFreq)); } if( m_bNotifyXY && m_pCom->flagXY ){ memcpy(m_xy, m_pCom->arrayX, sizeof(m_xy)); m_pCom->flagXY = 0; FireOnNotifyXY(m_xy); } #ifndef _UNICODE if( m_bNotifyComChange && strcmp(m_pCom->comName, m_ComName) ){ m_ComName = m_pCom->comName; FireOnComNameChanged(m_ComName); } if( m_bNotifyComChange && strcmp(m_pCom->comRadio, m_RadioName) ){ m_RadioName = m_pCom->comRadio; FireOnComNameChanged(m_RadioName); } #endif } break; case TXM_FIGEVENT: m_NMMR.m_fig = lParam; if( !m_bTranslateAllMessages ) FireOnFigChanged(SHORT(lParam)); break; case TXM_NOTCH: m_NMMR.m_notch1 = LOWORD(lParam); m_NMMR.m_notch2 = HIWORD(lParam); if( !m_bTranslateAllMessages ) FireOnNotchChanged(SHORT(m_NMMR.m_notch1), SHORT(m_NMMR.m_notch2)); break; case TXM_RADIOFREQ: m_NMMR.m_radiofreq = lParam; if( !m_bTranslateAllMessages ) FireOnRadioFreqChanged(lParam); break; default: if( !m_bTranslateAllMessages ) FireOnTranslateMessage(wParam, lParam); break; } if( m_bTranslateAllMessages ) FireOnTranslateMessage(wParam, lParam); return FALSE; }