1 | /* $Id: NetworkAdapterImpl.h 8155 2008-04-18 15:16:47Z 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 |
|
---|
32 | class ATL_NO_VTABLE NetworkAdapter :
|
---|
33 | public VirtualBoxBaseNEXT,
|
---|
34 | public VirtualBoxSupportErrorInfoImpl <NetworkAdapter, INetworkAdapter>,
|
---|
35 | public VirtualBoxSupportTranslation <NetworkAdapter>,
|
---|
36 | public INetworkAdapter
|
---|
37 | {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | struct Data
|
---|
41 | {
|
---|
42 | Data()
|
---|
43 | : mSlot (0), mEnabled (FALSE)
|
---|
44 | , mAttachmentType (NetworkAttachmentType_Null)
|
---|
45 | , mCableConnected (TRUE), mLineSpeed (0), mTraceEnabled (FALSE)
|
---|
46 | #ifdef RT_OS_WINDOWS
|
---|
47 | , mHostInterface ("") // cannot be null
|
---|
48 | #endif
|
---|
49 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
50 | , mTAPFD (NIL_RTFILE)
|
---|
51 | #endif
|
---|
52 | , mInternalNetwork ("") // cannot be null
|
---|
53 | {}
|
---|
54 |
|
---|
55 | bool operator== (const Data &that) const
|
---|
56 | {
|
---|
57 | return this == &that ||
|
---|
58 | (mSlot == that.mSlot &&
|
---|
59 | mEnabled == that.mEnabled &&
|
---|
60 | mMACAddress == that.mMACAddress &&
|
---|
61 | mAttachmentType == that.mAttachmentType &&
|
---|
62 | mCableConnected == that.mCableConnected &&
|
---|
63 | mLineSpeed == that.mLineSpeed &&
|
---|
64 | mTraceEnabled == that.mTraceEnabled &&
|
---|
65 | mHostInterface == that.mHostInterface &&
|
---|
66 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
67 | mTAPSetupApplication == that.mTAPSetupApplication &&
|
---|
68 | mTAPTerminateApplication == that.mTAPTerminateApplication &&
|
---|
69 | mTAPFD == that.mTAPFD &&
|
---|
70 | #endif
|
---|
71 | mInternalNetwork == that.mInternalNetwork);
|
---|
72 | }
|
---|
73 |
|
---|
74 | NetworkAdapterType_T mAdapterType;
|
---|
75 | ULONG mSlot;
|
---|
76 | BOOL mEnabled;
|
---|
77 | Bstr mMACAddress;
|
---|
78 | NetworkAttachmentType_T mAttachmentType;
|
---|
79 | BOOL mCableConnected;
|
---|
80 | ULONG mLineSpeed;
|
---|
81 | BOOL mTraceEnabled;
|
---|
82 | Bstr mTraceFile;
|
---|
83 | Bstr mHostInterface;
|
---|
84 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
85 | Bstr mTAPSetupApplication;
|
---|
86 | Bstr mTAPTerminateApplication;
|
---|
87 | RTFILE mTAPFD;
|
---|
88 | #endif
|
---|
89 | Bstr mInternalNetwork;
|
---|
90 | };
|
---|
91 |
|
---|
92 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (NetworkAdapter)
|
---|
93 |
|
---|
94 | DECLARE_NOT_AGGREGATABLE(NetworkAdapter)
|
---|
95 |
|
---|
96 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
97 |
|
---|
98 | BEGIN_COM_MAP(NetworkAdapter)
|
---|
99 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
100 | COM_INTERFACE_ENTRY(INetworkAdapter)
|
---|
101 | END_COM_MAP()
|
---|
102 |
|
---|
103 | NS_DECL_ISUPPORTS
|
---|
104 |
|
---|
105 | DECLARE_EMPTY_CTOR_DTOR (NetworkAdapter)
|
---|
106 |
|
---|
107 | HRESULT FinalConstruct();
|
---|
108 | void FinalRelease();
|
---|
109 |
|
---|
110 | // public initializer/uninitializer for internal purposes only
|
---|
111 | HRESULT init (Machine *aParent, ULONG aSlot);
|
---|
112 | HRESULT init (Machine *aParent, NetworkAdapter *aThat);
|
---|
113 | HRESULT initCopy (Machine *aParent, NetworkAdapter *aThat);
|
---|
114 | void uninit();
|
---|
115 |
|
---|
116 | // INetworkAdapter properties
|
---|
117 | STDMETHOD(COMGETTER(AdapterType))(NetworkAdapterType_T *aAdapterType);
|
---|
118 | STDMETHOD(COMSETTER(AdapterType))(NetworkAdapterType_T aAdapterType);
|
---|
119 | STDMETHOD(COMGETTER(Slot)) (ULONG *aSlot);
|
---|
120 | STDMETHOD(COMGETTER(Enabled)) (BOOL *aEnabled);
|
---|
121 | STDMETHOD(COMSETTER(Enabled)) (BOOL aEnabled);
|
---|
122 | STDMETHOD(COMGETTER(MACAddress)) (BSTR *aMACAddress);
|
---|
123 | STDMETHOD(COMSETTER(MACAddress)) (INPTR BSTR aMACAddress);
|
---|
124 | STDMETHOD(COMGETTER(AttachmentType)) (NetworkAttachmentType_T *aAttachmentType);
|
---|
125 | STDMETHOD(COMGETTER(HostInterface)) (BSTR *aHostInterface);
|
---|
126 | STDMETHOD(COMSETTER(HostInterface)) (INPTR BSTR aHostInterface);
|
---|
127 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
128 | STDMETHOD(COMGETTER(TAPFileDescriptor)) (LONG *aTAPFileDescriptor);
|
---|
129 | STDMETHOD(COMSETTER(TAPFileDescriptor)) (LONG aTAPFileDescriptor);
|
---|
130 | STDMETHOD(COMGETTER(TAPSetupApplication)) (BSTR *aTAPSetupApplication);
|
---|
131 | STDMETHOD(COMSETTER(TAPSetupApplication)) (INPTR BSTR aTAPSetupApplication);
|
---|
132 | STDMETHOD(COMGETTER(TAPTerminateApplication)) (BSTR *aTAPTerminateApplication);
|
---|
133 | STDMETHOD(COMSETTER(TAPTerminateApplication)) (INPTR BSTR aTAPTerminateApplication);
|
---|
134 | #endif
|
---|
135 | STDMETHOD(COMGETTER(InternalNetwork)) (BSTR *aInternalNetwork);
|
---|
136 | STDMETHOD(COMSETTER(InternalNetwork)) (INPTR BSTR aInternalNetwork);
|
---|
137 | STDMETHOD(COMGETTER(CableConnected)) (BOOL *aConnected);
|
---|
138 | STDMETHOD(COMSETTER(CableConnected)) (BOOL aConnected);
|
---|
139 | STDMETHOD(COMGETTER(TraceEnabled)) (BOOL *aEnabled);
|
---|
140 | STDMETHOD(COMSETTER(TraceEnabled)) (BOOL aEnabled);
|
---|
141 | STDMETHOD(COMGETTER(LineSpeed)) (ULONG *aSpeed);
|
---|
142 | STDMETHOD(COMSETTER(LineSpeed)) (ULONG aSpeed);
|
---|
143 | STDMETHOD(COMGETTER(TraceFile)) (BSTR *aTraceFile);
|
---|
144 | STDMETHOD(COMSETTER(TraceFile)) (INPTR BSTR aTraceFile);
|
---|
145 |
|
---|
146 | // INetworkAdapter methods
|
---|
147 | STDMETHOD(AttachToNAT)();
|
---|
148 | STDMETHOD(AttachToHostInterface)();
|
---|
149 | STDMETHOD(AttachToInternalNetwork)();
|
---|
150 | STDMETHOD(Detach)();
|
---|
151 |
|
---|
152 | // public methods only for internal purposes
|
---|
153 |
|
---|
154 | HRESULT loadSettings (const settings::Key &aAdapterNode);
|
---|
155 | HRESULT saveSettings (settings::Key &aAdapterNode);
|
---|
156 |
|
---|
157 | bool isModified() { AutoWriteLock alock (this); return mData.isBackedUp(); }
|
---|
158 | bool isReallyModified() { AutoWriteLock alock (this); return mData.hasActualChanges(); }
|
---|
159 | bool rollback();
|
---|
160 | void commit();
|
---|
161 | void copyFrom (NetworkAdapter *aThat);
|
---|
162 |
|
---|
163 | // public methods for internal purposes only
|
---|
164 | // (ensure there is a caller and a read lock before calling them!)
|
---|
165 |
|
---|
166 | const Backupable <Data> &data() const { return mData; }
|
---|
167 |
|
---|
168 | // for VirtualBoxSupportErrorInfoImpl
|
---|
169 | static const wchar_t *getComponentName() { return L"NetworkAdapter"; }
|
---|
170 |
|
---|
171 | private:
|
---|
172 |
|
---|
173 | void detach();
|
---|
174 | void generateMACAddress();
|
---|
175 |
|
---|
176 | const ComObjPtr <Machine, ComWeakRef> mParent;
|
---|
177 | const ComObjPtr <NetworkAdapter> mPeer;
|
---|
178 |
|
---|
179 | Backupable <Data> mData;
|
---|
180 | };
|
---|
181 |
|
---|
182 | #endif // ____H_NETWORKADAPTER
|
---|