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 |
|
---|
29 | class Machine;
|
---|
30 | class Medium;
|
---|
31 |
|
---|
32 | class ATL_NO_VTABLE MediumAttachment :
|
---|
33 | public VirtualBoxBase,
|
---|
34 | public com::SupportErrorInfoImpl<MediumAttachment, IMediumAttachment>,
|
---|
35 | public VirtualBoxSupportTranslation<MediumAttachment>,
|
---|
36 | VBOX_SCRIPTABLE_IMPL(IMediumAttachment)
|
---|
37 | {
|
---|
38 | public:
|
---|
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 | CBSTR aController,
|
---|
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 | STDMETHOD(COMSETTER(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 controller() const { return m->controller; }
|
---|
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 aController, LONG aPort, LONG aDevice)
|
---|
91 | {
|
---|
92 | return ( aController == m->controller
|
---|
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, bool aImplicit)
|
---|
99 | {
|
---|
100 | m.backup();
|
---|
101 | m->medium = aMedium;
|
---|
102 | m->implicit = aImplicit;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /** For com::SupportErrorInfoImpl. */
|
---|
106 | static const char *ComponentName() { return "MediumAttachment"; }
|
---|
107 |
|
---|
108 | private:
|
---|
109 |
|
---|
110 | /** Reference to Machine object, for checking mutable state. */
|
---|
111 | const ComObjPtr<Machine, ComWeakRef> mParent;
|
---|
112 | /* later: const ComObjPtr<MediumAttachment> mPeer; */
|
---|
113 |
|
---|
114 | struct Data
|
---|
115 | {
|
---|
116 | Data() : port(0), device(0), type(DeviceType_Null),
|
---|
117 | passthrough(false), implicit(false) {}
|
---|
118 |
|
---|
119 | bool operator== (const Data &that) const
|
---|
120 | {
|
---|
121 | return this == &that
|
---|
122 | || (passthrough == that.passthrough);
|
---|
123 | }
|
---|
124 |
|
---|
125 | ComObjPtr<Medium> medium;
|
---|
126 | const Bstr controller;
|
---|
127 | const LONG port;
|
---|
128 | const LONG device;
|
---|
129 | const DeviceType_T type;
|
---|
130 | bool passthrough : 1;
|
---|
131 | bool implicit : 1;
|
---|
132 | };
|
---|
133 |
|
---|
134 | Backupable<Data> m;
|
---|
135 | };
|
---|
136 |
|
---|
137 | #endif // ____H_MEDIUMATTACHMENTIMPL
|
---|
138 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|