static/source/embindmaker/embindmaker.cxx          |    4 +++-
 static/source/unoembindhelpers/PrimaryBindings.cxx |   10 +++++++++-
 udkapi/org/libreoffice/embindtest/XTest.idl        |    2 ++
 unotest/source/embindtest/embindtest.cxx           |   14 ++++++++++++++
 unotest/source/embindtest/embindtest.js            |   10 ++++++++++
 5 files changed, 38 insertions(+), 2 deletions(-)

New commits:
commit da49e5edb2fba9e99ed7d58952dc761b0804e7fc
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Thu Mar 7 17:10:25 2024 +0100
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Thu Mar 7 23:13:31 2024 +0100

    Add Embind'ing of UNO Any getter for interfaces
    
    Change-Id: Ia56439e0e99c193c7cc56676677df2c671278e24
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164554
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/static/source/embindmaker/embindmaker.cxx 
b/static/source/embindmaker/embindmaker.cxx
index f0f14b7e31aa..4241d10b1575 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -975,7 +975,9 @@ SAL_IMPLEMENT_MAIN()
             }
             dumpAttributes(cppOut, mgr, ifc, ifcEnt, {});
             dumpMethods(cppOut, mgr, ifc, ifcEnt, {});
-            cppOut << "        ;
";
+            cppOut << "        ;
"
+                      "    
::unoembindhelpers::registerUnoType<::com::sun::star::uno::Reference<"
+                   << cppName(ifc) << ">>();
";
             dumpRegisterFunctionEpilog(cppOut, n);
             for (auto const& attr : ifcEnt->getDirectAttributes())
             {
diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx 
b/static/source/unoembindhelpers/PrimaryBindings.cxx
index 2e5ecac00054..985ebacc52b2 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -334,7 +334,15 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
                         _emval_take_value(getTypeId(self.getValueType()), 
argv));
                 }
                 case css::uno::TypeClass_INTERFACE:
-                    return emscripten::val::undefined(); //TODO
+                {
+                    auto const ifc = *static_cast<css::uno::XInterface* 
const*>(self.getValue());
+                    auto const copy = 
std::malloc(sizeof(css::uno::XInterface*));
+                    *static_cast<css::uno::XInterface**>(copy) = ifc;
+                    ifc->acquire();
+                    emscripten::internal::WireTypePack argv(std::move(copy));
+                    return emscripten::val::take_ownership(
+                        _emval_take_value(getTypeId(self.getValueType()), 
argv));
+                }
                 default:
                     O3TL_UNREACHABLE;
             };
diff --git a/udkapi/org/libreoffice/embindtest/XTest.idl 
b/udkapi/org/libreoffice/embindtest/XTest.idl
index e5b5a4535982..45042663cf47 100644
--- a/udkapi/org/libreoffice/embindtest/XTest.idl
+++ b/udkapi/org/libreoffice/embindtest/XTest.idl
@@ -76,6 +76,8 @@ interface XTest {
     boolean isAnyStruct([in] any value);
     any getAnyException();
     boolean isAnyException([in] any value);
+    any getAnyInterface();
+    boolean isAnyInterface([in] any value);
     sequence<boolean> getSequenceBoolean();
     boolean isSequenceBoolean([in] sequence<boolean> value);
     sequence<byte> getSequenceByte();
diff --git a/unotest/source/embindtest/embindtest.cxx 
b/unotest/source/embindtest/embindtest.cxx
index 1f8b916fbbf1..d437f3907e3a 100644
--- a/unotest/source/embindtest/embindtest.cxx
+++ b/unotest/source/embindtest/embindtest.cxx
@@ -10,6 +10,7 @@
 #include <sal/config.h>
 
 #include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Reference.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/uno/Type.hxx>
 #include <cppu/unotype.hxx>
@@ -283,6 +284,19 @@ class Test : public 
cppu::WeakImplHelper<org::libreoffice::embindtest::XTest>
                && e.m3 == u"hä";
     }
 
+    css::uno::Any SAL_CALL getAnyInterface() override
+    {
+        return 
css::uno::Any(css::uno::Reference<org::libreoffice::embindtest::XTest>(this));
+    }
+
+    sal_Bool SAL_CALL isAnyInterface(css::uno::Any const& value) override
+    {
+        return value.getValueType() == 
cppu::UnoType<org::libreoffice::embindtest::XTest>::get()
+               && 
*o3tl::forceAccess<css::uno::Reference<org::libreoffice::embindtest::XTest>>(
+                      value)
+                      == static_cast<OWeakObject*>(this);
+    }
+
     css::uno::Sequence<sal_Bool> SAL_CALL getSequenceBoolean() override
     {
         return { true, true, false };
diff --git a/unotest/source/embindtest/embindtest.js 
b/unotest/source/embindtest/embindtest.js
index c661589683f6..e238af32c003 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -302,6 +302,16 @@ Module.addOnPostRun(function() {
         //TODO: console.assert(test.isAnyException(a));
         //TODO: a.delete();
     }
+    {
+        let v = test.getAnyInterface();
+        console.log(v);
+        console.assert(v.get().$equals(test.$query()));
+        console.assert(test.isAnyInterface(v));
+        v.delete();
+        //TODO: let a = new Module.Any(test, css.uno.TypeClass.INTERFACE);
+        //TODO: console.assert(test.isAnyInterface(a));
+        //TODO: a.delete();
+    }
     {
         let v = test.getSequenceBoolean();
         console.log(v);

Reply via email to