mirror of https://github.com/BOINC/boinc.git
more idle time functionality
svn path=/trunk/boinc/; revision=629
This commit is contained in:
parent
647c46cfcc
commit
5942ca5d7d
|
@ -20,7 +20,6 @@
|
||||||
// include header
|
// include header
|
||||||
|
|
||||||
#include "wingui.h"
|
#include "wingui.h"
|
||||||
#include "win_idle_tracker.h"
|
|
||||||
|
|
||||||
// globals
|
// globals
|
||||||
|
|
||||||
|
@ -35,14 +34,14 @@ CMyApp myApp;
|
||||||
#define MAX_ID 4
|
#define MAX_ID 4
|
||||||
|
|
||||||
#define PROJECT_COLS 5
|
#define PROJECT_COLS 5
|
||||||
#define RESULT_COLS 6
|
#define RESULT_COLS 7
|
||||||
#define XFER_COLS 4
|
#define XFER_COLS 4
|
||||||
#define MAX_COLS 6
|
#define MAX_COLS 7
|
||||||
|
|
||||||
char* column_titles[MAX_ID][MAX_COLS] = {
|
char* column_titles[MAX_ID][MAX_COLS] = {
|
||||||
{"Project", "Account", "Total Credit", "Avg. Credit", "Resource Share", NULL},
|
{"Project", "Account", "Total Credit", "Avg. Credit", "Resource Share", NULL, NULL},
|
||||||
{"Project", "Application", "Name", "CPU time", "Progress", "Status"},
|
{"Project", "Application", "Name", "CPU time", "Progress", "To Completion", "Status"},
|
||||||
{"Project", "File", "Progress", "Direction", NULL, NULL}
|
{"Project", "File", "Progress", "Total", "Direction", NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
void show_message(char* message, char* priority) {
|
void show_message(char* message, char* priority) {
|
||||||
|
@ -989,25 +988,26 @@ CMainWindow::CMainWindow()
|
||||||
// id: the timer's id
|
// id: the timer's id
|
||||||
// time: milliseconds since system started
|
// time: milliseconds since system started
|
||||||
// returns: void
|
// returns: void
|
||||||
// function: updates client state, flushed output streams, and updates
|
// function: checks idle time, updates client state, flushed output streams,
|
||||||
// gui display.
|
// and updates gui display.
|
||||||
void CALLBACK CMainWindow::TimerProc(HWND h, UINT msg, UINT id, DWORD time)
|
void CALLBACK CMainWindow::TimerProc(HWND h, UINT msg, UINT id, DWORD time)
|
||||||
{
|
{
|
||||||
if (gstate.global_prefs.idle_time_to_run > 0) {
|
// update state and gui
|
||||||
if (GetTickCount()-IdleTrackerGetLastTickCount() > 1000*gstate.global_prefs.idle_time_to_run) {
|
|
||||||
gstate.user_idle = true;
|
|
||||||
} else {
|
|
||||||
gstate.user_idle = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gstate.user_idle = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(gstate.do_something());
|
while(gstate.do_something());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
if(myWnd) {
|
if(myWnd) {
|
||||||
|
// check user's idle time for suspension of apps
|
||||||
|
if (gstate.global_prefs.idle_time_to_run > 0) {
|
||||||
|
if (myWnd->GetUserIdleTime() > 1000 * gstate.global_prefs.idle_time_to_run) {
|
||||||
|
gstate.user_idle = true;
|
||||||
|
} else {
|
||||||
|
gstate.user_idle = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gstate.user_idle = true;
|
||||||
|
}
|
||||||
|
|
||||||
myWnd->UpdateGUI(&gstate);
|
myWnd->UpdateGUI(&gstate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1062,6 +1062,7 @@ void CMainWindow::UpdateGUI(CLIENT_STATE* cs)
|
||||||
for(i = 0; i < m_ResultListCtrl.GetItemCount(); i ++) {
|
for(i = 0; i < m_ResultListCtrl.GetItemCount(); i ++) {
|
||||||
RESULT* re = (RESULT*)m_ResultListCtrl.GetItemData(i);
|
RESULT* re = (RESULT*)m_ResultListCtrl.GetItemData(i);
|
||||||
if(!re) {
|
if(!re) {
|
||||||
|
m_XferListCtrl.SetItemProgress(i, 4, 100);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1084,11 +1085,22 @@ void CMainWindow::UpdateGUI(CLIENT_STATE* cs)
|
||||||
// progress
|
// progress
|
||||||
ACTIVE_TASK* at = gstate.lookup_active_task_by_result(re);
|
ACTIVE_TASK* at = gstate.lookup_active_task_by_result(re);
|
||||||
if(!at) {
|
if(!at) {
|
||||||
buf.Format("no active task");
|
m_ResultListCtrl.SetItemProgress(i, 4, 0);
|
||||||
} else {
|
} else {
|
||||||
buf.Format("%d%%", (int)(at->fraction_done * 100));
|
m_ResultListCtrl.SetItemProgress(i, 4, (int)(at->fraction_done * 100));
|
||||||
}
|
}
|
||||||
m_ResultListCtrl.SetItemText(i, 4, buf);
|
|
||||||
|
// to completion
|
||||||
|
if(!at || at->fraction_done == 0) {
|
||||||
|
buf.Format("unable to calculate");
|
||||||
|
} else {
|
||||||
|
int tocomp = (re->final_cpu_time / at->fraction_done) - re->final_cpu_time;
|
||||||
|
cpuhour = (int)(tocomp / (60 * 60));
|
||||||
|
cpumin = (int)(tocomp / 60) % 60;
|
||||||
|
cpusec = (int)(tocomp) % 60;
|
||||||
|
buf.Format("%0.2dh%0.2dm%0.2ds", cpuhour, cpumin, cpusec);
|
||||||
|
}
|
||||||
|
m_ResultListCtrl.SetItemText(i, 5, buf);
|
||||||
|
|
||||||
// status
|
// status
|
||||||
switch(re->state) {
|
switch(re->state) {
|
||||||
|
@ -1105,7 +1117,7 @@ void CMainWindow::UpdateGUI(CLIENT_STATE* cs)
|
||||||
default:
|
default:
|
||||||
buf.Format("%s", "Error: invalid state"); break;
|
buf.Format("%s", "Error: invalid state"); break;
|
||||||
}
|
}
|
||||||
m_ResultListCtrl.SetItemText(i, 5, buf);
|
m_ResultListCtrl.SetItemText(i, 6, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update xfers
|
// update xfers
|
||||||
|
@ -1325,6 +1337,31 @@ int CMainWindow::GetDiskFree()
|
||||||
return TotalNumberOfFreeBytes.QuadPart / (1024*1024);
|
return TotalNumberOfFreeBytes.QuadPart / (1024*1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////
|
||||||
|
// CMainWindow::GetUserIdleTime
|
||||||
|
// arguments: void
|
||||||
|
// returns: time the user has been idle in milliseconds
|
||||||
|
// function: calls a dll function to determine the the user's idle time
|
||||||
|
DWORD CMainWindow::GetUserIdleTime()
|
||||||
|
{
|
||||||
|
if(m_IdleDll) {
|
||||||
|
GetFn fn;
|
||||||
|
fn = (GetFn)GetProcAddress(m_IdleDll, "IdleTrackerGetLastTickCount");
|
||||||
|
if(fn) {
|
||||||
|
return GetTickCount() - fn();
|
||||||
|
} else {
|
||||||
|
TermFn tfn;
|
||||||
|
tfn = (TermFn)GetProcAddress(m_IdleDll, "IdleTrackerTerm");
|
||||||
|
if(tfn) {
|
||||||
|
tfn();
|
||||||
|
}
|
||||||
|
AfxFreeLibrary(m_IdleDll);
|
||||||
|
m_IdleDll = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// CMainWindow::Syncronize
|
// CMainWindow::Syncronize
|
||||||
// arguments: prog: pointer to a progress list control
|
// arguments: prog: pointer to a progress list control
|
||||||
|
@ -1441,6 +1478,8 @@ void CMainWindow::OnCommandStatusIconHide()
|
||||||
// function: cleans up, closes and quits everything
|
// function: cleans up, closes and quits everything
|
||||||
void CMainWindow::OnCommandStatusIconQuit()
|
void CMainWindow::OnCommandStatusIconQuit()
|
||||||
{
|
{
|
||||||
|
// quit
|
||||||
|
gstate.exit();
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
|
|
||||||
// status icon in taskbar
|
// status icon in taskbar
|
||||||
|
@ -1456,19 +1495,19 @@ void CMainWindow::OnCommandStatusIconQuit()
|
||||||
m_TabIL.DeleteImageList();
|
m_TabIL.DeleteImageList();
|
||||||
m_MainMenu.DestroyMenu();
|
m_MainMenu.DestroyMenu();
|
||||||
|
|
||||||
// Stop user idle detection
|
// free dll and idle detection
|
||||||
IdleTrackerTerm();
|
if(m_IdleDll) {
|
||||||
|
TermFn fn;
|
||||||
/*if (boincDLL != NULL) {
|
fn = (TermFn)GetProcAddress(m_IdleDll, "IdleTrackerTerm");
|
||||||
term_proc = (INITPROC) GetProcAddress(boincDLL, "IdleTrackerTerm");
|
if(!fn) {
|
||||||
if (term_proc != NULL) {
|
MessageUser("Error in DLL, can't find procedure \"IdleTrackerTerm\"", "low");
|
||||||
(term_proc)();
|
} else {
|
||||||
|
fn();
|
||||||
}
|
}
|
||||||
|
AfxFreeLibrary(m_IdleDll);
|
||||||
|
m_IdleDll = NULL;
|
||||||
}
|
}
|
||||||
FreeLibrary(boincDLL);*/
|
|
||||||
|
|
||||||
// kill child processes
|
|
||||||
gstate.active_tasks.exit_tasks();
|
|
||||||
SaveUserSettings();
|
SaveUserSettings();
|
||||||
CWnd::OnClose();
|
CWnd::OnClose();
|
||||||
}
|
}
|
||||||
|
@ -1587,17 +1626,25 @@ int CMainWindow::OnCreate(LPCREATESTRUCT lpcs)
|
||||||
if (retval) exit(retval);
|
if (retval) exit(retval);
|
||||||
SetTimer(ID_TIMER, 1000, TimerProc);
|
SetTimer(ID_TIMER, 1000, TimerProc);
|
||||||
|
|
||||||
// Start user idle detection
|
// load dll and start idle detection
|
||||||
IdleTrackerInit();
|
m_IdleDll = AfxLoadLibrary("boinc.dll");
|
||||||
|
if(!m_IdleDll) {
|
||||||
//boincDLL = LoadLibrary((LPCTSTR) "boinc.dll");
|
MessageUser("Can't load \"boinc.dll\", will not be able to determine idle time", "high");
|
||||||
|
} else {
|
||||||
/*if (boincDLL != NULL) {
|
InitFn fn;
|
||||||
init_proc = (INITPROC) GetProcAddress(boincDLL, "IdleTrackerInit");
|
fn = (InitFn)GetProcAddress(m_IdleDll, "IdleTrackerInit");
|
||||||
if (init_proc != NULL) {
|
if(!fn) {
|
||||||
(init_proc)();
|
MessageUser("Error in DLL, can't find procedure \"IdleTrackerInit\"", "low");
|
||||||
|
AfxFreeLibrary(m_IdleDll);
|
||||||
|
m_IdleDll = NULL;
|
||||||
|
} else {
|
||||||
|
if(!fn()) {
|
||||||
|
MessageUser("Error in DLL, can't create hooks", "low");
|
||||||
|
AfxFreeLibrary(m_IdleDll);
|
||||||
|
m_IdleDll = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
LoadUserSettings();
|
LoadUserSettings();
|
||||||
UpdateGUI(&gstate);
|
UpdateGUI(&gstate);
|
||||||
|
|
|
@ -53,6 +53,12 @@
|
||||||
#define PIE_DEPTH 0.25 // depth of pie chart
|
#define PIE_DEPTH 0.25 // depth of pie chart
|
||||||
#define PI 3.14159 // pi
|
#define PI 3.14159 // pi
|
||||||
|
|
||||||
|
// typedefs
|
||||||
|
|
||||||
|
typedef BOOL (CALLBACK* InitFn)();
|
||||||
|
typedef void (CALLBACK* TermFn)();
|
||||||
|
typedef DWORD (CALLBACK* GetFn)();
|
||||||
|
|
||||||
// classes
|
// classes
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
|
@ -189,12 +195,14 @@ protected:
|
||||||
CTabCtrl m_TabCtrl; // tab control for choosing display
|
CTabCtrl m_TabCtrl; // tab control for choosing display
|
||||||
CImageList m_TabIL; // image list for tab control
|
CImageList m_TabIL; // image list for tab control
|
||||||
CBitmap m_TabBMP[5]; // bitmaps for tab image list
|
CBitmap m_TabBMP[5]; // bitmaps for tab image list
|
||||||
|
HINSTANCE m_IdleDll; // handle to dll for user idle
|
||||||
|
|
||||||
void StatusIcon(DWORD);
|
void StatusIcon(DWORD);
|
||||||
void SaveUserSettings();
|
void SaveUserSettings();
|
||||||
void LoadUserSettings();
|
void LoadUserSettings();
|
||||||
int GetDiskSize();
|
int GetDiskSize();
|
||||||
int GetDiskFree();
|
int GetDiskFree();
|
||||||
|
DWORD GetUserIdleTime();
|
||||||
void Syncronize(CProgressListCtrl*, vector<void*>*);
|
void Syncronize(CProgressListCtrl*, vector<void*>*);
|
||||||
virtual void PostNcDestroy();
|
virtual void PostNcDestroy();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue