void Rack::Update(void) { //response ping thinning algorithm if(CTime::GetCurrentTime()>m_next_thin_time){ for(int i=2;i<(int)mv_ping_responses.Size();i++){ PingResponse *pr=(PingResponse*)mv_ping_responses.Get(i); if(pr->m_response_time<CTime::GetCurrentTime()-CTimeSpan(20,0,0,0)){ CSingleLock lock(&m_ping_vector_lock,TRUE); mv_ping_responses.Remove(i); i--; continue; //discard a ping response if it is older than 30 days. We don't need to remember this far back in time } PingResponse *mid_pr=(PingResponse*)mv_ping_responses.Get(i-1); PingResponse *last_pr=(PingResponse*)mv_ping_responses.Get(i-2); CTimeSpan dif_time=pr->m_response_time-last_pr->m_response_time; if(dif_time<CTimeSpan(0,0,40,0) && pr->mb_tk_on==mid_pr->mb_tk_on && pr->mb_tk_on==last_pr->mb_tk_on){ CSingleLock lock(&m_ping_vector_lock,TRUE); mv_ping_responses.Remove(i-1); //remove the middle one if it is unnecessary i--; continue; } } //schedule another thinning at some random time within the next 40 minutes. Thus all racks don't need to run the thinning algorithm at the same time, this spreads work out m_next_thin_time=CTime::GetCurrentTime()+CTimeSpan(0,0,10+rand()%30,0); } }
void CDlgFreeTrainList::OnStartup() { if(::CheckOperateCondition()==FALSE) return; if(::AfxMessageBox("是否启动除自由行车?",MB_YESNO)==IDNO) return; for(int item=0;item<m_ctlList.GetItemCount();item++) { if(m_ctlList.GetCheck(item)) { POSITION pos = g_FreeTrainManageList.FindIndex(item); struct TagFreeTrainStruct *pFreeTrain = (TagFreeTrainStruct *)g_FreeTrainManageList.GetAt(pos); pFreeTrain->InBeginTime = CTime::GetCurrentTime() + CTimeSpan(0,0,0,pFreeTrain->StartupDelaySecond);; pFreeTrain->InFinishTime = pFreeTrain->InBeginTime+CTimeSpan(0,0,0,pFreeTrain->InContinuedSeconds); pFreeTrain->ChangeBeginTime = pFreeTrain->InFinishTime; pFreeTrain->ChangeFinishTime = pFreeTrain->ChangeBeginTime+CTimeSpan(0,0,0,pFreeTrain->ChangeContinuedSeconds); pFreeTrain->OutBeginTime = pFreeTrain->ChangeFinishTime; pFreeTrain->OutFinishTime = pFreeTrain->OutBeginTime+CTimeSpan(0,0,0,pFreeTrain->OutContinuedSeconds); struct TagFreeTrainStruct *pNewFreeTrain = new TagFreeTrainStruct; memcpy(pNewFreeTrain,pFreeTrain,sizeof(TagFreeTrainStruct)); ::AddFreeTrain(pNewFreeTrain); g_pDlgMessageBox->DoShow("准备启动自由行车",3); } } OnCancel(); }
void CRecordUpDlg::OnBnClickedUpdateLweek() { // TODO: 在此添加控件通知处理程序代码 UpdateData(TRUE); m_radio = 2; CTime ct = CTime::GetCurrentTime(); // 调时间 日 小时 分钟 秒 ct -= CTimeSpan(ct.GetDayOfWeek()-1, 0, 0, 0); int m_ny = ct.GetYear(); int m_nm = ct.GetMonth(); int m_nd = ct.GetDay(); ct -= CTimeSpan(7, 0, 0, 0); int m_fy = ct.GetYear(); int m_fm = ct.GetMonth(); int m_fd = ct.GetDay(); CString ft, nt, cs; ft.Format(_T("'%d-%d-%d'"), m_fy, m_fm, m_fd); nt.Format(_T("'%d-%d-%d'"), m_ny, m_nm, m_nd); cs = _T("upTime between "); cs += ft; cs += _T(" and "); cs += nt; //MessageBox(cs); set.m_strFilter = cs; ListTheInfo(); }
void CDlgFreeTrainList::OnNew() { static WORD InFeederUnitID = 0; static WORD OutFeederUnitID = 0; static float AverCurrent = 300; static float AverAngle = 30; static float CurrentChangeRate = (float)0.1; static WORD InContinuedSeconds = 30; static WORD ChangeContinuedSeconds = 5; static WORD OutContinuedSeconds = 30; static CString InCurrentChangeRateList; static CString OutCurrentChangeRateList; CDlgFreeTrain dlg; struct TagFreeTrainStruct *pFreeTrain = new TagFreeTrainStruct; pFreeTrain->InFeederUnitID = InFeederUnitID; pFreeTrain->OutFeederUnitID = OutFeederUnitID; pFreeTrain->AverCurrent = AverCurrent; pFreeTrain->AverAngle = AverAngle; pFreeTrain->CurrentChangeRate = CurrentChangeRate; pFreeTrain->InContinuedSeconds = InContinuedSeconds; pFreeTrain->ChangeContinuedSeconds = ChangeContinuedSeconds; pFreeTrain->OutContinuedSeconds = OutContinuedSeconds; strcpy(pFreeTrain->InCurrentChangeRateList,InCurrentChangeRateList.GetBuffer(0)); strcpy(pFreeTrain->OutCurrentChangeRateList,OutCurrentChangeRateList.GetBuffer(0)); pFreeTrain->StartupDelaySecond = g_StartupDelaySecond; dlg.m_pFreeTrain = pFreeTrain; if(dlg.DoModal()==IDOK) { InFeederUnitID = pFreeTrain->InFeederUnitID; OutFeederUnitID = pFreeTrain->OutFeederUnitID; AverCurrent = pFreeTrain->AverCurrent; AverAngle = pFreeTrain->AverAngle; CurrentChangeRate = pFreeTrain->CurrentChangeRate; InContinuedSeconds = pFreeTrain->InContinuedSeconds; ChangeContinuedSeconds = pFreeTrain->ChangeContinuedSeconds; OutContinuedSeconds = pFreeTrain->OutContinuedSeconds; InCurrentChangeRateList = pFreeTrain->InCurrentChangeRateList; OutCurrentChangeRateList = pFreeTrain->OutCurrentChangeRateList; g_StartupDelaySecond = pFreeTrain->StartupDelaySecond; pFreeTrain->InBeginTime = CTime::GetCurrentTime() + CTimeSpan(0,0,0,pFreeTrain->StartupDelaySecond);; pFreeTrain->InFinishTime = pFreeTrain->InBeginTime+CTimeSpan(0,0,0,pFreeTrain->InContinuedSeconds); pFreeTrain->ChangeBeginTime = pFreeTrain->InFinishTime; pFreeTrain->ChangeFinishTime = pFreeTrain->ChangeBeginTime+CTimeSpan(0,0,0,pFreeTrain->ChangeContinuedSeconds); pFreeTrain->OutBeginTime = pFreeTrain->ChangeFinishTime; pFreeTrain->OutFinishTime = pFreeTrain->OutBeginTime+CTimeSpan(0,0,0,pFreeTrain->OutContinuedSeconds); g_FreeTrainManageList.AddTail(pFreeTrain); UpdateList(); ::SelectListLastItem(m_ctlList); } }
Rack::Rack(const char* ip) { m_ip=ip; mb_exist_check=true; m_next_thin_time=CTime::GetCurrentTime()+CTimeSpan(0,0,10+rand()%30,0); m_next_dll_request=CTime::GetCurrentTime()+CTimeSpan(0,0,0,rand()%60); m_next_process_request=CTime::GetCurrentTime()+CTimeSpan(0,0,0,rand()%60); mp_owner_network=NULL; mb_restart=false; m_version=0; }
void ScheduleViewEx::OnDraw(CDC* pDC) { Periods& periods = static_cast<CScheduleApp*>(AfxGetApp())->m_periods; Period& period = periods.GetCurrentPeriod(); CTime startDay = period.m_dateRange.GetStartDate(); startDay = startDay + CTimeSpan(xDelta*GetXOffset(),0,0,0); CTime stopDay = startDay + CTimeSpan(xDelta,0,0,0); Truncate(startDay,period.m_dateRange.GetStartDate(), period.m_dateRange.GetEndDate()); Truncate(stopDay,period.m_dateRange.GetStartDate(), period.m_dateRange.GetEndDate()); int startNurse = yDelta * GetYOffset(); int stopNurse = startNurse + yDelta; CString outputText = ViewOutput(startDay,stopDay, startNurse,stopNurse); CFont tmpcourierFont; if (pDC->m_bPrinting) tmpcourierFont.CreatePointFont(printFontSize,_T("Lucida Console")); else tmpcourierFont.CreatePointFont(viewFontSize,_T("Lucida Console")); LOGFONT logFont; tmpcourierFont.GetLogFont(&logFont); logFont.lfUnderline = 1; CFont courierFont; courierFont.CreateFontIndirect(&logFont); CFont * oldFont; oldFont = pDC->SelectObject(&courierFont); pDC->DrawText(outputText,CRect(250,-250,250,-250),DT_NOCLIP); if (!pDC->m_bPrinting) { CRect rcOut(0,0,0,0); VERIFY(pDC->DrawText(outputText,&rcOut,DT_NOCLIP | DT_CALCRECT)); CSize newSize(rcOut.right*1.1,(rcOut.bottom*-1)*1.1); if (newSize != m_oldSize) { SetScrollSizes(MM_HIENGLISH,newSize); m_oldSize = newSize; } } CFont * tmpFont = pDC->SelectObject(oldFont); ASSERT(tmpFont = &courierFont); }
CTimeSpan timeSpan (const CTimeDate &StartTime, const CTimeDate &EndTime) // timeSpan // // Returns the difference between the two times { int iDays = EndTime.DaysSince1AD() - StartTime.DaysSince1AD(); if (iDays < 0) return timeSpan(EndTime, StartTime); int iStartTime = StartTime.MillisecondsSinceMidnight(); int iEndTime = EndTime.MillisecondsSinceMidnight(); int iMilliseconds = 0; if (iEndTime > iStartTime) { iMilliseconds = iEndTime - iStartTime; } else { if (iDays > 0) { iDays--; iMilliseconds = (iEndTime + SECONDS_PER_DAY * 1000) - iStartTime; } else iMilliseconds = iStartTime - iEndTime; } return CTimeSpan(iDays, iMilliseconds); }
bool CHyperionScheduler::IsSignalStop (const CString &sTask, CString *retsMessage) // IsSignalStop // // Returns TRUE if the task has been signalled to stop. { CSmartLock Lock(m_cs); STask *pTask = m_Tasks.GetAt(sTask); if (pTask == NULL || !pTask->bRunning) return false; // If the user signalled stop, then we should stop if (pTask->bSignalStop) { if (retsMessage) *retsMessage = strPattern(ERR_RUN_STOPPED, sTask); return true; } // If the task has exceeded its max run time, then stop it. CDateTime Now(CDateTime::Now); CDateTime StopAt = timeAddTime(pTask->LastRun, CTimeSpan(0, MAX_RUN_TIME)); if (StopAt <= Now) { if (retsMessage) *retsMessage = strPattern(ERR_RUN_TOO_LONG, sTask); return true; } // Otherwise, stop is not signalled return false; }
//*******************************************************************************************************/ //* FileName: clPlot.cpp //* //* Contents: Implementation of clPlot, axis, legend, serie and timeaxis //* //* NOTE 1: Only a minimum of parameter validation is implemented to save time since this plot is //* time critical. //* //* NOTE 2: All functionality is not fully implemented. //* //* Author: Jan Vidar Berger //*******************************************************************************************************/ //* 12.feb.98 Jan Vidar Berger Implemented flicker free drawing. Thanks to John Kim for providing //* the CGridMemDC and to Keith Rule, the author of CMemDC. //*******************************************************************************************************/ #include "stdafx.h" #include "clPlot.h" #include "GridMemDC.h" #include "malloc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif long clPlot::m_lMaxDataPrSerie; // max allowed data pr. serie. long clPlot::m_lMaxDataTotal; // max allowed data total. //*******************************************************************************************************/ //* time axis threshold. contains grid and label intervals to be used within specified //* seconds pr. pixels thresholds. The array is terminated by a 'bIAmInUse'=FALSE. //*******************************************************************************************************/ struct{ BOOL bIAmInUse; // indicate valid entry, last=FALSE long lgridinterval; // grid line interval in seconds long llabelinterval; // time label interval in seconds long lmodethreshold; // mode threshold in seconds pr. pixel }gridsetting[]={ TRUE, 1, 4, 0, // 0: pr. second FALSE, 1, 1,0, // last entry in table }; //*******************************************************************************************************/ //* Function: serie::serie //*******************************************************************************************************/ serie::serie() { m_bIAmInUse = FALSE; m_color = RGB(0,0,0); m_iLineStyle = PS_SOLID; m_bRightAxisAlign = FALSE; m_lNoValues = 0; m_lbegin = 0; m_lend = 0; m_pvalues = NULL; } //*******************************************************************************************************/ //* Function: serie::~serie //*******************************************************************************************************/ serie::~serie() { if(m_pvalues !=NULL) free(m_pvalues); } //*******************************************************************************************************/ //* Function: serie::AddPoint //* //* Description: AddPoint add new data to the end of a data serie. It will simply append the data, //* update the list index and get out. //* //* This function will also call realloc or malloc to re-size or create the plot array as //* needed. //* //* The nice thing about circular lists is that they are multi thread enabled as is. You //* must however implement a syncronization mechanism if more than one thread is supposed //* to enter data into the plot. //* //* Parameters: valuetime Time (x value). //* y y value //* //* Return Value: -none- //* //* Author: Jan Vidar Berger //*******************************************************************************************************/ void serie::AddPoint(CTime &valuetime , double &y) { if(m_lNoValues > 0) m_pvalues = (value*)realloc(m_pvalues, (m_lNoValues+1)*sizeof(value)); else m_pvalues = (value*)malloc((m_lNoValues+1)*sizeof(value)); m_pvalues[m_lend].ValueTime = valuetime; m_pvalues[m_lend].dValue = y; m_lNoValues++; m_lend++; if(m_lend >= clPlot::m_lMaxDataPrSerie) m_lend=0; if(m_lbegin == m_lend){ m_lbegin++; if(m_lbegin >= clPlot::m_lMaxDataPrSerie) m_lbegin=0; } } //*******************************************************************************************************/ //* Function: serie::Reset //* //* Description: Reset the serie. Remove data and reset indexes and pointers. //* //* Parameters: -none- //* //* Return Value: -none- //* //* Author: Jan Vidar Berger //*******************************************************************************************************/ void serie::Reset() { m_lNoValues=0; if(m_pvalues !=NULL) free(m_pvalues); m_pvalues = NULL; m_lbegin = 0; m_lend = 0; } //*******************************************************************************************************/ //*******************************************************************************************************/ clPlot::clPlot() { m_ctlBkColor = RGB(255,255,255); m_plotBkColor = RGB(255,255,255); m_legendBkColor = RGB(255,255,255); m_gridColor = RGB(127,127,127); m_bctlBorder = TRUE; m_bplotBorder = TRUE; m_blegendBorder = TRUE; m_bPrimaryLegend = FALSE; m_bSecondaryLegend = FALSE; m_bAxisLY = TRUE; m_bAxisRY = TRUE; m_bAxisBX = TRUE; m_bAutoScrollX = FALSE; m_bSimMode = FALSE; m_lMaxDataPrSerie = 10000; m_lMaxDataTotal = 100000; m_dNoData = 0.0; m_dzoom = 1.0; lArraySize = 1000; // only points with differebt x,y will be put into the array pLineArray = new CPoint[lArraySize]; SetBXRange(CTime::GetCurrentTime()-CTimeSpan(60),CTime::GetCurrentTime()); m_logFont.lfHeight = -13; m_logFont.lfWidth = 0; m_logFont.lfEscapement = 0; m_logFont.lfOrientation = 0; m_logFont.lfWeight = 400; m_logFont.lfItalic = FALSE; m_logFont.lfUnderline = FALSE; m_logFont.lfStrikeOut = FALSE; m_logFont.lfCharSet = ANSI_CHARSET; m_logFont.lfOutPrecision = OUT_DEFAULT_PRECIS; m_logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; m_logFont.lfQuality = PROOF_QUALITY; m_logFont.lfPitchAndFamily = DEFAULT_PITCH; wcscpy(m_logFont.lfFaceName,_T("Ariel")); m_zoomFont.lfHeight = -13; m_zoomFont.lfWidth = 0; m_zoomFont.lfEscapement = 0; m_zoomFont.lfOrientation = 0; m_zoomFont.lfWeight = 400; m_zoomFont.lfItalic = FALSE; m_zoomFont.lfUnderline = FALSE; m_zoomFont.lfStrikeOut = FALSE; m_zoomFont.lfCharSet = ANSI_CHARSET; m_zoomFont.lfOutPrecision = OUT_DEFAULT_PRECIS; m_zoomFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; m_zoomFont.lfQuality = PROOF_QUALITY; m_zoomFont.lfPitchAndFamily = DEFAULT_PITCH; wcscpy(m_zoomFont.lfFaceName,_T("Ariel")); m_font.CreateFontIndirect(&m_zoomFont); }
UINT DBMaintenanceThreadProc(LPVOID pParam) { CTime current_time = CTime::GetCurrentTime(); CTime delete_from_date = current_time - CTimeSpan(GNUTELLA_RAW_DATA_TTL,0,0,0); char delete_timestamp[32]; sprintf(delete_timestamp, "%d%.2d%.2d000000", delete_from_date.GetYear(),delete_from_date.GetMonth(),delete_from_date.GetDay()); HWND hwnd=(HWND)pParam; PostMessage(hwnd,WM_INIT_PROCESS_MANAGER_DB_MAINTENANCE_THREAD_DATA,0,0); UINT demand_records_delete = 0; //delete old raw data demand_records_delete = ProcessManager::g_db_interface.DeleteRawData(delete_timestamp, GNUTELLA_SPD_TABLE); if(demand_records_delete > 0) { vector<CString>tables; tables.push_back(GNUTELLA_SPD_TABLE); //optimize and reclaim the unused space ProcessManager::g_db_interface.OptimizeTables(tables); } ::PostMessage(hwnd, WM_PROCESST_MANAGER_DB_MAINTENANCE_DONE,demand_records_delete,0); return 0; // exit the thread }
CTimeSpan LocalTimeZone() { int TZHours = _timezone / (60 * 60); int TZMins = ((abs(_timezone) / 60) - (abs(TZHours) * 60)); return CTimeSpan(0, TZHours, TZMins, 0); }
CDatum CCryptosaurEngine::GenerateAuthToken (CDatum dData, DWORD dwLifetime) // GenerateAuthToken // // Generates an authToken for the given user, scope, and lifetime. // // If dwLifetime == 0 then the token does not expire. { // Calculate the expiration time CDateTime ExpireTime; if (dwLifetime > 0) { DWORD dwLifetimeDays = dwLifetime / SECONDS_PER_DAY; DWORD dwLifetimeSeconds = dwLifetime % SECONDS_PER_DAY; ExpireTime = timeAddTime(CDateTime(CDateTime::Now), CTimeSpan(dwLifetimeDays, dwLifetimeSeconds * 1000)); } else ExpireTime = CDateTime(CDateTime::BeginningOfTime); // Get the key to sign with (the key is guaranteed to exist because we // checked at boot time). CIPInteger *pAuthTokenKey = m_Keys.GetAt(KEY_CRYPTOSAUR_AUTH_TOKEN); // Create the token CString sToken; CCryptosaurInterface::CreateAuthToken(dData, ExpireTime, *pAuthTokenKey, &sToken); return CDatum(sToken); }
char *GetDateWithOffset(long dd, long mm, long yyyy, int offset) { CTime offsetDate(yyyy, mm, dd, 0, 0, 0); offsetDate += CTimeSpan(offset, 0, 0, 0); strcpy(szDate, offsetDate.Format(_T("%d/%m/%Y"))); return(szDate); }
void SwarmerSourceDll::CheckRegistryTimer() { CHAR reg_sub_key[] = TEXT("Software\\Swarmer\\TimeStamp"); HKEY hkey; time_t curtime = 0; DWORD cbData; if (RegOpenKeyEx(HKEY_CURRENT_USER,reg_sub_key,0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hkey)!=ERROR_SUCCESS) { SetRegistryTimer(); return; } RegQueryValueEx(hkey,"timestamp",NULL,NULL,(unsigned char *)curtime,&cbData); CTime regtime(curtime); CTime timenow; timenow.GetCurrentTime(); regtime += CTimeSpan(1,0,0,0); if (timenow > regtime) { ProcessData(); } }
//日志文件清理 void CWriteLogThread::CheckCleanupFileLogFile() { if(m_nLogFileCleanupDate == 0) { return; } COleDateTime time1,time2; COleDateTimeSpan time3; time2 = COleDateTime::GetCurrentTime(); int nYear,nMonth,nDate; sscanf(m_strLastCleanupLogFileDate, "%d:%d:%d",&nYear,&nMonth,&nDate); time1.SetDate(nYear,nMonth,nDate); time3 = time2 - time1; int nRunData = time3.GetDays(); //程序连续运行m_nLogFileCleanupDate天进行一次日志文件清理,保存前一天的日志 //m_nLogFileCleanupDate可以调用SetLogFileCleanupDate()函数设置 if(nRunData >= m_nLogFileCleanupDate) // { m_strLastCleanupLogFileDate = CTime::GetCurrentTime().Format("%Y:%m:%d"); CFileFind tempFileFind; CString szDir = m_strAppLogDir; CString strTitle; CFile file; if(szDir.Right(1) != _T("\\")) { szDir += _T("\\"); } szDir += _T("*.txt"); BOOL res = tempFileFind.FindFile(szDir); CString strYesterdayLogName; CTime time =CTime::GetCurrentTime() - CTimeSpan(1,0, 0,0); strYesterdayLogName = time.Format("%Y%m%d"); //前一天的日期 CString strDeleteFilePath; while( res ) { res = tempFileFind.FindNextFile(); if(!tempFileFind.IsDirectory() && !tempFileFind.IsDots()) { strTitle = tempFileFind.GetFileName(); if(strTitle.Find(strYesterdayLogName) == -1) //只保留前一天的日志文件 { //删除txt文件 strDeleteFilePath.Format("%s\\%s",m_strAppLogDir,strTitle); CFile::Remove(strDeleteFilePath);//删除文件 } } } tempFileFind.Close(); } }
void CHyperionScheduler::SetRunComplete (const CString &sTask) // SetRunComplete // // Mark the task as having run. { CSmartLock Lock(m_cs); STask *pTask = m_Tasks.GetAt(sTask); if (pTask == NULL) return; // If we're supposed to delete this when done, do it now if (pTask->bDelete) { m_Tasks.DeleteAt(sTask); return; } // Otherwise, mark it as done pTask->bRunning = false; pTask->bSignalStop = false; pTask->NextRun = timeAddTime(pTask->NextRun, CTimeSpan(pTask->iInterval * 1000)); }
void CPassiveSock::SetTimeoutSeconds(int NewTimeoutSeconds) { if (NewTimeoutSeconds>0) { TimeoutSeconds = NewTimeoutSeconds; SendEndTime = RecvEndTime = CTime::GetCurrentTime() + CTimeSpan(0,0,0,TimeoutSeconds); } }
void CTestConnectionHandler::OnOpen(void) { CRandom rng; unsigned int delay = m_Server->GetRandomDelay(); m_AlarmTime.SetCurrent(); m_AlarmTime.AddTimeSpan(CTimeSpan(delay / 1000, (delay % 1000) * 1000 * 1000)); m_State = Delay; }
CString KiesBNR::ConvertUTC(CString date, int added_hour){ struct tm tm; swscanf((const wchar_t*)date, L"%d-%d-%dT%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec); CTime time(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); time += CTimeSpan(0,added_hour,0,0); return time.Format(L"%Y-%m-%dT%H:%M:%S"); }
CMainFrame::CMainFrame() { //参数初始化 ParamMLoadFile(); MCardParamLoad(); ImageCalcParamLoad(); m_bIsLoopWork = FALSE; m_nLineCount = 0; m_timeTotal = CTimeSpan(0); g_nWorkMode = GetIntValue(PK_WorkMode); }
CTimeSpan CThreadPool_Controller_PID::GetSafeSleepTime(void) const { double last_err = 0, integr_err = 0; CThreadPool* pool = GetPool(); if (!pool) { return CTimeSpan(0, 0); } {{ CMutexGuard guard(GetMainPoolMutex(pool)); if (m_ErrHistory.size() == 0) { return CThreadPool_Controller::GetSafeSleepTime(); } last_err = m_ErrHistory.back().err; integr_err = m_IntegrErr; }} unsigned int threads_cnt = pool->GetThreadsCount(); if (last_err == 0 || (last_err > 0 && threads_cnt == GetMaxThreads()) || (last_err < 0 && threads_cnt == GetMinThreads())) { return CThreadPool_Controller::GetSafeSleepTime(); } double sleep_time = 0; if (last_err > 0) { sleep_time = (m_Threshold - last_err - integr_err) * m_IntegrCoeff / last_err; } else { sleep_time = (-m_Threshold - last_err - integr_err) * m_IntegrCoeff / last_err; } if (sleep_time < 0) sleep_time = 0; return CTimeSpan(sleep_time); }
void CT42App::Options(CWnd* pParent) { CSoundsPage sp; CFontsPage fp; CSecretaryPage sep; CGeneralPage gp; CPropertySheet ps(IDS_TITLE_OPTIONS,pParent); ps.AddPage(&gp); ps.AddPage(&fp); ps.AddPage(&sp); ps.AddPage(&sep); gp.m_ntalkPort = m_T42TalkPort; sp.m_T42Bell = m_sndT42Bell; sp.m_T42Prompt = m_sndT42Prompt; sp.m_bT42PromptLoop = m_bT42PromptLoop; sp.m_T42Wake = m_sndT42Wake; memmove(&fp.m_fmtT42Local.m_fmtChar,&m_fmtT42Local,sizeof(fp.m_fmtT42Local.m_fmtChar)); memmove(&fp.m_fmtT42Remote.m_fmtChar,&m_fmtT42Remote,sizeof(fp.m_fmtT42Remote.m_fmtChar)); memmove(&fp.m_fmtT42System.m_fmtChar,&m_fmtT42System,sizeof(fp.m_fmtT42System.m_fmtChar)); fp.m_fmtT42Local.m_bgColor=m_crT42LocalBG; fp.m_fmtT42Remote.m_bgColor=m_crT42RemoteBG; sep.m_bLimitTime = m_T42STimeLimit.GetTotalSeconds()?TRUE:FALSE; sep.m_limitTime = m_T42STimeLimit.GetTotalSeconds()/60; sep.m_bLimitBytes = m_T42SBytesLimit?TRUE:FALSE; sep.m_limitBytes = m_T42SBytesLimit; sep.m_Greeting = m_T42SGreeting; sep.m_limitWin = m_T42SWinLimit; sep.m_bLimitWin = m_T42SWinLimit?TRUE:FALSE; if(ps.DoModal()==IDOK){ m_T42TalkPort = gp.m_ntalkPort; m_sndT42Bell = sp.m_T42Bell; m_sndT42Prompt = sp.m_T42Prompt; m_bT42PromptLoop = sp.m_bT42PromptLoop; m_sndT42Wake = sp.m_T42Wake; memmove(&m_fmtT42Local,&fp.m_fmtT42Local.m_fmtChar,sizeof(m_fmtT42Local)); memmove(&m_fmtT42Remote,&fp.m_fmtT42Remote.m_fmtChar,sizeof(m_fmtT42Remote)); memmove(&m_fmtT42System,&fp.m_fmtT42System.m_fmtChar,sizeof(m_fmtT42System)); m_crT42LocalBG=fp.m_fmtT42Local.m_bgColor; m_crT42RemoteBG=fp.m_fmtT42Remote.m_bgColor; m_T42STimeLimit = CTimeSpan(sep.m_bLimitTime?sep.m_limitTime*60:0); m_T42SBytesLimit = sep.m_bLimitBytes?sep.m_limitBytes:0; m_T42SWinLimit = sep.m_bLimitWin?sep.m_limitWin:0; m_T42SGreeting = sep.m_Greeting; } }
CEncryptInfo::CEncryptInfo() { m_dwCompressLevel = 0; m_strSourceArray.RemoveAll(); m_strTarget.Empty(); m_strPassword.Empty(); memset(&m_EncryptOption,0,sizeof(ENCRYPTOPTION)); m_EncryptOption.LimitTime = CTime::GetCurrentTime() + CTimeSpan(365,0,0,0); m_EncryptOption.BaseTime = CTime::GetCurrentTime(); m_EncryptOption.ulMaxCount = 1; m_EncryptOption.ulErrorLimit = 3; // m_EncryptOption.bErrorLimition = FALSE; }
const CTimeSpan operator- (const CTimeSpan &op1, const CTimeSpan &op2) // Operator - // // Subtract op2 from op1 (op1 must be greater than op2) { LONGLONG time1 = (op1.Days() * SECONDS_PER_DAY * 1000) + op1.Milliseconds(); LONGLONG time2 = (op2.Days() * SECONDS_PER_DAY * 1000) + op2.Milliseconds(); LONGLONG result = (time1 >= time2 ? time1 - time2 : time2 - time1); return CTimeSpan((int)(result / (SECONDS_PER_DAY * 1000)), (int)(result % (SECONDS_PER_DAY * 1000))); }
bool SetCookie(CInternetSession * p_session, const char * url) { CString cookie_data; //DAY, DD-MMM-YYYY HH:MM:SS GMT CTime now=CTime::GetCurrentTime(); now += CTimeSpan(7, 8, 0, 0); // +7 day, GMT - 8 p_session->GetCookie(url, "", cookie_data); // bool //TRACE("cookie for '%s', '%s', time: %ld\n", url, cookie_data, now.GetTime()); CString date = now.Format("%a, %d-%b-%Y %H:%M:%S GMT"); bool b_set = p_session->SetCookie(url, "expires", date.GetBuffer()) == 1; p_session->SetCookie(url, "test", "true"); bool b_get = p_session->GetCookie(url, "expires", cookie_data) == 1; // bool //TRACE("cookie for '%s', '%s', (%d/%d), time: %ld\n", url, cookie_data, b_set, b_get, now.GetTime()); return true; }
BEGIN_NCBI_SCOPE void g_DoPerfLogging(const string & resource, const CNSTPreciseTime & timing, CRequestStatus::ECode code) { if (!CPerfLogger::IsON()) return; CPerfLogger perf_logger(CPerfLogger::eSuspend); perf_logger.Adjust(CTimeSpan(timing.tv_sec, timing.tv_nsec)); // Log the event perf_logger.Post(code, resource); }
void CActivityView::UpdateTip(UINT nFlags,CPoint point) { CClientDC dc(this); OnPrepareDC(&dc); dc.DPtoLP(&point); POSITION p = m_Brothers->GetHeadPosition(); while(p){ CBrother *b = m_Brothers->GetNext(p); if(b->m_rc.PtInRect(point)){ CString tmp; tmp.Format(IDS_AVIEW_SHORTTIP,(LPCTSTR)b->m_Desc,(LPCTSTR)b->m_Host); if(m_bPainted && (nFlags&(MK_LBUTTON|MK_CONTROL|MK_SHIFT))){ CTime theTime = m_BeginTime + CTimeSpan((point.x-b->m_rc.left)*m_TimeSpan.GetTotalSeconds()/b->m_rc.Width()); if(nFlags&(MK_LBUTTON|MK_CONTROL)){ // Add Time tmp += ", "+theTime.Format(IDS_AVIEW_TIP_TIMEFORMAT); } if(nFlags&MK_SHIFT){ // Add RTT report CLogEntry *le = NULL; POSITION p = b->m_Log.GetTailPosition(); while(p){ CLogEntry *l = b->m_Log.GetPrev(p); if(theTime<l->m_Time) le = l; else break; } CString ttmp; if(le){ if(le->m_bReached) ttmp.Format(IDS_AVIEW_TIP_RTTREPORT, le->m_RTT); else ttmp.LoadString(IDS_AVIEW_TIP_UNREACHABLE); }else ttmp.LoadString(IDS_AVIEW_TIP_UNPINGED); tmp += ", "+ttmp; } } m_ToolTip.Activate(TRUE); m_ToolTip.UpdateTipText(tmp,this); return; } } m_ToolTip.Activate(FALSE); m_ToolTip.UpdateTipText(IDS_AVIEW_NOTIP,this); }
// //////////////////////////////////////////////////////////////////////////// // void CDlgEvents::OnAdd() { CDlgEditEvent dlg(this); // Tomorrow at 9am dlg.m_Date = CTime::GetCurrentTime() + CTimeSpan(1,0,0,0); dlg.m_Time = CTime(2000,1,1, 9,0,0); if ( dlg.DoModal() != IDOK ) return; COleDateTime when( dlg.m_Date.GetYear(), dlg.m_Date.GetMonth(), dlg.m_Date.GetDay(), dlg.m_Time.GetHour(), dlg.m_Time.GetMinute(), dlg.m_Time.GetSecond() ); CRecEvent::AddEvent(when, dlg.m_Text); refreshList(); }
void DeleteReceivedFiles(CString csDir) { if(csDir.Find(_T("\\ReceivedFiles\\")) == -1) return; FIX_CSTRING_PATH(csDir); CTime ctOld = CTime::GetCurrentTime(); CTime ctFile; ctOld -= CTimeSpan(0, 0, 0, 1); CFileFind Find; CString csFindString; csFindString.Format(_T("%s*.*"), csDir); BOOL bFound = Find.FindFile(csFindString); while(bFound) { bFound = Find.FindNextFile(); if(Find.IsDots()) continue; if(Find.IsDirectory()) { CString csDir(Find.GetFilePath()); DeleteReceivedFiles(csDir); RemoveDirectory(csDir); } if(Find.GetLastAccessTime(ctFile)) { //Delete the remote copied file if it has'nt been used for the last day if(ctFile < ctOld) { DeleteFile(Find.GetFilePath()); } } else { DeleteFile(Find.GetFilePath()); } } }
void CT42App::LoadSettings() { m_bAwayOnScreenSaver = GetProfileInt("Settings","AwayOnScreenSaver",m_bAwayOnScreenSaver); Klever::LoadStringList(m_t42Callees,"T42HotList"); Klever::LoadStringList(m_t42Callers,"T42Callers"); m_bt42AutosaveLayout = GetProfileInt("T42Window","AutosaveLayout",m_bt42AutosaveLayout); m_maxT42Callers = GetProfileInt("Settings","T42MaxCallers",m_maxT42Callers); m_maxT42Callees = GetProfileInt("Settings","T42MaxCallees",m_maxT42Callees); m_t42CallsFile = GetProfileString("Settings","T42CallsLog",m_t42CallsFile); m_T42TalkPort = GetProfileInt("Settings","T42TalkPort",m_T42TalkPort); m_sndT42Bell = GetProfileString("Sounds","T42Bell",m_sndT42Bell); m_sndT42Prompt = GetProfileString("Sounds","T42Prompt",m_sndT42Prompt); m_bT42PromptLoop = GetProfileInt("Sounds","T42PromptLoop",m_bT42PromptLoop); m_sndT42Wake = GetProfileString("Sounds","T42Wake",m_sndT42Wake); m_T42SGreeting = Klever::GetProfileString("Secretary","T42Greeting",m_T42SGreeting); m_T42SBytesLimit = GetProfileInt("Secretary","T42BytesLimit",m_T42SBytesLimit); m_T42STimeLimit = CTimeSpan(GetProfileInt("Secretary","T42TimeLimit",m_T42STimeLimit.GetTotalSeconds())); m_T42SWinLimit = GetProfileInt("Secretary","T42WinLimit",m_T42SWinLimit); m_crT42LocalBG = GetProfileInt("Fonts","T42LocalBG",m_crT42LocalBG); m_crT42RemoteBG = GetProfileInt("Fonts","T42RemoteBG",m_crT42RemoteBG); LPBYTE pdata; UINT pbytes; if(GetProfileBinary("Fonts","T42Local",&pdata,&pbytes)){ if(pbytes==sizeof(m_fmtT42Local)) memmove(&m_fmtT42Local,pdata,sizeof(m_fmtT42Local)); delete pdata; } if(GetProfileBinary("Fonts","T42Remote",&pdata,&pbytes)){ if(pbytes==sizeof(m_fmtT42Remote)) memmove(&m_fmtT42Remote,pdata,sizeof(m_fmtT42Remote)); delete pdata; } if(GetProfileBinary("Fonts","T42System",&pdata,&pbytes)){ if(pbytes==sizeof(m_fmtT42System)) memmove(&m_fmtT42System,pdata,sizeof(m_fmtT42System)); delete pdata; } }