- Timestamp:
- Jan 23, 2009 12:46:45 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r16190 r16198 3331 3331 }; 3332 3332 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 3333 3334 STDMETHODIMP Host::FindHostNetworkInterfaceByName(IN_BSTR name, IHostNetworkInterface **networkInterface) 3335 { 3336 #ifndef VBOX_WITH_HOSTNETIF_API 3337 return E_NOTIMPL; 3338 #else 3339 if (!name) 3340 return E_INVALIDARG; 3341 if (!networkInterface) 3342 return E_POINTER; 3343 3344 *networkInterface = NULL; 3345 ComObjPtr <HostNetworkInterface> found; 3346 std::list <ComObjPtr <HostNetworkInterface> > list; 3347 int rc = NetIfList(list); 3348 if (RT_FAILURE(rc)) 3349 { 3350 Log(("Failed to get host network interface list with rc=%Vrc\n", rc)); 3351 return E_FAIL; 3352 } 3353 std::list <ComObjPtr <HostNetworkInterface> >::iterator it; 3354 for (it = list.begin(); it != list.end(); ++it) 3355 { 3356 Bstr n; 3357 (*it)->COMGETTER(Name) (n.asOutParam()); 3358 if (n == name) 3359 found = *it; 3360 } 3361 3362 if (!found) 3363 return setError (E_INVALIDARG, HostNetworkInterface::tr ( 3364 "The host network interface with the given name could not be found")); 3365 3366 return found.queryInterfaceTo (networkInterface); 3367 #endif 3368 } 3369 3370 STDMETHODIMP Host::FindHostNetworkInterfaceById(IN_GUID id, IHostNetworkInterface **networkInterface) 3371 { 3372 #ifndef VBOX_WITH_HOSTNETIF_API 3373 return E_NOTIMPL; 3374 #else 3375 if (Guid(id).isEmpty()) 3376 return E_INVALIDARG; 3377 if (!networkInterface) 3378 return E_POINTER; 3379 3380 *networkInterface = NULL; 3381 ComObjPtr <HostNetworkInterface> found; 3382 std::list <ComObjPtr <HostNetworkInterface> > list; 3383 int rc = NetIfList(list); 3384 if (RT_FAILURE(rc)) 3385 { 3386 Log(("Failed to get host network interface list with rc=%Vrc\n", rc)); 3387 return E_FAIL; 3388 } 3389 std::list <ComObjPtr <HostNetworkInterface> >::iterator it; 3390 for (it = list.begin(); it != list.end(); ++it) 3391 { 3392 Guid g; 3393 (*it)->COMGETTER(Id) (g.asOutParam()); 3394 if (g == Guid(id)) 3395 found = *it; 3396 } 3397 3398 if (!found) 3399 return setError (E_INVALIDARG, HostNetworkInterface::tr ( 3400 "The host network interface with the given GUID could not be found")); 3401 3402 return found.queryInterfaceTo (networkInterface); 3403 #endif 3404 } 3405 3333 3406 /* vi: set tabstop=4 shiftwidth=4 expandtab: */ -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r16188 r16198 6300 6300 <interface 6301 6301 name="IHost" extends="$unknown" 6302 uuid=" f39438d7-abfd-409b-bc80-5f5291d92897"6302 uuid="7c172c42-b209-4bdc-9ddf-a84f222bd59a" 6303 6303 wsmap="managed" 6304 6304 > … … 6590 6590 </method> 6591 6591 6592 <method name="findHostNetworkInterfaceByName"> 6593 <desc> 6594 Searches through all host network interfaces for an interface with 6595 the given name. 6596 <note> 6597 The method returns an error if the given name does not 6598 correspond to any host network interface. 6599 </note> 6600 </desc> 6601 <param name="name" type="wstring" dir="in"> 6602 <desc>Name of the host network interface to search for.</desc> 6603 </param> 6604 <param name="networkInterface" type="IHostNetworkInterface" dir="return"> 6605 <desc>Found host network interface object.</desc> 6606 </param> 6607 </method> 6608 <method name="findHostNetworkInterfaceById"> 6609 <desc> 6610 Searches through all host network interfaces for an interface with 6611 the given GUID. 6612 <note> 6613 The method returns an error if the given GUID does not 6614 correspond to any host network interface. 6615 </note> 6616 </desc> 6617 <param name="id" type="uuid" dir="in"> 6618 <desc>GUID of the host network interface to search for.</desc> 6619 </param> 6620 <param name="networkInterface" type="IHostNetworkInterface" dir="return"> 6621 <desc>Found host network interface object.</desc> 6622 </param> 6623 </method> 6592 6624 </interface> 6593 6625 -
trunk/src/VBox/Main/include/HostImpl.h
r15570 r16198 110 110 STDMETHOD(RemoveUSBDeviceFilter) (ULONG aPosition, IHostUSBDeviceFilter **aFilter); 111 111 112 STDMETHOD(FindHostNetworkInterfaceByName) (IN_BSTR aName, IHostNetworkInterface **networkInterface); 113 STDMETHOD(FindHostNetworkInterfaceById) (IN_GUID id, IHostNetworkInterface **networkInterface); 114 112 115 // public methods only for internal purposes 113 116 -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r16188 r16198 1127 1127 #endif 1128 1128 1129 #if 0 1130 do { 1131 // Get host 1132 ComPtr <IHost> host; 1133 CHECK_ERROR_BREAK (virtualBox, COMGETTER(Host) (host.asOutParam())); 1134 1135 ULONG uMemSize, uMemAvail; 1136 CHECK_ERROR_BREAK (host, COMGETTER(MemorySize) (&uMemSize)); 1137 printf("Total memory (MB): %u\n", uMemSize); 1138 CHECK_ERROR_BREAK (host, COMGETTER(MemoryAvailable) (&uMemAvail)); 1139 printf("Free memory (MB): %u\n", uMemAvail); 1140 } while (0); 1141 #endif 1142 1129 1143 #if 1 1130 1144 do { … … 1133 1147 CHECK_ERROR_BREAK (virtualBox, COMGETTER(Host) (host.asOutParam())); 1134 1148 1135 ULONG uMemSize, uMemAvail; 1136 CHECK_ERROR_BREAK (host, COMGETTER(MemorySize) (&uMemSize)); 1137 printf("Total memory (MB): %u\n", uMemSize); 1138 CHECK_ERROR_BREAK (host, COMGETTER(MemoryAvailable) (&uMemAvail)); 1139 printf("Free memory (MB): %u\n", uMemAvail); 1149 com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces; 1150 CHECK_ERROR_BREAK(host, 1151 COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces))); 1152 if (hostNetworkInterfaces.size() > 0) 1153 { 1154 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[0]; 1155 Bstr interfaceName; 1156 networkInterface->COMGETTER(Name)(interfaceName.asOutParam()); 1157 printf("Found %d network interfaces, testing with %lS...\n", hostNetworkInterfaces.size(), interfaceName.raw()); 1158 Guid interfaceGuid; 1159 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam()); 1160 // Find the interface by its name 1161 networkInterface.setNull(); 1162 CHECK_ERROR_BREAK(host, 1163 FindHostNetworkInterfaceByName (interfaceName, networkInterface.asOutParam())); 1164 Guid interfaceGuid2; 1165 networkInterface->COMGETTER(Id)(interfaceGuid2.asOutParam()); 1166 if (interfaceGuid2 != interfaceGuid) 1167 printf("Failed to retrive an interface by name %lS.\n", interfaceName.raw()); 1168 // Find the interface by its guid 1169 networkInterface.setNull(); 1170 CHECK_ERROR_BREAK(host, 1171 FindHostNetworkInterfaceById (interfaceGuid, networkInterface.asOutParam())); 1172 Bstr interfaceName2; 1173 networkInterface->COMGETTER(Name)(interfaceName2.asOutParam()); 1174 if (interfaceName != interfaceName2) 1175 printf("Failed to retrive an interface by GUID %lS.\n", Bstr(interfaceGuid.toString()).raw()); 1176 } 1177 else 1178 { 1179 printf("No network interfaces found!\n"); 1180 } 1140 1181 } while (0); 1141 1182 #endif … … 1255 1296 } while (false); 1256 1297 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 1257 #if 11298 #if 0 1258 1299 // check of OVF appliance handling 1259 1300 ///////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.