VirtualBox

Changeset 55437 in vbox


Ignore:
Timestamp:
Apr 27, 2015 9:35:19 AM (9 years ago)
Author:
vboxsync
Message:

Main/Console+Machine: deliver OnGuestPropertyChanged for the current VM also through the Console event source, to make event delivery more efficient (less broadcasting/filtering compared to using the VirtualBox event source), which of course only works within VM processes.
VBoxHeadless: make use of the more efficient event delivery path, which as an additional bonus often allows VBoxSVC to skip queueing the guest property changed events, which for fast delivery rates needs quite some memory.

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r51618 r55437  
    55
    66/*
    7  * Copyright (C) 2006-2014 Oracle Corporation
     7 * Copyright (C) 2006-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    128128
    129129/**
    130  *  Handler for global events.
     130 *  Handler for machine events.
    131131 */
    132 class VirtualBoxEventListener
     132class ConsoleEventListener
    133133{
    134134public:
    135     VirtualBoxEventListener()
    136     {
    137         mfNoLoggedInUsers = true;
    138     }
    139 
    140     virtual ~VirtualBoxEventListener()
     135    ConsoleEventListener() :
     136        mLastVRDEPort(-1),
     137        m_fIgnorePowerOffEvents(false),
     138        m_fNoLoggedInUsers(true)
     139    {
     140    }
     141
     142    virtual ~ConsoleEventListener()
    141143    {
    142144    }
     
    155157        switch (aType)
    156158        {
     159            case VBoxEventType_OnMouseCapabilityChanged:
     160            {
     161
     162                ComPtr<IMouseCapabilityChangedEvent> mccev = aEvent;
     163                Assert(!mccev.isNull());
     164
     165                BOOL fSupportsAbsolute = false;
     166                mccev->COMGETTER(SupportsAbsolute)(&fSupportsAbsolute);
     167
     168                /* Emit absolute mouse event to actually enable the host mouse cursor. */
     169                if (fSupportsAbsolute && gConsole)
     170                {
     171                    ComPtr<IMouse> mouse;
     172                    gConsole->COMGETTER(Mouse)(mouse.asOutParam());
     173                    if (mouse)
     174                    {
     175                        mouse->PutMouseEventAbsolute(-1, -1, 0, 0 /* Horizontal wheel */, 0);
     176                    }
     177                }
     178                break;
     179            }
     180            case VBoxEventType_OnStateChanged:
     181            {
     182                ComPtr<IStateChangedEvent> scev = aEvent;
     183                Assert(scev);
     184
     185                MachineState_T machineState;
     186                scev->COMGETTER(State)(&machineState);
     187
     188                /* Terminate any event wait operation if the machine has been
     189                 * PoweredDown/Saved/Aborted. */
     190                if (machineState < MachineState_Running && !m_fIgnorePowerOffEvents)
     191                {
     192                    g_fTerminateFE = true;
     193                    gEventQ->interruptEventQueueProcessing();
     194                }
     195
     196                break;
     197            }
     198            case VBoxEventType_OnVRDEServerInfoChanged:
     199            {
     200                ComPtr<IVRDEServerInfoChangedEvent> rdicev = aEvent;
     201                Assert(rdicev);
     202
     203                if (gConsole)
     204                {
     205                    ComPtr<IVRDEServerInfo> info;
     206                    gConsole->COMGETTER(VRDEServerInfo)(info.asOutParam());
     207                    if (info)
     208                    {
     209                        LONG port;
     210                        info->COMGETTER(Port)(&port);
     211                        if (port != mLastVRDEPort)
     212                        {
     213                            if (port == -1)
     214                                RTPrintf("VRDE server is inactive.\n");
     215                            else if (port == 0)
     216                                RTPrintf("VRDE server failed to start.\n");
     217                            else
     218                                RTPrintf("VRDE server is listening on port %d.\n", port);
     219
     220                            mLastVRDEPort = port;
     221                        }
     222                    }
     223                }
     224                break;
     225            }
     226            case VBoxEventType_OnCanShowWindow:
     227            {
     228                ComPtr<ICanShowWindowEvent> cswev = aEvent;
     229                Assert(cswev);
     230                cswev->AddVeto(NULL);
     231                break;
     232            }
     233            case VBoxEventType_OnShowWindow:
     234            {
     235                ComPtr<IShowWindowEvent> swev = aEvent;
     236                Assert(swev);
     237                swev->COMSETTER(WinId)(0);
     238                break;
     239            }
    157240            case VBoxEventType_OnGuestPropertyChanged:
    158241            {
     
    166249                {
    167250                    hrc = gConsole->COMGETTER(Machine)(pMachine.asOutParam());
    168                     if (SUCCEEDED(hrc) && pMachine)
    169                     {
    170                         Bstr gpMachineId, machineId;
    171                         hrc = pMachine->COMGETTER(Id)(gpMachineId.asOutParam());
    172                         AssertComRC(hrc);
    173                         hrc = pChangedEvent->COMGETTER(MachineId)(machineId.asOutParam());
    174                         AssertComRC(hrc);
    175                         if (gpMachineId != machineId)
    176                             hrc = VBOX_E_OBJECT_NOT_FOUND;
    177                     }
     251                    if (FAILED(hrc) || !pMachine)
     252                        hrc = VBOX_E_OBJECT_NOT_FOUND;
    178253                }
    179254                else
     
    216291                        LogRelFlow(("VRDE: hrc=%Rhrc: Host %s disconnecting clients (current host state known: %s)\n",
    217292                                    hrc, fProcessDisconnectOnGuestLogout ? "will handle" : "does not handle",
    218                                     mfNoLoggedInUsers ? "No users logged in" : "Users logged in"));
     293                                    m_fNoLoggedInUsers ? "No users logged in" : "Users logged in"));
    219294
    220295                        if (fProcessDisconnectOnGuestLogout)
    221296                        {
    222297                            bool fDropConnection = false;
    223                             if (!mfNoLoggedInUsers) /* Only if the property really changes. */
     298                            if (!m_fNoLoggedInUsers) /* Only if the property really changes. */
    224299                            {
    225300                                if (   utf8Value == "true"
     
    228303                                    || utf8Value.isEmpty())
    229304                                {
    230                                     mfNoLoggedInUsers = true;
     305                                    m_fNoLoggedInUsers = true;
    231306                                    fDropConnection = true;
    232307                                }
    233308                            }
    234309                            else if (utf8Value == "false")
    235                                 mfNoLoggedInUsers = false;
     310                                m_fNoLoggedInUsers = false;
    236311                            /* Guest property got deleted due to reset,
    237                              * take the shortcut without touching the mfNoLoggedInUsers
     312                             * take the shortcut without touching the m_fNoLoggedInUsers
    238313                             * state. */
    239314                            else if (utf8Value.isEmpty())
    240315                                fDropConnection = true;
    241316
    242                             LogRelFlow(("VRDE: szNoLoggedInUsers=%s, mfNoLoggedInUsers=%RTbool, fDropConnection=%RTbool\n",
    243                                         utf8Value.c_str(), mfNoLoggedInUsers, fDropConnection));
     317                            LogRelFlow(("VRDE: szNoLoggedInUsers=%s, m_fNoLoggedInUsers=%RTbool, fDropConnection=%RTbool\n",
     318                                        utf8Value.c_str(), m_fNoLoggedInUsers, fDropConnection));
    244319
    245320                            if (fDropConnection)
     
    283358                AssertFailed();
    284359        }
    285 
    286         return S_OK;
    287     }
    288 
    289 private:
    290 
    291     bool mfNoLoggedInUsers;
    292 };
    293 
    294 /**
    295  *  Handler for machine events.
    296  */
    297 class ConsoleEventListener
    298 {
    299 public:
    300     ConsoleEventListener() :
    301         mLastVRDEPort(-1),
    302         m_fIgnorePowerOffEvents(false)
    303     {
    304     }
    305 
    306     virtual ~ConsoleEventListener()
    307     {
    308     }
    309 
    310     HRESULT init()
    311     {
    312         return S_OK;
    313     }
    314 
    315     void uninit()
    316     {
    317     }
    318 
    319     STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
    320     {
    321         switch (aType)
    322         {
    323             case VBoxEventType_OnMouseCapabilityChanged:
    324             {
    325 
    326                 ComPtr<IMouseCapabilityChangedEvent> mccev = aEvent;
    327                 Assert(!mccev.isNull());
    328 
    329                 BOOL fSupportsAbsolute = false;
    330                 mccev->COMGETTER(SupportsAbsolute)(&fSupportsAbsolute);
    331 
    332                 /* Emit absolute mouse event to actually enable the host mouse cursor. */
    333                 if (fSupportsAbsolute && gConsole)
    334                 {
    335                     ComPtr<IMouse> mouse;
    336                     gConsole->COMGETTER(Mouse)(mouse.asOutParam());
    337                     if (mouse)
    338                     {
    339                         mouse->PutMouseEventAbsolute(-1, -1, 0, 0 /* Horizontal wheel */, 0);
    340                     }
    341                 }
    342                 break;
    343             }
    344             case VBoxEventType_OnStateChanged:
    345             {
    346                 ComPtr<IStateChangedEvent> scev = aEvent;
    347                 Assert(scev);
    348 
    349                 MachineState_T machineState;
    350                 scev->COMGETTER(State)(&machineState);
    351 
    352                 /* Terminate any event wait operation if the machine has been
    353                  * PoweredDown/Saved/Aborted. */
    354                 if (machineState < MachineState_Running && !m_fIgnorePowerOffEvents)
    355                 {
    356                     g_fTerminateFE = true;
    357                     gEventQ->interruptEventQueueProcessing();
    358                 }
    359 
    360                 break;
    361             }
    362             case VBoxEventType_OnVRDEServerInfoChanged:
    363             {
    364                 ComPtr<IVRDEServerInfoChangedEvent> rdicev = aEvent;
    365                 Assert(rdicev);
    366 
    367                 if (gConsole)
    368                 {
    369                     ComPtr<IVRDEServerInfo> info;
    370                     gConsole->COMGETTER(VRDEServerInfo)(info.asOutParam());
    371                     if (info)
    372                     {
    373                         LONG port;
    374                         info->COMGETTER(Port)(&port);
    375                         if (port != mLastVRDEPort)
    376                         {
    377                             if (port == -1)
    378                                 RTPrintf("VRDE server is inactive.\n");
    379                             else if (port == 0)
    380                                 RTPrintf("VRDE server failed to start.\n");
    381                             else
    382                                 RTPrintf("VRDE server is listening on port %d.\n", port);
    383 
    384                             mLastVRDEPort = port;
    385                         }
    386                     }
    387                 }
    388                 break;
    389             }
    390             case VBoxEventType_OnCanShowWindow:
    391             {
    392                 ComPtr<ICanShowWindowEvent> cswev = aEvent;
    393                 Assert(cswev);
    394                 cswev->AddVeto(NULL);
    395                 break;
    396             }
    397             case VBoxEventType_OnShowWindow:
    398             {
    399                 ComPtr<IShowWindowEvent> swev = aEvent;
    400                 Assert(swev);
    401                 swev->COMSETTER(WinId)(0);
    402                 break;
    403             }
    404             default:
    405                 AssertFailed();
    406         }
    407360        return S_OK;
    408361    }
     
    417370    long mLastVRDEPort;
    418371    bool m_fIgnorePowerOffEvents;
     372    bool m_fNoLoggedInUsers;
    419373};
    420374
    421375typedef ListenerImpl<VirtualBoxClientEventListener> VirtualBoxClientEventListenerImpl;
    422 typedef ListenerImpl<VirtualBoxEventListener> VirtualBoxEventListenerImpl;
    423376typedef ListenerImpl<ConsoleEventListener> ConsoleEventListenerImpl;
    424377
    425378VBOX_LISTENER_DECLARE(VirtualBoxClientEventListenerImpl)
    426 VBOX_LISTENER_DECLARE(VirtualBoxEventListenerImpl)
    427379VBOX_LISTENER_DECLARE(ConsoleEventListenerImpl)
    428380
     
    10571009            eventTypes.push_back(VBoxEventType_OnCanShowWindow);
    10581010            eventTypes.push_back(VBoxEventType_OnShowWindow);
     1011            eventTypes.push_back(VBoxEventType_OnGuestPropertyChanged);
    10591012            CHECK_ERROR(es, RegisterListener(consoleListener, ComSafeArrayAsInParam(eventTypes), true));
    10601013        }
     
    12071160        }
    12081161
    1209         /* VirtualBox events registration. */
    1210         {
    1211             ComPtr<IEventSource> es;
    1212             CHECK_ERROR(virtualBox, COMGETTER(EventSource)(es.asOutParam()));
    1213             ComObjPtr<VirtualBoxEventListenerImpl> listener;
    1214             listener.createObject();
    1215             listener->init(new VirtualBoxEventListener());
    1216             vboxListener = listener;
    1217             com::SafeArray<VBoxEventType_T> eventTypes;
    1218             eventTypes.push_back(VBoxEventType_OnGuestPropertyChanged);
    1219 
    1220             /**
    1221              * @todo Set the notification pattern to "/VirtualBox/GuestInfo/OS/ *Logged*"
    1222              *       to not cause too much load. The current API is broken as
    1223              *       IMachine::GuestPropertyNotificationPatterns() would change the
    1224              *       filter for _all_ clients. This is not what we want!
    1225              */
    1226             CHECK_ERROR(es, RegisterListener(vboxListener, ComSafeArrayAsInParam(eventTypes), true));
    1227         }
    1228 
    12291162#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
    12301163        signal(SIGINT, SaveState);
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r55422 r55437  
    35923592  <interface
    35933593    name="IInternalMachineControl" extends="$unknown"
    3594     uuid="f0b3bf6e-c609-4d5e-9fd7-77537a52c31b"
     3594    uuid="2cfec73b-4447-4ff8-bae5-e4306e6197e8"
    35953595    internal="yes"
    35963596    wsmap="suppress"
     
    38173817        <desc>
    38183818          The flags of the property.
     3819        </desc>
     3820      </param>
     3821      <param name="notify" type="boolean" dir="return">
     3822        <desc>
     3823          Returns if a guest property change notification event should be fired.
    38193824        </desc>
    38203825      </param>
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r55214 r55437  
    146146
    147147    const ComPtr<IMachine> &i_machine() const { return mMachine; }
     148    const Bstr &i_getId() const { return mstrUuid; }
    148149
    149150    bool i_useHostClipboard() { return mfUseHostClipboard; }
     
    975976    MachineState_T mMachineState;
    976977
     978    /** Machine uuid string. */
     979    Bstr mstrUuid;
     980
    977981    /** Pointer to the progress object of a live cancelable task.
    978982     *
  • trunk/src/VBox/Main/include/MachineImpl.h

    r55214 r55437  
    12301230                              const com::Utf8Str &aValue,
    12311231                              LONG64 aTimestamp,
    1232                               const com::Utf8Str &aFlags);
     1232                              const com::Utf8Str &aFlags,
     1233                              BOOL *aNotify);
    12331234    HRESULT lockMedia();
    12341235    HRESULT unlockMedia();
     
    13781379                              const com::Utf8Str &aValue,
    13791380                              LONG64 aTimestamp,
    1380                               const com::Utf8Str &aFlags);
     1381                              const com::Utf8Str &aFlags,
     1382                              BOOL *aNotify);
    13811383    HRESULT lockMedia();
    13821384    HRESULT unlockMedia();
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r55382 r55437  
    266266    }
    267267
    268     STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
     268    STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
    269269    {
    270270        switch(aType)
     
    278278                Assert(pNREv);
    279279
    280                 Bstr interestedId;
    281                 rc = pMachine->COMGETTER(Id)(interestedId.asOutParam());
    282                 AssertComRC(rc);
    283280                rc = pNREv->COMGETTER(MachineId)(id.asOutParam());
    284281                AssertComRC(rc);
    285                 if (id != interestedId)
     282                if (id != mConsole->i_getId())
    286283                    break;
    287284                /* now we can operate with redirects */
     
    342339              AssertFailed();
    343340        }
     341
    344342        return S_OK;
    345343    }
     
    478476    AssertComRCReturnRC(rc);
    479477
     478    rc = mMachine->COMGETTER(Id)(mstrUuid.asOutParam());
     479    AssertComRCReturnRC(rc);
     480
    480481#ifdef VBOX_WITH_EXTPACK
    481482    unconst(mptrExtPackManager).createObject();
     
    10651066    }
    10661067
    1067     Bstr id;
    1068     HRESULT hrc = mMachine->COMGETTER(Id)(id.asOutParam());
    1069     Guid uuid = Guid(id);
    1070 
    1071     AssertComRCReturn(hrc, VERR_ACCESS_DENIED);
     1068    Guid uuid = Guid(i_getId());
    10721069
    10731070    AuthType_T authType = AuthType_Null;
    1074     hrc = mVRDEServer->COMGETTER(AuthType)(&authType);
     1071    HRESULT hrc = mVRDEServer->COMGETTER(AuthType)(&authType);
    10751072    AssertComRCReturn(hrc, VERR_ACCESS_DENIED);
    10761073
     
    14191416    }
    14201417
    1421     Bstr uuid;
    1422     HRESULT hrc = mMachine->COMGETTER(Id)(uuid.asOutParam());
     1418    AuthType_T authType = AuthType_Null;
     1419    HRESULT hrc = mVRDEServer->COMGETTER(AuthType)(&authType);
    14231420    AssertComRC(hrc);
    14241421
    1425     AuthType_T authType = AuthType_Null;
    1426     hrc = mVRDEServer->COMGETTER(AuthType)(&authType);
    1427     AssertComRC(hrc);
    1428 
    14291422    if (authType == AuthType_External)
    1430         mConsoleVRDPServer->AuthDisconnect(uuid, u32ClientId);
     1423        mConsoleVRDPServer->AuthDisconnect(i_getId(), u32ClientId);
    14311424
    14321425#ifdef VBOX_WITH_GUEST_PROPS
     
    17621755    Bstr flags(pCBData->pcszFlags);
    17631756    ComObjPtr<Console> pConsole = reinterpret_cast<Console *>(pvExtension);
     1757    BOOL fNotify = FALSE;
    17641758    HRESULT hrc = pConsole->mControl->PushGuestProperty(name.raw(),
    17651759                                                        value.raw(),
    17661760                                                        pCBData->u64Timestamp,
    1767                                                         flags.raw());
     1761                                                        flags.raw(),
     1762                                                        &fNotify);
    17681763    if (SUCCEEDED(hrc))
    17691764        rc = VINF_SUCCESS;
     
    17741769        rc = Global::vboxStatusCodeFromCOM(hrc);
    17751770    }
     1771    if (fNotify)
     1772        fireGuestPropertyChangedEvent(pConsole->mEventSource, pConsole->i_getId().raw(), name.raw(), value.raw(), flags.raw());
    17761773    return rc;
    17771774}
     
    56705667    HRESULT hrc = S_OK;
    56715668    Bstr idMachine(aMachineId);
    5672     Bstr idSelf;
    5673     hrc = mMachine->COMGETTER(Id)(idSelf.asOutParam());
    56745669    if (   FAILED(hrc)
    5675         || idMachine != idSelf)
     5670        || idMachine != i_getId())
    56765671        return hrc;
    56775672
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r55233 r55437  
    1337113371}
    1337213372
    13373 HRESULT SessionMachine::pushGuestProperty(const  com::Utf8Str &aName,
    13374                                           const  com::Utf8Str &aValue,
    13375                                                  LONG64       aTimestamp,
    13376                                           const  com::Utf8Str &aFlags)
     13373HRESULT SessionMachine::pushGuestProperty(const com::Utf8Str &aName,
     13374                                          const com::Utf8Str &aValue,
     13375                                          LONG64 aTimestamp,
     13376                                          const com::Utf8Str &aFlags,
     13377                                          BOOL *aNotify)
    1337713378{
    1337813379    LogFlowThisFunc(("\n"));
     
    1338013381#ifdef VBOX_WITH_GUEST_PROPS
    1338113382    using namespace guestProp;
     13383
     13384    *aNotify = FALSE;
    1338213385
    1338313386    try
     
    1346313466                                             Bstr(aValue).raw(),
    1346413467                                             Bstr(aFlags).raw());
     13468            *aNotify = TRUE;
    1346513469        }
    1346613470    }
     
    1470514709                                   const com::Utf8Str &aValue,
    1470614710                                   LONG64 aTimestamp,
    14707                                    const com::Utf8Str &aFlags)
     14711                                   const com::Utf8Str &aFlags,
     14712                                   BOOL *aNotify)
    1470814713{
    1470914714    NOREF(aName);
     
    1471114716    NOREF(aTimestamp);
    1471214717    NOREF(aFlags);
     14718    NOREF(aNotify);
    1471314719    ReturnComNotImplemented();
    1471414720}
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