Ticket #463: boinc-idlefix.patch

File boinc-idlefix.patch, 4.1 KB (added by oteodoro, 16 years ago)

alternative mouse idle detection for linux clients

  • client/client_state.C

    old new  
    3434#endif
    3535#endif
    3636
     37#ifdef linux
     38#include <sys/fcntl.h>
     39#endif
     40
    3741#include "parse.h"
    3842#include "str_util.h"
    3943#include "util.h"
     
    125129    launched_by_manager = false;
    126130    initialized = false;
    127131    last_wakeup_time = dtime();
     132#ifdef linux
     133    mouse_moved = true;
     134    mouse_event_t = time(NULL);
     135    mouse_fd = open("/dev/input/mouse0", O_RDONLY);
     136#endif   
     137}
     138
     139CLIENT_STATE::~CLIENT_STATE()
     140{
     141#ifdef linux
     142    if(mouse_fd != -1)
     143        close(mouse_fd);
     144#endif
    128145}
    129146
    130147void CLIENT_STATE::show_host_info() {
     
    414431                http_ops->get_fdset(curl_fds);
    415432        all_fds = curl_fds;
    416433        gui_rpcs.get_fdset(gui_rpc_fds, all_fds);
     434#ifdef linux
     435        FD_SET(mouse_fd, &all_fds.read_fds);
     436        if (mouse_fd > all_fds.max_fd) all_fds.max_fd = mouse_fd;
     437#endif       
    417438        double_to_timeval(x, tv);
    418439        n = select(
    419440            all_fds.max_fd+1,
     
    429451
    430452        http_ops->got_select(all_fds, x);
    431453        gui_rpcs.got_select(all_fds);
     454#ifdef linux
     455        if (mouse_fd != -1) {
     456            if (FD_ISSET(mouse_fd, &all_fds.read_fds)) {
     457                char ps2_packet[3]; //assume ps/2 mouse protocol 3 byte packet
     458                if(read(mouse_fd, ps2_packet, 3) == 3) {
     459                    mouse_moved = true;
     460                    mouse_event_t = time(NULL);
     461                }
     462            }
     463        }
     464#endif
    432465
    433466        if (n==0) break;
    434467
     
    496529#ifdef __APPLE__
    497530         , &idletime
    498531#endif
     532#ifdef linux
     533         , &mouse_moved
     534         , mouse_event_t
     535#endif
    499536    );
    500537
    501538    if (user_active != old_user_active) {
  • client/client_state.h

    old new  
    213213// --------------- client_state.C:
    214214public:
    215215    CLIENT_STATE();
     216    ~CLIENT_STATE();   
    216217    void show_host_info();
    217218    int init();
    218219    bool poll_slow_events();
     
    243244    bool garbage_collect_always();
    244245    bool update_results();
    245246    int nresults_for_project(PROJECT*);
     247#ifdef linux
     248    int mouse_fd;
     249    bool mouse_moved;
     250    time_t mouse_event_t;
     251#endif
    246252
    247253// --------------- cpu_sched.C:
    248254private:
  • client/hostinfo_unix.C

    old new  
    946946    return (idleTime > (60 * idle_time_to_run));
    947947}
    948948
     949#elif linux
     950
     951bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run, bool* mouse_moved, time_t mouse_event_t) {
     952    time_t cur_time = time(NULL);
     953    time_t idle_time = cur_time - (long) (60 * idle_time_to_run);
     954    if (mouse_event_t != 0) {
     955        if (mouse_moved && mouse_event_t < idle_time)
     956            *mouse_moved = false;
     957    }
     958
     959    bool idle_result = true;
     960#ifdef HAVE_UTMP_H
     961    idle_result = idle_result && all_logins_idle(idle_time);
     962#endif
     963    idle_result = idle_result && (mouse_moved ? !*mouse_moved : true);
     964    return idle_result;
     965}
     966
    949967#else  // ! __APPLE__
    950968
    951969bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) {
  • lib/hostinfo.h

    old new  
    7272    bool host_is_running_on_batteries();
    7373#ifdef __APPLE__
    7474    bool users_idle(bool check_all_logins, double idle_time_to_run, double *actual_idle_time=NULL);
     75#elif linux
     76    bool users_idle(bool check_all_logins, double idle_time_to_run, bool* mouse_moved = NULL, time_t mouse_event_t = 0);
    7577#else
    7678    bool users_idle(bool check_all_logins, double idle_time_to_run);
    7779#endif
  • checkin_notes

    old new  
    79857985    mac_installer/
    79867986        release_boinc.sh
    79877987        release_GridRepublic.sh
     7988
     7989Orson Teodoro 04 Jan 2008
     7990    - Linux: Input event mouse idle detection and segfault fix
     7991    client/
     7992        client_state.C
     7993        client_state.h
     7994        hostinfo_unix.C
     7995        main.C
     7996    lib/
     7997        hostinfo.h