VirtualBox

Changeset 49349 in vbox for trunk/src/VBox/Main/include


Ignore:
Timestamp:
Oct 31, 2013 4:40:46 PM (11 years ago)
Author:
vboxsync
Message:

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.
Location:
trunk/src/VBox/Main/include
Files:
4 edited

Legend:

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

    r47817 r49349  
    101101
    102102    std::map <Utf8Str, Utf8Str> mEnvironment;
     103};
     104
     105
     106/**
     107 * Structure for keeping all the relevant guest directory
     108 * information around.
     109 */
     110struct GuestDirectoryOpenInfo
     111{
     112    /** The directory path. */
     113    Utf8Str                 mPath;
     114    /** Then open filter. */
     115    Utf8Str                 mFilter;
     116    /** Opening flags. */
     117    uint32_t                mFlags;
    103118};
    104119
     
    313328#endif
    314329
    315     uint32_t GetOffset();
    316 
    317     uint32_t GetSize();
     330    uint32_t GetOffset() { return m_cbOffset; }
     331
     332    size_t GetSize() { return m_cbSize; }
    318333
    319334    int ParseBlock(GuestProcessStreamBlock &streamBlock);
     
    324339    uint32_t m_cbAllocated;
    325340    /** Currently used size of allocated internal stream buffer. */
    326     uint32_t m_cbSize;
     341    size_t m_cbSize;
    327342    /** Current offset within the internal stream buffer. */
    328343    uint32_t m_cbOffset;
     
    378393};
    379394
    380 class GuestWaitEvent
    381 {
    382 
    383 public:
    384 
    385     GuestWaitEvent(uint32_t mCID, const std::list<VBoxEventType_T> &lstEvents);
    386     virtual ~GuestWaitEvent(void);
    387 
    388 public:
    389 
    390     uint32_t                         ContextID(void) { return mCID; };
    391     const ComPtr<IEvent>             Event(void) { return mEvent; };
    392     const std::list<VBoxEventType_T> Types(void) { return mEventTypes; };
    393     size_t                           TypeCount(void) { return mEventTypes.size(); }
    394     virtual int                      Signal(IEvent *pEvent);
    395     int                              Wait(RTMSINTERVAL uTimeoutMS);
     395class GuestWaitEventPayload
     396{
     397
     398public:
     399
     400    GuestWaitEventPayload(void)
     401        : uType(0),
     402          cbData(0),
     403          pvData(NULL) { }
     404
     405    GuestWaitEventPayload(uint32_t uTypePayload,
     406                          const void *pvPayload, uint32_t cbPayload)
     407    {
     408        if (cbPayload)
     409        {
     410            pvData = RTMemAlloc(cbPayload);
     411            if (pvData)
     412            {
     413                uType = uTypePayload;
     414
     415                memcpy(pvData, pvPayload, cbPayload);
     416                cbData = cbPayload;
     417            }
     418            else /* Throw IPRT error. */
     419                throw VERR_NO_MEMORY;
     420        }
     421        else
     422        {
     423            uType = uTypePayload;
     424
     425            pvData = NULL;
     426            cbData = 0;
     427        }
     428    }
     429
     430    virtual ~GuestWaitEventPayload(void)
     431    {
     432        Clear();
     433    }
     434
     435    GuestWaitEventPayload& operator=(const GuestWaitEventPayload &that)
     436    {
     437        CopyFromDeep(that);
     438        return *this;
     439    }
     440
     441public:
     442
     443    void Clear(void)
     444    {
     445        if (pvData)
     446        {
     447            RTMemFree(pvData);
     448            cbData = 0;
     449        }
     450        uType = 0;
     451    }
     452
     453    int CopyFromDeep(const GuestWaitEventPayload &payload)
     454    {
     455        Clear();
     456
     457        int rc;
     458        if (payload.cbData)
     459        {
     460            Assert(payload.cbData);
     461            pvData = RTMemAlloc(payload.cbData);
     462            if (pvData)
     463            {
     464                memcpy(pvData, payload.pvData, payload.cbData);
     465                cbData = payload.cbData;
     466                uType = payload.uType;
     467            }
     468            else
     469                rc = VERR_NO_MEMORY;
     470        }
     471        else
     472            rc = VINF_SUCCESS;
     473
     474        return rc;
     475    }
     476
     477    const void* Raw(void) const { return pvData; }
     478
     479    size_t Size(void) const { return cbData; }
     480
     481    uint32_t Type(void) const { return uType; }
     482
     483    void* MutableRaw(void) { return pvData; }
     484
     485protected:
     486
     487    /** Type of payload. */
     488    uint32_t uType;
     489    /** Size (in bytes) of payload. */
     490    uint32_t cbData;
     491    /** Pointer to actual payload data. */
     492    void *pvData;
     493};
     494
     495class GuestWaitEventBase
     496{
     497
     498protected:
     499
     500    GuestWaitEventBase(void);
     501    virtual ~GuestWaitEventBase(void);
     502
     503public:
     504
     505    uint32_t                        ContextID(void) { return mCID; };
     506    int                             GuestResult(void) { return mGuestRc; }
     507    int                             Result(void) { return mRc; }
     508    GuestWaitEventPayload &         Payload(void) { return mPayload; }
     509    int                             SignalInternal(int rc, int guestRc, const GuestWaitEventPayload *pPayload);
     510    int                             Wait(RTMSINTERVAL uTimeoutMS);
     511
     512protected:
     513
     514    int             Init(uint32_t uCID);
    396515
    397516protected:
    398517
    399518    /* Shutdown indicator. */
    400     bool                       fAborted;
     519    bool                       mfAborted;
    401520    /* Associated context ID (CID). */
    402521    uint32_t                   mCID;
    403     /** List of event types this event should
    404      *  be signalled on. */
    405     std::list<VBoxEventType_T> mEventTypes;
    406522    /** The event semaphore for triggering
    407523     *  the actual event. */
    408524    RTSEMEVENT                 mEventSem;
    409     /** Pointer to the actual event. */
     525    /** The event's overall result. If
     526     *  set to VERR_GSTCTL_GUEST_ERROR,
     527     *  mGuestRc will contain the actual
     528     *  error code from the guest side. */
     529    int                        mRc;
     530    /** The event'S overall result from the
     531     *  guest side. If used, mRc must be
     532     *  set to VERR_GSTCTL_GUEST_ERROR. */
     533    int                        mGuestRc;
     534    /** The event's payload data. Optional. */
     535    GuestWaitEventPayload      mPayload;
     536};
     537
     538/** List of public guest event types. */
     539typedef std::list < VBoxEventType_T > GuestEventTypes;
     540
     541class GuestWaitEvent : public GuestWaitEventBase
     542{
     543
     544public:
     545
     546    GuestWaitEvent(uint32_t uCID);
     547    GuestWaitEvent(uint32_t uCID, const GuestEventTypes &lstEvents);
     548    virtual ~GuestWaitEvent(void);
     549
     550public:
     551
     552    int                              Cancel(void);
     553    const ComPtr<IEvent>             Event(void) { return mEvent; }
     554    int                              SignalExternal(IEvent *pEvent);
     555    const GuestEventTypes            Types(void) { return mEventTypes; }
     556    size_t                           TypeCount(void) { return mEventTypes.size(); }
     557
     558protected:
     559
     560    int                              Init(uint32_t uCID);
     561
     562protected:
     563
     564    /** List of public event types this event should
     565     *  be signalled on. Optional. */
     566    GuestEventTypes            mEventTypes;
     567    /** Pointer to the actual public event, if any. */
    410568    ComPtr<IEvent>             mEvent;
    411569};
    412 typedef std::list < GuestWaitEvent* > GuestWaitEvents;
    413 typedef std::map < VBoxEventType_T, GuestWaitEvents > GuestWaitEventTypes;
     570/** Map of pointers to guest events. The primary key
     571 *  contains the context ID. */
     572typedef std::map < uint32_t, GuestWaitEvent* > GuestWaitEvents;
     573/** Map of wait events per public guest event. Nice for
     574 *  faster lookups when signalling a whole event group. */
     575typedef std::map < VBoxEventType_T, GuestWaitEvents > GuestEventGroup;
    414576
    415577class GuestBase
     
    423585public:
    424586
    425     /** For external event listeners. */
    426     int signalWaitEvents(VBoxEventType_T aType, IEvent *aEvent);
    427 
     587    /** Signals a wait event using a public guest event; also used for
     588     *  for external event listeners. */
     589    int signalWaitEvent(VBoxEventType_T aType, IEvent *aEvent);
     590    /** Signals a wait event using a guest rc. */
     591    int signalWaitEventInternal(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, int guestRc, const GuestWaitEventPayload *pPayload);
     592    /** Signals a wait event without letting public guest events know,
     593     *  extended director's cut version. */
     594    int signalWaitEventInternalEx(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, int rc, int guestRc, const GuestWaitEventPayload *pPayload);
    428595public:
    429596
     
    431598    void baseUninit(void);
    432599    int cancelWaitEvents(void);
     600    int dispatchGeneric(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
    433601    int generateContextID(uint32_t uSessionID, uint32_t uObjectID, uint32_t *puContextID);
    434     int registerWaitEvent(uint32_t uSessionID, uint32_t uObjectID, const std::list<VBoxEventType_T> &lstEvents, GuestWaitEvent **ppEvent);
     602    int registerWaitEvent(uint32_t uSessionID, uint32_t uObjectID, GuestWaitEvent **ppEvent);
     603    int registerWaitEvent(uint32_t uSessionID, uint32_t uObjectID, const GuestEventTypes &lstEvents, GuestWaitEvent **ppEvent);
    435604    void unregisterWaitEvent(GuestWaitEvent *pEvent);
    436605    int waitForEvent(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, VBoxEventType_T *pType, IEvent **ppEvent);
     
    448617    /** Critical section for wait events access. */
    449618    RTCRITSECT               mWaitEventCritSect;
    450     /** Map of internal events to wait for. */
    451     GuestWaitEventTypes      mWaitEvents;
     619    /** Map of registered wait events per event group. */
     620    GuestEventGroup          mWaitEventGroups;
     621    /** Map of registered wait events. */
     622    GuestWaitEvents          mWaitEvents;
    452623};
    453624
     
    476647
    477648    int bindToSession(Console *pConsole, GuestSession *pSession, uint32_t uObjectID);
    478     int registerWaitEvent(const std::list<VBoxEventType_T> &lstEvents, GuestWaitEvent **ppEvent);
     649    int registerWaitEvent(const GuestEventTypes &lstEvents, GuestWaitEvent **ppEvent);
    479650    int sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
    480651
  • trunk/src/VBox/Main/include/GuestDirectoryImpl.h

    r43162 r49349  
    3030class ATL_NO_VTABLE GuestDirectory :
    3131    public VirtualBoxBase,
     32    public GuestObject,
    3233    VBOX_SCRIPTABLE_IMPL(IGuestDirectory)
    3334{
     
    4445    DECLARE_EMPTY_CTOR_DTOR(GuestDirectory)
    4546
    46     int     init(GuestSession *aSession, const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags);
     47    int     init(Console *pConsole, GuestSession *pSession, ULONG uDirID, const GuestDirectoryOpenInfo &openInfo);
    4748    void    uninit(void);
    4849    HRESULT FinalConstruct(void);
     
    6162    /** @name Public internal methods.
    6263     * @{ */
     64    int            callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
     65    static Utf8Str guestErrorToString(int guestRc);
     66    static HRESULT setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
    6367    /** @}  */
    6468
     
    7175    struct Data
    7276    {
    73         GuestSession              *mSession;
    74         Utf8Str                    mName;
    75         Utf8Str                    mFilter;
    76         uint32_t                   mFlags;
     77        /** The directory's open info. */
     78        GuestDirectoryOpenInfo     mOpenInfo;
     79        /** The directory's ID. */
     80        uint32_t                   mID;
    7781        GuestProcessTool           mProcessTool;
    7882    } mData;
  • trunk/src/VBox/Main/include/GuestProcessImpl.h

    r47817 r49349  
    8282    int startProcessAsync(void);
    8383    int terminateProcess(uint32_t uTimeoutMS, int *pGuestRc);
    84     static ProcessWaitResult_T waitFlagsToResultEx(uint32_t fWaitFlags, ProcessStatus_T procStatus, uint32_t uProcFlags, uint32_t uProtocol);
     84    static ProcessWaitResult_T waitFlagsToResultEx(uint32_t fWaitFlags, ProcessStatus_T oldStatus, ProcessStatus_T newStatus, uint32_t uProcFlags, uint32_t uProtocol);
    8585    ProcessWaitResult_T waitFlagsToResult(uint32_t fWaitFlags);
    8686    int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, ProcessWaitResult_T &waitResult, int *pGuestRc);
     
    135135 * Guest process tool flags.
    136136 */
    137 /** No flags specified. */
     137/** No flags specified; wait until process terminates.
     138 *  The maximum waiting time is set in the process' startup
     139 *  info. */
    138140#define GUESTPROCESSTOOL_FLAG_NONE            0
    139 /** Run until next stream block from stdout has been
     141/** Wait until next stream block from stdout has been
    140142 *  read in completely, then return.
    141143 */
     
    169171    bool IsRunning(void);
    170172
     173    static int Run(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, int *pGuestRc);
     174
     175    static int RunEx(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, GuestCtrlStreamObjects *pStrmOutObjects,
     176                     uint32_t cStrmOutObjects, int *pGuestRc);
     177
    171178    int TerminatedOk(LONG *pExitCode);
    172179
     
    175182protected:
    176183
    177     GuestSession               *pSession;
     184    ComObjPtr<GuestSession>     pSession;
    178185    ComObjPtr<GuestProcess>     pProcess;
    179186    GuestProcessStartupInfo     mStartupInfo;
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r47817 r49349  
    327327private:
    328328
    329     typedef std::vector <ComObjPtr<GuestDirectory> > SessionDirectories;
     329    /** Map of guest directories. The key specifies the internal directory ID. */
     330    typedef std::map <uint32_t, ComObjPtr<GuestDirectory> > SessionDirectories;
    330331    /** Map of guest files. The key specifies the internal file ID. */
    331332    typedef std::map <uint32_t, ComObjPtr<GuestFile> > SessionFiles;
     
    338339     * @{ */
    339340    int                     closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc);
     341    inline bool             directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir);
    340342    int                     directoryRemoveFromList(GuestDirectory *pDirectory);
     343    int                     directoryRemoveInternal(const Utf8Str &strPath, uint32_t uFlags, int *pGuestRc);
    341344    int                     directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
    342345    int                     objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory, const Utf8Str &strName, int *pGuestRc);
    343     int                     directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
     346    int                     directoryOpenInternal(const GuestDirectoryOpenInfo &openInfo, ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc);
    344347    int                     directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
     348    int                     dispatchToDirectory(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
    345349    int                     dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
     350    int                     dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
    346351    int                     dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
    347352    int                     dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
     
    367372    Guest                  *getParent(void) { return mParent; }
    368373    uint32_t                getProtocolVersion(void) { return mData.mProtocolVersion; }
     374    int                     pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags, int *pGuestRc);
    369375    int                     processRemoveFromList(GuestProcess *pProcess);
    370376    int                     processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
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