~ubuntu-branches/debian/sid/boinc/sid

« back to all changes in this revision

Viewing changes to client/hostinfo_unix.cpp

  • Committer: Package Import Robot
  • Author(s): Steffen Moeller
  • Date: 2011-08-08 01:36:51 UTC
  • mfrom: (6.1.11 experimental)
  • Revision ID: package-import@ubuntu.com-20110808013651-m1hs3cltiveuteyn
Tags: 6.13.1+dfsg-2
* Bringing notify patch to unstable.
* Adjusted build dependency to libjpeg-dev (Closes: #641093)
* Further improvements on stripchart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
#define _SC_PAGESIZE _SC_PAGE_SIZE
150
150
#endif
151
151
 
 
152
#if HAVE_XSS
 
153
#include <X11/extensions/scrnsaver.h>
 
154
#endif
 
155
 
152
156
// The following is intended to be true both on Linux
153
157
// and Debian GNU/kFreeBSD (see trac #521)
154
158
//
711
715
        // this CPU doesn't support cpuid
712
716
        return;
713
717
    }
714
 
        
 
718
 
715
719
    snprintf(host.p_vendor, sizeof(host.p_vendor), "%.12s",
716
720
        cpuInfo.eax_0.vendor_id);
717
721
    
762
766
    }
763
767
 
764
768
    get_cpuid(&cpuInfo, 1, cpu);
765
 
        
 
769
 
766
770
    int family, stepping, model;
767
771
 
768
772
    family = cpuInfo.eax_1.family + (cpuInfo.eax_1.family == 0xf ?
842
846
// detect the network usage totals for the host.
843
847
//
844
848
int get_network_usage_totals(unsigned int& total_received, unsigned int& total_sent) {
845
 
        static size_t  sysctlBufferSize = 0;
846
 
        static uint8_t *sysctlBuffer = NULL;
 
849
    static size_t  sysctlBufferSize = 0;
 
850
    static uint8_t *sysctlBuffer = NULL;
847
851
 
848
 
        int     mib[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
 
852
    int    mib[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
849
853
    struct if_msghdr *ifmsg;
850
 
        size_t currentSize = 0;
 
854
    size_t currentSize = 0;
851
855
 
852
856
    total_received = 0;
853
857
    total_sent = 0;
993
997
}
994
998
 
995
999
 
996
 
kern_return_t SMCReadKey(UInt32 key, SMCBytes_t val)
997
 
{
 
1000
kern_return_t SMCReadKey(UInt32 key, SMCBytes_t val) {
998
1001
    kern_return_t       result;
999
1002
    SMCKeyData_t        inputStructure;
1000
1003
    SMCKeyData_t        outputStructure;
1001
 
        size_t              structureInputSize;
 
1004
     size_t              structureInputSize;
1002
1005
    size_t              structureOutputSize;
1003
1006
 
1004
1007
    memset(&inputStructure, 0, sizeof(SMCKeyData_t));
1010
1013
 
1011
1014
    structureInputSize = sizeof(inputStructure);
1012
1015
    structureOutputSize = sizeof(outputStructure);
1013
 
        result = IOConnectMethodStructureIStructureO(
1014
 
                    conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize, 
1015
 
                    &inputStructure, &outputStructure
1016
 
            );
1017
 
    if (result != kIOReturnSuccess)
 
1016
    result = IOConnectMethodStructureIStructureO(
 
1017
        conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize, 
 
1018
        &inputStructure, &outputStructure
 
1019
    );
 
1020
    if (result != kIOReturnSuccess) {
1018
1021
        return result;
 
1022
    }
1019
1023
 
1020
1024
    inputStructure.keyInfo.dataSize = outputStructure.keyInfo.dataSize;
1021
1025
    inputStructure.data8 = SMC_CMD_READ_BYTES;
1022
1026
 
1023
 
        result = IOConnectMethodStructureIStructureO(
1024
 
                    conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize, 
1025
 
                    &inputStructure, &outputStructure
1026
 
            );
 
1027
    result = IOConnectMethodStructureIStructureO(
 
1028
        conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize, 
 
1029
        &inputStructure, &outputStructure
 
1030
    );
1027
1031
    if (result != kIOReturnSuccess)
1028
1032
        return result;
1029
1033
 
1145
1149
    return 0;
1146
1150
}
1147
1151
 
 
1152
 
1148
1153
// Rules:
1149
1154
// - Keep code in the right place
1150
1155
// - only one level of #if
1678
1683
    }
1679
1684
    return last_irq < t;
1680
1685
}
1681
 
#endif
 
1686
 
 
1687
#if HAVE_XSS
 
1688
// Ask the X server for user idle time (using XScreenSaver API)
 
1689
// Returns true if the idle_treshold is smaller than the
 
1690
// idle time of the user (means: true = user is idle)
 
1691
bool xss_idle(long idle_treshold) {
 
1692
    static XScreenSaverInfo* xssInfo = NULL;
 
1693
    static Display* disp = NULL;
 
1694
    
 
1695
    long idle_time = 0;
 
1696
    
 
1697
    if(disp != NULL) {
 
1698
        XScreenSaverQueryInfo(disp, DefaultRootWindow(disp), xssInfo);
 
1699
        idle_time = xssInfo->idle / 1000; // xssInfo->idle is in ms
 
1700
    } else {
 
1701
        disp = XOpenDisplay(NULL);
 
1702
        // XOpenDisplay may return NULL if there is no running X
 
1703
        // or DISPLAY points to wrong/invalid display
 
1704
        if(disp != NULL) {
 
1705
            xssInfo = XScreenSaverAllocInfo();
 
1706
        }
 
1707
    }
 
1708
 
 
1709
    return idle_treshold < idle_time;
 
1710
}
 
1711
#endif // HAVE_XSS
 
1712
#endif // LINUX_LIKE_SYSTEM
1682
1713
 
1683
1714
bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) {
1684
1715
    time_t idle_time = time(0) - (long) (60 * idle_time_to_run);
1700
1731
    if (!interrupts_idle(idle_time)) {
1701
1732
        return false;
1702
1733
    }
 
1734
 
 
1735
#if HAVE_XSS
 
1736
    if (!xss_idle((long)(idle_time_to_run * 60))) {
 
1737
        return false;
 
1738
    }
 
1739
#endif
 
1740
 
1703
1741
#else
1704
1742
    // We should find out which of the following are actually relevant
1705
1743
    // on which systems (if any)