VirtualBox

Changeset 75974 in vbox for trunk/src


Ignore:
Timestamp:
Dec 5, 2018 3:24:38 PM (6 years ago)
Author:
vboxsync
Message:

GuestProperties: Added /VirtualBox/VMInfo/ResumeCounter and /VirtualBox/VMInfo/ResetCounter. The former can be waited on to detect VM suspend/resume cycles. (For waiting on restore any of the HostInfo/VBox* properties can be waited on.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r75969 r75974  
    291291        if (RTStrStartsWith(pszName, "/VirtualBox/HostInfo/"))
    292292            return true;
     293        if (RTStrStartsWith(pszName, "/VirtualBox/VMInfo/"))
     294            return true;
    293295        return false;
    294296    }
     
    359361                                           void * /* pvClient */)
    360362    {
     363        /** @todo r=bird: Here be dragons! You must complete all calls for the client as
     364         * it disconnects or we'll end wasting space...  We're also confused after
     365         * restoring state, but that's a bug somewhere in VMMDev, I think. */
    361366        return VINF_SUCCESS;
    362367    }
     
    416421
    417422    void setHostVersionProps();
     423    void incrementCounterProp(const char *pszName);
    418424    static DECLCALLBACK(void) svcNotify(void *pvService, HGCMNOTIFYEVENT enmEvent);
    419425
     
    428434    int getProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    429435    int setProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest);
    430     int setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp, bool fIsGuest);
     436    int setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp,
     437                            bool fIsGuest = false);
    431438    int delProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest);
    432439    int enumProps(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
     
    779786 * @thread  HGCM
    780787 */
    781 int Service::setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp, bool fIsGuest)
     788int Service::setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp,
     789                                 bool fIsGuest /*= false*/)
    782790{
    783791    /*
     
    15971605}
    15981606
     1607/**
     1608 * Increments a counter property.
     1609 *
     1610 * It is assumed that this a transient property that is read-only to the guest.
     1611 *
     1612 * @param   pszName     The property name.
     1613 * @throws  std::bad_alloc  if an out of memory condition occurs
     1614 */
     1615void Service::incrementCounterProp(const char *pszName)
     1616{
     1617    /* Format the incremented value. */
     1618    char szValue[64];
     1619    Property *pProp = getPropertyInternal(pszName);
     1620    if (pProp)
     1621    {
     1622        uint64_t uValue = RTStrToUInt64(pProp->mValue.c_str());
     1623        RTStrFormatU64(szValue, sizeof(szValue), uValue + 1, 10, 0, 0, 0);
     1624    }
     1625    else
     1626    {
     1627        szValue[0] = '1';
     1628        szValue[1] = '\0';
     1629    }
     1630
     1631    /* Set it. */
     1632    setPropertyInternal(pszName, szValue, GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, getCurrentTimestamp());
     1633}
    15991634
    16001635/**
     
    16081643     * version comparison. */
    16091644    setPropertyInternal("/VirtualBox/HostInfo/VBoxVer", VBOX_VERSION_STRING_RAW,
    1610                         GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp, false /*fIsGuest*/);
     1645                        GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp);
    16111646
    16121647    /* Set the full VBox version string as a guest property. Can contain vendor-specific
    16131648     * information/branding and/or pre-release tags. */
    16141649    setPropertyInternal("/VirtualBox/HostInfo/VBoxVerExt", VBOX_VERSION_STRING,
    1615                         GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp, false /*fIsGuest*/);
     1650                        GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp);
    16161651
    16171652    /* Set the VBox SVN revision as a guest property */
    16181653    setPropertyInternal("/VirtualBox/HostInfo/VBoxRev", RTBldCfgRevisionStr(),
    1619                         GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp, false /*fIsGuest*/);
     1654                        GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp);
    16201655}
    16211656
     
    16291664    AssertPtrReturnVoid(pThis);
    16301665
    1631     /* Make sure the host version properties have been touched and are
    1632        up-to-date after a restore: */
    1633     if (   !pThis->m_fSetHostVersionProps
    1634         && (enmEvent == HGCMNOTIFYEVENT_RESUME || enmEvent == HGCMNOTIFYEVENT_POWER_ON))
    1635     {
    1636         pThis->setHostVersionProps();
    1637         pThis->m_fSetHostVersionProps = true;
    1638     }
    1639 
    1640     /** @todo add suspend/resume property? */
    1641     /** @todo add reset counter? */
     1666    try
     1667    {
     1668        /* Make sure the host version properties have been touched and are
     1669           up-to-date after a restore: */
     1670        if (   !pThis->m_fSetHostVersionProps
     1671            && (enmEvent == HGCMNOTIFYEVENT_RESUME || enmEvent == HGCMNOTIFYEVENT_POWER_ON))
     1672        {
     1673            pThis->setHostVersionProps();
     1674            pThis->m_fSetHostVersionProps = true;
     1675        }
     1676
     1677        if (enmEvent == HGCMNOTIFYEVENT_RESUME)
     1678            pThis->incrementCounterProp("/VirtualBox/VMInfo/ResumeCounter");
     1679
     1680        if (enmEvent == HGCMNOTIFYEVENT_RESET)
     1681            pThis->incrementCounterProp("/VirtualBox/VMInfo/ResetCounter");
     1682    }
     1683    catch (std::bad_alloc &)
     1684    {
     1685        /* ignore */
     1686    }
    16421687}
    16431688
     
    16921737
    16931738        /* Sysprep execution by VBoxService (host is allowed to change these). */
    1694         uint64_t nsTimestamp = getCurrentTimestamp();
    1695         setPropertyInternal("/VirtualBox/HostGuest/SysprepExec", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST,
    1696                             nsTimestamp, false /*fIsGuest*/);
    1697         setPropertyInternal("/VirtualBox/HostGuest/SysprepArgs", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST,
    1698                             nsTimestamp, false /*fIsGuest*/);
     1739        uint64_t nsNow = getCurrentTimestamp();
     1740        setPropertyInternal("/VirtualBox/HostGuest/SysprepExec", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
     1741        setPropertyInternal("/VirtualBox/HostGuest/SysprepArgs", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
     1742
     1743        /* Resume and reset counters. */
     1744        setPropertyInternal("/VirtualBox/VMInfo/ResumeCounter", "0", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
     1745        setPropertyInternal("/VirtualBox/VMInfo/ResetCounter", "0", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
    16991746    }
    17001747    catch (std::bad_alloc &)
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