GuestSessionImpl.cpp revision b1cc3e87518139898395f96974ecff9e6bf228fb
/* $Id$ */
/** @file
* VirtualBox Main - XXX.
*/
/*
* Copyright (C) 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "GuestImpl.h"
#include "GuestSessionImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "Global.h"
#include "AutoCaller.h"
#include "ProgressImpl.h"
#include <memory> /* For auto_ptr. */
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
LogFlowThisFunc(("\n"));
return BaseFinalConstruct();
}
void GuestSession::FinalRelease(void)
{
uninit();
}
// session task classes
/////////////////////////////////////////////////////////////////////////////
{
}
GuestSessionTask::~GuestSessionTask(void)
{
}
{
if (fCanceled)
return VERR_CANCELLED;
return VINF_SUCCESS;
}
int GuestSessionTask::setProgressSuccess(void)
{
&& !fCanceled
&& !fCompleted)
{
return VERR_COM_UNEXPECTED; /** @todo Find a better rc. */
}
return VINF_SUCCESS;
}
{
&& !fCanceled
&& !fCompleted)
{
return VERR_COM_UNEXPECTED;
}
return VINF_SUCCESS;
}
{
}
SessionTaskCopyTo::~SessionTaskCopyTo(void)
{
}
int SessionTaskCopyTo::Run(void)
{
return 0;
}
{
LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n",
"gctlCpyTo");
return rc;
}
/* static */
{
}
{
}
{
}
int SessionTaskCopyFrom::Run(void)
{
return 0;
}
{
LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n",
"gctlCpyFrom");
return rc;
}
/* static */
{
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
{
/* Enclose the state transition NotReady->InInit->Ready. */
AutoInitSpan autoInitSpan(this);
mData.mNextProcessID = 0;
/* Confirm a successful initialization when it's the case. */
return VINF_SUCCESS;
}
/**
* Uninitializes the instance.
* Called from FinalRelease().
*/
void GuestSession::uninit(void)
{
/* Enclose the state transition Ready->InUninit->NotReady. */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
#ifdef VBOX_WITH_GUEST_CONTROL
{
}
{
}
{
}
{
}
#endif
}
/////////////////////////////////////////////////////////////////////////////
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
{
}
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
int rc = VINF_SUCCESS;
{
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
{
{
if (pDirectory == (*itDirs))
{
return VINF_SUCCESS;
}
}
return VERR_NOT_FOUND;
}
int GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory)
{
LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
int rc = VINF_SUCCESS;
/* Construct arguments. */
procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
if (uMode)
{
char szMode[16];
{
}
else
}
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
{
if (lExitCode != 0)
return VERR_CANT_CREATE;
}
else
}
}
if (RT_FAILURE(rc))
return rc;
try
{
/* Create the directory object. */
object here. */
/* Add the created directory to our vector. */
LogFlowFunc(("Added new directory (Session: %RU32) with process ID=%RU32\n",
}
catch (int rc2)
{
}
return rc;
}
int GuestSession::dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
{
#ifdef DEBUG
LogFlowFunc(("uProcessID=%RU32 (%RU32 total)\n",
#endif
int rc;
{
}
else
rc = VERR_NOT_FOUND;
return rc;
}
{
{
{
return VINF_SUCCESS;
}
}
return VERR_NOT_FOUND;
}
/* Note: Will work on directories and others, too. */
{
/* Construct arguments. */
if (RT_SUCCESS(rc))
{
for (;;)
{
if ( RT_FAILURE(rc)
{
break;
}
&cbRead);
if (RT_FAILURE(rc))
break;
if (RT_FAILURE(rc))
break;
}
LogFlowThisFunc(("rc=%Rrc, cbRead=%RU32, cbStreamOut=%RU32\n",
}
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
}
else
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
else
}
return rc;
}
{
return mData.mCredentials;
}
{
return mData.mEnvironment;
}
{
}
{
{
{
return VINF_SUCCESS;
}
}
return VERR_NOT_FOUND;
}
int GuestSession::processCreateExInteral(GuestProcessInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
{
LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
/* Validate flags. */
{
{
return VERR_INVALID_PARAMETER;
}
}
/* Adjust timeout. If set to 0, we define
* an infinite timeout. */
if (procInfo.mTimeoutMS == 0)
/** @tood Implement process priority + affinity. */
int rc = VERR_MAX_PROCS_REACHED;
return rc;
/* Create a new (host-based) process ID and assign it. */
for (;;)
{
/* Is the context ID already used? */
{
/* Callback with context ID was not found. This means
* we can use this context ID for our new callback we want
* to add below. */
rc = VINF_SUCCESS;
break;
}
mData.mNextProcessID = 0;
if (++uTries == UINT32_MAX)
break; /* Don't try too hard. */
}
try
{
/* Create the process object. */
/* Add the created process to our map. */
LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32\n",
}
catch (int rc2)
{
}
return rc;
}
{
{
if (pProcess)
return true;
}
return false;
}
{
AssertReturn(uPID, false);
/* pProcess is optional. */
{
if (procCaller.rc())
return VERR_COM_INVALID_OBJECT_STATE;
{
if (pProcess)
return VINF_SUCCESS;
}
}
return VERR_NOT_FOUND;
}
{
int rc;
try
{
/* Create the progress object. */
TRUE /* aCancelable */);
/* Initialize our worker task. */
/* Don't destruct on success. */
}
catch (int rc2)
{
}
return rc;
}
/**
* This is necessary to know which guest control protocol version to use,
* among other things (later).
*
* @return IPRT status code.
*/
int GuestSession::queryInfo(void)
{
#if 1
/* Since the new functions were not implemented yet, force Main to use protocol ver 1. */
#else
/*
* Try querying the guest control protocol version running on the guest.
* This is done using the Guest Additions version
*/
? 2 /* Guest control 2.0. */
: 1; /* Legacy guest control (VBox < 4.2). */
/* Build revision is ignored. */
/* Tell the user but don't bitch too often. */
static short s_gctrlLegacyWarning = 0;
LogRel((tr("Warning: Guest Additions are older (%ld.%ld) than host capabilities for guest control, please upgrade them. Using protocol version %ld now\n"),
VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions), VBOX_FULL_VERSION_GET_MINOR(uVerAdditions), mData.mProtocolVersion));
#endif
return VINF_SUCCESS;
}
// implementation of public methods
/////////////////////////////////////////////////////////////////////////////
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
uninit();
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (aFlags)
{
}
int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from guest to \"%ls\" on the host"), aSource, aDest),
if (RT_SUCCESS(rc))
{
/* Return progress to the caller. */
}
/** @todo rc -> hr error lookup. */
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (aFlags)
{
}
int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from host to \"%ls\" on the guest"), aSource, aDest),
if (RT_SUCCESS(rc))
{
/* Return progress to the caller. */
}
/** @todo rc -> hr error lookup. */
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
/* aDirectory is optional. */
AutoCaller autoCaller(this);
if (aFlags)
{
if (!(fFlags & DirectoryCreateFlag_Parents))
}
if (RT_SUCCESS(rc))
{
if (aDirectory)
{
/* Return directory object to the caller. */
}
else
{
if (RT_FAILURE(rc))
}
}
else
{
switch (rc)
{
case VERR_INVALID_PARAMETER:
break;
case VERR_BROKEN_PIPE:
break;
case VERR_CANT_CREATE:
break;
default:
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (RT_SUCCESS(rc))
{
}
else
{
switch (rc)
{
/** @todo Add more errors here! */
default:
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, IN_BSTR aFlags, IGuestDirectory **aDirectory)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestFile **aFile)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (RT_SUCCESS(rc))
{
}
else
{
switch (rc)
{
/** @todo Add more errors here! */
default:
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (RT_SUCCESS(rc))
{
}
else
{
switch (rc)
{
/** @todo Add more errors here! */
default:
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
HRESULT hr = ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess);
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (aArguments)
{
}
int rc = VINF_SUCCESS;
/*
* Create the process environment:
* - Apply the session environment in a first step, and
* - Apply environment variables specified by this call to
* have the chance of overwriting/deleting session entries.
*/
if (aEnvironment)
{
}
if (RT_SUCCESS(rc))
{
if (aFlags)
{
}
if (aAffinity)
{
}
if (RT_SUCCESS(rc))
{
/* Return guest session to the caller. */
if (RT_SUCCESS(rc))
}
}
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
if (aPID == 0)
AutoCaller autoCaller(this);
if (RT_FAILURE(rc))
/* This will set (*aProcess) to NULL if pProgress is NULL. */
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestSession::SymlinkRead(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}