VBoxManageGuestProp.cpp revision eefdbb59e1d1963e09e7924e2121f2cfb03f1432
/* $Id$ */
/** @file
* VBoxManage - The 'guestproperty' command.
*/
/*
* Copyright (C) 2006-2009 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 "VBoxManage.h"
#ifdef USE_XPCOM_QUEUE
# include <errno.h>
#endif
#ifdef RT_OS_DARWIN
# include <CoreFoundation/CFRunLoop.h>
#endif
using namespace com;
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 <msec>] [--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 event listener and wait until found match or timeout.
*/
bool fSignalled = false;
do
{
unsigned cMsWait;
if (cMsTimeout == RT_INDEFINITE_WAIT)
cMsWait = 1000;
else
{
if (cMsElapsed >= cMsTimeout)
break; /* timed out */
}
if (ev)
{
switch (aType)
{
{
continue;
{
RTPrintf("Name: %lS, value: %lS, flags: %lS\n",
fSignalled = true;
break;
}
break;
}
default:
AssertFailed();
}
}
} while (!fSignalled);
int rcRet = 0;
if (!fSignalled)
{
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: */
}