From d4b6aa63051153129a9ecf7e24596bfe376bac15 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 20 Jan 2023 11:20:20 +0100 Subject: [PATCH] vbox: Introduce VBOX_QUERY_INTERFACE() 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 Reviewed-by: Martin Kletzander --- src/vbox/vbox_common.h | 3 +++ src/vbox/vbox_tmpl.c | 6 ++++++ src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 10 insertions(+) diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h index ec2f9637dc..a2d0903c45 100644 --- a/src/vbox/vbox_common.h +++ b/src/vbox/vbox_common.h @@ -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) \ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 9976867004..32bfbecabc 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -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, }; diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index c1a2af1d42..ba655feb95 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -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;