]> xenbits.xensource.com Git - libvirt.git/commitdiff
vbox: Introduce VBOX_QUERY_INTERFACE()
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 20 Jan 2023 10:20:20 +0000 (11:20 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 24 Jan 2023 09:45:26 +0000 (10:45 +0100)
So far we haven't needed to use a different interface for objects
we are working with. We were happy with calling their respective
vtbl callbacks. Well, this will change soon as we will query an
exception (type of nsIException) but will need to promote it to
IVirtualBoxErrorInfo class. This promoting is done by
QueryInterface() callback which accepts 3 arguments: the original
object, ID of the new interface and address where to store the
promoted object.

As this is very basic operation, available to every object, it is
part of the ISupports interface among with other goodies like
AddRef() and Release().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/vbox/vbox_common.h
src/vbox/vbox_tmpl.c
src/vbox/vbox_uniformed_api.h

index ec2f9637dc4f44b84e3ebe13c2acd989218c7f4f..a2d0903c45156a3c8b53e75511c4804211ba08f0 100644 (file)
@@ -405,6 +405,9 @@ typedef nsISupports IKeyboard;
             abort(); \
     } while (0)
 
+#define VBOX_QUERY_INTERFACE(nsi, iid, resultp) \
+    gVBoxAPI.nsUISupports.QueryInterface((void*)(nsi), iid, resultp)
+
 #define VBOX_ADDREF(arg)                gVBoxAPI.nsUISupports.AddRef((void *)(arg))
 
 #define VBOX_RELEASE(arg) \
index 9976867004e3e51cd5743d69d133a3c8dea3080c..32bfbecabc3a910dda189f498b8c8e0c63039ab3 100644 (file)
@@ -561,6 +561,11 @@ static void* _handleHostGetNetworkInterfaces(IHost *host)
     return host->vtbl->GetNetworkInterfaces;
 }
 
+static nsresult _nsisupportsQueryInterface(nsISupports *nsi, const nsID *iid, void **resultp)
+{
+    return nsi->vtbl->QueryInterface(nsi, iid, resultp);
+}
+
 static nsresult _nsisupportsRelease(nsISupports *nsi)
 {
     return nsi->vtbl->Release(nsi);
@@ -2219,6 +2224,7 @@ static vboxUniformedArray _UArray = {
 };
 
 static vboxUniformednsISupports _nsUISupports = {
+    .QueryInterface = _nsisupportsQueryInterface,
     .Release = _nsisupportsRelease,
     .AddRef = _nsisupportsAddRef,
 };
index c1a2af1d425dcc8fe7c92e1ead46a2358888e20a..ba655feb95fed6a527c244475085bcfce2b57a81 100644 (file)
@@ -145,6 +145,7 @@ typedef struct {
 
 /* Functions for nsISupports */
 typedef struct {
+    nsresult (*QueryInterface)(nsISupports *nsi, const nsID *iid, void **resultp);
     nsresult (*Release)(nsISupports *nsi);
     nsresult (*AddRef)(nsISupports *nsi);
 } vboxUniformednsISupports;