VirtualBox

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


Ignore:
Timestamp:
Sep 4, 2012 1:53:59 PM (12 years ago)
Author:
vboxsync
Message:

Main/Guest Control 2.0: Cleanup, separated guest error handling.

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

Legend:

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

    r43061 r43162  
    7171
    7272/**
    73  * Generic class for a all guest control callbacks/events.
     73 * Base class for a all guest control callbacks/events.
    7474 */
    7575class GuestCtrlEvent
     
    121121{
    122122public:
     123
    123124    GuestCtrlCallback(void);
    124125
     
    165166typedef std::map < uint32_t, GuestCtrlCallback* > GuestCtrlCallbacks;
    166167
    167 struct GuestProcessWaitResult
    168 {
    169     GuestProcessWaitResult(void)
    170         : mResult(ProcessWaitResult_None),
    171           mRC(VINF_SUCCESS) { }
    172 
    173     /** The wait result when returning from the wait call. */
     168
     169/*
     170 * Class representing a guest control process waiting
     171 * event.
     172 */
     173class GuestProcessWaitEvent : public GuestCtrlEvent
     174{
     175public:
     176
     177    GuestProcessWaitEvent(void);
     178
     179    GuestProcessWaitEvent(uint32_t uWaitFlags);
     180
     181    virtual ~GuestProcessWaitEvent(void);
     182
     183public:
     184
     185    void Destroy(void);
     186
     187    int Init(uint32_t uWaitFlags);
     188
     189    uint32_t GetWaitFlags(void) { return ASMAtomicReadU32(&mFlags); }
     190
     191    ProcessWaitResult_T GetWaitResult(void) { return mResult; }
     192
     193    int GetWaitRc(void) { return mRC; }
     194
     195    int Signal(ProcessWaitResult_T enmResult, int rc = VINF_SUCCESS);
     196
     197protected:
     198
     199    /** The waiting flag(s). The specifies what to
     200     *  wait for. See ProcessWaitFlag_T. */
     201    uint32_t                    mFlags;
     202    /** Structure containing the overall result. */
    174203    ProcessWaitResult_T         mResult;
    175     /** Optional rc to this result. */
    176     int                         mRC;
    177 };
    178 
    179 
    180 /*
    181  * Class representing a guest control process event.
    182  */
    183 class GuestProcessEvent : public GuestCtrlEvent
    184 {
    185 public:
    186     GuestProcessEvent(void);
    187 
    188     GuestProcessEvent(uint32_t uWaitFlags);
    189 
    190     virtual ~GuestProcessEvent(void);
    191 
    192 public:
    193 
    194     void Destroy(void);
    195 
    196     int Init(uint32_t uWaitFlags);
    197 
    198     uint32_t GetWaitFlags(void) { return ASMAtomicReadU32(&mWaitFlags); }
    199 
    200     GuestProcessWaitResult GetResult(void) { return mWaitResult; }
    201 
    202     int Signal(ProcessWaitResult_T enmResult, int rc = VINF_SUCCESS);
    203 
    204 protected:
    205 
    206     /** The waiting flag(s). The specifies what to
    207      *  wait for. */
    208     uint32_t                    mWaitFlags;
    209     /** Structure containing the overall result. */
    210     GuestProcessWaitResult      mWaitResult;
    211204};
    212205
  • trunk/src/VBox/Main/include/GuestDirectoryImpl.h

    r42897 r43162  
    2121
    2222#include "VirtualBoxBase.h"
    23 #include "GuestCtrlImplPrivate.h"
     23#include "GuestProcessImpl.h"
    2424
    25 class GuestProcess;
    2625class GuestSession;
    2726
     
    4544    DECLARE_EMPTY_CTOR_DTOR(GuestDirectory)
    4645
    47     int     init(GuestSession *aSession, const Utf8Str &strPath, const Utf8Str &strFilter = "", uint32_t uFlags = 0);
     46    int     init(GuestSession *aSession, const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags);
    4847    void    uninit(void);
    4948    HRESULT FinalConstruct(void);
     
    6867    /** @name Private internal methods.
    6968     * @{ */
    70     int parseData(GuestProcessStreamBlock &streamBlock);
    7169    /** @}  */
    7270
     
    7775        Utf8Str                    mFilter;
    7876        uint32_t                   mFlags;
    79         /** The stdout stream object which contains all
    80          *  read out data for parsing. Must be persisent
    81          *  between several read() calls. */
    82         GuestProcessStream         mStream;
    83         /** The guest process which is responsible for
    84          *  getting the stdout stream. */
    85         GuestProcess              *mProcess;
     77        GuestProcessTool           mProcessTool;
    8678    } mData;
    8779};
  • trunk/src/VBox/Main/include/GuestFileImpl.h

    r42897 r43162  
    4646    DECLARE_EMPTY_CTOR_DTOR(GuestFile)
    4747
    48     int     init(GuestSession *pSession, const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition, uint32_t uCreationMode, int64_t iOffset);
     48    int     init(GuestSession *pSession, const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition, uint32_t uCreationMode, int64_t iOffset, int *pGuestRc);
    4949    void    uninit(void);
    5050    HRESULT FinalConstruct(void);
  • trunk/src/VBox/Main/include/GuestProcessImpl.h

    r42897 r43162  
    7575    inline bool callbackExists(uint32_t uContextID);
    7676    inline int checkPID(uint32_t uPID);
    77     Utf8Str errorMsg(void) { return mData.mErrorMsg; }
     77    static Utf8Str guestErrorToString(int guestRc);
    7878    bool isReady(void);
    7979    ULONG getProcessID(void) { return mData.mProcessID; }
    80     int rc(void) { return mData.mRC; }
    81     int readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData, size_t cbData, size_t *pcbRead);
    82     int startProcess(void);
     80    int readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData, size_t cbData, size_t *pcbRead, int *pGuestRc);
     81    static HRESULT setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
     82    int startProcess(int *pGuestRc);
    8383    int startProcessAsync(void);
    8484    int terminateProcess(void);
    85     int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestProcessWaitResult &guestResult);
    86     int waitForStart(uint32_t uTimeoutMS);
    87     int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten);
     85    int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, ProcessWaitResult_T &waitResult, int *pGuestRc);
     86    int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten, int *pGuestRc);
    8887    /** @}  */
    8988
     
    101100    int prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
    102101    int sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
    103     int setErrorInternal(int rc, const Utf8Str &strMessage);
    104     HRESULT setErrorExternal(void);
    105     int signalWaiters(ProcessWaitResult_T enmWaitResult);
     102    int setProcessStatus(ProcessStatus_T procStatus, int procRc);
     103    int signalWaiters(ProcessWaitResult_T enmWaitResult, int rc = VINF_SUCCESS);
    106104    static DECLCALLBACK(int) startProcessThread(RTTHREAD Thread, void *pvUser);
    107105    /** @}  */
     
    130128        /** The current process status. */
    131129        ProcessStatus_T          mStatus;
    132         /** The overall rc of the process execution. */
    133130        int                      mRC;
    134         /** The overall error message of the
    135          *  process execution. */
    136         Utf8Str                  mErrorMsg;
    137131        /** The next upcoming context ID. */
    138132        ULONG                    mNextContextID;
     
    144138        /** The actual process event for doing the waits.
    145139         *  At the moment we only support one wait a time. */
    146         GuestProcessEvent       *mWaitEvent;
     140        GuestProcessWaitEvent   *mWaitEvent;
    147141    } mData;
     142};
     143
     144/**
     145 * Guest process tool flags.
     146 */
     147/** No flags specified. */
     148#define GUESTPROCESSTOOL_FLAG_NONE            0
     149/** Run until next stream block from stdout has been
     150 *  read in completely, then return.
     151 */
     152#define GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK    RT_BIT(0)
     153
     154/**
     155 * Internal class for handling a VBoxService tool ("vbox_ls", vbox_stat", ...).
     156 */
     157class GuestProcessTool
     158{
     159public:
     160
     161    GuestProcessTool(void);
     162
     163    virtual ~GuestProcessTool(void);
     164
     165public:
     166
     167    int Init(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, bool fAsync, int *pGuestRc);
     168
     169    GuestProcessStream &GetStdOut(void) { return mStdOut; }
     170
     171    GuestProcessStream &GetStdErr(void) { return mStdErr; }
     172
     173    int Wait(uint32_t fFlags, int *pGuestRc);
     174
     175    int WaitEx(uint32_t fFlags, GuestProcessStreamBlock *pStreamBlock, int *pGuestRc);
     176
     177    int GetCurrentBlock(uint32_t uHandle, GuestProcessStreamBlock &strmBlock);
     178
     179    bool IsRunning(void);
     180
     181    int TerminatedOk(LONG *pExitCode);
     182
     183    void Terminate(void);
     184
     185protected:
     186
     187    GuestSession               *pSession;
     188    ComObjPtr<GuestProcess>     pProcess;
     189    GuestProcessStartupInfo     mStartupInfo;
     190    GuestProcessStream          mStdOut;
     191    GuestProcessStream          mStdErr;
    148192};
    149193
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r43002 r43162  
    297297     * @{ */
    298298    int                     directoryRemoveFromList(GuestDirectory *pDirectory);
    299     int                     directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags);
    300     int                     objectCreateTempInternal(Utf8Str strTemplate,
    301                                                      Utf8Str strPath,
    302                                                      bool fDirectory,
    303                                                      Utf8Str &strName,
    304                                                      int *prc);
     299    int                     directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
     300    int                     objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory, const Utf8Str &strName, int *pGuestRc);
    305301    int                     directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
    306     int                     directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
     302    int                     directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
    307303    int                     dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
    308304    int                     fileRemoveFromList(GuestFile *pFile);
    309     int                     fileRemoveInternal(Utf8Str strPath, int *prc);
     305    int                     fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc);
    310306    int                     fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
    311                                              uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile);
    312     int                     fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
    313     int                     fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize);
    314     int                     fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
     307                                             uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile, int *pGuestRc);
     308    int                     fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
     309    int                     fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize, int *pGuestRc);
     310    int                     fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
    315311    const GuestCredentials &getCredentials(void);
    316312    const GuestEnvironment &getEnvironment(void);
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