mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-03 11:51:11 +00:00
vbox: Rewrite vboxConnectListNetworks
This commit is contained in:
parent
a8b1b043bf
commit
ce1cef1c57
@ -25,6 +25,7 @@
|
|||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
#include "domain_event.h"
|
#include "domain_event.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
|
#include "virstring.h"
|
||||||
|
|
||||||
#include "vbox_common.h"
|
#include "vbox_common.h"
|
||||||
#include "vbox_uniformed_api.h"
|
#include "vbox_uniformed_api.h"
|
||||||
@ -33,6 +34,25 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("vbox.vbox_network");
|
VIR_LOG_INIT("vbox.vbox_network");
|
||||||
|
|
||||||
|
#define VBOX_UTF16_FREE(arg) \
|
||||||
|
do { \
|
||||||
|
if (arg) { \
|
||||||
|
gVBoxAPI.UPFN.Utf16Free(data->pFuncs, arg); \
|
||||||
|
(arg) = NULL; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define VBOX_UTF8_FREE(arg) \
|
||||||
|
do { \
|
||||||
|
if (arg) { \
|
||||||
|
gVBoxAPI.UPFN.Utf8Free(data->pFuncs, arg); \
|
||||||
|
(arg) = NULL; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define VBOX_UTF16_TO_UTF8(arg1, arg2) gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2)
|
||||||
|
#define VBOX_UTF8_TO_UTF16(arg1, arg2) gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2)
|
||||||
|
|
||||||
#define VBOX_RELEASE(arg) \
|
#define VBOX_RELEASE(arg) \
|
||||||
do { \
|
do { \
|
||||||
if (arg) { \
|
if (arg) { \
|
||||||
@ -120,3 +140,60 @@ int vboxConnectNumOfNetworks(virConnectPtr conn)
|
|||||||
VIR_DEBUG("numActive: %d", ret);
|
VIR_DEBUG("numActive: %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames)
|
||||||
|
{
|
||||||
|
vboxGlobalData *data = conn->privateData;
|
||||||
|
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
||||||
|
IHost *host = NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!data->vboxObj)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gVBoxAPI.UIVirtualBox.GetHost(data->vboxObj, &host);
|
||||||
|
if (!host)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host,
|
||||||
|
gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host));
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) {
|
||||||
|
IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
|
||||||
|
char *nameUtf8 = NULL;
|
||||||
|
PRUnichar *nameUtf16 = NULL;
|
||||||
|
PRUint32 interfaceType = 0;
|
||||||
|
PRUint32 status = HostNetworkInterfaceStatus_Unknown;
|
||||||
|
|
||||||
|
if (!networkInterface)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType);
|
||||||
|
|
||||||
|
if (interfaceType != HostNetworkInterfaceType_HostOnly)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status);
|
||||||
|
|
||||||
|
if (status != HostNetworkInterfaceStatus_Up)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetName(networkInterface, &nameUtf16);
|
||||||
|
VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
|
||||||
|
|
||||||
|
VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
|
||||||
|
if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
|
||||||
|
ret++;
|
||||||
|
|
||||||
|
VBOX_UTF8_FREE(nameUtf8);
|
||||||
|
VBOX_UTF16_FREE(nameUtf16);
|
||||||
|
}
|
||||||
|
|
||||||
|
gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces);
|
||||||
|
|
||||||
|
VBOX_RELEASE(host);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -2060,51 +2060,6 @@ _registerDomainEvent(virDriverPtr driver)
|
|||||||
* The Network Functions here on
|
* The Network Functions here on
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) {
|
|
||||||
VBOX_OBJECT_HOST_CHECK(conn, int, 0);
|
|
||||||
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces);
|
|
||||||
|
|
||||||
for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) {
|
|
||||||
IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
|
|
||||||
|
|
||||||
if (networkInterface) {
|
|
||||||
PRUint32 interfaceType = 0;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
|
|
||||||
|
|
||||||
if (interfaceType == HostNetworkInterfaceType_HostOnly) {
|
|
||||||
PRUint32 status = HostNetworkInterfaceStatus_Unknown;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetStatus(networkInterface, &status);
|
|
||||||
|
|
||||||
if (status == HostNetworkInterfaceStatus_Up) {
|
|
||||||
char *nameUtf8 = NULL;
|
|
||||||
PRUnichar *nameUtf16 = NULL;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetName(networkInterface, &nameUtf16);
|
|
||||||
VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
|
|
||||||
|
|
||||||
VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
|
|
||||||
if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
|
|
||||||
ret++;
|
|
||||||
|
|
||||||
VBOX_UTF8_FREE(nameUtf8);
|
|
||||||
VBOX_UTF16_FREE(nameUtf16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vboxArrayRelease(&networkInterfaces);
|
|
||||||
|
|
||||||
VBOX_RELEASE(host);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
|
static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
VBOX_OBJECT_HOST_CHECK(conn, int, 0);
|
VBOX_OBJECT_HOST_CHECK(conn, int, 0);
|
||||||
@ -6032,6 +5987,12 @@ _hnInterfaceGetStatus(IHostNetworkInterface *hni, PRUint32 *status)
|
|||||||
return hni->vtbl->GetStatus(hni, status);
|
return hni->vtbl->GetStatus(hni, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
_hnInterfaceGetName(IHostNetworkInterface *hni, PRUnichar **name)
|
||||||
|
{
|
||||||
|
return hni->vtbl->GetName(hni, name);
|
||||||
|
}
|
||||||
|
|
||||||
static bool _machineStateOnline(PRUint32 state)
|
static bool _machineStateOnline(PRUint32 state)
|
||||||
{
|
{
|
||||||
return ((state >= MachineState_FirstOnline) &&
|
return ((state >= MachineState_FirstOnline) &&
|
||||||
@ -6338,6 +6299,7 @@ static vboxUniformedIDisplay _UIDisplay = {
|
|||||||
static vboxUniformedIHNInterface _UIHNInterface = {
|
static vboxUniformedIHNInterface _UIHNInterface = {
|
||||||
.GetInterfaceType = _hnInterfaceGetInterfaceType,
|
.GetInterfaceType = _hnInterfaceGetInterfaceType,
|
||||||
.GetStatus = _hnInterfaceGetStatus,
|
.GetStatus = _hnInterfaceGetStatus,
|
||||||
|
.GetName = _hnInterfaceGetName,
|
||||||
};
|
};
|
||||||
|
|
||||||
static uniformedMachineStateChecker _machineStateChecker = {
|
static uniformedMachineStateChecker _machineStateChecker = {
|
||||||
|
@ -470,6 +470,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
|
nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
|
||||||
nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status);
|
nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status);
|
||||||
|
nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name);
|
||||||
} vboxUniformedIHNInterface;
|
} vboxUniformedIHNInterface;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -548,6 +549,7 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
|
|||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
int vboxNetworkClose(virConnectPtr conn);
|
int vboxNetworkClose(virConnectPtr conn);
|
||||||
int vboxConnectNumOfNetworks(virConnectPtr conn);
|
int vboxConnectNumOfNetworks(virConnectPtr conn);
|
||||||
|
int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames);
|
||||||
|
|
||||||
/* Version specified functions for installing uniformed API */
|
/* Version specified functions for installing uniformed API */
|
||||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||||
|
Loading…
Reference in New Issue
Block a user