VirtualBox

Changeset 42530 in vbox


Ignore:
Timestamp:
Aug 2, 2012 12:11:44 PM (12 years ago)
Author:
vboxsync
Message:

Guest Control 2.0: Update.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r42525 r42530  
    7272typedef std::vector <Utf8Str> ProcessArguments;
    7373
     74class GuestProcessStreamBlock;
     75
    7476
    7577/**
     
    116118    int                         mRC;
    117119};
     120
    118121
    119122/*
     
    174177};
    175178
     179
    176180/*
    177181 * Class representing a guest control process event.
     
    207211};
    208212
     213
    209214/**
    210215 * Simple structure mantaining guest credentials.
     
    217222};
    218223
     224
    219225typedef std::vector <Utf8Str> GuestEnvironmentArray;
    220226class GuestEnvironment
     
    259265
    260266    std::map <Utf8Str, Utf8Str> mEnvironment;
     267};
     268
     269
     270/**
     271 * Structure representing information of a
     272 * file system object.
     273 */
     274struct GuestFsObjData
     275{
     276    /** Helper function to extract the data from
     277     *  a guest stream block. */
     278    int From(const GuestProcessStreamBlock &strmBlk);
     279
     280    int64_t              mAccessTime;
     281    int64_t              mAllocatedSize;
     282    int64_t              mBirthTime;
     283    int64_t              mChangeTime;
     284    uint32_t             mDeviceNumber;
     285    Utf8Str              mFileAttrs;
     286    uint32_t             mGenerationID;
     287    uint32_t             mGID;
     288    Utf8Str              mGroupName;
     289    uint32_t             mNumHardLinks;
     290    int64_t              mModificationTime;
     291    Utf8Str              mName;
     292    int64_t              mNodeID;
     293    uint32_t             mNodeIDDevice;
     294    int64_t              mObjectSize;
     295    FsObjType_T          mType;
     296    uint32_t             mUID;
     297    uint32_t             mUserFlags;
     298    Utf8Str              mUserName;
     299    Utf8Str              mACL;
    261300};
    262301
     
    281320};
    282321
     322
    283323/**
    284324 * Class representing the "value" side of a "key=value" pair.
     
    313353public:
    314354
    315     GuestProcessStreamBlock();
    316 
    317     //GuestProcessStreamBlock(GuestProcessStreamBlock &);
    318 
    319     virtual ~GuestProcessStreamBlock();
     355    GuestProcessStreamBlock(void);
     356
     357    virtual ~GuestProcessStreamBlock(void);
    320358
    321359public:
     
    327365#endif
    328366
    329     int GetInt64Ex(const char *pszKey, int64_t *piVal);
    330 
    331     int64_t GetInt64(const char *pszKey);
    332 
    333     size_t GetCount();
    334 
    335     const char* GetString(const char *pszKey);
    336 
    337     int GetUInt32Ex(const char *pszKey, uint32_t *puVal);
    338 
    339     uint32_t GetUInt32(const char *pszKey);
     367    int GetInt64Ex(const char *pszKey, int64_t *piVal) const;
     368
     369    int64_t GetInt64(const char *pszKey) const;
     370
     371    size_t GetCount(void) const;
     372
     373    const char* GetString(const char *pszKey) const;
     374
     375    int GetUInt32Ex(const char *pszKey, uint32_t *puVal) const;
     376
     377    uint32_t GetUInt32(const char *pszKey) const;
    340378
    341379    int SetValue(const char *pszKey, const char *pszValue);
  • trunk/src/VBox/Main/include/GuestFsObjInfoImpl.h

    r42095 r42530  
    2121
    2222#include "VirtualBoxBase.h"
     23#include "GuestCtrlImplPrivate.h"
    2324
    2425/**
     
    7879private:
    7980
    80     struct Data
    81     {
    82         LONG64               mAccessTime;
    83         LONG64               mAllocatedSize;
    84         LONG64               mBirthTime;
    85         LONG64               mChangeTime;
    86         ULONG                mDeviceNumber;
    87         Utf8Str              mFileAttrs;
    88         ULONG                mGenerationID;
    89         ULONG                mGID;
    90         Utf8Str              mGroupName;
    91         ULONG                mNumHardLinks;
    92         LONG64               mModificationTime;
    93         Utf8Str              mName;
    94         LONG64               mNodeID;
    95         ULONG                mNodeIDDevice;
    96         LONG64               mObjectSize;
    97         FsObjType            mType;
    98         ULONG                mUID;
    99         ULONG                mUserFlags;
    100         Utf8Str              mUserName;
    101         Utf8Str              mACL;
    102     } mData;
     81    GuestFsObjData mData;
    10382};
    10483
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r42525 r42530  
    127127    int                     dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
    128128    int                     fileClose(ComObjPtr<GuestFile> pFile);
     129    int                     fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
     130    int                     fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize);
    129131    const GuestCredentials &getCredentials(void);
    130132    const GuestEnvironment &getEnvironment(void);
  • trunk/src/VBox/Main/src-client/GuestCtrlPrivate.cpp

    r42507 r42530  
    586586}
    587587
     588int GuestFsObjData::From(const GuestProcessStreamBlock &strmBlk)
     589{
     590    int rc = VINF_SUCCESS;
     591
     592    try
     593    {
     594        Utf8Str strType(strmBlk.GetString("ftype"));
     595        if (strType.equalsIgnoreCase("-"))
     596            mType = FsObjType_File;
     597        else if (strType.equalsIgnoreCase("d"))
     598            mType = FsObjType_Directory;
     599        /** @todo Add more types! */
     600        else
     601            mType = FsObjType_Undefined;
     602
     603        rc = strmBlk.GetInt64Ex("st_size", &mObjectSize);
     604        if (RT_FAILURE(rc)) throw rc;
     605
     606        /** @todo Add complete GuestFsObjData info! */
     607    }
     608    catch (int rc2)
     609    {
     610        rc = rc2;
     611    }
     612
     613    return rc;
     614}
     615
    588616///////////////////////////////////////////////////////////////////////////////
    589617
     
    621649 * @return  IPRT status code.
    622650 */
    623 void GuestProcessStreamBlock::Clear()
     651void GuestProcessStreamBlock::Clear(void)
    624652{
    625653    m_mapPairs.clear();
     
    627655
    628656#ifdef DEBUG
    629 void GuestProcessStreamBlock::Dump()
     657void GuestProcessStreamBlock::Dump(void)
    630658{
    631659    LogFlowFunc(("Dumping contents of stream block=0x%p (%ld items):\n",
     
    647675 * @param  piVal                Pointer to value to return.
    648676 */
    649 int GuestProcessStreamBlock::GetInt64Ex(const char *pszKey, int64_t *piVal)
     677int GuestProcessStreamBlock::GetInt64Ex(const char *pszKey, int64_t *piVal) const
    650678{
    651679    AssertPtrReturn(pszKey, VERR_INVALID_POINTER);
     
    666694 * @param   pszKey              Name of key to get the value for.
    667695 */
    668 int64_t GuestProcessStreamBlock::GetInt64(const char *pszKey)
     696int64_t GuestProcessStreamBlock::GetInt64(const char *pszKey) const
    669697{
    670698    int64_t iVal;
     
    679707 * @return  uint32_t            Current number of stream pairs.
    680708 */
    681 size_t GuestProcessStreamBlock::GetCount()
     709size_t GuestProcessStreamBlock::GetCount(void) const
    682710{
    683711    return m_mapPairs.size();
     
    690718 * @param   pszKey              Name of key to get the value for.
    691719 */
    692 const char* GuestProcessStreamBlock::GetString(const char *pszKey)
     720const char* GuestProcessStreamBlock::GetString(const char *pszKey) const
    693721{
    694722    AssertPtrReturn(pszKey, NULL);
     
    714742 * @param  puVal                Pointer to value to return.
    715743 */
    716 int GuestProcessStreamBlock::GetUInt32Ex(const char *pszKey, uint32_t *puVal)
     744int GuestProcessStreamBlock::GetUInt32Ex(const char *pszKey, uint32_t *puVal) const
    717745{
    718746    AssertPtrReturn(pszKey, VERR_INVALID_POINTER);
     
    733761 * @param   pszKey              Name of key to get the value for.
    734762 */
    735 uint32_t GuestProcessStreamBlock::GetUInt32(const char *pszKey)
     763uint32_t GuestProcessStreamBlock::GetUInt32(const char *pszKey) const
    736764{
    737765    uint32_t uVal;
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r42525 r42530  
    504504}
    505505
     506/* Note: Will work on directories and others, too. */
     507int GuestSession::fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData)
     508{
     509    LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
     510
     511    GuestProcessInfo procInfo;
     512    procInfo.mName    = Utf8StrFmt(tr("Querying info for \"%s\"", strPath.c_str()));
     513    procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_STAT);
     514    procInfo.mFlags   = ProcessCreateFlag_WaitForStdOut;
     515
     516    /* Construct arguments. */
     517    procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
     518    procInfo.mArguments.push_back(strPath);
     519
     520    GuestProcessStream streamOut;
     521
     522    ComObjPtr<GuestProcess> pProcess;
     523    int rc = processCreateExInteral(procInfo, pProcess);
     524    if (RT_SUCCESS(rc))
     525    {
     526        GuestProcessWaitResult waitRes;
     527        BYTE byBuf[_64K];
     528        size_t cbRead;
     529
     530        for (;;)
     531        {
     532            rc = pProcess->waitFor(ProcessWaitForFlag_StdOut,
     533                                   30 * 1000 /* Timeout */, waitRes);
     534            if (   RT_FAILURE(rc)
     535                || waitRes.mResult != ProcessWaitResult_StdOut)
     536            {
     537                break;
     538            }
     539
     540            rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
     541                                    30 * 1000 /* Timeout */, byBuf, sizeof(byBuf),
     542                                    &cbRead);
     543            if (RT_FAILURE(rc))
     544                break;
     545
     546            rc = streamOut.AddData(byBuf, cbRead);
     547            if (RT_FAILURE(rc))
     548                break;
     549        }
     550
     551        LogFlowThisFunc(("rc=%Rrc, cbRead=%RU32, cbStreamOut=%RU32\n",
     552                         rc, cbRead, streamOut.GetSize()));
     553    }
     554
     555    if (RT_SUCCESS(rc))
     556    {
     557        GuestProcessStreamBlock streamBlock;
     558        rc = streamOut.ParseBlock(streamBlock);
     559        if (RT_SUCCESS(rc))
     560        {
     561            rc = objData.From(streamBlock);
     562        }
     563        else
     564            AssertMsgFailed(("Parsing stream block failed: %Rrc\n", rc));
     565    }
     566
     567    LogFlowFuncLeaveRC(rc);
     568    return rc;
     569}
     570
     571int GuestSession::fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize)
     572{
     573    AssertPtrReturn(pllSize, VERR_INVALID_POINTER);
     574
     575    GuestFsObjData objData;
     576    int rc = fileQueryInfoInternal(strPath, objData);
     577    if (RT_SUCCESS(rc))
     578    {
     579        if (objData.mType == FsObjType_File)
     580            *pllSize = objData.mObjectSize;
     581        else
     582            rc = VERR_NOT_A_FILE;
     583    }
     584
     585    return rc;
     586}
     587
    506588const GuestCredentials& GuestSession::getCredentials(void)
    507589{
     
    10821164    LogFlowThisFuncEnter();
    10831165
    1084     AutoCaller autoCaller(this);
    1085     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1086 
    1087     ReturnComNotImplemented();
     1166    if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
     1167        return setError(E_INVALIDARG, tr("No file to query size for specified"));
     1168    CheckComArgOutPointerValid(aSize);
     1169
     1170    AutoCaller autoCaller(this);
     1171    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1172
     1173    HRESULT hr = S_OK;
     1174
     1175    int64_t llSize;
     1176    int rc = fileQuerySizeInternal(Utf8Str(aPath), &llSize);
     1177    if (RT_SUCCESS(rc))
     1178    {
     1179        *aSize = llSize;
     1180    }
     1181    else
     1182    {
     1183        switch (rc)
     1184        {
     1185            /** @todo Add more errors here! */
     1186
     1187            default:
     1188               hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file size failed: %Rrc"), rc);
     1189               break;
     1190        }
     1191    }
     1192
     1193    return hr;
    10881194#endif /* VBOX_WITH_GUEST_CONTROL */
    10891195}
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