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

« back to all changes in this revision

Viewing changes to src/VBox/Main/SessionImpl.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:
29
29
 
30
30
#include "SessionImpl.h"
31
31
#include "ConsoleImpl.h"
 
32
#include "Global.h"
32
33
 
33
34
#include "Logging.h"
34
35
 
49
50
    do { \
50
51
        if (mState != SessionState_Open) \
51
52
            return setError (E_UNEXPECTED, \
52
 
                tr ("The session is not open")); \
 
53
                tr ("The session is not open (session state: %s)"), \
 
54
                Global::stringifySessionState(mState)); \
53
55
    } while (0)
54
56
 
55
57
// constructor / destructor
57
59
 
58
60
HRESULT Session::FinalConstruct()
59
61
{
60
 
    LogFlowThisFunc (("\n"));
 
62
    LogFlowThisFunc(("\n"));
61
63
 
62
64
    return init();
63
65
}
64
66
 
65
67
void Session::FinalRelease()
66
68
{
67
 
    LogFlowThisFunc (("\n"));
 
69
    LogFlowThisFunc(("\n"));
68
70
 
69
71
    uninit (true /* aFinalRelease */);
70
72
}
78
80
HRESULT Session::init()
79
81
{
80
82
    /* Enclose the state transition NotReady->InInit->Ready */
81
 
    AutoInitSpan autoInitSpan (this);
82
 
    AssertReturn (autoInitSpan.isOk(), E_FAIL);
 
83
    AutoInitSpan autoInitSpan(this);
 
84
    AssertReturn(autoInitSpan.isOk(), E_FAIL);
83
85
 
84
86
    LogFlowThisFuncEnter();
85
87
 
114
116
void Session::uninit (bool aFinalRelease)
115
117
{
116
118
    LogFlowThisFuncEnter();
117
 
    LogFlowThisFunc (("aFinalRelease=%d\n", aFinalRelease));
 
119
    LogFlowThisFunc(("aFinalRelease=%d\n", aFinalRelease));
118
120
 
119
121
    /* Enclose the state transition Ready->InUninit->NotReady */
120
 
    AutoUninitSpan autoUninitSpan (this);
 
122
    AutoUninitSpan autoUninitSpan(this);
121
123
    if (autoUninitSpan.uninitDone())
122
124
    {
123
 
        LogFlowThisFunc (("Already uninitialized.\n"));
 
125
        LogFlowThisFunc(("Already uninitialized.\n"));
124
126
        LogFlowThisFuncLeave();
125
127
        return;
126
128
    }
127
129
 
128
130
    /* close() needs write lock */
129
 
    AutoWriteLock alock (this);
 
131
    AutoWriteLock alock(this);
130
132
 
131
133
    if (mState != SessionState_Closed)
132
134
    {
147
149
{
148
150
    CheckComArgOutPointerValid(aState);
149
151
 
150
 
    AutoCaller autoCaller (this);
151
 
    CheckComRCReturnRC (autoCaller.rc());
 
152
    AutoCaller autoCaller(this);
 
153
    CheckComRCReturnRC(autoCaller.rc());
152
154
 
153
 
    AutoReadLock alock (this);
 
155
    AutoReadLock alock(this);
154
156
 
155
157
    *aState = mState;
156
158
 
161
163
{
162
164
    CheckComArgOutPointerValid(aType);
163
165
 
164
 
    AutoCaller autoCaller (this);
165
 
    CheckComRCReturnRC (autoCaller.rc());
 
166
    AutoCaller autoCaller(this);
 
167
    CheckComRCReturnRC(autoCaller.rc());
166
168
 
167
 
    AutoReadLock alock (this);
 
169
    AutoReadLock alock(this);
168
170
 
169
171
    CHECK_OPEN();
170
172
 
176
178
{
177
179
    CheckComArgOutPointerValid(aMachine);
178
180
 
179
 
    AutoCaller autoCaller (this);
180
 
    CheckComRCReturnRC (autoCaller.rc());
 
181
    AutoCaller autoCaller(this);
 
182
    CheckComRCReturnRC(autoCaller.rc());
181
183
 
182
 
    AutoReadLock alock (this);
 
184
    AutoReadLock alock(this);
183
185
 
184
186
    CHECK_OPEN();
185
187
 
186
188
    HRESULT rc = E_FAIL;
187
189
 
188
190
    if (mConsole)
189
 
        rc = mConsole->machine().queryInterfaceTo (aMachine);
 
191
        rc = mConsole->machine().queryInterfaceTo(aMachine);
190
192
    else
191
 
        rc = mRemoteMachine.queryInterfaceTo (aMachine);
 
193
        rc = mRemoteMachine.queryInterfaceTo(aMachine);
192
194
    ComAssertComRC (rc);
193
195
 
194
196
    return rc;
198
200
{
199
201
    CheckComArgOutPointerValid(aConsole);
200
202
 
201
 
    AutoCaller autoCaller (this);
202
 
    CheckComRCReturnRC (autoCaller.rc());
 
203
    AutoCaller autoCaller(this);
 
204
    CheckComRCReturnRC(autoCaller.rc());
203
205
 
204
 
    AutoReadLock alock (this);
 
206
    AutoReadLock alock(this);
205
207
 
206
208
    CHECK_OPEN();
207
209
 
208
210
    HRESULT rc = E_FAIL;
209
211
 
210
212
    if (mConsole)
211
 
        rc = mConsole.queryInterfaceTo (aConsole);
 
213
        rc = mConsole.queryInterfaceTo(aConsole);
212
214
    else
213
 
        rc = mRemoteConsole.queryInterfaceTo (aConsole);
 
215
        rc = mRemoteConsole.queryInterfaceTo(aConsole);
214
216
    ComAssertComRC (rc);
215
217
 
216
218
    return rc;
221
223
 
222
224
STDMETHODIMP Session::Close()
223
225
{
224
 
    LogFlowThisFunc (("mState=%d, mType=%d\n", mState, mType));
 
226
    LogFlowThisFunc(("mState=%d, mType=%d\n", mState, mType));
225
227
 
226
 
    AutoCaller autoCaller (this);
227
 
    CheckComRCReturnRC (autoCaller.rc());
 
228
    AutoCaller autoCaller(this);
 
229
    CheckComRCReturnRC(autoCaller.rc());
228
230
 
229
231
    /* close() needs write lock */
230
 
    AutoWriteLock alock (this);
 
232
    AutoWriteLock alock(this);
231
233
 
232
234
    CHECK_OPEN();
233
235
 
239
241
 
240
242
STDMETHODIMP Session::GetPID (ULONG *aPid)
241
243
{
242
 
    AssertReturn (aPid, E_POINTER);
 
244
    AssertReturn(aPid, E_POINTER);
243
245
 
244
 
    AutoCaller autoCaller (this);
 
246
    AutoCaller autoCaller(this);
245
247
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
246
248
 
247
 
    AutoReadLock alock (this);
 
249
    AutoReadLock alock(this);
248
250
 
249
251
    *aPid = (ULONG) RTProcSelf();
250
252
    AssertCompile (sizeof (*aPid) == sizeof (RTPROCESS));
255
257
STDMETHODIMP Session::GetRemoteConsole (IConsole **aConsole)
256
258
{
257
259
    LogFlowThisFuncEnter();
258
 
    AssertReturn (aConsole, E_POINTER);
 
260
    AssertReturn(aConsole, E_POINTER);
259
261
 
260
 
    AutoCaller autoCaller (this);
 
262
    AutoCaller autoCaller(this);
261
263
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
262
264
 
263
 
    AutoReadLock alock (this);
 
265
    AutoReadLock alock(this);
264
266
 
265
 
    AssertReturn (mState != SessionState_Closed, VBOX_E_INVALID_VM_STATE);
 
267
    AssertReturn(mState != SessionState_Closed, VBOX_E_INVALID_VM_STATE);
266
268
 
267
269
    AssertMsgReturn (mType == SessionType_Direct && !!mConsole,
268
270
      ("This is not a direct session!\n"), VBOX_E_INVALID_OBJECT_STATE);
272
274
    if (mState != SessionState_Open)
273
275
        return VBOX_E_INVALID_VM_STATE;
274
276
 
275
 
    mConsole.queryInterfaceTo (aConsole);
 
277
    mConsole.queryInterfaceTo(aConsole);
276
278
 
277
279
    LogFlowThisFuncLeave();
278
280
 
282
284
STDMETHODIMP Session::AssignMachine (IMachine *aMachine)
283
285
{
284
286
    LogFlowThisFuncEnter();
285
 
    LogFlowThisFunc (("aMachine=%p\n", aMachine));
 
287
    LogFlowThisFunc(("aMachine=%p\n", aMachine));
286
288
 
287
 
    AutoCaller autoCaller (this);
 
289
    AutoCaller autoCaller(this);
288
290
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
289
291
 
290
 
    AutoWriteLock alock (this);
 
292
    AutoWriteLock alock(this);
291
293
 
292
 
    AssertReturn (mState == SessionState_Closed, VBOX_E_INVALID_VM_STATE);
 
294
    AssertReturn(mState == SessionState_Closed, VBOX_E_INVALID_VM_STATE);
293
295
 
294
296
    if (!aMachine)
295
297
    {
300
302
         *  called.
301
303
         */
302
304
 
303
 
        AssertReturn (mType == SessionType_Null, VBOX_E_INVALID_OBJECT_STATE);
 
305
        AssertReturn(mType == SessionType_Null, VBOX_E_INVALID_OBJECT_STATE);
304
306
        mType = SessionType_Remote;
305
307
        mState = SessionState_Spawning;
306
308
 
312
314
 
313
315
    /* query IInternalMachineControl interface */
314
316
    mControl = aMachine;
315
 
    AssertReturn (!!mControl, E_FAIL);
 
317
    AssertReturn(!!mControl, E_FAIL);
316
318
 
317
319
    rc = mConsole.createObject();
318
320
    AssertComRCReturn (rc, rc);
326
328
     *  Reference the VirtualBox object to ensure the server is up
327
329
     *  until the session is closed
328
330
     */
329
 
    if (SUCCEEDED (rc))
 
331
    if (SUCCEEDED(rc))
330
332
       rc = aMachine->COMGETTER(Parent) (mVirtualBox.asOutParam());
331
333
 
332
 
    if (SUCCEEDED (rc))
333
 
    {
 
334
    if (SUCCEEDED(rc))
 
335
    {        
334
336
        mType = SessionType_Direct;
335
337
        mState = SessionState_Open;
336
338
    }
342
344
        mConsole.setNull();
343
345
    }
344
346
 
345
 
    LogFlowThisFunc (("rc=%08X\n", rc));
 
347
    LogFlowThisFunc(("rc=%08X\n", rc));
346
348
    LogFlowThisFuncLeave();
347
349
 
348
350
    return rc;
351
353
STDMETHODIMP Session::AssignRemoteMachine (IMachine *aMachine, IConsole *aConsole)
352
354
{
353
355
    LogFlowThisFuncEnter();
354
 
    LogFlowThisFunc (("aMachine=%p, aConsole=%p\n", aMachine, aConsole));
355
 
 
356
 
    AssertReturn (aMachine && aConsole, E_INVALIDARG);
357
 
 
358
 
    AutoCaller autoCaller (this);
 
356
    LogFlowThisFunc(("aMachine=%p, aConsole=%p\n", aMachine, aConsole));
 
357
 
 
358
    AssertReturn(aMachine && aConsole, E_INVALIDARG);
 
359
 
 
360
    AutoCaller autoCaller(this);
359
361
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
360
362
 
361
 
    AutoWriteLock alock (this);
 
363
    AutoWriteLock alock(this);
362
364
 
363
 
    AssertReturn (mState == SessionState_Closed ||
 
365
    AssertReturn(mState == SessionState_Closed ||
364
366
                  mState == SessionState_Spawning, VBOX_E_INVALID_VM_STATE);
365
367
 
366
368
    HRESULT rc = E_FAIL;
367
369
 
368
370
    /* query IInternalMachineControl interface */
369
371
    mControl = aMachine;
370
 
    AssertReturn (!!mControl, E_FAIL); // This test appears to be redundant --JS
 
372
    AssertReturn(!!mControl, E_FAIL); // This test appears to be redundant --JS
371
373
 
372
374
    /// @todo (dmik)
373
375
    //      currently, the remote session returns the same machine and
394
396
     */
395
397
    rc = aMachine->COMGETTER(Parent) (mVirtualBox.asOutParam());
396
398
 
397
 
    if (SUCCEEDED (rc))
 
399
    if (SUCCEEDED(rc))
398
400
    {
399
401
        /*
400
402
         *  RemoteSession type can be already set by AssignMachine() when its
415
417
        mRemoteConsole.setNull();
416
418
    }
417
419
 
418
 
    LogFlowThisFunc (("rc=%08X\n", rc));
 
420
    LogFlowThisFunc(("rc=%08X\n", rc));
419
421
    LogFlowThisFuncLeave();
420
422
 
421
423
    return rc;
423
425
 
424
426
STDMETHODIMP Session::UpdateMachineState (MachineState_T aMachineState)
425
427
{
426
 
    AutoCaller autoCaller (this);
 
428
    AutoCaller autoCaller(this);
427
429
 
428
430
    if (autoCaller.state() != Ready)
429
431
    {
431
433
         *  We might have already entered Session::uninit() at this point, so
432
434
         *  return silently (not interested in the state change during uninit)
433
435
         */
434
 
        LogFlowThisFunc (("Already uninitialized.\n"));
 
436
        LogFlowThisFunc(("Already uninitialized.\n"));
435
437
        return S_OK;
436
438
    }
437
439
 
438
 
    AutoReadLock alock (this);
 
440
    AutoReadLock alock(this);
439
441
 
440
442
    if (mState == SessionState_Closing)
441
443
    {
442
 
        LogFlowThisFunc (("Already being closed.\n"));
 
444
        LogFlowThisFunc(("Already being closed.\n"));
443
445
        return S_OK;
444
446
    }
445
447
 
446
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
447
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
448
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
449
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
448
450
 
449
 
    AssertReturn (!mControl.isNull(), E_FAIL);
450
 
    AssertReturn (!mConsole.isNull(), E_FAIL);
 
451
    AssertReturn(!mControl.isNull(), E_FAIL);
 
452
    AssertReturn(!mConsole.isNull(), E_FAIL);
451
453
 
452
454
    return mConsole->updateMachineState (aMachineState);
453
455
}
456
458
{
457
459
    LogFlowThisFuncEnter();
458
460
 
459
 
    AutoCaller autoCaller (this);
 
461
    AutoCaller autoCaller(this);
460
462
 
461
463
    HRESULT rc = S_OK;
462
464
 
463
465
    if (autoCaller.state() == Ready)
464
466
    {
465
467
        /* close() needs write lock */
466
 
        AutoWriteLock alock (this);
 
468
        AutoWriteLock alock(this);
467
469
 
468
 
        LogFlowThisFunc (("mState=%d, mType=%d\n", mState, mType));
 
470
        LogFlowThisFunc(("mState=%s, mType=%d\n", Global::stringifySessionState(mState), mType));
469
471
 
470
472
        if (mState == SessionState_Closing)
471
473
        {
472
 
            LogFlowThisFunc (("Already being closed.\n"));
 
474
            LogFlowThisFunc(("Already being closed.\n"));
473
475
            return S_OK;
474
476
        }
475
477
 
476
 
        AssertReturn (mState == SessionState_Open ||
 
478
        AssertReturn(mState == SessionState_Open ||
477
479
                      mState == SessionState_Spawning, VBOX_E_INVALID_VM_STATE);
478
480
 
479
481
        /* close ourselves */
485
487
         *  We might have already entered Session::uninit() at this point,
486
488
         *  return silently
487
489
         */
488
 
        LogFlowThisFunc (("Already uninitialized.\n"));
 
490
        LogFlowThisFunc(("Already uninitialized.\n"));
489
491
    }
490
492
    else
491
493
    {
492
 
        LogWarningThisFunc (("UNEXPECTED uninitialization!\n"));
 
494
        LogWarningThisFunc(("UNEXPECTED uninitialization!\n"));
493
495
        rc = autoCaller.rc();
494
496
    }
495
497
 
496
 
    LogFlowThisFunc (("rc=%08X\n", rc));
 
498
    LogFlowThisFunc(("rc=%08X\n", rc));
497
499
    LogFlowThisFuncLeave();
498
500
 
499
501
    return rc;
500
502
}
501
503
 
502
 
STDMETHODIMP Session::OnDVDDriveChange()
503
 
{
504
 
    LogFlowThisFunc (("\n"));
505
 
 
506
 
    AutoCaller autoCaller (this);
507
 
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
508
 
 
509
 
    AutoReadLock alock (this);
510
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
511
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
512
 
 
513
 
    return mConsole->onDVDDriveChange();
514
 
}
515
 
 
516
 
STDMETHODIMP Session::OnFloppyDriveChange()
517
 
{
518
 
    LogFlowThisFunc (("\n"));
519
 
 
520
 
    AutoCaller autoCaller (this);
521
 
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
522
 
 
523
 
    AutoReadLock alock (this);
524
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
525
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
526
 
 
527
 
    return mConsole->onFloppyDriveChange();
528
 
}
529
 
 
530
 
STDMETHODIMP Session::OnNetworkAdapterChange(INetworkAdapter *networkAdapter)
531
 
{
532
 
    LogFlowThisFunc (("\n"));
533
 
 
534
 
    AutoCaller autoCaller (this);
535
 
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
536
 
 
537
 
    AutoReadLock alock (this);
538
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
539
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
540
 
 
541
 
    return mConsole->onNetworkAdapterChange(networkAdapter);
 
504
STDMETHODIMP Session::OnNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter)
 
505
{
 
506
    LogFlowThisFunc(("\n"));
 
507
 
 
508
    AutoCaller autoCaller(this);
 
509
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
 
510
 
 
511
    AutoReadLock alock(this);
 
512
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
513
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
514
 
 
515
    return mConsole->onNetworkAdapterChange(networkAdapter, changeAdapter);
542
516
}
543
517
 
544
518
STDMETHODIMP Session::OnSerialPortChange(ISerialPort *serialPort)
545
519
{
546
 
    LogFlowThisFunc (("\n"));
 
520
    LogFlowThisFunc(("\n"));
547
521
 
548
 
    AutoCaller autoCaller (this);
 
522
    AutoCaller autoCaller(this);
549
523
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
550
524
 
551
 
    AutoReadLock alock (this);
552
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
553
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
525
    AutoReadLock alock(this);
 
526
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
527
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
554
528
 
555
529
    return mConsole->onSerialPortChange(serialPort);
556
530
}
557
531
 
558
532
STDMETHODIMP Session::OnParallelPortChange(IParallelPort *parallelPort)
559
533
{
560
 
    LogFlowThisFunc (("\n"));
 
534
    LogFlowThisFunc(("\n"));
561
535
 
562
 
    AutoCaller autoCaller (this);
 
536
    AutoCaller autoCaller(this);
563
537
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
564
538
 
565
 
    AutoReadLock alock (this);
566
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
567
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
539
    AutoReadLock alock(this);
 
540
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
541
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
568
542
 
569
543
    return mConsole->onParallelPortChange(parallelPort);
570
544
}
571
545
 
572
546
STDMETHODIMP Session::OnStorageControllerChange()
573
547
{
574
 
    LogFlowThisFunc (("\n"));
 
548
    LogFlowThisFunc(("\n"));
575
549
 
576
 
    AutoCaller autoCaller (this);
 
550
    AutoCaller autoCaller(this);
577
551
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
578
552
 
579
 
    AutoReadLock alock (this);
580
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
581
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
553
    AutoReadLock alock(this);
 
554
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
555
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
582
556
 
583
557
    return mConsole->onStorageControllerChange();
584
558
}
585
559
 
 
560
STDMETHODIMP Session::OnMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce)
 
561
{
 
562
    LogFlowThisFunc(("\n"));
 
563
 
 
564
    AutoCaller autoCaller(this);
 
565
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
 
566
 
 
567
    AutoReadLock alock(this);
 
568
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
569
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
570
 
 
571
    return mConsole->onMediumChange(aMediumAttachment, aForce);
 
572
}
 
573
 
586
574
STDMETHODIMP Session::OnVRDPServerChange()
587
575
{
588
 
    LogFlowThisFunc (("\n"));
 
576
    LogFlowThisFunc(("\n"));
589
577
 
590
 
    AutoCaller autoCaller (this);
 
578
    AutoCaller autoCaller(this);
591
579
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
592
580
 
593
 
    AutoReadLock alock (this);
594
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
595
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
581
    AutoReadLock alock(this);
 
582
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
583
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
596
584
 
597
585
    return mConsole->onVRDPServerChange();
598
586
}
599
587
 
600
588
STDMETHODIMP Session::OnUSBControllerChange()
601
589
{
602
 
    LogFlowThisFunc (("\n"));
 
590
    LogFlowThisFunc(("\n"));
603
591
 
604
 
    AutoCaller autoCaller (this);
 
592
    AutoCaller autoCaller(this);
605
593
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
606
594
 
607
 
    AutoReadLock alock (this);
608
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
609
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
595
    AutoReadLock alock(this);
 
596
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
597
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
610
598
 
611
599
    return mConsole->onUSBControllerChange();
612
600
}
613
601
 
614
602
STDMETHODIMP Session::OnSharedFolderChange (BOOL aGlobal)
615
603
{
616
 
    LogFlowThisFunc (("\n"));
 
604
    LogFlowThisFunc(("\n"));
617
605
 
618
 
    AutoCaller autoCaller (this);
 
606
    AutoCaller autoCaller(this);
619
607
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
620
608
 
621
 
    AutoReadLock alock (this);
622
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
623
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
609
    AutoReadLock alock(this);
 
610
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
611
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
624
612
 
625
613
    return mConsole->onSharedFolderChange (aGlobal);
626
614
}
629
617
                                         IVirtualBoxErrorInfo *aError,
630
618
                                         ULONG aMaskedIfs)
631
619
{
632
 
    LogFlowThisFunc (("\n"));
 
620
    LogFlowThisFunc(("\n"));
633
621
 
634
 
    AutoCaller autoCaller (this);
 
622
    AutoCaller autoCaller(this);
635
623
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
636
624
 
637
 
    AutoReadLock alock (this);
638
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
639
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
625
    AutoReadLock alock(this);
 
626
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
627
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
640
628
 
641
629
    return mConsole->onUSBDeviceAttach (aDevice, aError, aMaskedIfs);
642
630
}
644
632
STDMETHODIMP Session::OnUSBDeviceDetach (IN_BSTR aId,
645
633
                                         IVirtualBoxErrorInfo *aError)
646
634
{
647
 
    LogFlowThisFunc (("\n"));
 
635
    LogFlowThisFunc(("\n"));
648
636
 
649
 
    AutoCaller autoCaller (this);
 
637
    AutoCaller autoCaller(this);
650
638
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
651
639
 
652
 
    AutoReadLock alock (this);
653
 
    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
654
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
640
    AutoReadLock alock(this);
 
641
    AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
 
642
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
655
643
 
656
644
    return mConsole->onUSBDeviceDetach (aId, aError);
657
645
}
658
646
 
659
647
STDMETHODIMP Session::OnShowWindow (BOOL aCheck, BOOL *aCanShow, ULONG64 *aWinId)
660
648
{
661
 
    AutoCaller autoCaller (this);
 
649
    AutoCaller autoCaller(this);
662
650
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
663
651
 
664
 
    AutoReadLock alock (this);
 
652
    AutoReadLock alock(this);
665
653
 
666
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
654
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
667
655
 
668
656
    if (mState != SessionState_Open)
669
657
    {
683
671
                                           BOOL aIsSetter, BSTR *aRetValue, ULONG64 *aRetTimestamp, BSTR *aRetFlags)
684
672
{
685
673
#ifdef VBOX_WITH_GUEST_PROPS
686
 
    AutoCaller autoCaller (this);
 
674
    AutoCaller autoCaller(this);
687
675
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
688
676
 
689
677
    if (mState != SessionState_Open)
690
678
        return setError (VBOX_E_INVALID_VM_STATE,
691
 
            tr ("Machine session is not open (session state: %d)."),
692
 
            mState);
693
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
679
            tr ("Machine session is not open (session state: %s)."),
 
680
            Global::stringifySessionState(mState));
 
681
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
694
682
    CheckComArgNotNull(aName);
695
683
    if (!aIsSetter && !VALID_PTR (aRetValue))
696
684
        return E_POINTER;
720
708
                                                ComSafeArrayOut(BSTR, aFlags))
721
709
{
722
710
#ifdef VBOX_WITH_GUEST_PROPS
723
 
    AutoCaller autoCaller (this);
 
711
    AutoCaller autoCaller(this);
724
712
    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
725
713
 
726
714
    if (mState != SessionState_Open)
727
715
        return setError (VBOX_E_INVALID_VM_STATE,
728
 
            tr ("Machine session is not open (session state: %d)."),
729
 
            mState);
730
 
    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
716
            tr ("Machine session is not open (session state: %s)."),
 
717
            Global::stringifySessionState(mState));
 
718
    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
731
719
    if (!VALID_PTR (aPatterns) && (aPatterns != NULL))
732
720
        return E_POINTER;
733
 
    if (ComSafeArrayOutIsNull (aNames))
734
 
        return E_POINTER;
735
 
    if (ComSafeArrayOutIsNull (aValues))
736
 
        return E_POINTER;
737
 
    if (ComSafeArrayOutIsNull (aTimestamps))
738
 
        return E_POINTER;
739
 
    if (ComSafeArrayOutIsNull (aFlags))
 
721
    if (ComSafeArrayOutIsNull(aNames))
 
722
        return E_POINTER;
 
723
    if (ComSafeArrayOutIsNull(aValues))
 
724
        return E_POINTER;
 
725
    if (ComSafeArrayOutIsNull(aTimestamps))
 
726
        return E_POINTER;
 
727
    if (ComSafeArrayOutIsNull(aFlags))
740
728
        return E_POINTER;
741
729
    return mConsole->enumerateGuestProperties(aPatterns,
742
730
                                              ComSafeArrayOutArg(aNames),
763
751
HRESULT Session::close (bool aFinalRelease, bool aFromServer)
764
752
{
765
753
    LogFlowThisFuncEnter();
766
 
    LogFlowThisFunc (("aFinalRelease=%d, isFromServer=%d\n",
 
754
    LogFlowThisFunc(("aFinalRelease=%d, isFromServer=%d\n",
767
755
                      aFinalRelease, aFromServer));
768
756
 
769
 
    AutoCaller autoCaller (this);
770
 
    AssertComRCReturnRC (autoCaller.rc());
771
 
 
772
 
    AutoWriteLock alock (this);
773
 
 
774
 
    LogFlowThisFunc (("mState=%d, mType=%d\n", mState, mType));
 
757
    AutoCaller autoCaller(this);
 
758
    AssertComRCReturnRC(autoCaller.rc());
 
759
 
 
760
    AutoWriteLock alock(this);
 
761
 
 
762
    LogFlowThisFunc(("mState=%s, mType=%d\n", Global::stringifySessionState(mState), mType));
775
763
 
776
764
    if (mState != SessionState_Open)
777
765
    {
804
792
    }
805
793
 
806
794
    /* go to the closing state */
807
 
    mState =  SessionState_Closing;
 
795
    mState = SessionState_Closing;
808
796
 
809
797
    if (mType == SessionType_Direct)
810
798
    {
817
805
        mRemoteConsole.setNull();
818
806
    }
819
807
 
820
 
    ComPtr <IProgress> progress;
 
808
    ComPtr<IProgress> progress;
821
809
 
822
810
    if (!aFinalRelease && !aFromServer)
823
811
    {
840
828
         */
841
829
        alock.leave();
842
830
 
843
 
        LogFlowThisFunc (("Calling mControl->OnSessionEnd()...\n"));
 
831
        LogFlowThisFunc(("Calling mControl->OnSessionEnd()...\n"));
844
832
        HRESULT rc = mControl->OnSessionEnd (this, progress.asOutParam());
845
 
        LogFlowThisFunc (("mControl->OnSessionEnd()=%08X\n", rc));
 
833
        LogFlowThisFunc(("mControl->OnSessionEnd()=%08X\n", rc));
846
834
 
847
835
        alock.enter();
848
836
 
892
880
    /* open the IPC semaphore based on the sessionId and try to grab it */
893
881
    Bstr ipcId;
894
882
    rc = mControl->GetIPCId (ipcId.asOutParam());
895
 
    AssertComRCReturnRC (rc);
 
883
    AssertComRCReturnRC(rc);
896
884
 
897
 
    LogFlowThisFunc (("ipcId='%ls'\n", ipcId.raw()));
 
885
    LogFlowThisFunc(("ipcId='%ls'\n", ipcId.raw()));
898
886
 
899
887
#if defined(RT_OS_WINDOWS)
900
888
 
961
949
 
962
950
    /* wait until thread init is completed */
963
951
    vrc = RTThreadUserWait (mIPCThread, RT_INDEFINITE_WAIT);
964
 
    AssertReturn (RT_SUCCESS (vrc) || vrc == VERR_INTERRUPTED, E_FAIL);
 
952
    AssertReturn(RT_SUCCESS(vrc) || vrc == VERR_INTERRUPTED, E_FAIL);
965
953
 
966
954
    /* the thread must succeed */
967
 
    AssertReturn ((bool) data [2], E_FAIL);
 
955
    AssertReturn((bool) data [2], E_FAIL);
968
956
 
969
957
#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
970
958
 
1034
1022
 
1035
1023
        /* wait for the thread to finish */
1036
1024
        vrc = RTThreadUserWait (mIPCThread, RT_INDEFINITE_WAIT);
1037
 
        Assert (RT_SUCCESS (vrc) || vrc == VERR_INTERRUPTED);
 
1025
        Assert (RT_SUCCESS(vrc) || vrc == VERR_INTERRUPTED);
1038
1026
 
1039
1027
        mIPCThread = NIL_RTTHREAD;
1040
1028
    }