[libvirt] [dbus PATCH 10/15] Implement InterfaceLookupByName method for Connect Interface

Anya Harter posted 15 patches 7 years, 7 months ago
[libvirt] [dbus PATCH 10/15] Implement InterfaceLookupByName method for Connect Interface
Posted by Anya Harter 7 years, 7 months ago
Signed-off-by: Anya Harter <aharter@redhat.com>
---
 data/org.libvirt.Connect.xml |  6 ++++++
 src/connect.c                | 29 +++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 7c97117..f99e205 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -170,6 +170,12 @@
       <arg name="flags" type="u" direction="in"/>
       <arg name="interface" type="o" direction="out"/>
     </method>
+    <method name="InterfaceLookupByName">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByName"/>
+      <arg name="name" type="s" direction="in"/>
+      <arg name="interface" type="o" direction="out"/>
+    </method>
     <method name="ListDomains">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDomains"/>
diff --git a/src/connect.c b/src/connect.c
index 563535c..51a6ba0 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -827,6 +827,34 @@ virtDBusConnectInterfaceDefineXML(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static void
+virtDBusConnectInterfaceLookupByName(GVariant *inArgs,
+                                     GUnixFDList *inFDs G_GNUC_UNUSED,
+                                     const gchar *objectPath G_GNUC_UNUSED,
+                                     gpointer userData,
+                                     GVariant **outArgs,
+                                     GUnixFDList **outFDs G_GNUC_UNUSED,
+                                     GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virInterface) interface = NULL;
+    g_autofree gchar *path = NULL;
+    const gchar *name;
+
+    g_variant_get(inArgs, "(s)", &name);
+
+    if (!virtDBusConnectOpen(connect, NULL))
+        return;
+
+    interface = virInterfaceLookupByName(connect->connection, name);
+    if (!interface)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirInterface(interface, connect->interfacePath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static void
 virtDBusConnectListDomains(GVariant *inArgs,
                            GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -1899,6 +1927,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "InterfaceChangeCommit", virtDBusConnectInterfaceChangeCommit },
     { "InterfaceChangeRollback", virtDBusConnectInterfaceChangeRollback },
     { "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML },
+    { "InterfaceLookupByName", virtDBusConnectInterfaceLookupByName },
     { "ListDomains", virtDBusConnectListDomains },
     { "ListInterfaces", virtDBusConnectListInterfaces },
     { "ListNetworks", virtDBusConnectListNetworks },
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus PATCH 10/15] Implement InterfaceLookupByName method for Connect Interface
Posted by Pavel Hrdina 7 years, 7 months ago
On Fri, Jul 06, 2018 at 05:36:50PM -0400, Anya Harter wrote:
> Signed-off-by: Anya Harter <aharter@redhat.com>
> ---
>  data/org.libvirt.Connect.xml |  6 ++++++
>  src/connect.c                | 29 +++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+)

[...]

> diff --git a/src/connect.c b/src/connect.c
> index 563535c..51a6ba0 100644
> --- a/src/connect.c
> +++ b/src/connect.c
> @@ -827,6 +827,34 @@ virtDBusConnectInterfaceDefineXML(GVariant *inArgs,
>      *outArgs = g_variant_new("(o)", path);
>  }
>  
> +static void
> +virtDBusConnectInterfaceLookupByName(GVariant *inArgs,
> +                                     GUnixFDList *inFDs G_GNUC_UNUSED,
> +                                     const gchar *objectPath G_GNUC_UNUSED,
> +                                     gpointer userData,
> +                                     GVariant **outArgs,
> +                                     GUnixFDList **outFDs G_GNUC_UNUSED,
> +                                     GError **error)
> +{
> +    virtDBusConnect *connect = userData;
> +    g_autoptr(virInterface) interface = NULL;
> +    g_autofree gchar *path = NULL;
> +    const gchar *name;
> +
> +    g_variant_get(inArgs, "(s)", &name);

The format string needs to be "(&s)", the explanation is in the
following patch.

Pavel
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list