VBoxControl.cpp revision c785dbab313731d1f4662b4684c0808cc14703db
/** $Id$ */
/** @file
* VBoxControl - Guest Additions Command Line Management Interface
*/
/*
* Copyright (C) 2007 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 <iprt/initterm.h>
#include <VBox/VBoxGuest.h>
#ifdef VBOX_WITH_INFO_SVC
#endif
#include "VBoxControl.h"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The program name (derived from argv[0]). */
char const *g_pszProgName = "";
/** The current verbosity level. */
int g_cVerbosity = 0;
/**
* Displays the program usage message.
*
* @param u64Which
*
* @{
*/
/** Helper function */
{
}
/** Enumerate the different parts of the usage we might want to print out */
enum g_eUsage
{
#ifdef VBOX_WITH_INFO_SVC
#endif
};
{
RTPrintf("Usage:\n\n");
}
/** @} */
/**
* Displays an error message.
*
* @param pszFormat The message text.
* @param ... Format arguments.
*/
static void VBoxControlError(const char *pszFormat, ...)
{
// RTStrmPrintf(g_pStdErr, "%s: error: ", g_pszProgName);
}
#ifdef VBOX_WITH_INFO_SVC
/**
* This is accessed through the "VBoxSharedInfoSvc" HGCM service.
*
* @returns 0 on success, 1 on failure
* @param key (string) the key which the value is stored under.
*/
{
using namespace svcInfo;
uint32_t u32ClientID = 0;
int rc = VINF_SUCCESS;
char szValue[KEY_MAX_VALUE_LEN];
if (argc != 1)
{
return 1;
}
if (!RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
}
{
if (RT_SUCCESS(rc))
else
RTPrintf("No value set!\n");
}
if (u32ClientID != 0)
}
/**
* This is accessed through the "VBoxSharedInfoSvc" HGCM service.
*
* @returns 0 on success, 1 on failure
* @param key (string) the key which the value is stored under.
* @param value (string) the value to write. If empty, the key will be
* removed.
*/
{
{
usage();
return 1;
}
int rc = VINF_SUCCESS;
uint32_t u32ClientID = 0;
if (2 == argc)
if (!RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
if (!RT_SUCCESS(rc))
}
if (u32ClientID != 0)
}
#endif
/** command handler type */
typedef FNHANDLER *PFNHANDLER;
/** The table of all registered command handlers. */
struct
{
const char *command;
} g_commandHandlers[] =
{
#ifdef VBOX_WITH_INFO_SVC
{ "getguestproperty", getGuestProperty },
{ "setguestproperty", setGuestProperty }
#endif
};
/** Main function */
{
/** The application's global return code */
int rc = 0;
/** An IPRT return code for local use */
int rrc = VINF_SUCCESS;
/** The index of the command line argument we are currently processing */
int iArg = 1;
/** Should we show the logo text? */
bool showlogo = true;
/** Should we print the usage after the logo? For the --help switch. */
bool dohelp = false;
/** Will we be executing a command or just printing information? */
bool onlyinfo = false;
/*
* Start by handling command line switches
*/
/** Are we finished with handling switches? */
bool done = false;
{
)
{
/* Print version number, and do nothing else. */
onlyinfo = true;
showlogo = false;
done = true;
}
showlogo = false;
{
onlyinfo = true;
dohelp = true;
done = true;
}
else
/* We have found an argument which isn't a switch. Exit to the
* command processing bit. */
done = true;
if (!done)
++iArg;
}
/*
* Find the application name, show our logo if the user hasn't suppressed it,
* and show the usage if the user asked us to
*/
if (showlogo)
RTPrintf("VirtualBox Guest Additions Command Line Management Interface Version "
VBOX_VERSION_STRING "\n"
"(C) 2008 Sun Microsystems, Inc.\n"
"All rights reserved\n\n");
if (dohelp)
usage();
/*
* Do global initialisation for the programme if we will be handling a command
*/
if (!onlyinfo)
{
if (!RT_SUCCESS(rrc))
{
rc = 1;
}
if (0 == rc)
{
if (!RT_SUCCESS(VbglR3Init()))
{
VBoxControlError("Could not contact the host system. Make sure that you are running this\n"
"application inside a VirtualBox guest system, and that you have sufficient\n"
"user permissions.\n");
rc = 1;
}
}
}
/*
* Now look for an actual command in the argument list and handle it.
*/
{
{
/** Is next parameter a known command? */
bool found = false;
/** And if so, what is its position in the table? */
unsigned index = 0;
{
found = true;
else
++index;
}
if (found)
else
{
rc = 1;
usage();
}
}
else
{
/* The user didn't specify a command. */
rc = 1;
usage();
}
}
/*
* And exit, returning the status
*/
return rc;
}