www.pudn.com > acdx.rar > HouseKeeper.cpp


 /*============================================================= 
 This work is published under the GNU Public License (GPL) 
 see file COPYING for details. 
  
 Function: 
		 
 
 
 Author: Leon Wang  
==============================================================*/ 
// HouseKeeper.cpp: implementation of the HouseKeeper class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "HouseKeeper.h" 
#include "Acdconfig.h" 
#include "acdx.h" 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
//##ModelId=424BB6450327 
int HouseKeeper::DEFAULT_SANITY_INTERVAL = -1; 
 
class ACDConfig; 
//##ModelId=424BB6450324 
HouseKeeper::HouseKeeper() 
{ 
	running = TRUE; 
	 
} 
 
//##ModelId=424BB6450325 
HouseKeeper::~HouseKeeper() 
{ 
 
} 
 
//##ModelId=424BB6450317 
void HouseKeeper::init(ACDX* _router, CCallBacklog* _backlog) 
{ 
    router = _router; 
    backlog = _backlog; 
	//ACDConfig* p_acdconfig = (ACDConfig*)(ACDConfig::getInstance()); 
    sanityInterval = ACDConfig::getInstance()->getConfigKey("Main","sanity_interval",-1); 
	// 
} 
//##ModelId=424BB6450307 
unsigned __stdcall  HouseKeeper::_RUN(void *p) 
{ 
	HouseKeeper * pThis = (HouseKeeper*)p; 
	pThis->RUN(); 
	delete pThis; 
	return 0;	 
} 
//##ModelId=424BB6450306 
void HouseKeeper::RUN() 
{ 
	//SYSTEMTIME systemtime; 
	//GetSystemTime(&systemtime); 
    //long lastSanityCheck = systemtime.wMilliseconds; 
	long lastSanityCheck = GetTickCount(); 
    while(running) { 
          // do the work 
          backlog->expire();   // expire old requests every second 
		  //SYSTEMTIME systemtime2; 
		  //GetSystemTime(&systemtime2); 
            if ( (sanityInterval > 0) && 
                 //(systemtime2.wMilliseconds > lastSanityCheck + (sanityInterval * 1000)))  
				 (GetTickCount() > lastSanityCheck + (sanityInterval * 1000)))  
				  
			{ 
                router->agentSanityCheck(); 
				//SYSTEMTIME systemtime3; 
				//GetSystemTime(&systemtime3); 
                //lastSanityCheck = systemtime3.wMilliseconds; 
				lastSanityCheck = GetTickCount(); 
            } 
 
            // sleep 
			Sleep(1000); 
        }	 
}