From 42a6cdd6788d0b25cfc5844ed4982a4e9214e605 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Tue, 22 Mar 2022 09:27:07 +0100 Subject: QWaylandClientExtension: Allow specifying destructor for wayland objects While the template takes care of creating proxies automatically, destroying them is harder since an interface can have 0 to multiple destructors. However in the most common case there is only one or always calling one is sufficient. An additional template parameter is introduced that allows user code to specify a callable taking a pointer to the scanner generated class that should be called when the wayland object is to be be destroyed. This is done when the global is removed or upon destruction of the C++ object itself. The clientextension test is changed how it can be used. Since it works via a non-type template parameter a pointer to a (member) function can be passed or when compiled in c++20 mode a lambda or for example a function object. This new functionality is opt-in and the default behavior is unchanged. The default value is nullptr used as a tag to do not enable the new behavior. Change-Id: I8043f7106fec0cd6f2a79682e5872cfa8da3d11b Reviewed-by: David Edmundson --- tests/auto/client/clientextension/tst_clientextension.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/client/clientextension/tst_clientextension.cpp b/tests/auto/client/clientextension/tst_clientextension.cpp index 91b02e3b..c1cd1cb1 100644 --- a/tests/auto/client/clientextension/tst_clientextension.cpp +++ b/tests/auto/client/clientextension/tst_clientextension.cpp @@ -14,17 +14,12 @@ using namespace MockCompositor; -class TestExtension : public QWaylandClientExtensionTemplate, - public QtWayland::test_interface +class TestExtension + : public QWaylandClientExtensionTemplate, + public QtWayland::test_interface { public: - TestExtension() : QWaylandClientExtensionTemplate(1) { } - ~TestExtension() - { - if (object()) { - release(); - } - } + TestExtension() : QWaylandClientExtensionTemplate(1){}; void initialize() { QWaylandClientExtension::initialize(); } }; -- cgit v1.2.1