VirtualBox

source: vbox/trunk/src/VBox/Main/include/HardDiskAttachmentImpl.h@ 18719

Last change on this file since 18719 was 17671, checked in by vboxsync, 16 years ago

Main: Try to fix Windows builds

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
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
29class ATL_NO_VTABLE HardDiskAttachment :
30 public VirtualBoxBaseNEXT,
31 public com::SupportErrorInfoImpl<HardDiskAttachment, IHardDiskAttachment>,
32 public VirtualBoxSupportTranslation<HardDiskAttachment>,
33 public IHardDiskAttachment
34{
35public:
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 END_COM_MAP()
77
78 NS_DECL_ISUPPORTS
79
80 HRESULT FinalConstruct();
81 void FinalRelease();
82
83 // public initializer/uninitializer for internal purposes only
84 HRESULT init(HardDisk *aHD, CBSTR aController, LONG aPort,
85 LONG aDevice, bool aImplicit = false);
86 void uninit();
87
88 // IHardDiskAttachment properties
89 STDMETHOD(COMGETTER(HardDisk)) (IHardDisk **aHardDisk);
90 STDMETHOD(COMGETTER(Controller)) (BSTR *aController);
91 STDMETHOD(COMGETTER(Port)) (LONG *aPort);
92 STDMETHOD(COMGETTER(Device)) (LONG *aDevice);
93
94 // unsafe inline public methods for internal purposes only (ensure there is
95 // a caller and a read lock before calling them!)
96
97 bool isImplicit() const { return m.implicit; }
98 void setImplicit (bool aImplicit) { m.implicit = aImplicit; }
99
100 const ComObjPtr<HardDisk> &hardDisk() const { return m.hardDisk; }
101 Bstr controller() const { return m.controller; }
102 LONG port() const { return m.port; }
103 LONG device() const { return m.device; }
104
105 /** Must be called from under this object's write lock. */
106 void updateHardDisk (const ComObjPtr<HardDisk> &aHardDisk, bool aImplicit)
107 {
108 m.hardDisk = aHardDisk;
109 m.implicit = aImplicit;
110 }
111
112 /** For com::SupportErrorInfoImpl. */
113 static const char *ComponentName() { return "HardDiskAttachment"; }
114
115private:
116
117 struct Data
118 {
119 Data() : port (0), device (0)
120 , implicit (false) {}
121
122 /// @todo NEWMEDIA shouldn't it be constant too? It'd be nice to get
123 /// rid of locks at all in this simple readonly structure-like interface
124 ComObjPtr<HardDisk> hardDisk;
125 const Bstr controller;
126 const LONG port;
127 const LONG device;
128
129 bool implicit : 1;
130 };
131
132 Data m;
133};
134
135#endif // ____H_HARDDISKATTACHMENTIMPL
136/* 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