VBoxServicePropCache.cpp revision 5cb35d1d57b75115e455960d167c7e30c16c0e1a
/* $Id$ */
/** @file
* VBoxServicePropCache - Guest property cache.
*/
/*
* 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;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#include "VBoxServiceUtils.h"
#include "VBoxServicePropCache.h"
/** Internal functions, not for public use. */
PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheFindInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags);
PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheInsertEntryInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName);
/** @todo Docs */
PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheFindInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags)
{
/** @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
* implementation (AVL tree). However, this is not important at the
* moment. */
{
{
{
break;
}
}
}
return pNode;
}
/** @todo Docs */
PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheInsertEntryInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName)
{
PVBOXSERVICEVEPROPCACHEENTRY pNode = (PVBOXSERVICEVEPROPCACHEENTRY)RTMemAlloc(sizeof(VBOXSERVICEVEPROPCACHEENTRY));
if (pNode)
{
{
return NULL;
}
if (RT_SUCCESS(rc))
{
}
}
return pNode;
}
/** @todo Docs */
int vboxServicePropCacheWritePropF(uint32_t u32ClientId, const char *pszName, uint32_t fFlags, const char *pszValueFormat, ...)
{
int rc;
if (pszValueFormat != NULL)
{
char *pszValue;
{
{
/*
* Because a value can be temporary we have to make sure it also
* gets deleted when the property cache did not have the chance to
* gracefully clean it up (due to a hard VM reset etc), so set this
* guest property using the TRANSRESET flag..
*/
if (rc == VERR_PARSE_ERROR)
{
/* Host does not support the "TRANSRESET" flag, so only
* use the "TRANSIENT" flag -- better than nothing :-). */
/** @todo r=bird: Remember that the host doesn't support
* this. */
}
}
else
}
else
rc = VERR_NO_MEMORY;
}
else
{
}
return rc;
}
/**
* Creates a property cache.
*
* @returns IPRT status code.
* @param pCache Pointer to the cache.
* @param uClientId The HGCM handle of to the guest property service.
*/
{
/** @todo Prevent init the cache twice!
* r=bird: Use a magic. */
}
/**
* Updates a cache entry without submitting any changes to the host.
*
* @returns VBox status code.
*
* @param pCache The property cache.
* @param pszName The property name.
* @param fFlags The property flags to set.
* @param pszValueReset The property reset value.
*/
{
int rc;
{
if (RT_SUCCESS(rc))
{
if (pszValueReset)
{
if (pNode->pszValueReset)
}
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/**
* Updates the local guest property cache and writes it to HGCM if outdated.
*
* @returns VBox status code.
*
* @param pCache The property cache.
* @param pszName The property name.
* @param pszValueFormat The property format string. If this is NULL then
* the property will be deleted (if possible).
* @param ... Format arguments.
*/
int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...)
{
/*
* Format the value first.
*/
if (pszValueFormat)
{
if (!pszValue)
return VERR_NO_STR_MEMORY;
}
/* Lock the cache. */
if (RT_SUCCESS(rc))
{
if (pszValue) /* Do we have a value to check for? */
{
bool fUpdate = false;
/* Always update this property, no matter what? */
fUpdate = true;
/* Did the value change so we have to update? */
fUpdate = true;
/* No value stored at the moment but we have a value now? */
fUpdate = true;
if (fUpdate)
{
/* Write the update. */
{
rc = VERR_NO_MEMORY;
}
}
else
}
else
{
/* No value specified. Deletion (or no action required). */
{
{
/* Delete property (but do not remove from cache) if not deleted yet. */
}
}
else
}
/* Release cache. */
}
/* Delete temp stuff. */
return rc;
}
/**
* Updates all cache values which are matching the specified path.
*
* @returns VBox status code.
*
* @param pCache The property cache.
* @param pszValue The value to set. A NULL will delete the value.
* @param fFlags Flags to set.
* @param pszPathFormat The path format string. May not be null and has
* to be an absolute path.
* @param ... Format arguments.
*/
int VBoxServicePropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char *pszValue, uint32_t fFlags, const char *pszPathFormat, ...)
{
int rc = VERR_NOT_FOUND;
{
/*
* Format the value first.
*/
if (!pszPath)
{
}
else
{
/* Iterate through all nodes and compare their paths. */
{
{
/** @todo Use some internal function to update the node directly, this is slow atm. */
}
if (RT_FAILURE(rc))
break;
}
}
}
return rc;
}
/**
* Flushes the cache by writing every item regardless of its state.
*
* @param pCache The property cache.
*/
{
int rc = VINF_SUCCESS;
{
{
if (RT_FAILURE(rc))
break;
}
}
return rc;
}
/**
* Reset all temporary properties and destroy the cache.
*
* @param pCache The property cache.
*/
{
/* Lock the cache. */
if (RT_SUCCESS(rc))
{
PVBOXSERVICEVEPROPCACHEENTRY pNode = RTListGetFirst(&pCache->NodeHead, VBOXSERVICEVEPROPCACHEENTRY, NodeSucc);
while (pNode)
{
? NULL :
{
}
}
}
/* Destroy critical section. */
}