VBoxManageBandwidthControl.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* VBoxManage - The bandwidth control related commands.
*/
/*
* Copyright (C) 2006-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.
*/
#ifndef VBOX_ONLY_DOCS
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
using namespace com;
// funcs
///////////////////////////////////////////////////////////////////////////////
/**
* Parses a string in the following format "n[k|m|g|K|M|G]". Stores the value
* of n expressed in bytes to *pLimit. k meas kilobit, while K means kilobyte.
*
* @returns Error message or NULL if successful.
* @param pcszLimit The string to parse.
* @param pLimit Where to store the result.
*/
{
int iMultiplier = _1M;
switch (rc)
{
case VINF_SUCCESS:
break;
case VWRN_NUMBER_TOO_BIG:
return "Limit is too big\n";
case VWRN_TRAILING_CHARS:
switch (*pszNext)
{
default: return "Invalid unit suffix. Valid suffixes are: k, m, g, K, M, G\n";
}
break;
case VWRN_TRAILING_SPACES:
return "Trailing spaces in limit!\n";
case VERR_NO_DIGITS:
return "No digits in limit specifier\n";
default:
return "Invalid limit specifier\n";
}
if (*pLimit < 0)
return "Limit cannot be negative\n";
return "Limit is too big\n";
*pLimit *= iMultiplier;
return NULL;
}
/**
* Handles the 'bandwidthctl myvm add' sub-command.
* @returns Exit code.
* @param a The handler argument package.
* @param bwCtrl Reference to the bandwidth control interface.
*/
{
static const RTGETOPTDEF g_aBWCtlAddOptions[] =
{
};
int c;
{
switch (c)
{
case 't': // bandwidth group type
{
if (ValueUnion.psz)
else
break;
}
case 'l': // limit
{
if (ValueUnion.psz)
{
if (pcszError)
{
return RTEXITCODE_FAILURE;
}
}
else
break;
}
default:
{
break;
}
}
}
else
{
errorArgument("Invalid bandwidth group type\n");
return RTEXITCODE_FAILURE;
}
CHECK_ERROR2_RET(bwCtrl, CreateBandwidthGroup(name.raw(), enmType, (LONG64)cMaxBytesPerSec), RTEXITCODE_FAILURE);
return RTEXITCODE_SUCCESS;
}
/**
* Handles the 'bandwidthctl myvm set' sub-command.
* @returns Exit code.
* @param a The handler argument package.
* @param bwCtrl Reference to the bandwidth control interface.
*/
{
static const RTGETOPTDEF g_aBWCtlAddOptions[] =
{
};
int c;
{
switch (c)
{
case 'l': // limit
{
if (ValueUnion.psz)
{
if (pcszError)
{
return RTEXITCODE_FAILURE;
}
}
else
break;
}
default:
{
break;
}
}
}
if (cMaxBytesPerSec != INT64_MAX)
{
}
return RTEXITCODE_SUCCESS;
}
/**
* Handles the 'bandwidthctl myvm remove' sub-command.
* @returns Exit code.
* @param a The handler argument package.
* @param bwCtrl Reference to the bandwidth control interface.
*/
{
return RTEXITCODE_SUCCESS;
}
/**
* Handles the 'bandwidthctl myvm list' sub-command.
* @returns Exit code.
* @param a The handler argument package.
* @param bwCtrl Reference to the bandwidth control interface.
*/
static RTEXITCODE handleBandwidthControlList(HandlerArg *pArgs, ComPtr<IBandwidthControl> &rptrBWControl)
{
static const RTGETOPTDEF g_aOptions[] =
{
};
int c;
RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, g_aOptions, RT_ELEMENTS(g_aOptions), 2 /*iArg*/, 0 /*fFlags*/);
{
switch (c)
{
}
}
/* See showVMInfo. */
return RTEXITCODE_FAILURE;
return RTEXITCODE_SUCCESS;
}
/**
* Handles the 'bandwidthctl' command.
* @returns Exit code.
* @param a The handler argument package.
*/
int handleBandwidthControl(HandlerArg *a)
{
int c = VERR_INTERNAL_ERROR; /* initialized to shut up gcc */
if (a->argc < 2)
else if (a->argc > 7)
/* try to find the given machine */
/* open a session for the VM (new or shared) */
/* get the mutable session machine */
{
if (fRunTime)
{
errorArgument("Bandwidth groups cannot be created while the VM is running\n");
goto leave;
}
}
{
if (fRunTime)
{
errorArgument("Bandwidth groups cannot be deleted while the VM is running\n");
goto leave;
}
}
else
{
}
/* commit changes */
/* it's important to always close sessions */
a->session->UnlockMachine();
}
#endif /* !VBOX_ONLY_DOCS */