VirtualBox

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

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

Main/MediumAttchment: back out API change which changed the return type of the Controller attribute from string to IStorageController *

File size: 4.7 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
29class Machine;
30class Medium;
31
32class ATL_NO_VTABLE MediumAttachment :
33 public VirtualBoxBase,
34 public com::SupportErrorInfoImpl<MediumAttachment, IMediumAttachment>,
35 public VirtualBoxSupportTranslation<MediumAttachment>,
36 VBOX_SCRIPTABLE_IMPL(IMediumAttachment)
37{
38public:
39
40 DECLARE_NOT_AGGREGATABLE(MediumAttachment)
41
42 DECLARE_PROTECT_FINAL_CONSTRUCT()
43
44 BEGIN_COM_MAP(MediumAttachment)
45 COM_INTERFACE_ENTRY(ISupportErrorInfo)
46 COM_INTERFACE_ENTRY(IMediumAttachment)
47 COM_INTERFACE_ENTRY(IDispatch)
48 END_COM_MAP()
49
50 DECLARE_EMPTY_CTOR_DTOR(MediumAttachment)
51
52 // public initializer/uninitializer for internal purposes only
53 HRESULT init(Machine *aParent,
54 Medium *aMedium,
55 const Bstr &aControllerName,
56 LONG aPort,
57 LONG aDevice,
58 DeviceType_T aType,
59 bool aImplicit = false);
60 void uninit();
61
62 HRESULT FinalConstruct();
63 void FinalRelease();
64
65 bool rollback();
66 void commit();
67
68 // IMediumAttachment properties
69 STDMETHOD(COMGETTER(Medium))(IMedium **aMedium);
70 STDMETHOD(COMGETTER(Controller))(BSTR *aController);
71 STDMETHOD(COMGETTER(Port))(LONG *aPort);
72 STDMETHOD(COMGETTER(Device))(LONG *aDevice);
73 STDMETHOD(COMGETTER(Type))(DeviceType_T *aType);
74 STDMETHOD(COMGETTER(Passthrough))(BOOL *aPassthrough);
75
76 // unsafe inline public methods for internal purposes only (ensure there is
77 // a caller and a read lock before calling them!)
78
79 bool isImplicit() const { return m->implicit; }
80 void setImplicit(bool aImplicit) { m->implicit = aImplicit; }
81
82 const ComObjPtr<Medium> &medium() const { return m->medium; }
83 Bstr controllerName() const { return m->controllerName; }
84 LONG port() const { return m->port; }
85 LONG device() const { return m->device; }
86 DeviceType_T type() const { return m->type; }
87 bool passthrough() const { AutoReadLock lock(this); return m->passthrough; }
88
89 bool matches(CBSTR aControllerName, LONG aPort, LONG aDevice)
90 {
91 return ( aControllerName == m->controllerName
92 && aPort == m->port
93 && aDevice == m->device);
94 }
95
96 /** Must be called from under this object's write lock. */
97 void updateMedium(const ComObjPtr<Medium> &aMedium, bool aImplicit)
98 {
99 m.backup();
100 m->medium = aMedium;
101 m->implicit = aImplicit;
102 }
103
104 /** Must be called from under this object's write lock. */
105 void updatePassthrough(bool aPassthrough)
106 {
107 m.backup();
108 m->passthrough = aPassthrough;
109 }
110
111 /** For com::SupportErrorInfoImpl. */
112 static const char *ComponentName() { return "MediumAttachment"; }
113
114private:
115
116 /** Reference to Machine object, for checking mutable state. */
117 const ComObjPtr<Machine, ComWeakRef> mParent;
118 /* later: const ComObjPtr<MediumAttachment> mPeer; */
119
120 struct Data
121 {
122 Data() : port(0), device(0), type(DeviceType_Null),
123 passthrough(false), implicit(false) {}
124
125 bool operator== (const Data &that) const
126 {
127 return this == &that
128 || (passthrough == that.passthrough);
129 }
130
131 ComObjPtr<Medium> medium;
132 /* Since MediumAttachment is not a first class citizen when it
133 * comes to managing settings, having a reference to the storage
134 * controller will not work - when settings are changed it will point
135 * to the old, uninitialized instance. Changing this requires
136 * substantial changes to MediumImpl.cpp. */
137 const Bstr controllerName;
138 const LONG port;
139 const LONG device;
140 const DeviceType_T type;
141 bool passthrough : 1;
142 bool implicit : 1;
143 };
144
145 Backupable<Data> m;
146};
147
148#endif // ____H_MEDIUMATTACHMENTIMPL
149/* 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