Commit 692d5e60 authored by Anya Harter's avatar Anya Harter Committed by Katerina Koukiou

Introduce Interface Interface

Signed-off-by: 's avatarAnya Harter <aharter@redhat.com>
Reviewed-by: 's avatarJán Tomko <jtomko@redhat.com>
parent c67913c9
......@@ -33,6 +33,7 @@ polkit_DATA = \
interfaces_files = \
org.libvirt.Connect.xml \
org.libvirt.Domain.xml \
org.libvirt.Interface.xml \
org.libvirt.Network.xml \
org.libvirt.NodeDevice.xml \
org.libvirt.NWFilter.xml \
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/libvirt/interface">
<interface name="org.libvirt.Interface">
</interface>
</node>
......@@ -41,6 +41,8 @@ libvirt_dbus_SOURCES = \
events.h \
gdbus.c \
gdbus.h \
interface.c \
interface.h \
main.c \
network.c \
network.h \
......
#include "connect.h"
#include "domain.h"
#include "events.h"
#include "interface.h"
#include "network.h"
#include "nodedev.h"
#include "nwfilter.h"
......@@ -1809,6 +1810,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
virtDBusConnectClose(connect, TRUE);
g_free(connect->domainPath);
g_free(connect->interfacePath);
g_free(connect->networkPath);
g_free(connect->nodeDevPath);
g_free(connect->nwfilterPath);
......@@ -1869,6 +1871,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
if (error && *error)
return;
virtDBusInterfaceRegister(connect, error);
if (error && *error)
return;
virtDBusNetworkRegister(connect, error);
if (error && *error)
return;
......
......@@ -13,6 +13,7 @@ struct virtDBusConnect {
const gchar *uri;
const gchar *connectPath;
gchar *domainPath;
gchar *interfacePath;
gchar *networkPath;
gchar *nodeDevPath;
gchar *nwfilterPath;
......
#include "interface.h"
#include "util.h"
#include <libvirt/libvirt.h>
static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = {
{ 0 }
};
static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = {
{ 0 }
};
static gchar **
virtDBusInterfaceEnumerate(gpointer userData)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterfacePtr) interfaces = NULL;
gint num = 0;
gchar **ret = NULL;
if (!virtDBusConnectOpen(connect, NULL))
return NULL;
num = virConnectListAllInterfaces(connect->connection, &interfaces, 0);
if (num < 0)
return NULL;
if (num == 0)
return NULL;
ret = g_new0(gchar *, num + 1);
for (gint i = 0; i < num; i++) {
ret[i] = virtDBusUtilBusPathForVirInterface(interfaces[i],
connect->interfacePath);
}
return ret;
}
static GDBusInterfaceInfo *interfaceInfo;
void
virtDBusInterfaceRegister(virtDBusConnect *connect,
GError **error)
{
connect->interfacePath = g_strdup_printf("%s/interface",
connect->connectPath);
if (!interfaceInfo) {
interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_INTERFACE_INTERFACE,
error);
if (!interfaceInfo)
return;
}
virtDBusGDBusRegisterSubtree(connect->bus,
connect->interfacePath,
interfaceInfo,
virtDBusInterfaceEnumerate,
virtDBusInterfaceMethodTable,
virtDBusInterfacePropertyTable,
connect);
}
#pragma once
#include "connect.h"
#define VIRT_DBUS_INTERFACE_INTERFACE "org.libvirt.Interface"
void
virtDBusInterfaceRegister(virtDBusConnect *connect,
GError **error);
......@@ -278,6 +278,41 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains)
g_free(domains);
}
virInterfacePtr
virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *interfacePath)
{
g_autofree gchar *macstr = NULL;
gsize prefixLen = strlen(interfacePath) + 1;
macstr = virtDBusUtilDecodeStr(path + prefixLen);
return virInterfaceLookupByMACString(connection, macstr);
}
gchar *
virtDBusUtilBusPathForVirInterface(virInterfacePtr interface,
const gchar *interfacePath)
{
const gchar *macstr = NULL;
g_autofree const gchar *encodedMACStr = NULL;
macstr = virInterfaceGetMACString(interface);
encodedMACStr = virtDBusUtilEncodeStr(macstr);
return g_strdup_printf("%s/%s", interfacePath, encodedMACStr);
}
void
virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces)
{
for (gint i = 0; interfaces[i] != NULL; i++)
virInterfaceFree(interfaces[i]);
g_free(interfaces);
}
virNetworkPtr
virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
const gchar *path,
......
......@@ -65,6 +65,21 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecordListFree);
virInterfacePtr
virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *interfacePath);
gchar *
virtDBusUtilBusPathForVirInterface(virInterfacePtr interface,
const gchar *interfacePath);
void
virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterface, virInterfaceFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterfacePtr, virtDBusUtilVirInterfaceListFree);
virNetworkPtr
virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
const gchar *path,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment