1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ____H_NETWORKADAPTER
|
---|
23 | #define ____H_NETWORKADAPTER
|
---|
24 |
|
---|
25 | #include "VirtualBoxBase.h"
|
---|
26 | #include "Collection.h"
|
---|
27 |
|
---|
28 | class Machine;
|
---|
29 |
|
---|
30 | class ATL_NO_VTABLE NetworkAdapter :
|
---|
31 | public VirtualBoxBaseNEXT,
|
---|
32 | public VirtualBoxSupportErrorInfoImpl <NetworkAdapter, INetworkAdapter>,
|
---|
33 | public VirtualBoxSupportTranslation <NetworkAdapter>,
|
---|
34 | public INetworkAdapter
|
---|
35 | {
|
---|
36 | public:
|
---|
37 |
|
---|
38 | struct Data
|
---|
39 | {
|
---|
40 | Data()
|
---|
41 | : mSlot (0), mEnabled (FALSE)
|
---|
42 | , mAttachmentType (NetworkAttachmentType_NoNetworkAttachment)
|
---|
43 | , mCableConnected (TRUE), mTraceEnabled (FALSE)
|
---|
44 | #ifdef RT_OS_WINDOWS
|
---|
45 | , mHostInterface ("") // cannot be null
|
---|
46 | #endif
|
---|
47 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
48 | , mTAPFD (NIL_RTFILE)
|
---|
49 | #endif
|
---|
50 | , mInternalNetwork ("") // cannot be null
|
---|
51 | {}
|
---|
52 |
|
---|
53 | bool operator== (const Data &that) const
|
---|
54 | {
|
---|
55 | return this == &that ||
|
---|
56 | (mSlot == that.mSlot &&
|
---|
57 | mEnabled == that.mEnabled &&
|
---|
58 | mMACAddress == that.mMACAddress &&
|
---|
59 | mAttachmentType == that.mAttachmentType &&
|
---|
60 | mCableConnected == that.mCableConnected &&
|
---|
61 | mTraceEnabled == that.mTraceEnabled &&
|
---|
62 | mHostInterface == that.mHostInterface &&
|
---|
63 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
64 | mTAPSetupApplication == that.mTAPSetupApplication &&
|
---|
65 | mTAPTerminateApplication == that.mTAPTerminateApplication &&
|
---|
66 | mTAPFD == that.mTAPFD &&
|
---|
67 | #endif
|
---|
68 | mInternalNetwork == that.mInternalNetwork);
|
---|
69 | }
|
---|
70 |
|
---|
71 | NetworkAdapterType_T mAdapterType;
|
---|
72 | ULONG mSlot;
|
---|
73 | BOOL mEnabled;
|
---|
74 | Bstr mMACAddress;
|
---|
75 | NetworkAttachmentType_T mAttachmentType;
|
---|
76 | BOOL mCableConnected;
|
---|
77 | BOOL mTraceEnabled;
|
---|
78 | Bstr mTraceFile;
|
---|
79 | Bstr mHostInterface;
|
---|
80 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
81 | Bstr mTAPSetupApplication;
|
---|
82 | Bstr mTAPTerminateApplication;
|
---|
83 | RTFILE mTAPFD;
|
---|
84 | #endif
|
---|
85 | Bstr mInternalNetwork;
|
---|
86 | };
|
---|
87 |
|
---|
88 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (NetworkAdapter)
|
---|
89 |
|
---|
90 | DECLARE_NOT_AGGREGATABLE(NetworkAdapter)
|
---|
91 |
|
---|
92 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
93 |
|
---|
94 | BEGIN_COM_MAP(NetworkAdapter)
|
---|
95 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
96 | COM_INTERFACE_ENTRY(INetworkAdapter)
|
---|
97 | END_COM_MAP()
|
---|
98 |
|
---|
99 | NS_DECL_ISUPPORTS
|
---|
100 |
|
---|
101 | DECLARE_EMPTY_CTOR_DTOR (NetworkAdapter)
|
---|
102 |
|
---|
103 | HRESULT FinalConstruct();
|
---|
104 | void FinalRelease();
|
---|
105 |
|
---|
106 | // public initializer/uninitializer for internal purposes only
|
---|
107 | HRESULT init (Machine *aParent, ULONG aSlot);
|
---|
108 | HRESULT init (Machine *aParent, NetworkAdapter *aThat);
|
---|
109 | HRESULT initCopy (Machine *aParent, NetworkAdapter *aThat);
|
---|
110 | void uninit();
|
---|
111 |
|
---|
112 | // INetworkAdapter properties
|
---|
113 | STDMETHOD(COMGETTER(AdapterType))(NetworkAdapterType_T *aAdapterType);
|
---|
114 | STDMETHOD(COMSETTER(AdapterType))(NetworkAdapterType_T aAdapterType);
|
---|
115 | STDMETHOD(COMGETTER(Slot)) (ULONG *aSlot);
|
---|
116 | STDMETHOD(COMGETTER(Enabled)) (BOOL *aEnabled);
|
---|
117 | STDMETHOD(COMSETTER(Enabled)) (BOOL aEnabled);
|
---|
118 | STDMETHOD(COMGETTER(MACAddress)) (BSTR *aMACAddress);
|
---|
119 | STDMETHOD(COMSETTER(MACAddress)) (INPTR BSTR aMACAddress);
|
---|
120 | STDMETHOD(COMGETTER(AttachmentType)) (NetworkAttachmentType_T *aAttachmentType);
|
---|
121 | STDMETHOD(COMGETTER(HostInterface)) (BSTR *aHostInterface);
|
---|
122 | STDMETHOD(COMSETTER(HostInterface)) (INPTR BSTR aHostInterface);
|
---|
123 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
124 | STDMETHOD(COMGETTER(TAPFileDescriptor)) (LONG *aTAPFileDescriptor);
|
---|
125 | STDMETHOD(COMSETTER(TAPFileDescriptor)) (LONG aTAPFileDescriptor);
|
---|
126 | STDMETHOD(COMGETTER(TAPSetupApplication)) (BSTR *aTAPSetupApplication);
|
---|
127 | STDMETHOD(COMSETTER(TAPSetupApplication)) (INPTR BSTR aTAPSetupApplication);
|
---|
128 | STDMETHOD(COMGETTER(TAPTerminateApplication)) (BSTR *aTAPTerminateApplication);
|
---|
129 | STDMETHOD(COMSETTER(TAPTerminateApplication)) (INPTR BSTR aTAPTerminateApplication);
|
---|
130 | #endif
|
---|
131 | STDMETHOD(COMGETTER(InternalNetwork)) (BSTR *aInternalNetwork);
|
---|
132 | STDMETHOD(COMSETTER(InternalNetwork)) (INPTR BSTR aInternalNetwork);
|
---|
133 | STDMETHOD(COMGETTER(CableConnected)) (BOOL *aConnected);
|
---|
134 | STDMETHOD(COMSETTER(CableConnected)) (BOOL aConnected);
|
---|
135 | STDMETHOD(COMGETTER(TraceEnabled)) (BOOL *aEnabled);
|
---|
136 | STDMETHOD(COMSETTER(TraceEnabled)) (BOOL aEnabled);
|
---|
137 | STDMETHOD(COMGETTER(TraceFile)) (BSTR *aTraceFile);
|
---|
138 | STDMETHOD(COMSETTER(TraceFile)) (INPTR BSTR aTraceFile);
|
---|
139 |
|
---|
140 | // INetworkAdapter methods
|
---|
141 | STDMETHOD(AttachToNAT)();
|
---|
142 | STDMETHOD(AttachToHostInterface)();
|
---|
143 | STDMETHOD(AttachToInternalNetwork)();
|
---|
144 | STDMETHOD(Detach)();
|
---|
145 |
|
---|
146 | // public methods only for internal purposes
|
---|
147 |
|
---|
148 | bool isModified() { AutoLock alock (this); return mData.isBackedUp(); }
|
---|
149 | bool isReallyModified() { AutoLock alock (this); return mData.hasActualChanges(); }
|
---|
150 | bool rollback();
|
---|
151 | void commit();
|
---|
152 | void copyFrom (NetworkAdapter *aThat);
|
---|
153 |
|
---|
154 | // public methods for internal purposes only
|
---|
155 | // (ensure there is a caller and a read lock before calling them!)
|
---|
156 |
|
---|
157 | const Backupable <Data> &data() const { return mData; }
|
---|
158 |
|
---|
159 | // for VirtualBoxSupportErrorInfoImpl
|
---|
160 | static const wchar_t *getComponentName() { return L"NetworkAdapter"; }
|
---|
161 |
|
---|
162 | private:
|
---|
163 |
|
---|
164 | void detach();
|
---|
165 | void generateMACAddress();
|
---|
166 |
|
---|
167 | const ComObjPtr <Machine, ComWeakRef> mParent;
|
---|
168 | const ComObjPtr <NetworkAdapter> mPeer;
|
---|
169 |
|
---|
170 | Backupable <Data> mData;
|
---|
171 | };
|
---|
172 |
|
---|
173 | #endif // ____H_NETWORKADAPTER
|
---|