VirtualBox

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

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

Main: Logging.

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
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 /** Get a unique and somewhat descriptive name for logging. */
112 const char *logName(void) const { return mLogName.c_str(); }
113
114 /** For com::SupportErrorInfoImpl. */
115 static const char *ComponentName() { return "MediumAttachment"; }
116
117private:
118
119 /** Reference to Machine object, for checking mutable state. */
120 const ComObjPtr<Machine, ComWeakRef> mParent;
121 /* later: const ComObjPtr<MediumAttachment> mPeer; */
122
123 struct Data
124 {
125 Data() : port(0), device(0), type(DeviceType_Null),
126 passthrough(false), implicit(false) {}
127
128 bool operator== (const Data &that) const
129 {
130 return this == &that
131 || (passthrough == that.passthrough);
132 }
133
134 ComObjPtr<Medium> medium;
135 /* Since MediumAttachment is not a first class citizen when it
136 * comes to managing settings, having a reference to the storage
137 * controller will not work - when settings are changed it will point
138 * to the old, uninitialized instance. Changing this requires
139 * substantial changes to MediumImpl.cpp. */
140 const Bstr controllerName;
141 const LONG port;
142 const LONG device;
143 const DeviceType_T type;
144 bool passthrough : 1;
145 bool implicit : 1;
146 };
147
148 Backupable<Data> m;
149
150 Utf8Str mLogName; /**< For logging purposes */
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