VirtualBox

Changeset 42382 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jul 25, 2012 9:35:56 AM (12 years ago)
Author:
vboxsync
Message:

Main/Session+Console+Machine: minimal change to reduce the overhead of normal API client sessions, because they don't need a full Console object with all sub-objects associated with them. Much more work todo if we want to completely eliminate all VM machinery dependency since the methods of Console are a wild mix of VM related and unrelated.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r42354 r42382  
    961961  <enum
    962962    name="LockType"
    963     uuid="138b53f8-db4b-47c5-b32b-4ef52f769413"
     963    uuid="168a6a8e-12fd-4878-a1f9-38a750a56089"
    964964    >
    965965    <desc>
     
    971971    <const name="Shared" value="1">
    972972      <desc>Request only a shared read lock for remote-controlling the machine.</desc>
     973    </const>
     974    <const name="VM" value="3">
     975      <desc>Lock the machine for writing, and create objects necessary for
     976        running a VM in this process.</desc>
    973977    </const>
    974978  </enum>
     
    1639616400      </desc>
    1639716401      <param name="machine" type="IMachine" dir="in"/>
     16402      <param name="lockType" type="LockType" dir="in"/>
    1639816403    </method>
    1639916404
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r42261 r42382  
    114114
    115115    // public initializers/uninitializers for internal purposes only
    116     HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl);
     116    HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
    117117    void uninit();
    118118
  • trunk/src/VBox/Main/include/SessionImpl.h

    r42261 r42382  
    8181    STDMETHOD(GetPID)(ULONG *aPid);
    8282    STDMETHOD(GetRemoteConsole)(IConsole **aConsole);
    83     STDMETHOD(AssignMachine)(IMachine *aMachine);
     83    STDMETHOD(AssignMachine)(IMachine *aMachine, LockType_T aLockType);
    8484    STDMETHOD(AssignRemoteMachine)(IMachine *aMachine, IConsole *aConsole);
    8585    STDMETHOD(UpdateMachineState)(MachineState_T aMachineState);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r42261 r42382  
    434434/////////////////////////////////////////////////////////////////////////////
    435435
    436 HRESULT Console::init(IMachine *aMachine, IInternalMachineControl *aControl)
     436HRESULT Console::init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType)
    437437{
    438438    AssertReturn(aMachine && aControl, E_INVALIDARG);
     
    450450    unconst(mControl) = aControl;
    451451
    452     /* Cache essential properties and objects */
     452    /* Cache essential properties and objects, and create child objects */
    453453
    454454    rc = mMachine->COMGETTER(State)(&mMachineState);
    455455    AssertComRCReturnRC(rc);
    456456
    457     rc = mMachine->COMGETTER(VRDEServer)(unconst(mVRDEServer).asOutParam());
    458     AssertComRCReturnRC(rc);
    459 
    460     /* Create associated child COM objects */
     457#ifdef VBOX_WITH_EXTPACK
     458    unconst(mptrExtPackManager).createObject();
     459    rc = mptrExtPackManager->initExtPackManager(NULL, VBOXEXTPACKCTX_VM_PROCESS);
     460        AssertComRCReturnRC(rc);
     461#endif
    461462
    462463    // Event source may be needed by other children
     
    465466    AssertComRCReturnRC(rc);
    466467
    467     unconst(mGuest).createObject();
    468     rc = mGuest->init(this);
    469     AssertComRCReturnRC(rc);
    470 
    471     unconst(mKeyboard).createObject();
    472     rc = mKeyboard->init(this);
    473     AssertComRCReturnRC(rc);
    474 
    475     unconst(mMouse).createObject();
    476     rc = mMouse->init(this);
    477     AssertComRCReturnRC(rc);
    478 
    479     unconst(mDisplay).createObject();
    480     rc = mDisplay->init(this);
    481     AssertComRCReturnRC(rc);
    482 
    483     unconst(mVRDEServerInfo).createObject();
    484     rc = mVRDEServerInfo->init(this);
    485     AssertComRCReturnRC(rc);
    486 
    487 #ifdef VBOX_WITH_EXTPACK
    488     unconst(mptrExtPackManager).createObject();
    489     rc = mptrExtPackManager->initExtPackManager(NULL, VBOXEXTPACKCTX_VM_PROCESS);
    490     AssertComRCReturnRC(rc);
    491 #endif
    492 
    493     /* Grab global and machine shared folder lists */
    494 
    495     rc = fetchSharedFolders(true /* aGlobal */);
    496     AssertComRCReturnRC(rc);
    497     rc = fetchSharedFolders(false /* aGlobal */);
    498     AssertComRCReturnRC(rc);
    499 
    500     /* Create other child objects */
    501 
    502     unconst(mConsoleVRDPServer) = new ConsoleVRDPServer(this);
    503     AssertReturn(mConsoleVRDPServer, E_FAIL);
    504 
    505468    mcAudioRefs = 0;
    506469    mcVRDPClients = 0;
     
    508471    mcGuestCredentialsProvided = false;
    509472
    510     /* Figure out size of meAttachmentType vector */
    511     ComPtr<IVirtualBox> pVirtualBox;
    512     rc = aMachine->COMGETTER(Parent)(pVirtualBox.asOutParam());
    513     AssertComRC(rc);
    514     ComPtr<ISystemProperties> pSystemProperties;
    515     if (pVirtualBox)
    516         pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
    517     ChipsetType_T chipsetType = ChipsetType_PIIX3;
    518     aMachine->COMGETTER(ChipsetType)(&chipsetType);
    519     ULONG maxNetworkAdapters = 0;
    520     if (pSystemProperties)
    521         pSystemProperties->GetMaxNetworkAdapters(chipsetType, &maxNetworkAdapters);
    522     meAttachmentType.resize(maxNetworkAdapters);
    523     for (ULONG slot = 0; slot < maxNetworkAdapters; ++slot)
    524         meAttachmentType[slot] = NetworkAttachmentType_Null;
    525 
    526 
    527     // VirtualBox 4.0: We no longer initialize the VMMDev instance here,
    528     // which starts the HGCM thread. Instead, this is now done in the
    529     // power-up thread when a VM is actually being powered up to avoid
    530     // having HGCM threads all over the place every time a session is
    531     // opened, even if that session will not run a VM.
    532     //     unconst(m_pVMMDev) = new VMMDev(this);
    533     //     AssertReturn(mVMMDev, E_FAIL);
    534 
    535     unconst(mAudioSniffer) = new AudioSniffer(this);
    536     AssertReturn(mAudioSniffer, E_FAIL);
     473    /* Now the VM specific parts */
     474    if (aLockType == LockType_VM)
     475    {
     476        rc = mMachine->COMGETTER(VRDEServer)(unconst(mVRDEServer).asOutParam());
     477        AssertComRCReturnRC(rc);
     478
     479        unconst(mGuest).createObject();
     480        rc = mGuest->init(this);
     481        AssertComRCReturnRC(rc);
     482
     483        unconst(mKeyboard).createObject();
     484        rc = mKeyboard->init(this);
     485        AssertComRCReturnRC(rc);
     486
     487        unconst(mMouse).createObject();
     488        rc = mMouse->init(this);
     489        AssertComRCReturnRC(rc);
     490
     491        unconst(mDisplay).createObject();
     492        rc = mDisplay->init(this);
     493        AssertComRCReturnRC(rc);
     494
     495        unconst(mVRDEServerInfo).createObject();
     496        rc = mVRDEServerInfo->init(this);
     497        AssertComRCReturnRC(rc);
     498
     499        /* Grab global and machine shared folder lists */
     500
     501        rc = fetchSharedFolders(true /* aGlobal */);
     502        AssertComRCReturnRC(rc);
     503        rc = fetchSharedFolders(false /* aGlobal */);
     504        AssertComRCReturnRC(rc);
     505
     506        /* Create other child objects */
     507
     508        unconst(mConsoleVRDPServer) = new ConsoleVRDPServer(this);
     509        AssertReturn(mConsoleVRDPServer, E_FAIL);
     510
     511        /* Figure out size of meAttachmentType vector */
     512        ComPtr<IVirtualBox> pVirtualBox;
     513        rc = aMachine->COMGETTER(Parent)(pVirtualBox.asOutParam());
     514        AssertComRC(rc);
     515        ComPtr<ISystemProperties> pSystemProperties;
     516        if (pVirtualBox)
     517            pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
     518        ChipsetType_T chipsetType = ChipsetType_PIIX3;
     519        aMachine->COMGETTER(ChipsetType)(&chipsetType);
     520        ULONG maxNetworkAdapters = 0;
     521        if (pSystemProperties)
     522            pSystemProperties->GetMaxNetworkAdapters(chipsetType, &maxNetworkAdapters);
     523        meAttachmentType.resize(maxNetworkAdapters);
     524        for (ULONG slot = 0; slot < maxNetworkAdapters; ++slot)
     525            meAttachmentType[slot] = NetworkAttachmentType_Null;
     526
     527        // VirtualBox 4.0: We no longer initialize the VMMDev instance here,
     528        // which starts the HGCM thread. Instead, this is now done in the
     529        // power-up thread when a VM is actually being powered up to avoid
     530        // having HGCM threads all over the place every time a session is
     531        // opened, even if that session will not run a VM.
     532        //     unconst(m_pVMMDev) = new VMMDev(this);
     533        //     AssertReturn(mVMMDev, E_FAIL);
     534
     535        unconst(mAudioSniffer) = new AudioSniffer(this);
     536        AssertReturn(mAudioSniffer, E_FAIL);
    537537#ifdef VBOX_WITH_USB_VIDEO
    538     unconst(mUsbWebcamInterface) = new UsbWebcamInterface(this);
    539     AssertReturn(mUsbWebcamInterface, E_FAIL);
     538        unconst(mUsbWebcamInterface) = new UsbWebcamInterface(this);
     539        AssertReturn(mUsbWebcamInterface, E_FAIL);
    540540#endif
    541541#ifdef VBOX_WITH_USB_CARDREADER
    542     unconst(mUsbCardReader) = new UsbCardReader(this);
    543     AssertReturn(mUsbCardReader, E_FAIL);
     542        unconst(mUsbCardReader) = new UsbCardReader(this);
     543        AssertReturn(mUsbCardReader, E_FAIL);
    544544#endif
    545545
    546     /* VirtualBox events registration. */
    547     {
    548         ComPtr<IEventSource> pES;
    549         rc = pVirtualBox->COMGETTER(EventSource)(pES.asOutParam());
    550         AssertComRC(rc);
    551         ComObjPtr<VmEventListenerImpl> aVmListener;
    552         aVmListener.createObject();
    553         aVmListener->init(new VmEventListener(), this);
    554         mVmListener = aVmListener;
    555         com::SafeArray<VBoxEventType_T> eventTypes;
    556         eventTypes.push_back(VBoxEventType_OnNATRedirect);
    557         eventTypes.push_back(VBoxEventType_OnHostPciDevicePlug);
    558         rc = pES->RegisterListener(aVmListener, ComSafeArrayAsInParam(eventTypes), true);
    559         AssertComRC(rc);
    560     }
    561 
     546        /* VirtualBox events registration. */
     547        {
     548            ComPtr<IEventSource> pES;
     549            rc = pVirtualBox->COMGETTER(EventSource)(pES.asOutParam());
     550            AssertComRC(rc);
     551            ComObjPtr<VmEventListenerImpl> aVmListener;
     552            aVmListener.createObject();
     553            aVmListener->init(new VmEventListener(), this);
     554            mVmListener = aVmListener;
     555            com::SafeArray<VBoxEventType_T> eventTypes;
     556            eventTypes.push_back(VBoxEventType_OnNATRedirect);
     557            eventTypes.push_back(VBoxEventType_OnHostPciDevicePlug);
     558            rc = pES->RegisterListener(aVmListener, ComSafeArrayAsInParam(eventTypes), true);
     559            AssertComRC(rc);
     560        }
     561    }
    562562
    563563    /* Confirm a successful initialization when it's the case */
  • trunk/src/VBox/Main/src-client/SessionImpl.cpp

    r42261 r42382  
    300300}
    301301
    302 STDMETHODIMP Session::AssignMachine(IMachine *aMachine)
     302STDMETHODIMP Session::AssignMachine(IMachine *aMachine, LockType_T aLockType)
    303303{
    304304    LogFlowThisFuncEnter();
     
    337337    AssertComRCReturn(rc, rc);
    338338
    339     rc = mConsole->init(aMachine, mControl);
     339    rc = mConsole->init(aMachine, mControl, aLockType);
    340340    AssertComRCReturn(rc, rc);
    341341
     
    358358        /* some cleanup */
    359359        mControl.setNull();
    360         mConsole->uninit();
    361         mConsole.setNull();
     360        if (!mConsole.isNull())
     361        {
     362            mConsole->uninit();
     363            mConsole.setNull();
     364        }
    362365    }
    363366
     
    531534    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    532535    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     536    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    533537
    534538    return mConsole->onNetworkAdapterChange(networkAdapter, changeAdapter);
     
    545549    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    546550    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     551    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    547552
    548553    return mConsole->onSerialPortChange(serialPort);
     
    559564    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    560565    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     566    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    561567
    562568    return mConsole->onParallelPortChange(parallelPort);
     
    573579    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    574580    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     581    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    575582
    576583    return mConsole->onStorageControllerChange();
     
    587594    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    588595    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     596    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    589597
    590598    return mConsole->onMediumChange(aMediumAttachment, aForce);
     
    601609    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    602610    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     611    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    603612
    604613    return mConsole->onCPUChange(aCPU, aRemove);
     
    615624    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    616625    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     626    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    617627
    618628    return mConsole->onCPUExecutionCapChange(aExecutionCap);
     
    629639    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    630640    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     641    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    631642
    632643    return mConsole->onVRDEServerChange(aRestart);
     
    643654    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    644655    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     656    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    645657
    646658    return mConsole->onUSBControllerChange();
     
    657669    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    658670    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     671    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    659672
    660673    return mConsole->onSharedFolderChange(aGlobal);
     
    671684    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    672685    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     686    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    673687
    674688    return mConsole->onClipboardModeChange(aClipboardMode);
     
    701715    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    702716    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     717    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    703718
    704719    return mConsole->onUSBDeviceAttach(aDevice, aError, aMaskedIfs);
     
    716731    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    717732    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     733    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    718734
    719735    return mConsole->onUSBDeviceDetach(aId, aError);
     
    728744
    729745    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     746    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    730747
    731748    if (mState != SessionState_Locked)
     
    753770    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    754771    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     772    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    755773
    756774    return mConsole->onBandwidthGroupChange(aBandwidthGroup);
     
    767785    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    768786    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     787    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    769788
    770789    return mConsole->onStorageDeviceChange(aMediumAttachment, aRemove);
     
    796815    if (aIsSetter && (aFlags != NULL) && !VALID_PTR(aFlags))
    797816        return E_INVALIDARG;
     817
     818    /* If this session is not in a VM process fend off the call. The caller
     819     * handles this correctly, by doing the operation in VBoxSVC. */
     820    if (!mConsole)
     821        return E_ACCESSDENIED;
     822
    798823    if (!aIsSetter)
    799824        return mConsole->getGuestProperty(aName, aRetValue, aRetTimestamp, aRetFlags);
     
    830855    if (ComSafeArrayOutIsNull(aFlags))
    831856        return E_POINTER;
     857
     858    /* If this session is not in a VM process fend off the call. The caller
     859     * handles this correctly, by doing the operation in VBoxSVC. */
     860    if (!mConsole)
     861        return E_ACCESSDENIED;
     862
    832863    return mConsole->enumerateGuestProperties(aPatterns,
    833864                                              ComSafeArrayOutArg(aNames),
     
    856887                        Global::stringifySessionState(mState));
    857888    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     889    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    858890    CheckComArgNotNull(aMediumAttachment);
    859891    CheckComArgSafeArrayNotNull(aChildrenToReparent);
     
    874906    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    875907    AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
     908    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
    876909
    877910    mConsole->enableVMMStatistics(aEnable);
     
    940973    if (mType == SessionType_WriteLock)
    941974    {
    942         mConsole->uninit();
    943         mConsole.setNull();
     975        if (!mConsole.isNull())
     976        {
     977            mConsole->uninit();
     978            mConsole.setNull();
     979        }
    944980    }
    945981    else
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r42261 r42382  
    33043304
    33053305            LogFlowThisFunc(("Calling AssignMachine()...\n"));
    3306             rc = pSessionControl->AssignMachine(sessionMachine);
     3306            rc = pSessionControl->AssignMachine(sessionMachine, lockType);
    33073307            LogFlowThisFunc(("AssignMachine() returned %08X\n", rc));
    33083308
     
    34193419    {
    34203420        /*
    3421         *  tell the client watcher thread to update the set of
    3422         *  machines that have open sessions
    3423         */
     3421         *  tell the client watcher thread to update the set of
     3422         *  machines that have open sessions
     3423         */
    34243424        mParent->updateClientWatcher();
    34253425
     
    72397239    /* inform the session that it will be a remote one */
    72407240    LogFlowThisFunc(("Calling AssignMachine (NULL)...\n"));
    7241     HRESULT rc = aControl->AssignMachine(NULL);
     7241    HRESULT rc = aControl->AssignMachine(NULL, LockType_Write);
    72427242    LogFlowThisFunc(("AssignMachine (NULL) returned %08X\n", rc));
    72437243
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