VBoxServicePropCache.cpp revision 7480f639b6e81e4f5583e2dded360b77d3ad58a8
/* $Id$ */
/** @file
* VBoxServicePropCache - Guest property cache.
*/
/*
* Copyright (C) 2010 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"
/**
* Initializes the 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!
* VBoxServicePropCacheCreate(). */
}
/** @todo Docs
* @todo this looks internal to me, nobody should need to access the
* structures directly here. */
PVBOXSERVICEVEPROPCACHEENTRY VBoxServicePropCacheFind(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 */
{
int rc;
{
if (RT_SUCCESS(rc))
{
if (pszValueReset)
{
if (pszValueReset)
}
}
}
else
rc = VERR_NOT_FOUND;
return rc;
}
/**
* Updates the local guest property cache and writes it to HGCM if outdated.
*
* @returns VBox status code. Errors will be logged.
*
* @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, ...)
{
int rc;
if (pszValueFormat)
{
}
rc = VBoxServicePropCacheUpdateEx(pCache, pszName, 0 /* Not used */, NULL /* Not used */, pszValue);
if (pszValue)
return rc;
}
/**
* Updates the local guest property cache and writes it to HGCM if outdated.
*
* @returns VBox status code. Errors will be logged.
*
* @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 VBoxServicePropCacheUpdateEx(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags,
const char *pszValueReset, const char *pszValueFormat, ...)
{
/*
* Format the value first.
*/
if (pszValueFormat)
{
if (!pszValue)
return VERR_NO_STR_MEMORY;
}
/* Lock the cache. */
if (RT_SUCCESS(rc))
{
{
if (RT_UNLIKELY(!pNode))
{
return VERR_NO_MEMORY;
}
}
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. */
}
else
}
else
{
/* No value specified. Deletion (or no action required). */
{
/* Delete property (but do not remove from cache) if not deleted yet. */
}
else
/** @todo r=bird: Use VINF_NO_CHANGE. */
}
/* Update rest of the fields. */
if (pszValueReset)
{
if (pNode->pszValueReset)
}
if (fFlags)
/* Release cache. */
if (RT_SUCCESS(rc))
}
/* Delete temp stuff. */
return rc;
}
/**
* Reset all temporary properties and destroy the cache.
*
* @param pCache The property cache.
*/
{
{
}
while (pNode)
{
PVBOXSERVICEVEPROPCACHEENTRY pNext = RTListNodeGetNext(&pNode->Node, VBOXSERVICEVEPROPCACHEENTRY, Node);
/** @todo r=bird: hrm. missing RTMemFree(pNode)? Why don't you just combine the
* two loops? */
break;
}
/* Destroy mutex. */
}