~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VBoxManage/VBoxManageGuestProp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <VBox/com/errorprint.h>
33
33
 
34
34
#include <VBox/com/VirtualBox.h>
 
35
#include <VBox/com/EventQueue.h>
35
36
 
36
37
#include <VBox/log.h>
37
38
#include <iprt/asm.h>
38
 
#include <iprt/semaphore.h>
39
39
#include <iprt/stream.h>
40
40
#include <iprt/string.h>
41
41
#include <iprt/time.h>
66
66
#ifndef VBOX_WITH_XPCOM
67
67
        refcnt = 0;
68
68
#endif
69
 
#ifndef USE_XPCOM_QUEUE
70
 
        int rc = RTSemEventMultiCreate(&mhEvent);
71
 
        if (RT_FAILURE(rc))
72
 
            mhEvent = NIL_RTSEMEVENTMULTI;
73
 
#endif
74
69
    }
75
70
 
76
71
    virtual ~GuestPropertyCallback()
77
72
    {
78
 
#ifndef USE_XPCOM_QUEUE
79
 
        RTSemEventMultiDestroy(mhEvent);
80
 
        mhEvent = NIL_RTSEMEVENTMULTI;
81
 
#endif
82
73
    }
83
74
 
84
75
#ifndef VBOX_WITH_XPCOM
93
84
            delete this;
94
85
        return cnt;
95
86
    }
96
 
    STDMETHOD(QueryInterface)(REFIID riid , void **ppObj)
97
 
    {
98
 
        if (riid == IID_IUnknown)
99
 
        {
100
 
            *ppObj = this;
101
 
            AddRef();
102
 
            return S_OK;
103
 
        }
104
 
        if (riid == IID_IVirtualBoxCallback)
105
 
        {
106
 
            *ppObj = this;
107
 
            AddRef();
108
 
            return S_OK;
109
 
        }
110
 
        *ppObj = NULL;
111
 
        return E_NOINTERFACE;
112
 
    }
113
87
#endif /* !VBOX_WITH_XPCOM */
 
88
    VBOX_SCRIPTABLE_DISPATCH_IMPL(IVirtualBoxCallback)
114
89
 
115
90
    NS_DECL_ISUPPORTS
116
91
 
142
117
        return S_OK;
143
118
    }
144
119
 
145
 
    STDMETHOD(OnMediaRegistered)(IN_BSTR mediaId,
146
 
                                 DeviceType_T mediaType, BOOL registered)
 
120
    STDMETHOD(OnMediumRegistered)(IN_BSTR mediaId,
 
121
                                  DeviceType_T mediaType, BOOL registered)
147
122
    {
148
123
        NOREF(mediaId);
149
124
        NOREF(mediaType);
184
159
                                     IN_BSTR name, IN_BSTR value,
185
160
                                     IN_BSTR flags)
186
161
    {
187
 
        HRESULT rc = S_OK;
188
162
        Utf8Str utf8Name(name);
189
163
        Guid uuid(machineId);
190
 
        if (utf8Name.isNull())
191
 
            rc = E_OUTOFMEMORY;
192
 
        if (   SUCCEEDED(rc)
193
 
            && uuid == mUuid
 
164
        if (   uuid == mUuid
194
165
            && RTStrSimplePatternMultiMatch(mPatterns, RTSTR_MAX,
195
166
                                            utf8Name.raw(), RTSTR_MAX, NULL))
196
167
        {
197
168
            RTPrintf("Name: %lS, value: %lS, flags: %lS\n", name, value, flags);
198
169
            ASMAtomicWriteBool(&mSignalled, true);
199
 
#ifndef USE_XPCOM_QUEUE
200
 
            int rc = RTSemEventMultiSignal(mhEvent);
201
 
            AssertRC(rc);
202
 
#endif
 
170
            com::EventQueue::getMainEventQueue()->interruptEventQueueProcessing();
203
171
        }
204
 
        return rc;
 
172
        return S_OK;
205
173
    }
206
174
 
207
175
    bool Signalled(void) const
209
177
        return mSignalled;
210
178
    }
211
179
 
212
 
#ifndef USE_XPCOM_QUEUE
213
 
    /** Wrapper around RTSemEventMultiWait. */
214
 
    int wait(uint32_t cMillies)
215
 
    {
216
 
        return RTSemEventMultiWait(mhEvent, cMillies);
217
 
    }
218
 
