Changeset 75969 in vbox for trunk/src/VBox/HostServices/GuestProperties
- Timestamp:
- Dec 5, 2018 12:08:09 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 127186
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/GuestProperties/service.cpp
r75773 r75969 45 45 #include <iprt/asm.h> 46 46 #include <iprt/assert.h> 47 #include <iprt/buildconfig.h> 47 48 #include <iprt/cpp/autores.h> 48 49 #include <iprt/cpp/utils.h> … … 54 55 #include <iprt/time.h> 55 56 #include <VBox/vmm/dbgf.h> 57 #include <VBox/version.h> 56 58 57 59 #include <string> … … 97 99 uint32_t u32Flags) 98 100 : mName(name), mValue(value), mTimestamp(u64Timestamp), 99 mFlags(u32Flags) {} 101 mFlags(u32Flags) 102 {} 100 103 101 104 /** Does the property name match one of a set of patterns? */ … … 195 198 * values: {(mPrevTimestamp - mcTimestampAdjustments), ..., mPrevTimestamp} */ 196 199 uint64_t mcTimestampAdjustments; 200 /** For helping setting host version properties _after_ restoring VMs. */ 201 bool m_fSetHostVersionProps; 197 202 198 203 /** … … 311 316 , mPrevTimestamp(0) 312 317 , mcTimestampAdjustments(0) 318 , m_fSetHostVersionProps(false) 313 319 #ifdef ASYNC_HOST_NOTIFY 314 320 , mhThreadNotifyHost(NIL_RTTHREAD) … … 409 415 } 410 416 417 void setHostVersionProps(); 418 static DECLCALLBACK(void) svcNotify(void *pvService, HGCMNOTIFYEVENT enmEvent); 419 411 420 int initialize(); 412 421 … … 419 428 int getProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[]); 420 429 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); 421 431 int delProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest); 422 432 int enumProps(uint32_t cParms, VBOXHGCMSVCPARM paParms[]); … … 749 759 750 760 /* 761 * Hand it over to the internal setter method. 762 */ 763 rc = setPropertyInternal(pcszName, pcszValue, fFlags, u64TimeNano, isGuest); 764 765 LogFlowThisFunc(("%s=%s, rc=%Rrc\n", pcszName, pcszValue, rc)); 766 return rc; 767 } 768 769 /** 770 * Internal property setter. 771 * 772 * @returns VBox status code. 773 * @param pcszName The property name. 774 * @param pcszValue The new value. 775 * @param fFlags The flags. 776 * @param nsTimestamp The timestamp. 777 * @param fIsGuest Is it the guest calling. 778 * @throws std::bad_alloc if an out of memory condition occurs 779 * @thread HGCM 780 */ 781 int Service::setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp, bool fIsGuest) 782 { 783 /* 751 784 * If the property already exists, check its flags to see if we are allowed 752 785 * to change it. 753 786 */ 754 787 Property *pProp = getPropertyInternal(pcszName); 755 rc = checkPermission(pProp ? pProp->mFlags : GUEST_PROP_F_NILFLAG, isGuest);788 int rc = checkPermission(pProp ? pProp->mFlags : GUEST_PROP_F_NILFLAG, fIsGuest); 756 789 /* 757 790 * Handle names which are read-only for the guest. … … 759 792 if (rc == VINF_SUCCESS && checkHostReserved(pcszName)) 760 793 { 761 if ( isGuest)794 if (fIsGuest) 762 795 rc = VERR_PERMISSION_DENIED; 763 796 else … … 772 805 { 773 806 pProp->mValue = pcszValue; 774 pProp->mTimestamp = u64TimeNano;807 pProp->mTimestamp = nsTimestamp; 775 808 pProp->mFlags = fFlags; 776 809 } … … 780 813 { 781 814 /* Create a new string space record. */ 782 pProp = new Property(pcszName, pcszValue, u64TimeNano, fFlags);815 pProp = new Property(pcszName, pcszValue, nsTimestamp, fFlags); 783 816 AssertPtr(pProp); 784 817 … … 804 837 * Send a notification to the guest and host and return. 805 838 */ 806 // if ( isGuest)/* Notify the host even for properties that the host839 // if (fIsGuest) /* Notify the host even for properties that the host 807 840 // * changed. Less efficient, but ensures consistency. */ 808 int rc2 = doNotifications(pcszName, u64TimeNano);841 int rc2 = doNotifications(pcszName, nsTimestamp); 809 842 if (RT_SUCCESS(rc)) 810 843 rc = rc2; … … 1564 1597 } 1565 1598 1599 1600 /** 1601 * Sets the VBoxVer, VBoxVerExt and VBoxRev properties. 1602 */ 1603 void Service::setHostVersionProps() 1604 { 1605 uint64_t nsTimestamp = getCurrentTimestamp(); 1606 1607 /* Set the raw VBox version string as a guest property. Used for host/guest 1608 * version comparison. */ 1609 setPropertyInternal("/VirtualBox/HostInfo/VBoxVer", VBOX_VERSION_STRING_RAW, 1610 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp, false /*fIsGuest*/); 1611 1612 /* Set the full VBox version string as a guest property. Can contain vendor-specific 1613 * information/branding and/or pre-release tags. */ 1614 setPropertyInternal("/VirtualBox/HostInfo/VBoxVerExt", VBOX_VERSION_STRING, 1615 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp, false /*fIsGuest*/); 1616 1617 /* Set the VBox SVN revision as a guest property */ 1618 setPropertyInternal("/VirtualBox/HostInfo/VBoxRev", RTBldCfgRevisionStr(), 1619 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp, false /*fIsGuest*/); 1620 } 1621 1622 1623 /** 1624 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnNotify} 1625 */ 1626 /*static*/ DECLCALLBACK(void) Service::svcNotify(void *pvService, HGCMNOTIFYEVENT enmEvent) 1627 { 1628 SELF *pThis = reinterpret_cast<SELF *>(pvService); 1629 AssertPtrReturnVoid(pThis); 1630 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? */ 1642 } 1643 1644 1566 1645 #ifdef ASYNC_HOST_NOTIFY 1567 1646 … … 1602 1681 int Service::initialize() 1603 1682 { 1683 /* 1684 * Insert standard host properties. 1685 */ 1686 try 1687 { 1688 /* The host version will but updated again on power on or resume 1689 (after restore), however we need the properties now for restored 1690 guest notification/wait calls. */ 1691 setHostVersionProps(); 1692 1693 /* 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*/); 1699 } 1700 catch (std::bad_alloc &) 1701 { 1702 return VERR_NO_MEMORY; 1703 } 1704 1604 1705 #ifdef ASYNC_HOST_NOTIFY 1605 1706 /* The host notification thread and queue. */ … … 1728 1829 ptable->pfnLoadState = NULL; /* construction done before restoring suffices */ 1729 1830 ptable->pfnRegisterExtension = Service::svcRegisterExtension; 1831 ptable->pfnNotify = Service::svcNotify; 1730 1832 ptable->pvService = pService; 1731 1833
Note:
See TracChangeset
for help on using the changeset viewer.