コード例 #1
0
ファイル: xidle.c プロジェクト: slaweksiluk/BlueAuth
int det_user_interrupt(const int sample_period, const int debounces, 
        bool verbose){
        //const static int TIME_DIFF_MSECONDS = 0.5;
    int time1;
    int time2;
    int diff;
    int counter = 0;
    //sleep(5);
    //if(putenv("DISPLAY=:0") != 0){
    //    printf("putenv() error:  %s\n", strerror(errno));
    //    return -1;
    //}
    Display *dpy = XOpenDisplay(NULL);
    if (!dpy) {
        if(verbose) printf("err: display NULL\n");
        return(-1);
    }
    
    XScreenSaverInfo *info = XScreenSaverAllocInfo();
    if (!info) {
        if(verbose) printf("err: info NULL\n");
        return(-1);
    }

    while(1){
        //pierwszy pomiar
        time1 = GetIdleTime(dpy, info);
        //przerwa
        usleep(sample_period*1000);
        //drugi pomiar
        time2 = GetIdleTime(dpy, info);
        //byl ruch
        diff = time2 - time1;
        if(diff < 0){
            counter = counter + 1;
            if(verbose) printf("counter set to: %d\n", counter);
        }
        if(counter == debounces) 
            break;
    }
    if(verbose) printf("loop broken...\n");
    if(verbose) printf("time1 is: %d\n", time1);
    if(verbose) printf("time2 is: %d\n", time2);
    if(verbose) printf("diff is: %d\n", diff);
    
    if(dpy != NULL) XFree(dpy);
    if(info != NULL) XFree(info);
    if(verbose) printf("cleaned...\n");
    return 0;
}
コード例 #2
0
ファイル: CpuLoad.cpp プロジェクト: acasadoalonso/LK8000
int MeasureCPULoad() {
#if (WINDOWSPC>0) && !defined(__MINGW32__)
  static bool init=false;
  if (!init) {
    // get the pointer to the function
    GetIdleTime = (GetIdleTimeProc) 
      GetProcAddress(LoadLibrary(_T("coredll.dll")),
		     _T("GetIdleTime"));
    init=true;
  }
  if (!GetIdleTime) return 0;
#endif

  static int pi;
  static int PercentIdle;
  static int PercentLoad;
  static bool start=true;
  static DWORD dwStartTick;
  static DWORD dwIdleSt;
  static DWORD dwStopTick;
  static DWORD dwIdleEd;
  if (start) {
    dwStartTick = GetTickCount();
    dwIdleSt = GetIdleTime();
  }
  if (!start) {
    dwStopTick = GetTickCount();
    dwIdleEd = GetIdleTime();
    LKASSERT((dwStopTick-dwStartTick)!=0);
    pi = ((100 * (dwIdleEd - dwIdleSt))/(dwStopTick - dwStartTick));
    PercentIdle = (PercentIdle+pi)/2;
  }
  start = !start;
  PercentLoad = 100-PercentIdle;
  return PercentLoad;
}
コード例 #3
0
ファイル: inactivity.cpp プロジェクト: alexcb/tracker
void IdleDetector::Notify ()
{
	wxTimeSpan idleTime = GetIdleTime ();
	//
	// If not currently idle, then the state changes if the amount of time that
	// the session has been idle is greater than or equal to the idle timeout.
	//
	// If currently idle, then the state changes if the amount of time that
	// the session has been idle is less than the idle timeout. This assumes
	// that the idle timeout value is greater than the IDLE_TO_ACTIVE_TIMEOUT
	// timeout value, which it really should be.
	//
	if (!m_isIdle)
		SetState (idleTime >= m_timeout, idleTime);
	else if (idleTime < m_timeout)
		SetState (false, idleTime);
}
コード例 #4
0
ファイル: Cpu.c プロジェクト: Soorma07/dvsdk-dmai
/******************************************************************************
 * Cpu_getLoad
 ******************************************************************************/
Int Cpu_getLoad(Cpu_Handle hCpu, Int *cpuLoad)
{
    static DWORD startTick = 0;
    static DWORD endTick = 0;
    static DWORD idleStart = 0;
    static DWORD idleEnd = 0;
    DWORD load;
    
    startTick = endTick;
    endTick = GetTickCount();
    idleStart = idleEnd;
    idleEnd = GetIdleTime();
    
    load = 100 - ((100 * (idleEnd - idleStart)) / (endTick - startTick)); 
    
    *cpuLoad = load;

    return Dmai_EOK;
}
コード例 #5
0
ファイル: inactivity.cpp プロジェクト: alexcb/tracker
void IdleDetector::Resume ()
{
	SetState (m_isIdle, GetIdleTime());
}