VirtualBox

Changeset 47960 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Aug 21, 2013 10:32:05 AM (11 years ago)
Author:
vboxsync
Message:

VBoxTray/VBoxIPC: Perform user idle detection only on Windows 2000 and up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.cpp

    r47296 r47960  
    2727#include <iprt/critsect.h>
    2828#include <iprt/err.h>
     29#include <iprt/ldr.h>
    2930#include <iprt/list.h>
    3031#include <iprt/localipc.h>
     
    6869    /** The thread handle. */
    6970    RTTHREAD                            hThread;
     71    /** Pointer to GetLastInputInfo() function. */
     72    BOOL (WINAPI * pfnGetLastInputInfo)(PLASTINPUTINFO);
    7073
    7174} VBOXIPCSESSION, *PVBOXIPCSESSION;
     
    7376int vboxIPCSessionDestroyLocked(PVBOXIPCSESSION pSession);
    7477
    75 static int vboxIPCHandleVBoxTrayRestart(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr)
    76 {
     78static int vboxIPCHandleVBoxTrayRestart(PVBOXIPCSESSION pSession, PVBOXTRAYIPCHEADER pHdr)
     79{
     80    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
    7781    AssertPtrReturn(pHdr, VERR_INVALID_POINTER);
    7882
     
    8185}
    8286
    83 static int vboxIPCHandleShowBalloonMsg(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr)
    84 {
     87static int vboxIPCHandleShowBalloonMsg(PVBOXIPCSESSION pSession, PVBOXTRAYIPCHEADER pHdr)
     88{
     89    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
    8590    AssertPtrReturn(pHdr, VERR_INVALID_POINTER);
    8691    AssertReturn(pHdr->uMsgLen > 0, VERR_INVALID_PARAMETER);
    8792
    8893    VBOXTRAYIPCMSG_SHOWBALLOONMSG ipcMsg;
    89     int rc = RTLocalIpcSessionRead(hSession, &ipcMsg, pHdr->uMsgLen,
     94    int rc = RTLocalIpcSessionRead(pSession->hSession, &ipcMsg, pHdr->uMsgLen,
    9095                                   NULL /* Exact read, blocking */);
    9196    if (RT_SUCCESS(rc))
     
    103108}
    104109
    105 static int vboxIPCHandleUserLastInput(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr)
    106 {
     110static int vboxIPCHandleUserLastInput(PVBOXIPCSESSION pSession, PVBOXTRAYIPCHEADER pHdr)
     111{
     112    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
    107113    AssertPtrReturn(pHdr, VERR_INVALID_POINTER);
    108114    /* No actual message from client. */
     
    110116    int rc = VINF_SUCCESS;
    111117
    112     /* Note: This only works up to 49.7 days (= 2^32, 32-bit counter)
    113        since Windows was started. */
    114     LASTINPUTINFO lastInput;
    115     lastInput.cbSize = sizeof(LASTINPUTINFO);
    116     BOOL fRc = GetLastInputInfo(&lastInput);
    117     if (fRc)
    118     {
    119         VBOXTRAYIPCRES_USERLASTINPUT ipcRes;
    120         ipcRes.uLastInputMs = GetTickCount() - lastInput.dwTime;
    121         rc = RTLocalIpcSessionWrite(hSession, &ipcRes, sizeof(ipcRes));
    122     }
    123     else
    124         rc = RTErrConvertFromWin32(GetLastError());
     118    bool fLastInputAvailable = false;
     119    VBOXTRAYIPCRES_USERLASTINPUT ipcRes;
     120    if (pSession->pfnGetLastInputInfo)
     121    {
     122        /* Note: This only works up to 49.7 days (= 2^32, 32-bit counter)
     123           since Windows was started. */
     124        LASTINPUTINFO lastInput;
     125        lastInput.cbSize = sizeof(LASTINPUTINFO);
     126        BOOL fRc = pSession->pfnGetLastInputInfo(&lastInput);
     127        if (fRc)
     128        {
     129            VBOXTRAYIPCRES_USERLASTINPUT ipcRes;
     130            ipcRes.uLastInputMs = GetTickCount() - lastInput.dwTime;
     131            fLastInputAvailable = true;
     132        }
     133        else
     134            rc = RTErrConvertFromWin32(GetLastError());
     135    }
     136
     137    if (!fLastInputAvailable)
     138    {
     139        /* No last input available. */
     140        ipcRes.uLastInputMs = UINT32_MAX;
     141    }
     142
     143    int rc2 = RTLocalIpcSessionWrite(pSession->hSession, &ipcRes, sizeof(ipcRes));
     144    if (RT_SUCCESS(rc))
     145        rc = rc2;
    125146
    126147    return rc;
     
    306327                {
    307328                    case VBOXTRAYIPCMSGTYPE_RESTART:
    308                         rc = vboxIPCHandleVBoxTrayRestart(hSession, &ipcHdr);
     329                        rc = vboxIPCHandleVBoxTrayRestart(pThis, &ipcHdr);
    309330                        break;
    310331
    311332                    case VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG:
    312                         rc = vboxIPCHandleShowBalloonMsg(hSession, &ipcHdr);
     333                        rc = vboxIPCHandleShowBalloonMsg(pThis, &ipcHdr);
    313334                        break;
    314335
    315336                    case VBOXTRAYIPCMSGTYPE_USERLASTINPUT:
    316                         rc = vboxIPCHandleUserLastInput(hSession, &ipcHdr);
     337                        rc = vboxIPCHandleUserLastInput(pThis, &ipcHdr);
    317338                        break;
    318339
     
    417438            rc = VERR_NO_MEMORY;
    418439
     440        if (RT_SUCCESS(rc))
     441        {
     442            *(void **)&pSession->pfnGetLastInputInfo =
     443                RTLdrGetSystemSymbol("User32.dll", "GetLastInputInfo");
     444            /* GetLastInputInfo only is available starting at Windows 2000. */
     445        }
     446
    419447        int rc2 = RTCritSectLeave(&pCtx->CritSect);
    420448        AssertRC(rc2);
     
    427455{
    428456    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
     457
    429458    pSession->hThread = NIL_RTTHREAD;
     459    pSession->pfnGetLastInputInfo = NULL;
    430460
    431461    RTLOCALIPCSESSION hSession;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette