1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 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_HARDDISKATTACHMENTIMPL
|
---|
23 | #define ____H_HARDDISKATTACHMENTIMPL
|
---|
24 |
|
---|
25 | #include "VirtualBoxBase.h"
|
---|
26 |
|
---|
27 | #include "HardDiskImpl.h"
|
---|
28 |
|
---|
29 | class ATL_NO_VTABLE HardDiskAttachment :
|
---|
30 | public VirtualBoxBaseNEXT,
|
---|
31 | public com::SupportErrorInfoImpl<HardDiskAttachment, IHardDiskAttachment>,
|
---|
32 | public VirtualBoxSupportTranslation<HardDiskAttachment>,
|
---|
33 | VBOX_SCRIPTABLE_IMPL(IHardDiskAttachment)
|
---|
34 | {
|
---|
35 | public:
|
---|
36 |
|
---|
37 | /** Equality predicate for stdc++. */
|
---|
38 | struct EqualsTo
|
---|
39 | : public std::unary_function <ComObjPtr<HardDiskAttachment>, bool>
|
---|
40 | {
|
---|
41 | explicit EqualsTo (CBSTR aController, LONG aPort, LONG aDevice)
|
---|
42 | : controller(aController), port (aPort), device (aDevice) {}
|
---|
43 |
|
---|
44 | bool operator() (const argument_type &aThat) const
|
---|
45 | {
|
---|
46 | return aThat->controller() == controller && aThat->port() == port &&
|
---|
47 | aThat->device() == device;
|
---|
48 | }
|
---|
49 |
|
---|
50 | const Bstr controller;
|
---|
51 | const LONG port;
|
---|
52 | const LONG device;
|
---|
53 | };
|
---|
54 |
|
---|
55 | /** Hard disk reference predicate for stdc++. */
|
---|
56 | struct RefersTo
|
---|
57 | : public std::unary_function< ComObjPtr<HardDiskAttachment>, bool>
|
---|
58 | {
|
---|
59 | explicit RefersTo (HardDisk *aHardDisk) : hardDisk (aHardDisk) {}
|
---|
60 |
|
---|
61 | bool operator() (const argument_type &aThat) const
|
---|
62 | {
|
---|
63 | return aThat->hardDisk().equalsTo (hardDisk);
|
---|
64 | }
|
---|
65 |
|
---|
66 | const ComObjPtr <HardDisk> hardDisk;
|
---|
67 | };
|
---|
68 |
|
---|
69 | DECLARE_NOT_AGGREGATABLE(HardDiskAttachment)
|
---|
70 |
|
---|
71 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
72 |
|
---|
73 | BEGIN_COM_MAP (HardDiskAttachment)
|
---|
74 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
75 | COM_INTERFACE_ENTRY(IHardDiskAttachment)
|
---|
76 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
77 | END_COM_MAP()
|
---|
78 |
|
---|
79 | NS_DECL_ISUPPORTS
|
---|
80 |
|
---|
81 | HRESULT FinalConstruct();
|
---|
82 | void FinalRelease();
|
---|
83 |
|
---|
84 | // public initializer/uninitializer for internal purposes only
|
---|
85 | HRESULT init(HardDisk *aHD, CBSTR aController, LONG aPort,
|
---|
86 | LONG aDevice, bool aImplicit = false);
|
---|
87 | void uninit();
|
---|
88 |
|
---|
89 | // IHardDiskAttachment properties
|
---|
90 | STDMETHOD(COMGETTER(HardDisk)) (IHardDisk **aHardDisk);
|
---|
91 | STDMETHOD(COMGETTER(Controller)) (BSTR *aController);
|
---|
92 | STDMETHOD(COMGETTER(Port)) (LONG *aPort);
|
---|
93 | STDMETHOD(COMGETTER(Device)) (LONG *aDevice);
|
---|
94 |
|
---|
95 | // unsafe inline public methods for internal purposes only (ensure there is
|
---|
96 | // a caller and a read lock before calling them!)
|
---|
97 |
|
---|
98 | bool isImplicit() const { return m.implicit; }
|
---|
99 | void setImplicit (bool aImplicit) { m.implicit = aImplicit; }
|
---|
100 |
|
---|
101 | const ComObjPtr<HardDisk> &hardDisk() const { return m.hardDisk; }
|
---|
102 | Bstr controller() const { return m.controller; }
|
---|
103 | LONG port() const { return m.port; }
|
---|
104 | LONG device() const { return m.device; }
|
---|
105 |
|
---|
106 | /** Must be called from under this object's write lock. */
|
---|
107 | void updateHardDisk (const ComObjPtr<HardDisk> &aHardDisk, bool aImplicit)
|
---|
108 | {
|
---|
109 | m.hardDisk = aHardDisk;
|
---|
110 | m.implicit = aImplicit;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /** For com::SupportErrorInfoImpl. */
|
---|
114 | static const char *ComponentName() { return "HardDiskAttachment"; }
|
---|
115 |
|
---|
116 | private:
|
---|
117 |
|
---|
118 | struct Data
|
---|
119 | {
|
---|
120 | Data() : port (0), device (0)
|
---|
121 | , implicit (false) {}
|
---|
122 |
|
---|
123 | /// @todo NEWMEDIA shouldn't it be constant too? It'd be nice to get
|
---|
124 | /// rid of locks at all in this simple readonly structure-like interface
|
---|
125 | ComObjPtr<HardDisk> hardDisk;
|
---|
126 | const Bstr controller;
|
---|
127 | const LONG port;
|
---|
128 | const LONG device;
|
---|
129 |
|
---|
130 | bool implicit : 1;
|
---|
131 | };
|
---|
132 |
|
---|
133 | Data m;
|
---|
134 | };
|
---|
135 |
|
---|
136 | #endif // ____H_HARDDISKATTACHMENTIMPL
|
---|
137 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|