VirtualBox

source: vbox/trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h@ 15372

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

#3282: HostNetIf API implementation for Darwin. Common part revised. Stubs for other platforms.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: HostNetworkInterfaceImpl.h 15372 2008-12-12 14:51:29Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 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_HOSTNETWORKINTERFACEIMPL
25#define ____H_HOSTNETWORKINTERFACEIMPL
26
27#include "VirtualBoxBase.h"
28#include "Collection.h"
29#ifdef VBOX_WITH_HOSTNETIF_API
30#include "netif.h"
31#endif
32
33class ATL_NO_VTABLE HostNetworkInterface :
34 public VirtualBoxBaseNEXT,
35 public VirtualBoxSupportErrorInfoImpl <HostNetworkInterface, IHostNetworkInterface>,
36 public VirtualBoxSupportTranslation <HostNetworkInterface>,
37 public IHostNetworkInterface
38{
39public:
40
41 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostNetworkInterface)
42
43 DECLARE_NOT_AGGREGATABLE (HostNetworkInterface)
44
45 DECLARE_PROTECT_FINAL_CONSTRUCT()
46
47 BEGIN_COM_MAP (HostNetworkInterface)
48 COM_INTERFACE_ENTRY (ISupportErrorInfo)
49 COM_INTERFACE_ENTRY (IHostNetworkInterface)
50 END_COM_MAP()
51
52 NS_DECL_ISUPPORTS
53
54 DECLARE_EMPTY_CTOR_DTOR (HostNetworkInterface)
55
56 HRESULT FinalConstruct();
57 void FinalRelease();
58
59 // public initializer/uninitializer for internal purposes only
60 HRESULT init (Bstr interfaceName, Guid guid);
61#ifdef VBOX_WITH_HOSTNETIF_API
62 HRESULT init (PNETIFINFO pIfs);
63#endif
64
65 // IHostNetworkInterface properties
66 STDMETHOD(COMGETTER(Name)) (BSTR *aInterfaceName);
67 STDMETHOD(COMGETTER(Id)) (OUT_GUID aGuid);
68 STDMETHOD(COMGETTER(IPAddress)) (ULONG *aIPAddress);
69 STDMETHOD(COMGETTER(NetworkMask)) (ULONG *aNetworkMask);
70 STDMETHOD(COMGETTER(IPV6Address)) (BSTR *aIPV6Address);
71 STDMETHOD(COMGETTER(IPV6NetworkMask)) (BSTR *aIPV6Mask);
72 STDMETHOD(COMGETTER(HardwareAddress)) (BSTR *aHardwareAddress);
73 STDMETHOD(COMGETTER(Type)) (HostNetworkInterfaceType_T *aType);
74 STDMETHOD(COMGETTER(Status)) (HostNetworkInterfaceStatus_T *aStatus);
75
76 // for VirtualBoxSupportErrorInfoImpl
77 static const wchar_t *getComponentName() { return L"HostNetworkInterface"; }
78
79private:
80 const Bstr mInterfaceName;
81 const Guid mGuid;
82 struct Data
83 {
84 Data() : IPAddress (0), networkMask (0),
85 type (HostNetworkInterfaceType_Unknown),
86 status(HostNetworkInterfaceStatus_Down) {}
87
88 ULONG IPAddress;
89 ULONG networkMask;
90 Bstr IPV6Address;
91 Bstr IPV6NetworkMask;
92 Bstr hardwareAddress;
93 HostNetworkInterfaceType_T type;
94 HostNetworkInterfaceStatus_T status;
95 } m;
96
97};
98
99COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostNetworkInterface)
100
101 STDMETHOD(FindByName) (IN_BSTR name, IHostNetworkInterface **networkInterface)
102 {
103 if (!name)
104 return E_INVALIDARG;
105 if (!networkInterface)
106 return E_POINTER;
107
108 *networkInterface = NULL;
109 Vector::value_type found;
110 Vector::iterator it = vec.begin();
111 while (it != vec.end() && !found)
112 {
113 Bstr n;
114 (*it)->COMGETTER(Name) (n.asOutParam());
115 if (n == name)
116 found = *it;
117 ++ it;
118 }
119
120 if (!found)
121 return setError (E_INVALIDARG, HostNetworkInterfaceCollection::tr (
122 "The host network interface with the given name could not be found"));
123
124 return found.queryInterfaceTo (networkInterface);
125 }
126
127 STDMETHOD(FindById) (IN_GUID id, IHostNetworkInterface **networkInterface)
128 {
129 if (Guid(id).isEmpty())
130 return E_INVALIDARG;
131 if (!networkInterface)
132 return E_POINTER;
133
134 *networkInterface = NULL;
135 Vector::value_type found;
136 Vector::iterator it = vec.begin();
137 while (it != vec.end() && !found)
138 {
139 Guid g;
140 (*it)->COMGETTER(Id) (g.asOutParam());
141 if (g == Guid(id))
142 found = *it;
143 ++ it;
144 }
145
146 if (!found)
147 return setError (E_INVALIDARG, HostNetworkInterfaceCollection::tr (
148 "The host network interface with the given GUID could not be found"));
149
150 return found.queryInterfaceTo (networkInterface);
151 }
152
153
154COM_DECL_READONLY_ENUM_AND_COLLECTION_END (HostNetworkInterface)
155
156
157#endif // ____H_H_HOSTNETWORKINTERFACEIMPL
158/* 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