diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
---|---|---|
committer | <> | 2014-05-08 15:03:54 +0000 |
commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp | |
parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
download | VirtualBox-master.tar.gz |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp')
-rw-r--r-- | src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp b/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp index 347faa95..1e691c95 100644 --- a/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp +++ b/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2010 Oracle Corporation + * Copyright (C) 2010-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -38,8 +38,9 @@ PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheInsertEntryInternal(PVBOXSERVIC /** @todo Docs */ PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheFindInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags) { - AssertPtr(pCache); - AssertPtr(pszName); + AssertPtrReturn(pCache, NULL); + AssertPtrReturn(pszName, NULL); + /** @todo This is a O(n) lookup, maybe improve this later to O(1) using a * map. * r=bird: Use a string space (RTstrSpace*). That is O(log n) in its current @@ -65,11 +66,18 @@ PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheFindInternal(PVBOXSERVICEVEPROP /** @todo Docs */ PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheInsertEntryInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName) { - AssertPtr(pszName); + AssertPtrReturn(pCache, NULL); + AssertPtrReturn(pszName, NULL); + PVBOXSERVICEVEPROPCACHEENTRY pNode = (PVBOXSERVICEVEPROPCACHEENTRY)RTMemAlloc(sizeof(VBOXSERVICEVEPROPCACHEENTRY)); if (pNode) { pNode->pszName = RTStrDup(pszName); + if (!pNode->pszName) + { + RTMemFree(pNode); + return NULL; + } pNode->pszValue = NULL; pNode->fFlags = 0; pNode->pszValueReset = NULL; @@ -88,7 +96,8 @@ PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheInsertEntryInternal(PVBOXSERVIC /** @todo Docs */ int vboxServicePropCacheWritePropF(uint32_t u32ClientId, const char *pszName, uint32_t fFlags, const char *pszValueFormat, ...) { - AssertPtr(pszName); + AssertPtrReturn(pszName, VERR_INVALID_POINTER); + int rc; if (pszValueFormat != NULL) { @@ -141,7 +150,7 @@ int vboxServicePropCacheWritePropF(uint32_t u32ClientId, const char *pszName, ui */ int VBoxServicePropCacheCreate(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId) { - AssertPtr(pCache); + AssertPtrReturn(pCache, VERR_INVALID_POINTER); /** @todo Prevent init the cache twice! * r=bird: Use a magic. */ RTListInit(&pCache->NodeHead); @@ -164,8 +173,8 @@ int VBoxServicePropCacheCreate(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientI int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags, const char *pszValueReset) { - AssertPtr(pCache); - AssertPtr(pszName); + AssertPtrReturn(pCache, VERR_INVALID_POINTER); + AssertPtrReturn(pszName, VERR_INVALID_POINTER); PVBOXSERVICEVEPROPCACHEENTRY pNode = vboxServicePropCacheFindInternal(pCache, pszName, 0); if (pNode == NULL) pNode = vboxServicePropCacheInsertEntryInternal(pCache, pszName); @@ -182,6 +191,7 @@ int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, if (pNode->pszValueReset) RTStrFree(pNode->pszValueReset); pNode->pszValueReset = RTStrDup(pszValueReset); + AssertPtr(pNode->pszValueReset); } rc = RTCritSectLeave(&pCache->CritSect); } @@ -205,9 +215,10 @@ int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, */ int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...) { - AssertPtr(pCache); + AssertPtrReturn(pCache, VERR_INVALID_POINTER); + AssertPtrReturn(pszName, VERR_INVALID_POINTER); + Assert(pCache->uClientID); - AssertPtr(pszName); /* * Format the value first. @@ -250,8 +261,15 @@ int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszNa { /* Write the update. */ rc = vboxServicePropCacheWritePropF(pCache->uClientID, pNode->pszName, pNode->fFlags, pszValue); - RTStrFree(pNode->pszValue); - pNode->pszValue = RTStrDup(pszValue); + VBoxServiceVerbose(4, "[PropCache %p]: Written \"%s\"=\"%s\" (flags: %x), rc=%Rrc\n", + pCache, pNode->pszName, pszValue, pNode->fFlags, rc); + if (RT_SUCCESS(rc)) /* Only update the node's value on successful write. */ + { + RTStrFree(pNode->pszValue); + pNode->pszValue = RTStrDup(pszValue); + if (!pNode->pszValue) + rc = VERR_NO_MEMORY; + } } else rc = VINF_NO_CHANGE; /* No update needed. */ @@ -261,11 +279,16 @@ int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszNa /* No value specified. Deletion (or no action required). */ if (pNode->pszValue) /* Did we have a value before? Then the value needs to be deleted. */ { - /* Delete property (but do not remove from cache) if not deleted yet. */ - RTStrFree(pNode->pszValue); - pNode->pszValue = NULL; rc = vboxServicePropCacheWritePropF(pCache->uClientID, pNode->pszName, 0, /* Flags */ NULL /* Value */); + VBoxServiceVerbose(4, "[PropCache %p]: Deleted \"%s\"=\"%s\" (flags: %x), rc=%Rrc\n", + pCache, pNode->pszName, pNode->pszValue, pNode->fFlags, rc); + if (RT_SUCCESS(rc)) /* Only delete property value on successful Vbgl deletion. */ + { + /* Delete property (but do not remove from cache) if not deleted yet. */ + RTStrFree(pNode->pszValue); + pNode->pszValue = NULL; + } } else rc = VINF_NO_CHANGE; /* No update needed. */ @@ -275,6 +298,9 @@ int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszNa RTCritSectLeave(&pCache->CritSect); } + VBoxServiceVerbose(4, "[PropCache %p]: Updating \"%s\" resulted in rc=%Rrc\n", + pCache, pszName, rc); + /* Delete temp stuff. */ RTStrFree(pszValue); return rc; @@ -295,8 +321,9 @@ int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszNa */ int VBoxServicePropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char *pszValue, uint32_t fFlags, const char *pszPathFormat, ...) { - AssertPtr(pCache); - AssertPtr(pszPathFormat); + AssertPtrReturn(pCache, VERR_INVALID_POINTER); + AssertPtrReturn(pszPathFormat, VERR_INVALID_POINTER); + int rc = VERR_NOT_FOUND; PVBOXSERVICEVEPROPCACHEENTRY pNodeIt = NULL; if (RT_SUCCESS(RTCritSectEnter(&pCache->CritSect))) @@ -341,7 +368,8 @@ int VBoxServicePropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char */ int VBoxServicePropCacheFlush(PVBOXSERVICEVEPROPCACHE pCache) { - AssertPtr(pCache); + AssertPtrReturn(pCache, VERR_INVALID_POINTER); + int rc = VINF_SUCCESS; PVBOXSERVICEVEPROPCACHEENTRY pNodeIt = NULL; if (RT_SUCCESS(RTCritSectEnter(&pCache->CritSect))) @@ -366,7 +394,7 @@ int VBoxServicePropCacheFlush(PVBOXSERVICEVEPROPCACHE pCache) */ void VBoxServicePropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache) { - AssertPtr(pCache); + AssertPtrReturnVoid(pCache); Assert(pCache->uClientID); /* Lock the cache. */ |