Changeset 28978 in vbox
- Timestamp:
- May 3, 2010 2:22:54 PM (15 years ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp
r28972 r28978 93 93 int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...) 94 94 { 95 va_list va; 96 va_start(va, pszValueFormat); 97 char *pszValue; 98 int rc = RTStrAPrintfV(&pszValue, pszValueFormat, va); 99 if (RT_SUCCESS(rc)) 100 { 101 rc = VBoxServicePropCacheUpdateEx(pCache, pszName, 0 /* Not used */, NULL /* Not used */, pszValue); 95 char *pszValue = NULL; 96 int rc; 97 if (pszValueFormat) 98 { 99 va_list va; 100 va_start(va, pszValueFormat); 101 RTStrAPrintfV(&pszValue, pszValueFormat, va); 102 va_end(va); 103 } 104 rc = VBoxServicePropCacheUpdateEx(pCache, pszName, 0 /* Not used */, NULL /* Not used */, pszValue); 105 if (pszValue) 102 106 RTStrFree(pszValue); 103 }104 va_end(va);105 107 return rc; 106 108 } … … 123 125 Assert(pCache->uClientID); 124 126 AssertPtr(pszName); 125 AssertPtr(pszValueFormat); 126 127 int rc = VINF_SUCCESS; 127 128 128 char *pszValue = NULL; 129 129 if (pszValueFormat) … … 131 131 va_list va; 132 132 va_start(va, pszValueFormat); 133 rc =RTStrAPrintfV(&pszValue, pszValueFormat, va);133 RTStrAPrintfV(&pszValue, pszValueFormat, va); 134 134 va_end(va); 135 135 } 136 136 137 137 PVBOXSERVICEVEPROPCACHEENTRY pNode = VBoxServicePropCacheFind(pCache, pszName, 0); 138 if (pNode != NULL) 139 { 140 if (pszValue) 141 { 142 bool fUpdate = false; 143 if (pNode->uFlags & VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE) 144 fUpdate = true; 145 else if (pNode->pszValue && strcmp(pNode->pszValue, pszValue) != 0) 146 fUpdate = true; 147 148 if (fUpdate) 149 { 150 /* Write the update. */ 151 rc = VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, pszValue); 152 if (pNode->pszValue) 153 RTStrFree(pNode->pszValue); 154 pNode->pszValue = RTStrDup(pszValue); 155 if (pszValueReset) 156 { 157 if (pNode->pszValueReset) 158 RTStrFree(pNode->pszValueReset); 159 pNode->pszValueReset = RTStrDup(pszValueReset); 160 } 161 if (u32Flags) 162 pNode->uFlags = u32Flags; 163 } 164 else 165 rc = VINF_ALREADY_INITIALIZED; /* No update needed. */ 166 } 167 else if (pNode->pszValue) 138 if (pNode == NULL) 139 { 140 pNode = (PVBOXSERVICEVEPROPCACHEENTRY)RTMemAlloc(sizeof(VBOXSERVICEVEPROPCACHEENTRY)); 141 AssertPtrReturn(pNode, VERR_NO_MEMORY); 142 143 pNode->pszName = RTStrDup(pszName); 144 pNode->pszValue = NULL; 145 pNode->uFlags = 0; 146 pNode->pszValueReset = NULL; 147 148 /*rc =*/ RTListAppend(&pCache->Node, &pNode->Node); 149 } 150 151 int rc; 152 AssertPtr(pNode); 153 if (pszValue) /* Do we have a value to check for? */ 154 { 155 bool fUpdate = false; 156 /* Always update this property, no matter what? */ 157 if (pNode->uFlags & VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE) 158 fUpdate = true; 159 /* Did the value change so we have to update? */ 160 else if (pNode->pszValue && strcmp(pNode->pszValue, pszValue) != 0) 161 fUpdate = true; 162 /* No value stored at the moment but we have a value now? */ 163 else if (pNode->pszValue == NULL) 164 fUpdate = true; 165 166 if (fUpdate) 167 { 168 /* Write the update. */ 169 rc = VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, pszValue); 170 if (pNode->pszValue) 171 RTStrFree(pNode->pszValue); 172 pNode->pszValue = RTStrDup(pszValue); 173 } 174 else 175 rc = VINF_ALREADY_INITIALIZED; /* No update needed. */ 176 } 177 else 178 { 179 /* No value specified. Deletion (or no action required). */ 180 if (pNode->pszValue) /* Did we have a value before? Then the value needs to be deleted. */ 168 181 { 169 182 /* Delete property (but do not remove from cache) if not deleted yet. */ 170 VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, NULL);183 rc = VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, NULL); 171 184 RTStrFree(pNode->pszValue); 172 185 pNode->pszValue = NULL; 173 186 } 174 }175 else /* Node not found; add it and update HGCM service. */176 {177 PVBOXSERVICEVEPROPCACHEENTRY pNewNode = (PVBOXSERVICEVEPROPCACHEENTRY)RTMemAlloc(sizeof(VBOXSERVICEVEPROPCACHEENTRY));178 pNewNode->pszName = RTStrDup(pszName);179 if (pszValue)180 pNewNode->pszValue = RTStrDup(pszValue);181 187 else 182 pNewNode->pszValue = NULL; 183 if (pszValueReset) 184 pNewNode->pszValueReset = RTStrDup(pszValueReset); 185 else 186 pNewNode->pszValueReset = NULL; 187 pNewNode->uFlags = u32Flags; 188 /*rc =*/ RTListAppend(&pCache->Node, &pNewNode->Node); 189 if (RT_SUCCESS(rc)) 190 rc = VERR_NOT_FOUND; 191 } 192 188 rc = VINF_ALREADY_INITIALIZED; /* No update needed. */ 189 } 190 191 /* Update rest of the fields. */ 192 if (pszValueReset) 193 { 194 if (pNode->pszValueReset) 195 RTStrFree(pNode->pszValueReset); 196 pNode->pszValueReset = RTStrDup(pszValueReset); 197 } 198 if (u32Flags) 199 pNode->uFlags = u32Flags; 200 201 /* Delete temp stuff. */ 193 202 if (pszValue) 194 203 RTStrFree(pszValue); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r28967 r28978 131 131 VBoxServicePropCacheInit(&g_VMInfoPropCache, g_VMInfoGuestPropSvcClientID); 132 132 133 /* 134 * Set flags and reset values for some guest proerties that need to have that. 135 * Passing NULL as an actual value does not write the properties yet. 136 */ 137 VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", 138 VBOXSERVICEPROPCACHEFLAG_TEMPORARY, NULL /* Delete on exit */, NULL); 139 VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers", 140 VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "0", NULL); 141 VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", 142 VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "true", NULL); 143 /* 144 * This property is a beacon which is _always_ written, even if the network configuration 145 * does not change. If this property is missing, the host assumes that all other GuestInfo 146 * properties are no longer valid. 147 */ 133 148 VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count", 134 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, "0", "0"); 135 VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", 136 VBOXSERVICEPROPCACHEFLAG_TEMPORARY, NULL, NULL); 137 VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers", 138 VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "0", "0"); 139 VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", 140 VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "true", "true"); 149 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, "0", NULL); 141 150 } 142 151 return rc; … … 396 405 int iCurIface = 0; 397 406 398 /*399 * This property is a beacon which is _always_ written, even if the network configuration400 * does not change. If this property is missing, the host assumes that all other GuestInfo401 * properties are no longer valid.402 */403 407 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count", "%d", 404 408 nNumInterfaces > 1 ? nNumInterfaces-1 : 0);
Note:
See TracChangeset
for help on using the changeset viewer.