VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/NetworkAdapterImpl.h@ 44528

Last change on this file since 44528 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/** @file
2 *
3 * VBox frontends: Basic Frontend (BFE):
4 * Declaration of NetworkAdapter class
5 *
6 * This is adapted from frontends/VirtualBox/NetworkAdapter.cpp.
7 */
8
9/*
10 * Copyright (C) 2006-2010 Oracle Corporation
11 *
12 * This file is part of VirtualBox Open Source Edition (OSE), as
13 * available from http://www.virtualbox.org. This file is free software;
14 * you can redistribute it and/or modify it under the terms of the GNU
15 * General Public License (GPL) as published by the Free Software
16 * Foundation, in version 2 as it comes in the "COPYING" file of the
17 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19 */
20
21
22#ifndef ____H_NETWORKADAPTER
23#define ____H_NETWORKADAPTER
24
25
26#include <VBox/types.h>
27#include <COMDefs.h>
28#include <COMStr.h>
29#include <iprt/critsect.h>
30#include <iprt/assert.h>
31
32class Console;
33
34
35#define BSTR PRUnichar*
36
37#define INPTR const
38
39class NetworkAdapter
40{
41public:
42 RTCRITSECT mCritSec;
43 struct Data
44 {
45 Data()
46 : mSlot (0), mEnabled (FALSE)
47 , mCableConnected (TRUE), mTraceEnabled (FALSE)
48#ifdef RT_OS_LINUX
49 , mTAPFD (NIL_RTFILE)
50#endif
51 , mInternalNetwork ("") // cannot be null
52 {}
53
54 ULONG mSlot;
55 BOOL mEnabled;
56 Bstr mMACAddress;
57 BOOL mCableConnected;
58 BOOL mTraceEnabled;
59 Bstr mHostInterface;
60#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
61 Bstr mTAPSetupApplication;
62 Bstr mTAPTerminateApplication;
63 RTFILE mTAPFD;
64#endif
65 Bstr mInternalNetwork;
66 };
67
68 NetworkAdapter();
69 virtual ~NetworkAdapter();
70
71 HRESULT FinalConstruct();
72 void FinalRelease();
73
74 // public initializer/uninitializer for internal purposes only
75 int init (Console *parent, ULONG slot);
76 // int init (Console *parent, NetworkAdapter *that);
77 void uninit();
78
79 // INetworkAdapter properties
80 STDMETHOD(COMGETTER(Slot)) (ULONG *slot);
81 STDMETHOD(COMGETTER(Enabled)) (BOOL *enabled);
82 STDMETHOD(COMSETTER(Enabled)) (BOOL enabled);
83 STDMETHOD(COMGETTER(MACAddress))(BSTR *macAddress);
84 STDMETHOD(COMSETTER(MACAddress))(INPTR BSTR macAddress);
85 // STDMETHOD(COMGETTER(AttachmentType))(NetworkAttachmentType_T *attachmentType);
86 STDMETHOD(COMGETTER(HostInterface))(BSTR *hostInterface);
87 STDMETHOD(COMSETTER(HostInterface))(INPTR BSTR hostInterface);
88#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
89 STDMETHOD(COMGETTER(TAPFileDescriptor))(LONG *tapFileDescriptor);
90 STDMETHOD(COMSETTER(TAPFileDescriptor))(LONG tapFileDescriptor);
91 STDMETHOD(COMGETTER(TAPSetupApplication))(BSTR *tapSetupApplication);
92 STDMETHOD(COMSETTER(TAPSetupApplication))(INPTR BSTR tapSetupApplication);
93 STDMETHOD(COMGETTER(TAPTerminateApplication))(BSTR *tapTerminateApplication);
94 STDMETHOD(COMSETTER(TAPTerminateApplication))(INPTR BSTR tapTerminateApplication);
95#endif
96 STDMETHOD(COMGETTER(InternalNetwork))(BSTR *internalNetwork);
97 STDMETHOD(COMSETTER(InternalNetwork))(INPTR BSTR internalNetwork);
98 STDMETHOD(COMGETTER(CableConnected))(BOOL *connected);
99 STDMETHOD(COMSETTER(CableConnected))(BOOL connected);
100 STDMETHOD(COMGETTER(TraceEnabled))(BOOL *enabled);
101 STDMETHOD(COMSETTER(TraceEnabled))(BOOL enabled);
102
103 // INetworkAdapter methods
104 STDMETHOD(AttachToNAT)();
105 STDMETHOD(AttachToBridgedInterface)();
106 STDMETHOD(AttachToInternalNetwork)();
107 STDMETHOD(Detach)();
108
109 static const wchar_t *getComponentName() { return L"NetworkAdapter"; }
110
111private:
112
113 void detach();
114 void generateMACAddress();
115
116 Console *mParent;
117 Data mData;
118};
119
120class AutoLock
121 {
122 public:
123 AutoLock (NetworkAdapter *that) : outer (that), mLevel (0) { lock(); }
124 ~AutoLock() {
125 AssertMsg (mLevel <= 1, ("Lock level > 1: %d\n", mLevel));
126 while (mLevel --)
127 RTCritSectLeave (&outer->mCritSec);
128 }
129 void lock() {
130 ++ mLevel;
131 RTCritSectEnter (&outer->mCritSec);
132 }
133 void unlock() {
134 AssertMsg (mLevel > 0, ("Lock level is zero\n"));
135 if (mLevel > 0) {
136 RTCritSectLeave (&outer->mCritSec);
137 -- mLevel;
138 }
139 }
140 private:
141 AutoLock (const AutoLock &that);
142 AutoLock &operator = (const AutoLock &that);
143 NetworkAdapter *outer;
144 unsigned int mLevel;
145 };
146
147#endif // ____H_NETWORKADAPTER
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