third_party/virtualbox/src/VBox/Main/src-client/GuestSessionImpl.cpp
/**
 * Initializes a guest session but does *not* open in on the guest side
 * yet. This needs to be done via the openSession() / openSessionAsync calls.
 *
 * @return  IPRT status code.
 ** @todo Docs!
 */
Initializes a guest session but does *not* open in on the guest side
yet. This needs to be done via the openSession() / openSessionAsync calls.

@return  IPRT status code.
@todo Docs!
Initializes a guest session but does * not * open in on the guest side yet . This needs to be done via the openSession () / openSessionAsync calls . @return IPRT status code . @todo Docs!
int GuestSession::init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo,
                       const GuestCredentials &guestCreds)
{
    LogFlowThisFunc(("pGuest=%p, ssInfo=%p, guestCreds=%p\n",
                      pGuest, &ssInfo, &guestCreds));
    AutoInitSpan autoInitSpan(this);
    AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
    AssertPtrReturn(pGuest, VERR_INVALID_POINTER);
    mParent = pGuest;
    mData.mSession.mID = ssInfo.mID;
    mData.mSession.mIsInternal = ssInfo.mIsInternal;
    mData.mSession.mName = ssInfo.mName;
    mData.mSession.mOpenFlags = ssInfo.mOpenFlags;
    mData.mSession.mOpenTimeoutMS = ssInfo.mOpenTimeoutMS;
    mData.mCredentials.mUser = guestCreds.mUser;
    mData.mCredentials.mPassword = guestCreds.mPassword;
    mData.mCredentials.mDomain = guestCreds.mDomain;
    mData.mRC = VINF_SUCCESS;
    mData.mStatus = GuestSessionStatus_Undefined;
    mData.mNumObjects = 0;
    mData.mpBaseEnvironment = NULL;
    int rc = mData.mEnvironmentChanges.initChangeRecord();
    if (RT_SUCCESS(rc))
    {
        rc = RTCritSectInit(&mWaitEventCritSect);
        AssertRC(rc);
    }
    if (RT_SUCCESS(rc))
        rc = i_determineProtocolVersion();
    if (RT_SUCCESS(rc))
    {
        HRESULT hr = unconst(mEventSource).createObject();
        if (SUCCEEDED(hr))
            hr = mEventSource->init();
        if (SUCCEEDED(hr))
        {
            try
            {
                GuestSessionListener *pListener = new GuestSessionListener();
                ComObjPtr<GuestSessionListenerImpl> thisListener;
                hr = thisListener.createObject();
                if (SUCCEEDED(hr))
                    hr = thisListener->init(pListener, this);
                if (SUCCEEDED(hr))
                {
                    com::SafeArray <VBoxEventType_T> eventTypes;
                    eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
                    hr = mEventSource->RegisterListener(thisListener,
                                                        ComSafeArrayAsInParam(eventTypes),
                                                        TRUE );
                    if (SUCCEEDED(hr))
                    {
                        mLocalListener = thisListener;
                        autoInitSpan.setSucceeded();
                        LogFlowThisFunc(("mName=%s mID=%RU32 mIsInternal=%RTbool rc=VINF_SUCCESS\n",
                                         mData.mSession.mName.c_str(), mData.mSession.mID, mData.mSession.mIsInternal));
                        return VINF_SUCCESS;
                    }
                }
            }
            catch (std::bad_alloc &)
            {
                hr = E_OUTOFMEMORY;
            }
        }
        rc = Global::vboxStatusCodeFromCOM(hr);
    }
    autoInitSpan.setFailed();
    LogThisFunc(("Failed! mName=%s mID=%RU32 mIsInternal=%RTbool => rc=%Rrc\n",
                 mData.mSession.mName.c_str(), mData.mSession.mID, mData.mSession.mIsInternal, rc));
    return rc;
}
int GuestSession :: init ( Guest * pGuest , const GuestSessionStartupInfo & ssInfo , const GuestCredentials & guestCreds ) { LogFlowThisFunc ( ( " \n " , pGuest , & ssInfo , & guestCreds ) ) ; AutoInitSpan autoInitSpan ( this ) ; AssertReturn ( autoInitSpan . isOk ( ) , VERR_OBJECT_DESTROYED ) ; AssertPtrReturn ( pGuest , VERR_INVALID_POINTER ) ; mParent = pGuest ; mData . mSession . mID = ssInfo . mID ; mData . mSession . mIsInternal = ssInfo . mIsInternal ; mData . mSession . mName = ssInfo . mName ; mData . mSession . mOpenFlags = ssInfo . mOpenFlags ; mData . mSession . mOpenTimeoutMS = ssInfo . mOpenTimeoutMS ; mData . mCredentials . mUser = guestCreds . mUser ; mData . mCredentials . mPassword = guestCreds . mPassword ; mData . mCredentials . mDomain = guestCreds . mDomain ; mData . mRC = VINF_SUCCESS ; mData . mStatus = GuestSessionStatus_Undefined ; mData . mNumObjects = 0 ; mData . mpBaseEnvironment = NULL ; int rc = mData . mEnvironmentChanges . initChangeRecord ( ) ; if ( RT_SUCCESS ( rc ) ) { rc = RTCritSectInit ( & mWaitEventCritSect ) ; AssertRC ( rc ) ; } if ( RT_SUCCESS ( rc ) ) rc = i_determineProtocolVersion ( ) ; if ( RT_SUCCESS ( rc ) ) { HRESULT hr = unconst ( mEventSource ) . createObject ( ) ; if ( SUCCEEDED ( hr ) ) hr = mEventSource -> init ( ) ; if ( SUCCEEDED ( hr ) ) { try { GuestSessionListener * pListener = new GuestSessionListener ( ) ; ComObjPtr < GuestSessionListenerImpl > thisListener ; hr = thisListener . createObject ( ) ; if ( SUCCEEDED ( hr ) ) hr = thisListener -> init ( pListener , this ) ; if ( SUCCEEDED ( hr ) ) { com :: SafeArray < VBoxEventType_T > eventTypes ; eventTypes . push_back ( VBoxEventType_OnGuestSessionStateChanged ) ; hr = mEventSource -> RegisterListener ( thisListener , ComSafeArrayAsInParam ( eventTypes ) , TRUE ) ; if ( SUCCEEDED ( hr ) ) { mLocalListener = thisListener ; autoInitSpan . setSucceeded ( ) ; LogFlowThisFunc ( ( " \n " , mData . mSession . mName . c_str ( ) , mData . mSession . mID , mData . mSession . mIsInternal ) ) ; return VINF_SUCCESS ; } } } catch ( std :: bad_alloc & ) { hr = E_OUTOFMEMORY ; } } rc = Global :: vboxStatusCodeFromCOM ( hr ) ; } autoInitSpan . setFailed ( ) ; LogThisFunc ( ( " \n " , mData . mSession . mName . c_str ( ) , mData . mSession . mID , mData . mSession . mIsInternal , rc ) ) ; return rc ; }
Initializes a guest session but does *not* open in on the guest side
 yet.
Initializes a guest session but does * not * open in on the guest side yet .
/* Enclose the state transition NotReady->InInit->Ready. */ /*
     * Initialize our data members from the input.
     */ /* Copy over startup info. */ /** @todo Use an overloaded copy operator. Later. */ /** @todo Use an overloaded copy operator. Later. */ /* Initialize the remainder of the data. */ /*
         * <Replace this if you figure out what the code is doing.>
         */ /* Active listener */ /*
                         * Mark this object as operational and return success.
                         */