#endif
219
 
 
220
180
private:
221
181
    bool volatile mSignalled;
222
182
    const char *mPatterns;
224
184
#ifndef VBOX_WITH_XPCOM
225
185
    long refcnt;
226
186
#endif
227
 
#ifndef USE_XPCOM_QUEUE
228
 
    /** Event semaphore to wait on. */
229
 
    RTSEMEVENTMULTI mhEvent;
230
 
#endif
231
187
};
232
188
 
233
189
#ifdef VBOX_WITH_XPCOM
353
309
        a->session->COMGETTER(Machine)(machine.asOutParam());
354
310
 
355
311
        if (!pszValue && !pszFlags)
356
 
            CHECK_ERROR(machine, SetGuestPropertyValue(Bstr(pszName), NULL));
 
312
            CHECK_ERROR(machine, SetGuestPropertyValue(Bstr(pszName), Bstr("")));
357
313
        else if (!pszFlags)
358
314
            CHECK_ERROR(machine, SetGuestPropertyValue(Bstr(pszName), Bstr(pszValue)));
359
315
        else
438
394
}
439
395
 
440
396
/**
441
 
 * Callback for processThreadEventQueue.
442
 
 *
443
 
 * @param   pvUser  Pointer to the callback object.
444
 
 *
445
 
 * @returns true if it should return or false if it should continue waiting for
446
 
 *          events.
447
 
 */
448
 
static bool eventExitCheck(void *pvUser)
449
 
{
450
 
    GuestPropertyCallback const *pCallbacks = (GuestPropertyCallback const *)pvUser;
451
 
    return pCallbacks->Signalled();
452
 
}
453
 
 
454
 
/**
455
397
 * Enumerates the properties in the guest property store.
456
398
 *
457
399
 * @returns 0 on success, 1 on failure
500
442
        return errorSyntax(USAGE_GUESTPROPERTY, "Incorrect parameters");
501
443
 
502
444
    /*
503
 
     * Set up the callback and wait.
504
 
     *
505
 
     *
506
 
     * The waiting is done is 1 sec at the time since there there are races
507
 
     * between the callback and us going to sleep.  This also guards against
508
 
     * neglecting XPCOM event queues as well as any select timeout restrictions.
 
445
     * Set up the callback and loop until signal or timeout.
 
446
     *
 
447
     * We do this in 1000 ms chunks to be on the safe side (there used to be
 
448
     * better reasons for it).
509
449
     */
510
450
    Bstr uuid;
511
451
    machine->COMGETTER(Id)(uuid.asOutParam());
518
458
        return 1;
519
459
    }
520
460
    a->virtualBox->RegisterCallback(callback);
521
 
 
522
 
    int vrc = com::EventQueue::processThreadEventQueue(cMsTimeout, eventExitCheck, (void *)cbImpl,
523
 
                                                       1000 /*cMsPollInterval*/, false /*fReturnOnEvent*/);
524
 
    if (   RT_FAILURE(vrc)
525
 
        && vrc != VERR_CALLBACK_RETURN
526
 
        && vrc != VERR_TIMEOUT)
 
461
    uint64_t u64Started = RTTimeMilliTS();
 
462
    do
527
463
    {
528
 
        RTPrintf("Error waiting for event: %Rrc\n", vrc);
529
 
        return 1;
530
 
    }
 
464
        unsigned cMsWait;
 
465
        if (cMsTimeout == RT_INDEFINITE_WAIT)
 
466
            cMsWait = 1000;
 
467
        else
 
468
        {
 
469
            uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
 
470
            if (cMsElapsed >= cMsTimeout)
 
471
                break; /* timed out */
 
472
            cMsWait = RT_MIN(1000, cMsTimeout - (uint32_t)cMsElapsed);
 
473
        }
 
474
        int vrc = com::EventQueue::getMainEventQueue()->processEventQueue(cMsWait);
 
475
        if (    RT_FAILURE(vrc)
 
476
            &&  vrc != VERR_TIMEOUT)
 
477
        {
 
478
            RTPrintf("Error waiting for event: %Rrc\n", vrc);
 
479
            return 1;
 
480
        }
 
481
    } while (!cbImpl->Signalled());
531
482
 
532
483
    a->virtualBox->UnregisterCallback(callback);
533
484
 
569
520
    /* default: */
570
521
    return errorSyntax(USAGE_GUESTPROPERTY, "Incorrect parameters");
571
522
}
572