VirtualBox

Changeset 42525 in vbox for trunk/src


Ignore:
Timestamp:
Aug 2, 2012 10:24:28 AM (13 years ago)
Author:
vboxsync
Message:

Guest Control 2.0: Update.

Location:
trunk/src/VBox/Main
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r42507 r42525  
    92459245  <interface
    92469246    name="IGuestSession" extends="$unknown"
    9247     uuid="47a344ec-8495-49ad-bfab-8cd0ff8eb3cf"
     9247    uuid="89f39320-d86c-4705-a376-d083f3c5c4e3"
    92489248    wsmap="managed"
    92499249    >
     
    93729372    </method>
    93739373   
    9374     <method name="DirectoryCreate">
     9374    <method name="directoryCreate">
    93759375      <desc>
    93769376        TODO
     
    93869386        <desc>TODO</desc>
    93879387      </param>
    9388       <param name="flags" type="unsigned long" dir="in">
     9388      <param name="flags" type="DirectoryCreateFlag" dir="in" safearray="yes">
    93899389        <desc>TODO</desc>
    93909390      </param>
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r42507 r42525  
    268268struct GuestProcessInfo
    269269{
     270    /** The process' friendly name. */
     271    Utf8Str                     mName;
     272    /** The actual command to execute. */
    270273    Utf8Str                     mCommand;
    271274    ProcessArguments            mArguments;
     
    275278    ProcessPriority_T           mPriority;
    276279    ProcessAffinity             mAffinity;
     280
    277281};
    278282
  • trunk/src/VBox/Main/include/GuestDirectoryImpl.h

    r42084 r42525  
    2222#include "VirtualBoxBase.h"
    2323
     24class GuestSession;
     25
    2426/**
    2527 * TODO
     
    4143    DECLARE_EMPTY_CTOR_DTOR(GuestDirectory)
    4244
    43     HRESULT init(void);
     45    int     init(GuestSession *aSession, const Utf8Str &strPath);
    4446    void    uninit(void);
    4547    HRESULT FinalConstruct(void);
     
    5153    STDMETHOD(COMGETTER(DirectoryName))(BSTR *aName);
    5254
    53     STDMETHOD(Read)(IGuestFsObjInfo **aInfo);
     55    STDMETHOD(Read)(IFsObjInfo **aInfo);
    5456    /** @}  */
    5557
     
    6365    struct Data
    6466    {
     67        GuestSession           *mParent;
    6568        Utf8Str                 mName;
    6669        ComPtr<IGuestFsObjInfo> mFsObjInfo;
  • trunk/src/VBox/Main/include/GuestProcessImpl.h

    r42507 r42525  
    116116        /** All related callbacks to this process. */
    117117        GuestCtrlCallbacks       mCallbacks;
    118         /** The process' name. */
    119         Utf8Str                  mName;
    120118        /** The process start information. */
    121119        GuestProcessInfo         mProcess;
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r42485 r42525  
    7373    STDMETHOD(CopyFrom)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress);
    7474    STDMETHOD(CopyTo)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress);
    75     STDMETHOD(DirectoryCreate)(IN_BSTR aPath, ULONG aMode, ULONG aFlags, IGuestDirectory **aDirectory);
     75    STDMETHOD(DirectoryCreate)(IN_BSTR aPath, ULONG aMode, ComSafeArrayIn(DirectoryCreateFlag_T, aFlags), IGuestDirectory **aDirectory);
    7676    STDMETHOD(DirectoryCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory);
    7777    STDMETHOD(DirectoryExists)(IN_BSTR aPath, BOOL *aExists);
     
    124124     * @{ */
    125125    int                     directoryClose(ComObjPtr<GuestDirectory> pDirectory);
     126    int                     directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
    126127    int                     dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
    127128    int                     fileClose(ComObjPtr<GuestFile> pFile);
  • trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp

    r42478 r42525  
    5252/////////////////////////////////////////////////////////////////////////////
    5353
    54 HRESULT GuestDirectory::init(void)
     54int GuestDirectory::init(GuestSession *aSession, const Utf8Str &strPath)
    5555{
    5656    /* Enclose the state transition NotReady->InInit->Ready. */
     
    5858    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    5959
     60    mData.mParent = aSession;
     61    mData.mName = strPath;
     62
    6063    /* Confirm a successful initialization when it's the case. */
    6164    autoInitSpan.setSucceeded();
    6265
    63     return S_OK;
     66    return VINF_SUCCESS;
    6467}
    6568
     
    100103/////////////////////////////////////////////////////////////////////////////
    101104
    102 STDMETHODIMP GuestDirectory::Read(IGuestFsObjInfo **aInfo)
     105STDMETHODIMP GuestDirectory::Read(IFsObjInfo **aInfo)
    103106{
    104107#ifndef VBOX_WITH_GUEST_CONTROL
  • trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp

    r42509 r42525  
    266266    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    267267
    268     mData.mName.cloneTo(aName);
     268    mData.mProcess.mName.cloneTo(aName);
    269269
    270270    LogFlowFuncLeaveRC(S_OK);
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r42485 r42525  
    378378}
    379379
     380int GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory)
     381{
     382    LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
     383                     strPath.c_str(), uMode, uFlags));
     384
     385    GuestProcessInfo procInfo;
     386    procInfo.mName    = Utf8StrFmt(tr("Creating directory \"%s\"", strPath.c_str()));
     387    procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
     388
     389    int rc = VINF_SUCCESS;
     390
     391    /* Construct arguments. */
     392    if (uFlags & DirectoryCreateFlag_Parents)
     393        procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
     394    if (uMode)
     395    {
     396        procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
     397
     398        char szMode[16];
     399        if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
     400        {
     401            procInfo.mArguments.push_back(Utf8Str(szMode));
     402        }
     403        else
     404            rc = VERR_INVALID_PARAMETER;
     405    }
     406    procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
     407
     408    ComObjPtr<GuestProcess> pProcess;
     409    rc = processCreateExInteral(procInfo, pProcess);
     410    if (RT_SUCCESS(rc))
     411    {
     412        GuestProcessWaitResult waitRes;
     413        rc = pProcess->waitFor(ProcessWaitForFlag_Terminate, 30 * 1000 /* Timeout */, waitRes);
     414        if (RT_SUCCESS(rc))
     415        {
     416            ProcessStatus_T procStatus;
     417            HRESULT hr = pProcess->COMGETTER(Status)(&procStatus);
     418            ComAssertComRC(hr);
     419            if (procStatus == ProcessStatus_TerminatedNormally)
     420            {
     421                LONG lExitCode;
     422                pProcess->COMGETTER(ExitCode)(&lExitCode);
     423                if (lExitCode != 0)
     424                    return VERR_CANT_CREATE;
     425            }
     426            else
     427                rc = VERR_BROKEN_PIPE; /** @todo Find a better rc. */
     428        }
     429    }
     430
     431    if (RT_FAILURE(rc))
     432        return rc;
     433
     434    try
     435    {
     436        /* Create the directory object. */
     437        HRESULT hr = pDirectory.createObject();
     438        if (FAILED(hr)) throw VERR_COM_UNEXPECTED;
     439
     440        /* Note: There will be a race between creating and getting/initing the directory
     441                 object here. */
     442        rc = pDirectory->init(this /* Parent */, strPath);
     443        if (RT_FAILURE(rc)) throw rc;
     444
     445        /* Add the created directory to our vector. */
     446        mData.mDirectories.push_back(pDirectory);
     447
     448        LogFlowFunc(("Added new directory (Session: %RU32) with process ID=%RU32\n",
     449                     mData.mId, mData.mNextProcessID));
     450    }
     451    catch (int rc2)
     452    {
     453        rc = rc2;
     454    }
     455
     456    LogFlowFuncLeaveRC(rc);
     457    return rc;
     458}
     459
    380460int GuestSession::dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
    381461{
     
    504584            break; /* Don't try too hard. */
    505585    }
    506     if (RT_FAILURE(rc)) throw rc;
     586    if (RT_FAILURE(rc)) return rc;
    507587
    508588    try
     
    643723}
    644724
    645 STDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode, ULONG aFlags, IGuestDirectory **aProgress)
    646 {
    647 #ifndef VBOX_WITH_GUEST_CONTROL
    648     ReturnComNotImplemented();
    649 #else
    650     LogFlowThisFuncEnter();
    651 
    652     AutoCaller autoCaller(this);
    653     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    654 
    655     ReturnComNotImplemented();
     725STDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode,
     726                                           ComSafeArrayIn(DirectoryCreateFlag_T, aFlags), IGuestDirectory **aDirectory)
     727{
     728#ifndef VBOX_WITH_GUEST_CONTROL
     729    ReturnComNotImplemented();
     730#else
     731    LogFlowThisFuncEnter();
     732
     733    if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
     734        return setError(E_INVALIDARG, tr("No directory to create specified"));
     735    /* aDirectory is optional. */
     736
     737    AutoCaller autoCaller(this);
     738    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     739
     740    uint32_t fFlags = DirectoryCreateFlag_None;
     741    if (aFlags)
     742    {
     743        com::SafeArray<DirectoryCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
     744        for (size_t i = 0; i < flags.size(); i++)
     745            fFlags |= flags[i];
     746
     747        if (!(fFlags & DirectoryCreateFlag_Parents))
     748            return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), fFlags);
     749    }
     750
     751    HRESULT hr = S_OK;
     752
     753    ComObjPtr <GuestDirectory> pDirectory;
     754    int rc = directoryCreateInternal(Utf8Str(aPath), (uint32_t)aMode, (uint32_t)aFlags, pDirectory);
     755    if (RT_SUCCESS(rc))
     756    {
     757        if (aDirectory)
     758        {
     759            /* Return directory object to the caller. */
     760            hr = pDirectory.queryInterfaceTo(aDirectory);
     761        }
     762        else
     763        {
     764            rc = directoryClose(pDirectory);
     765            if (RT_FAILURE(rc))
     766                hr = setError(VBOX_E_IPRT_ERROR, tr("Unable to close directory object, rc=%Rrc"), rc);
     767        }
     768    }
     769    else
     770    {
     771        switch (rc)
     772        {
     773            case VERR_INVALID_PARAMETER:
     774               hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Invalid parameters given"));
     775               break;
     776
     777            case VERR_BROKEN_PIPE:
     778               hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Unexpectedly aborted"));
     779               break;
     780
     781            case VERR_CANT_CREATE:
     782               hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Could not create directory"));
     783               break;
     784
     785            default:
     786               hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
     787               break;
     788        }
     789    }
     790
     791    return hr;
    656792#endif /* VBOX_WITH_GUEST_CONTROL */
    657793}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette