VirtualBox

忽略:
時間撮記:
2013-10-31 下午04:40:46 (11 年 以前)
作者:
vboxsync
訊息:

Guest Control:

  • Implemented IGuestSession::DirectoryRemove, IGuestSession::DirectoryRemoveRecursive, IGuestSession::DirectoryRename + IGuestSession::FileRename.
  • Added appropriate commands to VBoxManage (basic support for now).
  • Implemented support for proper guest session process termination via SCM.
  • Implemented support for internal anonymous wait events which are not relying on the public API's VBoxEventType_T.
  • Various bugfixes.
檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp

    r47627 r49349  
    5959/////////////////////////////////////////////////////////////////////////////
    6060
    61 int GuestDirectory::init(GuestSession *aSession,
    62                          const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags)
    63 {
    64     LogFlowThisFunc(("strPath=%s, strFilter=%s, uFlags=%x\n",
    65                      strPath.c_str(), strFilter.c_str(), uFlags));
     61int GuestDirectory::init(Console *pConsole, GuestSession *pSession,
     62                         ULONG uDirID, const GuestDirectoryOpenInfo &openInfo)
     63{
     64    LogFlowThisFunc(("pConsole=%p, pSession=%p, uDirID=%RU32, strPath=%s, strFilter=%s, uFlags=%x\n",
     65                     pConsole, pSession, uDirID, openInfo.mPath.c_str(), openInfo.mFilter.c_str(),
     66                     openInfo.mFlags));
     67
     68    AssertPtrReturn(pConsole, VERR_INVALID_POINTER);
     69    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
    6670
    6771    /* Enclose the state transition NotReady->InInit->Ready. */
     
    6973    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    7074
    71     mData.mSession = aSession;
    72     mData.mName    = strPath;
    73     mData.mFilter  = strFilter;
    74     mData.mFlags   = uFlags;
    75 
    76     /* Start the directory process on the guest. */
    77     GuestProcessStartupInfo procInfo;
    78     procInfo.mName      = Utf8StrFmt(tr("Reading directory \"%s\"", strPath.c_str()));
    79     procInfo.mCommand   = Utf8Str(VBOXSERVICE_TOOL_LS);
    80     procInfo.mTimeoutMS = 5 * 60 * 1000; /* 5 minutes timeout. */
    81     procInfo.mFlags     = ProcessCreateFlag_WaitForStdOut;
    82 
    83     procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
    84     /* We want the long output format which contains all the object details. */
    85     procInfo.mArguments.push_back(Utf8Str("-l"));
     75#ifndef VBOX_WITH_GUEST_CONTROL
     76    autoInitSpan.setSucceeded();
     77    return VINF_SUCCESS;
     78#else
     79    int vrc = bindToSession(pConsole, pSession, uDirID /* Object ID */);
     80    if (RT_SUCCESS(vrc))
     81    {
     82        mSession = pSession;
     83
     84        mData.mID = uDirID;
     85        mData.mOpenInfo = openInfo;
     86    }
     87
     88    if (RT_SUCCESS(vrc))
     89    {
     90        /* Start the directory process on the guest. */
     91        GuestProcessStartupInfo procInfo;
     92        procInfo.mName      = Utf8StrFmt(tr("Reading directory \"%s\"", openInfo.mPath.c_str()));
     93        procInfo.mCommand   = Utf8Str(VBOXSERVICE_TOOL_LS);
     94        procInfo.mTimeoutMS = 5 * 60 * 1000; /* 5 minutes timeout. */
     95        procInfo.mFlags     = ProcessCreateFlag_WaitForStdOut;
     96
     97        procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
     98        /* We want the long output format which contains all the object details. */
     99        procInfo.mArguments.push_back(Utf8Str("-l"));
    86100#if 0 /* Flags are not supported yet. */
    87     if (uFlags & DirectoryOpenFlag_NoSymlinks)
    88         procInfo.mArguments.push_back(Utf8Str("--nosymlinks")); /** @todo What does GNU here? */
     101        if (uFlags & DirectoryOpenFlag_NoSymlinks)
     102            procInfo.mArguments.push_back(Utf8Str("--nosymlinks")); /** @todo What does GNU here? */
    89103#endif
    90     /** @todo Recursion support? */
    91     procInfo.mArguments.push_back(strPath); /* The directory we want to open. */
    92 
    93     /*
    94      * Start the process asynchronously and keep it around so that we can use
    95      * it later in subsequent read() calls.
    96      * Note: No guest rc available because operation is asynchronous.
    97      */
    98     int rc = mData.mProcessTool.Init(mData.mSession, procInfo,
    99                                      true /* Async */, NULL /* Guest rc */);
    100     if (RT_SUCCESS(rc))
     104        /** @todo Recursion support? */
     105        procInfo.mArguments.push_back(openInfo.mPath); /* The directory we want to open. */
     106
     107        /*
     108         * Start the process asynchronously and keep it around so that we can use
     109         * it later in subsequent read() calls.
     110         * Note: No guest rc available because operation is asynchronous.
     111         */
     112        vrc = mData.mProcessTool.Init(mSession, procInfo,
     113                                      true /* Async */, NULL /* Guest rc */);
     114    }
     115
     116    if (RT_SUCCESS(vrc))
    101117    {
    102118        /* Confirm a successful initialization when it's the case. */
    103119        autoInitSpan.setSucceeded();
    104         return rc;
    105     }
    106 
    107     autoInitSpan.setFailed();
    108     return rc;
     120        return vrc;
     121    }
     122    else
     123        autoInitSpan.setFailed();
     124
     125    return vrc;
     126#endif /* VBOX_WITH_GUEST_CONTROL */
    109127}
    110128
     
    139157    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    140158
    141     mData.mName.cloneTo(aName);
     159    mData.mOpenInfo.mPath.cloneTo(aName);
    142160
    143161    return S_OK;
     
    155173    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    156174
    157     mData.mFilter.cloneTo(aFilter);
     175    mData.mOpenInfo.mFilter.cloneTo(aFilter);
    158176
    159177    return S_OK;
     
    162180// private methods
    163181/////////////////////////////////////////////////////////////////////////////
     182
     183int GuestDirectory::callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
     184{
     185    AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
     186    AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
     187
     188    LogFlowThisFunc(("strPath=%s, uContextID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
     189                     mData.mOpenInfo.mPath.c_str(), pCbCtx->uContextID, pCbCtx->uFunction, pSvcCb));
     190
     191    int vrc;
     192    switch (pCbCtx->uFunction)
     193    {
     194        case GUEST_DIR_NOTIFY:
     195        {
     196            int idx = 1; /* Current parameter index. */
     197            CALLBACKDATA_DIR_NOTIFY dataCb;
     198            /* pSvcCb->mpaParms[0] always contains the context ID. */
     199            pSvcCb->mpaParms[idx++].getUInt32(&dataCb.uType);
     200            pSvcCb->mpaParms[idx++].getUInt32(&dataCb.rc);
     201
     202            int guestRc = (int)dataCb.rc; /* uint32_t vs. int. */
     203
     204            LogFlowFunc(("uType=%RU32, guestRc=%Rrc\n",
     205                         dataCb.uType, guestRc));
     206
     207            switch (dataCb.uType)
     208            {
     209                /* Nothing here yet, nothing to dispatch further. */
     210
     211                default:
     212                    vrc = VERR_NOT_SUPPORTED;
     213                    break;
     214            }
     215            break;
     216        }
     217
     218        default:
     219            /* Silently ignore not implemented functions. */
     220            vrc = VERR_NOT_SUPPORTED;
     221            break;
     222    }
     223
     224#ifdef DEBUG
     225    LogFlowFuncLeaveRC(vrc);
     226#endif
     227    return vrc;
     228}
     229
     230/* static */
     231Utf8Str GuestDirectory::guestErrorToString(int guestRc)
     232{
     233    Utf8Str strError;
     234
     235    /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
     236    switch (guestRc)
     237    {
     238        case VERR_DIR_NOT_EMPTY:
     239            strError += Utf8StrFmt("Directoy is not empty");
     240            break;
     241
     242        default:
     243            strError += Utf8StrFmt("%Rrc", guestRc);
     244            break;
     245    }
     246
     247    return strError;
     248}
     249
     250/* static */
     251HRESULT GuestDirectory::setErrorExternal(VirtualBoxBase *pInterface, int guestRc)
     252{
     253    AssertPtr(pInterface);
     254    AssertMsg(RT_FAILURE(guestRc), ("Guest rc does not indicate a failure when setting error\n"));
     255
     256    return pInterface->setError(VBOX_E_IPRT_ERROR, GuestDirectory::guestErrorToString(guestRc).c_str());
     257}
    164258
    165259// implementation of public methods
     
    176270    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    177271
    178     AssertPtr(mData.mSession);
    179     int rc = mData.mSession->directoryRemoveFromList(this);
     272    AssertPtr(mSession);
     273    int rc = mSession->directoryRemoveFromList(this);
    180274    AssertRC(rc);
    181275
     
    188282        switch (rc)
    189283        {
    190            case VERR_GSTCTL_GUEST_ERROR:
     284            case VERR_GSTCTL_GUEST_ERROR:
    191285                hr = GuestProcess::setErrorExternal(this, guestRc);
    192286                break;
     
    200294                hr = setError(VBOX_E_IPRT_ERROR,
    201295                              tr("Terminating open guest directory \"%s\" failed: %Rrc"),
    202                               mData.mName.c_str(), rc);
     296                              mData.mOpenInfo.mPath.c_str(), rc);
    203297                break;
    204298        }
     
    293387            case VERR_ACCESS_DENIED:
    294388                hr = setError(VBOX_E_IPRT_ERROR, tr("Reading directory \"%s\" failed: Unable to read / access denied"),
    295                               mData.mName.c_str());
     389                              mData.mOpenInfo.mPath.c_str());
    296390                break;
    297391
    298392            case VERR_PATH_NOT_FOUND:
    299393                hr = setError(VBOX_E_IPRT_ERROR, tr("Reading directory \"%s\" failed: Path not found"),
    300                               mData.mName.c_str());
     394                              mData.mOpenInfo.mPath.c_str());
    301395                break;
    302396
     
    304398                /* See SDK reference. */
    305399                hr = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No more entries for directory \"%s\""),
    306                               mData.mName.c_str());
     400                              mData.mOpenInfo.mPath.c_str());
    307401                break;
    308402
    309403            default:
    310404                hr = setError(VBOX_E_IPRT_ERROR, tr("Error while reading directory \"%s\": %Rrc\n"),
    311                               mData.mName.c_str(), rc);
     405                              mData.mOpenInfo.mPath.c_str(), rc);
    312406                break;
    313407        }
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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