711
715
// this CPU doesn't support cpuid
715
719
snprintf(host.p_vendor, sizeof(host.p_vendor), "%.12s",
716
720
cpuInfo.eax_0.vendor_id);
764
768
get_cpuid(&cpuInfo, 1, cpu);
766
770
int family, stepping, model;
768
772
family = cpuInfo.eax_1.family + (cpuInfo.eax_1.family == 0xf ?
842
846
// detect the network usage totals for the host.
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;
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;
852
856
total_received = 0;
996
kern_return_t SMCReadKey(UInt32 key, SMCBytes_t val)
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;
1004
1007
memset(&inputStructure, 0, sizeof(SMCKeyData_t));
1011
1014
structureInputSize = sizeof(inputStructure);
1012
1015
structureOutputSize = sizeof(outputStructure);
1013
result = IOConnectMethodStructureIStructureO(
1014
conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize,
1015
&inputStructure, &outputStructure
1017
if (result != kIOReturnSuccess)
1016
result = IOConnectMethodStructureIStructureO(
1017
conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize,
1018
&inputStructure, &outputStructure
1020
if (result != kIOReturnSuccess) {
1020
1024
inputStructure.keyInfo.dataSize = outputStructure.keyInfo.dataSize;
1021
1025
inputStructure.data8 = SMC_CMD_READ_BYTES;
1023
result = IOConnectMethodStructureIStructureO(
1024
conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize,
1025
&inputStructure, &outputStructure
1027
result = IOConnectMethodStructureIStructureO(
1028
conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize,
1029
&inputStructure, &outputStructure
1027
1031
if (result != kIOReturnSuccess)
1679
1684
return last_irq < t;
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;
1698
XScreenSaverQueryInfo(disp, DefaultRootWindow(disp), xssInfo);
1699
idle_time = xssInfo->idle / 1000; // xssInfo->idle is in ms
1701
disp = XOpenDisplay(NULL);
1702
// XOpenDisplay may return NULL if there is no running X
1703
// or DISPLAY points to wrong/invalid display
1705
xssInfo = XScreenSaverAllocInfo();
1709
return idle_treshold < idle_time;
1712
#endif // LINUX_LIKE_SYSTEM
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);