VirtualBox

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


Ignore:
Timestamp:
May 2, 2015 1:57:14 AM (10 years ago)
Author:
vboxsync
Message:

Main: Renamed IGuestSession::environment to IGuestSession::environmentChanges, IGuestSession::environmentSet to IGuestSession::environmentScheduleSet, IGuestSession::environmentUnset to IGuestSession::environmentScheduleUnset. Introduced read only IGuestSession::environmentBase attribute and associated IGuestSession::environmentGetBaseVariable and IGuestSession::environmentDoesBaseVariableExist for future exploitations. Changed IGuestProcess::environment back to it's originally documented behavior, though that means it will fail with VBOX_E_NOT_SUPPORTED until the session base environment is implemented.

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

Legend:

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

    r55588 r55591  
    2626#include <iprt/env.h>
    2727#include <iprt/semaphore.h>
     28#include <iprt/cpp/utils.h>
    2829
    2930#include <VBox/com/com.h>
     
    7879    GuestEnvironmentBase(void)
    7980        : m_hEnv(NIL_RTENV)
     81        , m_cRefs(1)
    8082    { }
    8183
     
    8587    virtual ~GuestEnvironmentBase(void)
    8688    {
     89        Assert(m_cRefs <= 1);
    8790        int rc = RTEnvDestroy(m_hEnv); AssertRC(rc);
    8891        m_hEnv = NIL_RTENV;
     
    9093
    9194    /**
    92      * Initialize this as a normal environment block.
    93      * @returns IPRT status code.
    94      */
    95     int initNormal(void)
    96     {
    97         AssertReturn(m_hEnv == NIL_RTENV, VERR_WRONG_ORDER);
    98         return RTEnvCreate(&m_hEnv);
     95     * Retains a reference to this object.
     96     * @returns New reference count.
     97     * @remarks Sharing an object is currently only safe if no changes are made to
     98     *          it because RTENV does not yet implement any locking.  For the only
     99     *          purpose we need this, implementing IGuestProcess::environment by
     100     *          using IGuestSession::environmentBase, that's fine as the session
     101     *          base environment is immutable.
     102     */
     103    uint32_t retain(void)
     104    {
     105        uint32_t cRefs = ASMAtomicIncU32(&m_cRefs);
     106        Assert(cRefs > 1); Assert(cRefs < _1M);
     107        return cRefs;
     108
     109    }
     110    /** Useful shortcut. */
     111    uint32_t retainConst(void) const { return unconst(this)->retain(); }
     112
     113    /**
     114     * Releases a reference to this object, deleting the object when reaching zero.
     115     * @returns New reference count.
     116     */
     117    uint32_t release(void)
     118    {
     119        uint32_t cRefs = ASMAtomicDecU32(&m_cRefs);
     120        Assert(cRefs < _1M);
     121        if (cRefs == 0)
     122            delete this;
     123        return cRefs;
     124    }
     125
     126    /** Useful shortcut. */
     127    uint32_t releaseConst(void) const { return unconst(this)->retain(); }
     128
     129    /**
     130     * Checks if the environment has been successfully initialized or not.
     131     *
     132     * @returns @c true if initialized, @c false if not.
     133     */
     134    bool isInitialized(void) const
     135    {
     136        return m_hEnv != NIL_RTENV;
    99137    }
    100138
     
    167205        return VINF_SUCCESS;
    168206    }
     207
     208    /**
     209     * Applies the changes from another environment to this.
     210     *
     211     * @returns IPRT status code.
     212     * @param   rChanges        Reference to an environment which variables will be
     213     *                          imported and, if it's a change record, schedule
     214     *                          variable unsets will be applied.
     215     * @sa      RTEnvApplyChanges
     216     */
     217    int applyChanges(const GuestEnvironmentBase &rChanges)
     218    {
     219        return RTEnvApplyChanges(m_hEnv, rChanges.m_hEnv);
     220    }
     221
    169222
    170223    /**
     
    219272
    220273    /**
     274     * Checks if the given variable exists.
     275     *
     276     * @returns @c true if it exists, @c false if not or if it's an scheduled unset
     277     *          in a environment change record.
     278     * @param   rName               The variable name.
     279     * @sa      RTEnvExistEx
     280     */
     281    bool doesVariableExist(const com::Utf8Str &rName) const
     282    {
     283        return RTEnvExistEx(m_hEnv, rName.c_str());
     284    }
     285
     286    /**
    221287     * Set an environment variable.
    222288     *
     
    243309    }
    244310
    245 #if 0
    246 private:
    247     /* No copy operator. */
    248     GuestEnvironmentBase(const GuestEnvironmentBase &) { throw E_FAIL; }
    249 #else
     311protected:
    250312    /**
    251313     * Copy constructor.
     
    259321            throw (Global::vboxStatusCodeToCOM(rc));
    260322    }
    261 #endif
    262 
    263 protected:
     323
    264324    /**
    265325     * Common clone/copy method with type conversion abilities.
     
    304364
    305365    /** The environment change record. */
    306     RTENV       m_hEnv;
    307 };
    308 
    309 
    310 #if 0 /* Not currently used. */
     366    RTENV               m_hEnv;
     367    /** Reference counter. */
     368    uint32_t volatile   m_cRefs;
     369};
     370
     371
    311372/**
    312373 * Wrapper around the RTEnv API for a normal environment.
     
    364425    }
    365426};
    366 #endif /* unused */
    367427
    368428
     
    548608    ProcessArguments            mArguments;
    549609    /** The process environment change record.  */
    550     GuestEnvironmentChanges     mEnvironment;
     610    GuestEnvironmentChanges     mEnvironmentChanges;
    551611    /** Process creation flags. */
    552612    uint32_t                    mFlags;
     
    9801040protected:
    9811041
    982     /**
    983      * Commom parameters for all derived objects, when then have
    984      * an own mData structure to keep their specific data around.
    985      */
    986 
     1042    /** @name Common parameters for all derived objects.  They have their own
     1043     * mData structure to keep their specific data around.
     1044     * @{ */
    9871045    /** Pointer to parent session. Per definition
    9881046     *  this objects *always* lives shorter than the
    989      *  parent. */
     1047     *  parent.
     1048     * @todo r=bird: When wanting to use mSession in the
     1049     * IGuestProcess::getEnvironment() implementation I wanted to access
     1050     * GuestSession::mData::mpBaseEnvironment.  Seeing the comment in
     1051     * GuestProcess::terminate() saying:
     1052     *      "Now only API clients still can hold references to it."
     1053     * and recalling seeing similar things in VirtualBox.xidl or some such place,
     1054     * I'm wondering how this "per definition" behavior is enforced.  Is there any
     1055     * GuestProcess:uninit() call or similar magic that invalidates objects that
     1056     * GuestSession loses track of in place like GuestProcess::terminate() that I've
     1057     * failed to spot?
     1058     *
     1059     * Please enlighten me.
     1060     */
    9901061    GuestSession            *mSession;
    9911062    /** The object ID -- must be unique for each guest
     
    9961067     *  for guest files this is the internal file ID. */
    9971068    uint32_t                 mObjectID;
    998 };
    999 #endif // ____H_GUESTIMPLPRIVATE
    1000 
     1069    /** @} */
     1070};
     1071#endif // !____H_GUESTIMPLPRIVATE
     1072
  • trunk/src/VBox/Main/include/GuestProcessImpl.h

    r51321 r55591  
    2222#include "GuestProcessWrap.h"
    2323
     24#include <iprt/cpp/utils.h>
     25
    2426class Console;
    2527class GuestSession;
     
    3739    DECLARE_EMPTY_CTOR_DTOR(GuestProcess)
    3840
    39     int     init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, const GuestProcessStartupInfo &aProcInfo);
     41    int     init(Console *aConsole, GuestSession *aSession, ULONG aProcessID,
     42                 const GuestProcessStartupInfo &aProcInfo, const GuestEnvironment *pBaseEnv);
    4043    void    uninit(void);
    4144    HRESULT FinalConstruct(void);
     
    137140        /** The process startup information. */
    138141        GuestProcessStartupInfo  mProcess;
     142        /** Reference to the immutable session base environment. NULL if the
     143         * environment feature isn't supported.
     144         * @remarks If there is proof that the uninit order of GuestSession and
     145         *          this class is what GuestObjectBase claims, then this isn't
     146         *          strictly necessary. */
     147        GuestEnvironment const  *mpSessionBaseEnv;
    139148        /** Exit code if process has been terminated. */
    140149        LONG                     mExitCode;
     
    146155         *  returned from the guest side. */
    147156        int                      mLastError;
     157
     158        Data(void) : mpSessionBaseEnv(NULL)
     159        { }
     160        ~Data(void)
     161        {
     162            if (mpSessionBaseEnv)
     163            {
     164                mpSessionBaseEnv->releaseConst();
     165                mpSessionBaseEnv = NULL;
     166            }
     167        }
    148168    } mData;
    149169};
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r55590 r55591  
    268268    HRESULT getProtocolVersion(ULONG *aProtocolVersion);
    269269    HRESULT getStatus(GuestSessionStatus_T *aStatus);
    270     HRESULT getEnvironment(std::vector<com::Utf8Str> &aEnvironment);
    271     HRESULT setEnvironment(const std::vector<com::Utf8Str> &aEnvironment);
     270    HRESULT getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges);
     271    HRESULT setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges);
     272    HRESULT getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase);
    272273    HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses);
    273274    HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories);
     
    312313    HRESULT directorySetACL(const com::Utf8Str &aPath,
    313314                             const com::Utf8Str &aAcl);
    314     HRESULT environmentSet(const com::Utf8Str &aName,
    315                            const com::Utf8Str &aValue);
    316     HRESULT environmentUnset(const com::Utf8Str &aName);
     315    HRESULT environmentScheduleSet(const com::Utf8Str &aName,
     316                                   const com::Utf8Str &aValue);
     317    HRESULT environmentScheduleUnset(const com::Utf8Str &aName);
     318    HRESULT environmentGetBaseVariable(const com::Utf8Str &aName,
     319                                       com::Utf8Str &aValue);
     320    HRESULT environmentDoesBaseVariableExist(const com::Utf8Str &aName,
     321                                             BOOL *aExists);
    317322    HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName,
    318323                           ULONG aMode,
     
    469474        /** The set of environment changes for the session for use when
    470475         *  creating new guest processes. */
    471         GuestEnvironmentChanges     mEnvironment;
     476        GuestEnvironmentChanges     mEnvironmentChanges;
     477        /** Pointer to the immutable base environment for the session.
     478         * @note This is not allocated until the guest reports it to the host. It is
     479         *       also shared with child processes. */
     480        GuestEnvironment const     *mpBaseEnvironment;
    472481        /** Directory objects bound to this session. */
    473482        SessionDirectories          mDirectories;
     
    488497         *  returned from the guest side. */
    489498        int                         mRC;
     499
     500        Data(void)
     501            : mpBaseEnvironment(NULL)
     502        { }
     503        Data(const Data &rThat)
     504            : mCredentials(rThat.mCredentials)
     505            , mSession(rThat.mSession)
     506            , mStatus(rThat.mStatus)
     507            , mEnvironmentChanges(rThat.mEnvironmentChanges)
     508            , mpBaseEnvironment(NULL)
     509            , mDirectories(rThat.mDirectories)
     510            , mFiles(rThat.mFiles)
     511            , mProcesses(rThat.mProcesses)
     512            , mProtocolVersion(rThat.mProtocolVersion)
     513            , mTimeout(rThat.mTimeout)
     514            , mNumObjects(rThat.mNumObjects)
     515            , mRC(rThat.mRC)
     516        { }
    490517    } mData;
    491518};
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