VirtualBox

Changeset 53000 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Oct 8, 2014 4:55:32 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI rework/cleanup for 7115 (part #9): Caching CSession in UISession instead of UIMachine; Improving UIMachine prepare/cleanup stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r52995 r53000  
    3232/* COM includes: */
    3333# include "CMachine.h"
     34# include "CSession.h"
    3435# include "CConsole.h"
    3536# include "CSnapshot.h"
     
    150151    }
    151152
     153    /* Try to create machine UI: */
     154    return create();
     155}
     156
     157/* static */
     158bool UIMachine::create()
     159{
     160    /* Make sure machine is null pointer: */
     161    AssertReturn(m_spInstance == 0, false);
     162
    152163    /* Create machine UI: */
    153164    new UIMachine;
    154     /* Prepare machine UI: */
    155     return m_spInstance->prepare();
     165    /* Make sure it's prepared: */
     166    if (!m_spInstance->prepare())
     167    {
     168        /* Destroy machine UI otherwise: */
     169        destroy();
     170        /* False in that case: */
     171        return false;
     172    }
     173    /* True by default: */
     174    return true;
    156175}
    157176
     
    159178void UIMachine::destroy()
    160179{
     180    /* Make sure machine is valid pointer: */
     181    AssertReturnVoid(m_spInstance != 0);
     182
    161183    /* Cleanup machine UI: */
    162184    m_spInstance->cleanup();
     
    229251bool UIMachine::prepare()
    230252{
    231     /* Create VM session: */
    232     m_session = vboxGlobal().openSession(vboxGlobal().managedVMUuid(),
    233                                          vboxGlobal().isSeparateProcess() ? KLockType_Shared : KLockType_VM);
    234     if (m_session.isNull())
     253    /* Try to create session UI: */
     254    if (!UISession::create(m_pSession, this))
    235255        return false;
    236 
    237     /* Create UI session: */
    238     m_pSession = new UISession(this, m_session);
    239256
    240257    /* Preventing application from closing in case of window(s) closed: */
     
    272289{
    273290    /* Load 'visual state' option: */
     291    if (uisession())
    274292    {
    275293        /* Load restricted visual states: */
     
    299317{
    300318    /* Save 'visual state' option: */
     319    if (uisession())
    301320    {
    302321        /* Get requested visual state: */
     
    324343    m_pVisualState = 0;
    325344
    326     /* Delete UI session: */
    327     delete m_pSession;
    328     m_pSession = 0;
    329 
    330     /* Free session finally: */
    331     m_session.UnlockMachine();
    332     m_session.detach();
     345    /* Destroy session UI if necessary: */
     346    if (uisession())
     347        UISession::destroy(m_pSession);
    333348
    334349    /* Quit application: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r52995 r53000  
    2727/* COM includes: */
    2828#include "COMEnums.h"
    29 #include "CSession.h"
    3029
    3130/* Forward declarations: */
     
    5150      * @return true if machine was started, false otherwise. */
    5251    static bool startMachine(const QString &strID);
     52    /** Static constructor. */
     53    static bool create();
    5354    /** Static destructor. */
    5455    static void destroy();
     
    9697    static UIMachine* m_spInstance;
    9798
    98     /** Holds the session instance. */
    99     CSession m_session;
    100 
    10199    /** Holds the session UI instance. */
    102100    UISession *m_pSession;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r52999 r53000  
    128128#endif /* Q_WS_MAC */
    129129
    130 UISession::UISession(UIMachine *pMachine, CSession &sessionReference)
     130/* static */
     131bool UISession::create(UISession *&pSession, UIMachine *pMachine)
     132{
     133    /* Make sure null pointer passed: */
     134    AssertReturn(pSession == 0, false);
     135
     136    /* Create session UI: */
     137    pSession = new UISession(pMachine);
     138    /* Make sure it's prepared: */
     139    if (!pSession->prepare())
     140    {
     141        /* Destroy session UI otherwise: */
     142        destroy(pSession);
     143        /* False in that case: */
     144        return false;
     145    }
     146    /* True by default: */
     147    return true;
     148}
     149
     150/* static */
     151void UISession::destroy(UISession *&pSession)
     152{
     153    /* Make sure valid pointer passed: */
     154    AssertReturnVoid(pSession != 0);
     155
     156    /* Cleanup session UI: */
     157    pSession->cleanup();
     158    /* Destroy session: */
     159    delete pSession;
     160    pSession = 0;
     161}
     162
     163UISession::UISession(UIMachine *pMachine)
    131164    : QObject(pMachine)
    132165    /* Base variables: */
    133166    , m_pMachine(pMachine)
    134     , m_session(sessionReference)
    135167    , m_pActionPool(0)
    136168#ifdef Q_WS_MAC
     
    139171    /* Common variables: */
    140172    , m_machineStatePrevious(KMachineState_Null)
    141     , m_machineState(session().GetMachine().GetState())
     173    , m_machineState(KMachineState_Null)
    142174#ifndef Q_WS_MAC
    143175    , m_pMachineWindowIcon(0)
     
    181213    , m_fIsHidingHostPointer(true)
    182214{
     215}
     216
     217bool UISession::prepare()
     218{
     219    /* Prepare session: */
     220    if (!prepareSession())
     221        return false;
     222
    183223    /* Prepare actions: */
    184224    prepareActions();
     
    206246    sigaction(SIGUSR1, &sa, NULL);
    207247#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
     248
     249    /* True by default: */
     250    return true;
    208251}
    209252
    210253UISession::~UISession()
     254{
     255}
     256
     257void UISession::cleanup()
    211258{
    212259#ifdef Q_WS_WIN
     
    230277    /* Cleanup actions: */
    231278    cleanupActions();
     279
     280    /* Cleanup session: */
     281    cleanupSession();
    232282}
    233283
     
    9661016}
    9671017
     1018bool UISession::prepareSession()
     1019{
     1020    /* Open session: */
     1021    m_session = vboxGlobal().openSession(vboxGlobal().managedVMUuid(),
     1022                                         vboxGlobal().isSeparateProcess()
     1023                                         ? KLockType_Shared : KLockType_VM);
     1024    if (m_session.isNull())
     1025        return false;
     1026
     1027    /* Update machine-state: */
     1028    m_machineState = m_session.GetMachine().GetState();
     1029
     1030    /* True by default: */
     1031    return true;
     1032}
     1033
    9681034void UISession::prepareConsoleEventHandlers()
    9691035{
     
    13251391}
    13261392
     1393void UISession::cleanupSession()
     1394{
     1395    /* Close session: */
     1396    if (!m_session.isNull())
     1397    {
     1398        m_session.UnlockMachine();
     1399        m_session.detach();
     1400    }
     1401}
     1402
    13271403#ifdef Q_WS_MAC
    13281404void UISession::updateMenu()
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r52558 r53000  
    2929/* COM includes: */
    3030#include "COMEnums.h"
     31#include "CSession.h"
    3132
    3233/* Forward declarations: */
     
    3637class UIMachineLogic;
    3738class UIActionPool;
    38 class CSession;
    3939class CUSBDevice;
    4040class CNetworkAdapter;
     
    7777public:
    7878
    79     /* Machine uisession constructor/destructor: */
    80     UISession(UIMachine *pMachine, CSession &session);
    81     virtual ~UISession();
     79    /** Factory constructor. */
     80    static bool create(UISession *&pSession, UIMachine *pMachine);
     81    /** Factory destructor. */
     82    static void destroy(UISession *&pSession);
    8283
    8384    /* API: Runtime UI stuff: */
     
    309310private:
    310311
     312    /** Constructor. */
     313    UISession(UIMachine *pMachine);
     314    /** Destructor. */
     315    ~UISession();
     316
    311317    /* Private getters: */
    312318    UIMachine* uimachine() const { return m_pMachine; }
    313319
    314320    /* Prepare helpers: */
     321    bool prepare();
     322    bool prepareSession();
    315323    void prepareActions();
    316324    void prepareConnections();
     
    327335    void cleanupConnections();
    328336    void cleanupActions();
     337    void cleanupSession();
     338    void cleanup();
    329339
    330340#ifdef Q_WS_MAC
     
    344354    /* Private variables: */
    345355    UIMachine *m_pMachine;
    346     CSession &m_session;
     356
     357    /** Holds the session instance. */
     358    CSession m_session;
    347359
    348360    /** Holds the action-pool instance. */
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