VirtualBox

Changeset 85286 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Jul 12, 2020 11:08:50 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139263
Message:

Main: Refactored the generated event code implementation as Clang 11 claims va_start() on an VBoxEventType_T may trigger undefined behaviour due to type promotion (or something to that effect), but also because that variadict approach was horrible from the start. Refactored code as a dedicated factory method for each event, removing a dependency on VBoxEventDesc in veto cases. The fireXxxxEvent functions now return a HRESULT are no longer DECLINLINE (no need to compile all of them all the time). Reusable events got a ReinitXxxxxEvent function for helping with that. The VirtualBox::CallbackEvent stuff was a horrid misdesign from the start, it could've been done with a single class carrying a VBoxEventDesc member that the i_onXxxx methods would init() with all the event specific parameters and stuff. Refactored code passes a IEvent around, as that's even easier. I've left much of the old code in place for reference, but will remove once I've had a chance to test it a bit more (still struggling building VBox on the mac). bugref:9790

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r85262 r85286  
    9090#include "CloudProviderManagerImpl.h"
    9191#include "ThreadTask.h"
     92#include "VBoxEvents.h"
    9293
    9394#include <QMTranslator.h>
     
    135136
    136137
     138#if 0 /* obsoleted by AsyncEvent */
    137139////////////////////////////////////////////////////////////////////////////////
    138140//
     
    173175protected:
    174176    VBoxEventType_T     mWhat;
     177};
     178#endif
     179
     180////////////////////////////////////////////////////////////////////////////////
     181//
     182// AsyncEvent class
     183//
     184////////////////////////////////////////////////////////////////////////////////
     185
     186/**
     187 * For firing off an event on asynchronously on an event thread.
     188 */
     189class VirtualBox::AsyncEvent : public Event
     190{
     191public:
     192    AsyncEvent(VirtualBox *a_pVirtualBox, ComPtr<IEvent> const &a_rEvent)
     193        : mVirtualBox(a_pVirtualBox), mEvent(a_rEvent)
     194    {
     195        Assert(a_pVirtualBox);
     196    }
     197
     198    void *handler() RT_OVERRIDE;
     199
     200private:
     201    /**
     202     * @note This is a weak ref -- the CallbackEvent handler thread is bound to the
     203     *       lifetime of the VirtualBox instance, so it's safe.
     204     */
     205    VirtualBox         *mVirtualBox;
     206    /** The event. */
     207    ComPtr<IEvent>      mEvent;
    175208};
    176209
     
    556589    try
    557590    {
     591        /* Create the event source early as we may fire async event during settings loading (media). */
     592        rc = unconst(m->pEventSource).createObject();
     593        if (FAILED(rc)) throw rc;
     594        rc = m->pEventSource->init();
     595        if (FAILED(rc)) throw rc;
     596
     597
    558598        /* Get the VirtualBox home directory. */
    559599        {
     
    718758        }
    719759#endif /* VBOX_WITH_CLOUD_NET */
    720 
    721         /* events */
    722         if (SUCCEEDED(rc = unconst(m->pEventSource).createObject()))
    723             rc = m->pEventSource->init();
    724         if (FAILED(rc)) throw rc;
    725760
    726761        /* cloud provider manager */
     
    31883223}
    31893224
    3190 /** Event for onMachineStateChange(), onMachineDataChange(), onMachineRegistered() */
    3191 struct MachineEvent : public VirtualBox::CallbackEvent
    3192 {
    3193     MachineEvent(VirtualBox *aVB, VBoxEventType_T aWhat, const Guid &aId, BOOL aBool)
    3194         : CallbackEvent(aVB, aWhat), id(aId.toUtf16())
    3195         , mBool(aBool)
    3196         { }
    3197 
    3198     MachineEvent(VirtualBox *aVB, VBoxEventType_T aWhat, const Guid &aId, MachineState_T aState)
    3199         : CallbackEvent(aVB, aWhat), id(aId.toUtf16())
    3200         , mState(aState)
    3201         {}
    3202 
    3203     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3204     {
    3205         switch (mWhat)
    3206         {
    3207             case VBoxEventType_OnMachineDataChanged:
    3208                 aEvDesc.init(aSource, mWhat, id.raw(), mBool);
    3209                 break;
    3210 
    3211             case VBoxEventType_OnMachineStateChanged:
    3212                 aEvDesc.init(aSource, mWhat, id.raw(), mState);
    3213                 break;
    3214 
    3215             case VBoxEventType_OnMachineRegistered:
    3216                 aEvDesc.init(aSource, mWhat, id.raw(), mBool);
    3217                 break;
    3218 
    3219             default:
    3220                 AssertFailedReturn(S_OK);
    3221          }
    3222          return S_OK;
    3223     }
    3224 
    3225     Bstr id;
    3226     MachineState_T mState;
    3227     BOOL mBool;
    3228 };
    3229 
    3230 
    32313225/**
    32323226 * VD plugin load
     
    32453239}
    32463240
    3247 
    3248 /** Event for onMediumRegistered() */
    3249 struct MediumRegisteredEventStruct : public VirtualBox::CallbackEvent
    3250 {
    3251     MediumRegisteredEventStruct(VirtualBox *aVB, const Guid &aMediumId,
    3252                           const DeviceType_T aDevType, const BOOL aRegistered)
    3253         : CallbackEvent(aVB, VBoxEventType_OnMediumRegistered)
    3254         , mMediumId(aMediumId.toUtf16()), mDevType(aDevType), mRegistered(aRegistered)
    3255     {}
    3256 
    3257     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3258     {
    3259         return aEvDesc.init(aSource, VBoxEventType_OnMediumRegistered, mMediumId.raw(), mDevType, mRegistered);
    3260     }
    3261 
    3262     Bstr mMediumId;
    3263     DeviceType_T mDevType;
    3264     BOOL mRegistered;
    3265 };
    3266 
    32673241/**
    32683242 *  @note Doesn't lock any object.
     
    32703244void VirtualBox::i_onMediumRegistered(const Guid &aMediumId, const DeviceType_T aDevType, const BOOL aRegistered)
    32713245{
    3272     i_postEvent(new MediumRegisteredEventStruct(this, aMediumId, aDevType, aRegistered));
    3273 }
    3274 
    3275 /** Event for onMediumConfigChanged() */
    3276 struct MediumConfigChangedEventStruct : public VirtualBox::CallbackEvent
    3277 {
    3278     MediumConfigChangedEventStruct(VirtualBox *aVB, IMedium *aMedium)
    3279         : CallbackEvent(aVB, VBoxEventType_OnMediumConfigChanged)
    3280         , mMedium(aMedium)
    3281     {}
    3282 
    3283     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3284     {
    3285         return aEvDesc.init(aSource, VBoxEventType_OnMediumConfigChanged, mMedium);
    3286     }
    3287 
    3288     IMedium* mMedium;
    3289 };
     3246    ComPtr<IEvent> ptrEvent;
     3247    HRESULT hrc = CreateMediumRegisteredEvent(ptrEvent.asOutParam(), m->pEventSource,
     3248                                              aMediumId.toUtf16().raw(), aDevType, aRegistered);
     3249    AssertComRCReturnVoid(hrc);
     3250    i_postEvent(new AsyncEvent(this, ptrEvent));
     3251}
    32903252
    32913253void VirtualBox::i_onMediumConfigChanged(IMedium *aMedium)
    32923254{
    3293     i_postEvent(new MediumConfigChangedEventStruct(this, aMedium));
    3294 }
    3295 
    3296 /** Event for onMediumChanged() */
    3297 struct MediumChangedEventStruct : public VirtualBox::CallbackEvent
    3298 {
    3299     MediumChangedEventStruct(VirtualBox *aVB, IMediumAttachment *aMediumAttachment)
    3300         : CallbackEvent(aVB, VBoxEventType_OnMediumChanged)
    3301         , mMediumAttachment(aMediumAttachment)
    3302     {}
    3303 
    3304     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3305     {
    3306         return aEvDesc.init(aSource, VBoxEventType_OnMediumChanged, mMediumAttachment);
    3307     }
    3308 
    3309     IMediumAttachment* mMediumAttachment;
    3310 };
     3255    ComPtr<IEvent> ptrEvent;
     3256    HRESULT hrc = CreateMediumConfigChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aMedium);
     3257    AssertComRCReturnVoid(hrc);
     3258    i_postEvent(new AsyncEvent(this, ptrEvent));
     3259}
    33113260
    33123261void VirtualBox::i_onMediumChanged(IMediumAttachment *aMediumAttachment)
    33133262{
    3314     i_postEvent(new MediumChangedEventStruct(this, aMediumAttachment));
    3315 }
    3316 
    3317 /** Event for onStorageControllerChanged() */
    3318 struct StorageControllerChangedEventStruct : public VirtualBox::CallbackEvent
    3319 {
    3320     StorageControllerChangedEventStruct(VirtualBox *aVB, const Guid &aMachineId,
    3321                                         const com::Utf8Str &aControllerName)
    3322         : CallbackEvent(aVB, VBoxEventType_OnStorageControllerChanged)
    3323         , mMachineId(aMachineId.toUtf16()), mControllerName(aControllerName)
    3324     {}
    3325 
    3326     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3327     {
    3328         return aEvDesc.init(aSource, VBoxEventType_OnStorageControllerChanged, mMachineId.raw(), mControllerName.raw());
    3329     }
    3330 
    3331     Bstr mMachineId;
    3332     Bstr mControllerName;
    3333 };
     3263    ComPtr<IEvent> ptrEvent;
     3264    HRESULT hrc = CreateMediumChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aMediumAttachment);
     3265    AssertComRCReturnVoid(hrc);
     3266    i_postEvent(new AsyncEvent(this, ptrEvent));
     3267}
    33343268
    33353269/**
     
    33383272void VirtualBox::i_onStorageControllerChanged(const Guid &aMachineId, const com::Utf8Str &aControllerName)
    33393273{
    3340     i_postEvent(new StorageControllerChangedEventStruct(this, aMachineId, aControllerName));
    3341 }
    3342 
    3343 /** Event for onStorageDeviceChanged() */
    3344 struct StorageDeviceChangedEventStruct : public VirtualBox::CallbackEvent
    3345 {
    3346     StorageDeviceChangedEventStruct(VirtualBox *aVB, IMediumAttachment *aStorageDevice, BOOL fRemoved, BOOL fSilent)
    3347         : CallbackEvent(aVB, VBoxEventType_OnStorageDeviceChanged)
    3348         , mStorageDevice(aStorageDevice)
    3349         , mRemoved(fRemoved)
    3350         , mSilent(fSilent)
    3351     {}
    3352 
    3353     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3354     {
    3355         return aEvDesc.init(aSource, VBoxEventType_OnStorageDeviceChanged, mStorageDevice, mRemoved, mSilent);
    3356     }
    3357 
    3358     IMediumAttachment* mStorageDevice;
    3359     BOOL mRemoved;
    3360     BOOL mSilent;
    3361 };
     3274    ComPtr<IEvent> ptrEvent;
     3275    HRESULT hrc = CreateStorageControllerChangedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3276                                                      aMachineId.toUtf16().raw(), Bstr(aControllerName).raw());
     3277    AssertComRCReturnVoid(hrc);
     3278    i_postEvent(new AsyncEvent(this, ptrEvent));
     3279}
    33623280
    33633281void VirtualBox::i_onStorageDeviceChanged(IMediumAttachment *aStorageDevice, const BOOL fRemoved, const BOOL fSilent)
    33643282{
    3365     i_postEvent(new StorageDeviceChangedEventStruct(this, aStorageDevice, fRemoved, fSilent));
     3283    ComPtr<IEvent> ptrEvent;
     3284    HRESULT hrc = CreateStorageDeviceChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aStorageDevice, fRemoved, fSilent);
     3285    AssertComRCReturnVoid(hrc);
     3286    i_postEvent(new AsyncEvent(this, ptrEvent));
    33663287}
    33673288
     
    33713292void VirtualBox::i_onMachineStateChange(const Guid &aId, MachineState_T aState)
    33723293{
    3373     i_postEvent(new MachineEvent(this, VBoxEventType_OnMachineStateChanged, aId, aState));
     3294    ComPtr<IEvent> ptrEvent;
     3295    HRESULT hrc = CreateMachineStateChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aState);
     3296    AssertComRCReturnVoid(hrc);
     3297    i_postEvent(new AsyncEvent(this, ptrEvent));
    33743298}
    33753299
     
    33793303void VirtualBox::i_onMachineDataChange(const Guid &aId, BOOL aTemporary)
    33803304{
    3381     i_postEvent(new MachineEvent(this, VBoxEventType_OnMachineDataChanged, aId, aTemporary));
     3305    ComPtr<IEvent> ptrEvent;
     3306    HRESULT hrc = CreateMachineDataChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aTemporary);
     3307    AssertComRCReturnVoid(hrc);
     3308    i_postEvent(new AsyncEvent(this, ptrEvent));
    33823309}
    33833310
     
    33883315                                        Bstr &aError)
    33893316{
    3390     LogFlowThisFunc(("machine={%s} aKey={%ls} aValue={%ls}\n",
    3391                       aId.toString().c_str(), aKey, aValue));
     3317    LogFlowThisFunc(("machine={%RTuuid} aKey={%ls} aValue={%ls}\n", aId.raw(), aKey, aValue));
    33923318
    33933319    AutoCaller autoCaller(this);
    33943320    AssertComRCReturn(autoCaller.rc(), FALSE);
    33953321
    3396     BOOL allowChange = TRUE;
    3397     Bstr id = aId.toUtf16();
    3398 
    3399     VBoxEventDesc evDesc;
    3400     evDesc.init(m->pEventSource, VBoxEventType_OnExtraDataCanChange, id.raw(), aKey, aValue);
    3401     BOOL fDelivered = evDesc.fire(3000); /* Wait up to 3 secs for delivery */
     3322    ComPtr<IEvent> ptrEvent;
     3323    HRESULT hrc = CreateExtraDataCanChangeEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aKey, aValue);
     3324    AssertComRCReturn(hrc, TRUE);
     3325    i_postEvent(new AsyncEvent(this, ptrEvent));
     3326
     3327    VBoxEventDesc EvtDesc(ptrEvent, m->pEventSource);
     3328    BOOL fDelivered = EvtDesc.fire(3000); /* Wait up to 3 secs for delivery */
    34023329    //Assert(fDelivered);
     3330    BOOL fAllowChange = TRUE;
    34033331    if (fDelivered)
    34043332    {
    3405         ComPtr<IEvent> aEvent;
    3406         evDesc.getEvent(aEvent.asOutParam());
    3407         ComPtr<IExtraDataCanChangeEvent> aCanChangeEvent = aEvent;
    3408         Assert(aCanChangeEvent);
     3333        ComPtr<IExtraDataCanChangeEvent> ptrCanChangeEvent = ptrEvent;
     3334        Assert(ptrCanChangeEvent);
     3335
    34093336        BOOL fVetoed = FALSE;
    3410         aCanChangeEvent->IsVetoed(&fVetoed);
    3411         allowChange = !fVetoed;
    3412 
    3413         if (!allowChange)
     3337        ptrCanChangeEvent->IsVetoed(&fVetoed);
     3338        fAllowChange = !fVetoed;
     3339
     3340        if (!fAllowChange)
    34143341        {
    34153342            SafeArray<BSTR> aVetos;
    3416             aCanChangeEvent->GetVetos(ComSafeArrayAsOutParam(aVetos));
     3343            ptrCanChangeEvent->GetVetos(ComSafeArrayAsOutParam(aVetos));
    34173344            if (aVetos.size() > 0)
    34183345                aError = aVetos[0];
    34193346        }
    34203347    }
    3421     else
    3422         allowChange = TRUE;
    3423 
    3424     LogFlowThisFunc(("allowChange=%RTbool\n", allowChange));
    3425     return allowChange;
    3426 }
    3427 
    3428 /** Event for onExtraDataChange() */
    3429 struct ExtraDataEvent : public VirtualBox::CallbackEvent
    3430 {
    3431     ExtraDataEvent(VirtualBox *aVB, const Guid &aMachineId,
    3432                    IN_BSTR aKey, IN_BSTR aVal)
    3433         : CallbackEvent(aVB, VBoxEventType_OnExtraDataChanged)
    3434         , machineId(aMachineId.toUtf16()), key(aKey), val(aVal)
    3435     {}
    3436 
    3437     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3438     {
    3439         return aEvDesc.init(aSource, VBoxEventType_OnExtraDataChanged, machineId.raw(), key.raw(), val.raw());
    3440     }
    3441 
    3442     Bstr machineId, key, val;
    3443 };
     3348
     3349    LogFlowThisFunc(("fAllowChange=%RTbool\n", fAllowChange));
     3350    return fAllowChange;
     3351}
    34443352
    34453353/**
    34463354 *  @note Doesn't lock any object.
     3355 *  @todo +d
    34473356 */
    34483357void VirtualBox::i_onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue)
    34493358{
    3450     i_postEvent(new ExtraDataEvent(this, aId, aKey, aValue));
     3359    ComPtr<IEvent> ptrEvent;
     3360    HRESULT hrc = CreateExtraDataChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aKey, aValue);
     3361    AssertComRCReturnVoid(hrc);
     3362    i_postEvent(new AsyncEvent(this, ptrEvent));
    34513363}
    34523364
     
    34563368void VirtualBox::i_onMachineRegistered(const Guid &aId, BOOL aRegistered)
    34573369{
    3458     i_postEvent(new MachineEvent(this, VBoxEventType_OnMachineRegistered, aId, aRegistered));
    3459 }
    3460 
    3461 /** Event for onSessionStateChange() */
    3462 struct SessionEvent : public VirtualBox::CallbackEvent
    3463 {
    3464     SessionEvent(VirtualBox *aVB, const Guid &aMachineId, SessionState_T aState)
    3465         : CallbackEvent(aVB, VBoxEventType_OnSessionStateChanged)
    3466         , machineId(aMachineId.toUtf16()), sessionState(aState)
    3467     {}
    3468 
    3469     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3470     {
    3471         return aEvDesc.init(aSource, VBoxEventType_OnSessionStateChanged, machineId.raw(), sessionState);
    3472     }
    3473     Bstr machineId;
    3474     SessionState_T sessionState;
    3475 };
     3370    ComPtr<IEvent> ptrEvent;
     3371    HRESULT hrc = CreateMachineRegisteredEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aRegistered);
     3372    AssertComRCReturnVoid(hrc);
     3373    i_postEvent(new AsyncEvent(this, ptrEvent));
     3374}
    34763375
    34773376/**
    34783377 *  @note Doesn't lock any object.
     3378 *  @todo +d
    34793379 */
    34803380void VirtualBox::i_onSessionStateChange(const Guid &aId, SessionState_T aState)
    34813381{
    3482     i_postEvent(new SessionEvent(this, aId, aState));
    3483 }
    3484 
    3485 /** Event for i_onSnapshotTaken(), i_onSnapshotDeleted(), i_onSnapshotRestored() and i_onSnapshotChange() */
    3486 struct SnapshotEvent : public VirtualBox::CallbackEvent
    3487 {
    3488     SnapshotEvent(VirtualBox *aVB, const Guid &aMachineId, const Guid &aSnapshotId,
    3489                   VBoxEventType_T aWhat)
    3490         : CallbackEvent(aVB, aWhat)
    3491         , machineId(aMachineId), snapshotId(aSnapshotId)
    3492         {}
    3493 
    3494     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3495     {
    3496         return aEvDesc.init(aSource, mWhat, machineId.toUtf16().raw(),
    3497                             snapshotId.toUtf16().raw());
    3498     }
    3499 
    3500     Guid machineId;
    3501     Guid snapshotId;
    3502 };
     3382    ComPtr<IEvent> ptrEvent;
     3383    HRESULT hrc = CreateSessionStateChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aState);
     3384    AssertComRCReturnVoid(hrc);
     3385    i_postEvent(new AsyncEvent(this, ptrEvent));
     3386}
    35033387
    35043388/**
     
    35073391void VirtualBox::i_onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId)
    35083392{
    3509     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3510                                   VBoxEventType_OnSnapshotTaken));
     3393    ComPtr<IEvent> ptrEvent;
     3394    HRESULT hrc = CreateSnapshotTakenEvent(ptrEvent.asOutParam(), m->pEventSource,
     3395                                           aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3396    AssertComRCReturnVoid(hrc);
     3397    i_postEvent(new AsyncEvent(this, ptrEvent));
    35113398}
    35123399
     
    35163403void VirtualBox::i_onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId)
    35173404{
    3518     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3519                                   VBoxEventType_OnSnapshotDeleted));
     3405    ComPtr<IEvent> ptrEvent;
     3406    HRESULT hrc = CreateSnapshotDeletedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3407                                             aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3408    AssertComRCReturnVoid(hrc);
     3409    i_postEvent(new AsyncEvent(this, ptrEvent));
    35203410}
    35213411
     
    35253415void VirtualBox::i_onSnapshotRestored(const Guid &aMachineId, const Guid &aSnapshotId)
    35263416{
    3527     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3528                                   VBoxEventType_OnSnapshotRestored));
     3417    ComPtr<IEvent> ptrEvent;
     3418    HRESULT hrc = CreateSnapshotRestoredEvent(ptrEvent.asOutParam(), m->pEventSource,
     3419                                              aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3420    AssertComRCReturnVoid(hrc);
     3421    i_postEvent(new AsyncEvent(this, ptrEvent));
    35293422}
    35303423
    35313424/**
    35323425 *  @note Doesn't lock any object.
     3426 *  @todo +d
    35333427 */
    35343428void VirtualBox::i_onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId)
    35353429{
    3536     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3537                                   VBoxEventType_OnSnapshotChanged));
    3538 }
    3539 
    3540 /** Event for onGuestPropertyChange() */
    3541 struct GuestPropertyEvent : public VirtualBox::CallbackEvent
    3542 {
    3543     GuestPropertyEvent(VirtualBox *aVBox, const Guid &aMachineId,
    3544                        IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags)
    3545         : CallbackEvent(aVBox, VBoxEventType_OnGuestPropertyChanged),
    3546           machineId(aMachineId),
    3547           name(aName),
    3548           value(aValue),
    3549           flags(aFlags)
    3550     {}
    3551 
    3552     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3553     {
    3554         return aEvDesc.init(aSource, VBoxEventType_OnGuestPropertyChanged,
    3555                             machineId.toUtf16().raw(), name.raw(), value.raw(), flags.raw());
    3556     }
    3557 
    3558     Guid machineId;
    3559     Bstr name, value, flags;
    3560 };
    3561 
    3562 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     3430    ComPtr<IEvent> ptrEvent;
     3431    HRESULT hrc = CreateSnapshotChangedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3432                                             aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3433    AssertComRCReturnVoid(hrc);
     3434    i_postEvent(new AsyncEvent(this, ptrEvent));
     3435}
     3436
     3437#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS /** @todo r=bird: Why is this still here?  */
     3438
    35633439/**
    35643440 * Generates a new clipboard area on the host by opening (and locking) a new, temporary directory.
     
    38333709    return cRefCount;
    38343710}
     3711
    38353712#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
    38363713
    38373714/**
    38383715 *  @note Doesn't lock any object.
     3716 *  @todo +d
    38393717 */
    38403718void VirtualBox::i_onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName,
    38413719                                         IN_BSTR aValue, IN_BSTR aFlags)
    38423720{
    3843     i_postEvent(new GuestPropertyEvent(this, aMachineId, aName, aValue, aFlags));
     3721    ComPtr<IEvent> ptrEvent;
     3722    HRESULT hrc = CreateGuestPropertyChangedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3723                                                  aMachineId.toUtf16().raw(), aName, aValue, aFlags);
     3724    AssertComRCReturnVoid(hrc);
     3725    i_postEvent(new AsyncEvent(this, ptrEvent));
    38443726}
    38453727
    38463728/**
    38473729 *  @note Doesn't lock any object.
     3730 *  @todo +d
    38483731 */
    38493732void VirtualBox::i_onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
     
    38553738}
    38563739
     3740/**  @todo +d  */
    38573741void VirtualBox::i_onNATNetworkChange(IN_BSTR aName)
    38583742{
     
    58025686////////////////////////////////////////////////////////////////////////////////
    58035687
     5688#if 0 /* obsoleted by AsyncEvent */
    58045689/**
    58055690 * Prepare the event using the overwritten #prepareEventDesc method and fire.
     
    58315716
    58325717    mVirtualBox = NULL; /* Not needed any longer. Still make sense to do this? */
     5718    return NULL;
     5719}
     5720#endif
     5721
     5722/**
     5723 * Called on the event handler thread.
     5724 *
     5725 * @note Locks the managed VirtualBox object for reading but leaves the lock
     5726 *       before iterating over callbacks and calling their methods.
     5727 */
     5728void *VirtualBox::AsyncEvent::handler()
     5729{
     5730    if (mVirtualBox)
     5731    {
     5732        AutoCaller autoCaller(mVirtualBox);
     5733        if (autoCaller.isOk())
     5734        {
     5735            VBoxEventDesc EvtDesc(mEvent, mVirtualBox->m->pEventSource);
     5736            EvtDesc.fire(/* don't wait for delivery */0);
     5737        }
     5738        else
     5739            Log1WarningFunc(("VirtualBox has been uninitialized (state=%d), the callback event is discarded!\n",
     5740                             mVirtualBox->getObjectState().getState()));
     5741        mVirtualBox = NULL; /* Old code did this, not really necessary, but whatever. */
     5742    }
     5743    mEvent.setNull();
    58335744    return NULL;
    58345745}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette