VBoxManageGuestProp.cpp revision 898e2046a1c301b8dbf5a2edb6e107334effd50b
/* $Id$ */
/** @file
* VBoxManage - The 'guestproperty' command.
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
#ifdef USE_XPCOM_QUEUE
# include <errno.h>
#endif
#ifdef RT_OS_DARWIN
# include <CoreFoundation/CFRunLoop.h>
#endif
using namespace com;
/**
* IVirtualBoxCallback implementation for handling the GuestPropertyCallback in
* relation to the "guestproperty wait" command.
*/
class GuestPropertyCallback :
{
public:
{
#ifndef VBOX_WITH_XPCOM
refcnt = 0;
#endif
}
virtual ~GuestPropertyCallback()
{
}
#ifndef VBOX_WITH_XPCOM
{
return ::InterlockedIncrement(&refcnt);
}
{
if (cnt == 0)
delete this;
return cnt;
}
#endif /* !VBOX_WITH_XPCOM */
{
return S_OK;
}
{
return S_OK;
}
{
/* we never disagree */
if (!changeAllowed)
return E_INVALIDARG;
*changeAllowed = TRUE;
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
{
ASMAtomicWriteBool(&mSignalled, true);
}
return S_OK;
}
bool Signalled(void) const
{
return mSignalled;
}
private:
bool volatile mSignalled;
const char *mPatterns;
#ifndef VBOX_WITH_XPCOM
long refcnt;
#endif
};
#ifdef VBOX_WITH_XPCOM
#endif /* VBOX_WITH_XPCOM */
void usageGuestProperty(void)
{
RTPrintf("VBoxManage guestproperty get <vmname>|<uuid>\n"
" <property> [--verbose]\n"
"\n");
RTPrintf("VBoxManage guestproperty set <vmname>|<uuid>\n"
" <property> [<value> [--flags <flags>]]\n"
"\n");
RTPrintf("VBoxManage guestproperty enumerate <vmname>|<uuid>\n"
" [--patterns <patterns>]\n"
"\n");
RTPrintf("VBoxManage guestproperty wait <vmname>|<uuid> <patterns>\n"
" [--timeout <milliseconds>] [--fail-on-timeout]\n"
"\n");
}
static int handleGetGuestProperty(HandlerArg *a)
{
bool verbose = false;
if ( a->argc == 3
verbose = true;
else if (a->argc != 2)
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
/* open a session for the VM - new or existing */
/* get the mutable session machine */
if (!value)
RTPrintf("No value set!\n");
if (value)
{
}
}
}
static int handleSetGuestProperty(HandlerArg *a)
{
/*
* Check the syntax. We can deduce the correct syntax from the number of
* arguments.
*/
bool usageOK = true;
if (a->argc == 3)
else if (a->argc == 4)
usageOK = false;
else if (a->argc == 5)
{
usageOK = false;
}
else if (a->argc != 2)
usageOK = false;
if (!usageOK)
/* This is always needed. */
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
/* open a session for the VM - new or existing */
/* get the mutable session machine */
else if (!pszFlags)
else
}
}
/**
* Enumerates the properties in the guest property store.
*
* @returns 0 on success, 1 on failure
* @note see the command line API description for parameters
*/
static int handleEnumGuestProperty(HandlerArg *a)
{
/*
* Check the syntax. We can deduce the correct syntax from the number of
* arguments.
*/
if ( a->argc < 1
|| a->argc == 2
|| ( a->argc > 3
/*
* Pack the patterns
*/
for (int i = 3; i < a->argc; ++i)
/*
* Make the actual call to Main.
*/
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
/* open a session for the VM - new or existing */
/* get the mutable session machine */
{
RTPrintf("No properties found.\n");
RTPrintf("Name: %lS, value: %lS, timestamp: %lld, flags: %lS\n",
}
}
}
/**
* Enumerates the properties in the guest property store.
*
* @returns 0 on success, 1 on failure
* @note see the command line API description for parameters
*/
static int handleWaitGuestProperty(HandlerArg *a)
{
/*
* Handle arguments
*/
bool fFailOnTimeout = false;
const char *pszPatterns = NULL;
bool usageOK = true;
if (a->argc < 2)
usageOK = false;
else
/* assume it's a UUID */
{
/* must be a name */
}
if (!machine)
usageOK = false;
{
{
if ( i + 1 >= a->argc
usageOK = false;
else
++i;
}
fFailOnTimeout = true;
else
usageOK = false;
}
if (!usageOK)
/*
* Set up the callback and loop until signal or timeout.
*
* We do this in 1000 ms chunks to be on the safe side (there used to be
* better reasons for it).
*/
{
return 1;
}
do
{
unsigned cMsWait;
if (cMsTimeout == RT_INDEFINITE_WAIT)
cMsWait = 1000;
else
{
if (cMsElapsed >= cMsTimeout)
break; /* timed out */
}
if ( RT_FAILURE(vrc)
&& vrc != VERR_TIMEOUT)
{
return 1;
}
int rcRet = 0;
{
RTPrintf("Time out or interruption while waiting for a notification.\n");
if (fFailOnTimeout)
rcRet = 2;
}
return rcRet;
}
/**
* Access the guest property store.
*
* @returns 0 on success, 1 on failure
* @note see the command line API description for parameters
*/
int handleGuestProperty(HandlerArg *a)
{
HandlerArg arg = *a;
if (a->argc == 0)
/* switch (cmd) */
return handleGetGuestProperty(&arg);
return handleSetGuestProperty(&arg);
return handleEnumGuestProperty(&arg);
return handleWaitGuestProperty(&arg);
/* default: */
}