1 | /* $Id: NetworkAdapterImpl.h 15708 2008-12-19 18:28:27Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #ifndef ____H_NETWORKADAPTER
|
---|
25 | #define ____H_NETWORKADAPTER
|
---|
26 |
|
---|
27 | #include "VirtualBoxBase.h"
|
---|
28 | #include "Collection.h"
|
---|
29 |
|
---|
30 | class Machine;
|
---|
31 | class GuestOSType;
|
---|
32 |
|
---|
33 | class ATL_NO_VTABLE NetworkAdapter :
|
---|
34 | public VirtualBoxBaseNEXT,
|
---|
35 | public VirtualBoxSupportErrorInfoImpl <NetworkAdapter, INetworkAdapter>,
|
---|
36 | public VirtualBoxSupportTranslation <NetworkAdapter>,
|
---|
37 | public INetworkAdapter
|
---|
38 | {
|
---|
39 | public:
|
---|
40 |
|
---|
41 | struct Data
|
---|
42 | {
|
---|
43 | Data()
|
---|
44 | : mSlot (0), mEnabled (FALSE)
|
---|
45 | , mAttachmentType (NetworkAttachmentType_Null)
|
---|
46 | , mCableConnected (TRUE), mLineSpeed (0), mTraceEnabled (FALSE)
|
---|
47 | , mHostInterface ("") /* cannot be null */
|
---|
48 | {}
|
---|
49 |
|
---|
50 | bool operator== (const Data &that) const
|
---|
51 | {
|
---|
52 | return this == &that ||
|
---|
53 | (mSlot == that.mSlot &&
|
---|
54 | mEnabled == that.mEnabled &&
|
---|
55 | mMACAddress == that.mMACAddress &&
|
---|
56 | mAttachmentType == that.mAttachmentType &&
|
---|
57 | mCableConnected == that.mCableConnected &&
|
---|
58 | mLineSpeed == that.mLineSpeed &&
|
---|
59 | mTraceEnabled == that.mTraceEnabled &&
|
---|
60 | mHostInterface == that.mHostInterface &&
|
---|
61 | mInternalNetwork == that.mInternalNetwork &&
|
---|
62 | mNATNetwork == that.mNATNetwork);
|
---|
63 | }
|
---|
64 |
|
---|
65 | NetworkAdapterType_T mAdapterType;
|
---|
66 | ULONG mSlot;
|
---|
67 | BOOL mEnabled;
|
---|
68 | Bstr mMACAddress;
|
---|
69 | NetworkAttachmentType_T mAttachmentType;
|
---|
70 | BOOL mCableConnected;
|
---|
71 | ULONG mLineSpeed;
|
---|
72 | BOOL mTraceEnabled;
|
---|
73 | Bstr mTraceFile;
|
---|
74 | Bstr mHostInterface;
|
---|
75 | Bstr mInternalNetwork;
|
---|
76 | Bstr mNATNetwork;
|
---|
77 | };
|
---|
78 |
|
---|
79 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (NetworkAdapter)
|
---|
80 |
|
---|
81 | DECLARE_NOT_AGGREGATABLE(NetworkAdapter)
|
---|
82 |
|
---|
83 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
84 |
|
---|
85 | BEGIN_COM_MAP(NetworkAdapter)
|
---|
86 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
87 | COM_INTERFACE_ENTRY(INetworkAdapter)
|
---|
88 | END_COM_MAP()
|
---|
89 |
|
---|
90 | NS_DECL_ISUPPORTS
|
---|
91 |
|
---|
92 | DECLARE_EMPTY_CTOR_DTOR (NetworkAdapter)
|
---|
93 |
|
---|
94 | HRESULT FinalConstruct();
|
---|
95 | void FinalRelease();
|
---|
96 |
|
---|
97 | // public initializer/uninitializer for internal purposes only
|
---|
98 | HRESULT init (Machine *aParent, ULONG aSlot);
|
---|
99 | HRESULT init (Machine *aParent, NetworkAdapter *aThat);
|
---|
100 | HRESULT initCopy (Machine *aParent, NetworkAdapter *aThat);
|
---|
101 | void uninit();
|
---|
102 |
|
---|
103 | // INetworkAdapter properties
|
---|
104 | STDMETHOD(COMGETTER(AdapterType))(NetworkAdapterType_T *aAdapterType);
|
---|
105 | STDMETHOD(COMSETTER(AdapterType))(NetworkAdapterType_T aAdapterType);
|
---|
106 | STDMETHOD(COMGETTER(Slot)) (ULONG *aSlot);
|
---|
107 | STDMETHOD(COMGETTER(Enabled)) (BOOL *aEnabled);
|
---|
108 | STDMETHOD(COMSETTER(Enabled)) (BOOL aEnabled);
|
---|
109 | STDMETHOD(COMGETTER(MACAddress)) (BSTR *aMACAddress);
|
---|
110 | STDMETHOD(COMSETTER(MACAddress)) (IN_BSTR aMACAddress);
|
---|
111 | STDMETHOD(COMGETTER(AttachmentType)) (NetworkAttachmentType_T *aAttachmentType);
|
---|
112 | STDMETHOD(COMGETTER(HostInterface)) (BSTR *aHostInterface);
|
---|
113 | STDMETHOD(COMSETTER(HostInterface)) (IN_BSTR aHostInterface);
|
---|
114 | STDMETHOD(COMGETTER(InternalNetwork)) (BSTR *aInternalNetwork);
|
---|
115 | STDMETHOD(COMSETTER(InternalNetwork)) (IN_BSTR aInternalNetwork);
|
---|
116 | STDMETHOD(COMGETTER(NATNetwork)) (BSTR *aNATNetwork);
|
---|
117 | STDMETHOD(COMSETTER(NATNetwork)) (IN_BSTR aNATNetwork);
|
---|
118 | STDMETHOD(COMGETTER(CableConnected)) (BOOL *aConnected);
|
---|
119 | STDMETHOD(COMSETTER(CableConnected)) (BOOL aConnected);
|
---|
120 | STDMETHOD(COMGETTER(TraceEnabled)) (BOOL *aEnabled);
|
---|
121 | STDMETHOD(COMSETTER(TraceEnabled)) (BOOL aEnabled);
|
---|
122 | STDMETHOD(COMGETTER(LineSpeed)) (ULONG *aSpeed);
|
---|
123 | STDMETHOD(COMSETTER(LineSpeed)) (ULONG aSpeed);
|
---|
124 | STDMETHOD(COMGETTER(TraceFile)) (BSTR *aTraceFile);
|
---|
125 | STDMETHOD(COMSETTER(TraceFile)) (IN_BSTR aTraceFile);
|
---|
126 |
|
---|
127 | // INetworkAdapter methods
|
---|
128 | STDMETHOD(AttachToNAT)();
|
---|
129 | STDMETHOD(AttachToHostInterface)();
|
---|
130 | STDMETHOD(AttachToInternalNetwork)();
|
---|
131 | STDMETHOD(Detach)();
|
---|
132 |
|
---|
133 | // public methods only for internal purposes
|
---|
134 |
|
---|
135 | HRESULT loadSettings (const settings::Key &aAdapterNode);
|
---|
136 | HRESULT saveSettings (settings::Key &aAdapterNode);
|
---|
137 |
|
---|
138 | bool isModified() { AutoWriteLock alock (this); return mData.isBackedUp(); }
|
---|
139 | bool isReallyModified() { AutoWriteLock alock (this); return mData.hasActualChanges(); }
|
---|
140 | bool rollback();
|
---|
141 | void commit();
|
---|
142 | void copyFrom (NetworkAdapter *aThat);
|
---|
143 | void applyDefaults (GuestOSType *aOsType);
|
---|
144 |
|
---|
145 | // public methods for internal purposes only
|
---|
146 | // (ensure there is a caller and a read lock before calling them!)
|
---|
147 |
|
---|
148 | const Backupable <Data> &data() const { return mData; }
|
---|
149 |
|
---|
150 | // for VirtualBoxSupportErrorInfoImpl
|
---|
151 | static const wchar_t *getComponentName() { return L"NetworkAdapter"; }
|
---|
152 |
|
---|
153 | private:
|
---|
154 |
|
---|
155 | void detach();
|
---|
156 | void generateMACAddress();
|
---|
157 |
|
---|
158 | const ComObjPtr <Machine, ComWeakRef> mParent;
|
---|
159 | const ComObjPtr <NetworkAdapter> mPeer;
|
---|
160 |
|
---|
161 | Backupable <Data> mData;
|
---|
162 | };
|
---|
163 |
|
---|
164 | #endif // ____H_NETWORKADAPTER
|
---|
165 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|