GuestCtrlImpl.cpp revision 16793803f63339106d16a55bc5b55ba9070b44e0
/* $Id$ */
/** @file
* VirtualBox COM class implementation: Guest
*/
/*
* Copyright (C) 2006-2013 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.
*/
#include "GuestImpl.h"
#include "GuestSessionImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "Global.h"
#include "ConsoleImpl.h"
#include "ProgressImpl.h"
#include "VBoxEvents.h"
#include "VMMDev.h"
#include "AutoCaller.h"
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
#include <memory>
#ifdef LOG_GROUP
#endif
#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
#ifdef VBOX_WITH_GUEST_CONTROL
/**
* Static callback function for receiving updates on guest control commands
* from the guest. Acts as a dispatcher for the actual class instance.
*
* @returns VBox status code.
*
* @todo
*
*/
/* static */
void *pvData,
{
using namespace guestControl;
/*
* No locking, as this is purely a notification which does not make any
* changes to the object state.
*/
LogFlowFunc(("pvExtension=%p, u32Function=%RU32, pvParms=%p, cbParms=%RU32\n",
/*
* For guest control 2.0 using the legacy commands we need to do the following here:
* - Get the callback header to access the context ID
* - Get the context ID of the callback
* - Extract the session ID out of the context ID
* - Dispatch the whole stuff to the appropriate session (if still exists)
*/
if (cbData != sizeof(VBOXGUESTCTRLHOSTCALLBACK))
return VERR_NOT_SUPPORTED;
return VERR_INVALID_PARAMETER;
#ifdef DEBUG
LogFlowFunc(("CID=%RU32, uSession=%RU32, uObject=%RU32, uCount=%RU32\n",
#endif
return rc;
}
#endif /* VBOX_WITH_GUEST_CONTROL */
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
AutoCaller autoCaller(this);
/* Validate flags. */
if (aFlags)
{
}
if (fFlags)
{
}
int rc = VINF_SUCCESS;
if (aArguments)
{
try
{
}
{
rc = VERR_NO_MEMORY;
}
}
/*
* Create an anonymous session. This is required to run the Guest Additions
* update process with administrative rights.
*/
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
{
switch (rc)
{
case VERR_MAX_PROCS_REACHED:
break;
/** @todo Add more errors here. */
default:
break;
}
}
else
{
int guestRc;
if (RT_FAILURE(rc))
{
/** @todo Handle guestRc! */
}
else
{
try
{
if (RT_SUCCESS(rc))
{
/* Return progress to the caller. */
}
else
}
{
hr = E_OUTOFMEMORY;
}
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
{
LogFlowFunc(("uFunction=%RU32, uContextID=%RU32, uProtocol=%RU32\n",
#ifdef DEBUG
LogFlowFunc(("uSessionID=%RU32 (%zu total)\n",
#endif
int rc;
{
bool fDispatch = true;
#ifdef DEBUG
/*
* Pre-check: If we got a status message with an error and VERR_TOO_MUCH_DATA
* it means that that guest could not handle the entire message
* because of its exceeding size. This should not happen on daily
* use but testcases might try this. It then makes no sense to dispatch
* this further because we don't have a valid context ID.
*/
{
/* pSvcCb->mpaParms[0] always contains the context ID. */
/** @todo Note: Due to legacy reasons we cannot change uFlags to
* int32_t, so just cast it for now. */
{
LogFlowFunc(("Requested command with too much data, skipping dispatching ...\n"));
fDispatch = false;
}
}
#endif
if (fDispatch)
{
{
case GUEST_DISCONNECTED:
break;
case GUEST_SESSION_NOTIFY:
break;
case GUEST_EXEC_STATUS:
case GUEST_EXEC_OUTPUT:
case GUEST_EXEC_INPUT_STATUS:
case GUEST_EXEC_IO_NOTIFY:
break;
case GUEST_FILE_NOTIFY:
break;
default:
break;
}
}
else
rc = VERR_NOT_FOUND;
}
else
rc = VERR_NOT_FOUND;
return rc;
}
{
int rc = VERR_NOT_FOUND;
{
{
/* Make sure to consume the pointer before the one of the
* iterator gets released. */
LogFlowFunc(("Removing session (pSession=%p, ID=%RU32) (now total %ld sessions)\n",
false /* Unregistered */);
rc = VINF_SUCCESS;
break;
}
itSessions++;
}
return rc;
}
{
int rc = VERR_MAX_PROCS_REACHED;
return rc;
try
{
/* Create a new session ID and assign it. */
for (;;)
{
/* Is the context ID already used? */
if (!sessionExists(uNewSessionID))
{
rc = VINF_SUCCESS;
break;
}
if (++uTries == VBOX_GUESTCTRL_MAX_SESSIONS)
break; /* Don't try too hard. */
}
/* Create the session object. */
/** @todo Use an overloaded copy operator. Later. */
{
/** @todo Use an overloaded copy operator. Later. */
}
else
{
/* Internal (annonymous) session. */
startupInfo.mIsInternal = true;
}
/*
* Add session object to our session map. This is necessary
* before calling openSession because the guest calls back
* with the creation result of this session.
*/
true /* Registered */);
}
catch (int rc2)
{
}
return rc;
}
{
}
// implementation of public methods
/////////////////////////////////////////////////////////////////////////////
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
/* Do not allow anonymous sessions (with system rights) with public API. */
/* Rest is optional. */
AutoCaller autoCaller(this);
if (RT_SUCCESS(rc))
{
/* Return guest session to the caller. */
}
if (RT_SUCCESS(rc))
{
/* Start (fork) the session asynchronously
* on the guest. */
}
if (RT_FAILURE(rc))
{
switch (rc)
{
case VERR_MAX_PROCS_REACHED:
break;
/** @todo Add more errors here. */
default:
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
{
if (strName.contains(itSessions->second->getName())) /** @todo Use a (simple) pattern match (IPRT?). */
itSessions++;
}
LogFlowFunc(("Sessions with \"%ls\" = %RU32\n",
if (listSessions.size())
{
return S_OK;
}
return setErrorNoLog(VBOX_E_OBJECT_NOT_FOUND,
tr("Could not find sessions with name '%ls'"),
#endif /* VBOX_WITH_GUEST_CONTROL */
}