VirtualBox

source: vbox/trunk/src/VBox/Main/include/MediumAttachmentImpl.h@ 24155

Last change on this file since 24155 was 24155, checked in by vboxsync, 15 years ago

Main: call medium->detachFrom() on the medium which just got detached

File size: 4.9 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ____H_MEDIUMATTACHMENTIMPL
23#define ____H_MEDIUMATTACHMENTIMPL
24
25#include "VirtualBoxBase.h"
26
27#include "MediumImpl.h"
28#include "StorageControllerImpl.h"
29
30class Machine;
31class Medium;
32
33class ATL_NO_VTABLE MediumAttachment :
34 public VirtualBoxBase,
35 public com::SupportErrorInfoImpl<MediumAttachment, IMediumAttachment>,
36 public VirtualBoxSupportTranslation<MediumAttachment>,
37 VBOX_SCRIPTABLE_IMPL(IMediumAttachment)
38{
39public:
40
41 DECLARE_NOT_AGGREGATABLE(MediumAttachment)
42
43 DECLARE_PROTECT_FINAL_CONSTRUCT()
44
45 BEGIN_COM_MAP(MediumAttachment)
46 COM_INTERFACE_ENTRY(ISupportErrorInfo)
47 COM_INTERFACE_ENTRY(IMediumAttachment)
48 COM_INTERFACE_ENTRY(IDispatch)
49 END_COM_MAP()
50
51 DECLARE_EMPTY_CTOR_DTOR(MediumAttachment)
52
53 // public initializer/uninitializer for internal purposes only
54 HRESULT init(Machine *aParent,
55 Medium *aMedium,
56 const Bstr &aControllerName,
57 LONG aPort,
58 LONG aDevice,
59 DeviceType_T aType,
60 bool aImplicit = false);
61 void uninit();
62
63 HRESULT FinalConstruct();
64 void FinalRelease();
65
66 bool rollback();
67 void commit();
68
69 // IMediumAttachment properties
70 STDMETHOD(COMGETTER(Medium))(IMedium **aMedium);
71 STDMETHOD(COMGETTER(Controller))(IStorageController **aController);
72 STDMETHOD(COMGETTER(Port))(LONG *aPort);
73 STDMETHOD(COMGETTER(Device))(LONG *aDevice);
74 STDMETHOD(COMGETTER(Type))(DeviceType_T *aType);
75 STDMETHOD(COMGETTER(Passthrough))(BOOL *aPassthrough);
76
77 // unsafe inline public methods for internal purposes only (ensure there is
78 // a caller and a read lock before calling them!)
79
80 bool isImplicit() const { return m->implicit; }
81 void setImplicit(bool aImplicit) { m->implicit = aImplicit; }
82
83 const ComObjPtr<Medium> &medium() const { return m->medium; }
84 Bstr controllerName() const { return m->controllerName; }
85 LONG port() const { return m->port; }
86 LONG device() const { return m->device; }
87 DeviceType_T type() const { return m->type; }
88 bool passthrough() const { AutoReadLock lock(this); return m->passthrough; }
89
90 bool matches(CBSTR aControllerName, LONG aPort, LONG aDevice)
91 {
92 return ( aControllerName == m->controllerName
93 && aPort == m->port
94 && aDevice == m->device);
95 }
96
97 /** Must be called from under this object's write lock. */
98 void updateMedium(const ComObjPtr<Medium> &aMedium,
99 bool aImplicit,
100 const Guid &aMachineId = Guid::Empty)
101 {
102 m.backup();
103 if (m->medium && aMachineId)
104 m->medium->detachFrom(aMachineId);
105 m->medium = aMedium;
106 m->implicit = aImplicit;
107 }
108
109 /** Must be called from under this object's write lock. */
110 void updatePassthrough(bool aPassthrough)
111 {
112 m.backup();
113 m->passthrough = aPassthrough;
114 }
115
116 /** For com::SupportErrorInfoImpl. */
117 static const char *ComponentName() { return "MediumAttachment"; }
118
119private:
120
121 /** Reference to Machine object, for checking mutable state. */
122 const ComObjPtr<Machine, ComWeakRef> mParent;
123 /* later: const ComObjPtr<MediumAttachment> mPeer; */
124
125 struct Data
126 {
127 Data() : port(0), device(0), type(DeviceType_Null),
128 passthrough(false), implicit(false) {}
129
130 bool operator== (const Data &that) const
131 {
132 return this == &that
133 || (passthrough == that.passthrough);
134 }
135
136 ComObjPtr<Medium> medium;
137 /* Since MediumAttachment is not a first class citizen when it
138 * comes to managing settings, having a reference to the storage
139 * controller will not work - when settings are changed it will point
140 * to the old, uninitialized instance. Changing this requires
141 * substantial changes to MediumImpl.cpp. */
142 Bstr controllerName;
143 const LONG port;
144 const LONG device;
145 const DeviceType_T type;
146 bool passthrough : 1;
147 bool implicit : 1;
148 };
149
150 Backupable<Data> m;
151};
152
153#endif // ____H_MEDIUMATTACHMENTIMPL
154/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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