1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <string_view>
12 #include <bridges/net_uno/net_context.hxx>
13 #include <cppuhelper/bootstrap.hxx>
14 #include <o3tl/string_view.hxx>
15 #include <rtl/bootstrap.hxx>
16 #include <rtl/ustring.hxx>
17 #include <sal/log.hxx>
18 #include <uno/mapping.hxx>
20 #include <com/sun/star/lang/XComponent.hpp>
21 #include <com/sun/star/uno/XComponentContext.hpp>
23 using namespace ::com::sun::star
;
24 using namespace ::com::sun::star::uno
;
29 SAL_DLLPUBLIC_EXPORT IntPtr
bootstrap(const Context aContext
)
33 // Bootstrap UNO and start a LibreOffice process if needed
34 Reference
<XComponentContext
> xContext(::cppu::bootstrap());
36 // Get a mapping between the C++ and .NET environments
37 Environment
cpp_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME
);
38 Environment
net_env(u
"" UNO_LB_NET
""_ustr
, new Context(aContext
));
39 Mapping
mapping(cpp_env
.get(), net_env
.get());
42 Reference
<lang::XComponent
> xComp(xContext
, UNO_QUERY
);
48 throw RuntimeException(u
"could not get mapping between C++ and .NET"_ustr
);
51 // Map the XComponentContext to a .NET proxy
52 return mapping
.mapInterface(xContext
.get(), cppu::UnoType
<decltype(xContext
)>::get());
54 catch (const Exception
& exc
)
56 SAL_WARN("net", ".NET bootstrap error: " << exc
.Message
);
57 aContext
.throwError((u
"" SAL_WHERE
""_ustr
).getStr(), exc
.Message
.getStr());
62 SAL_DLLPUBLIC_EXPORT IntPtr
defaultBootstrap_InitialComponentContext(const sal_Unicode
* sIniFile
,
63 const sal_Unicode
* sParams
,
64 const Context aContext
)
68 // Set bootstrap parameters, merged into a single string (at least for now)
69 // to avoid dealing with lifetimes and memory of multiple strings
72 OUString
paramsStr(sParams
);
73 for (size_t i
= 0; i
!= std::u16string_view::npos
;)
75 std::u16string_view
name(o3tl::getToken(paramsStr
, u
'|', i
));
76 OUString
key(name
.substr(0, name
.find_first_of('=')));
77 OUString
val(name
.substr(key
.getLength() + 1));
78 ::rtl::Bootstrap::set(key
, val
);
83 Reference
<XComponentContext
> xContext
;
86 xContext
= ::cppu::defaultBootstrap_InitialComponentContext(OUString(sIniFile
));
90 xContext
= ::cppu::defaultBootstrap_InitialComponentContext();
93 // Get a mapping between the C++ and .NET environments
94 Environment
cpp_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME
);
95 Environment
net_env(u
"" UNO_LB_NET
""_ustr
, new Context(aContext
));
96 Mapping
mapping(cpp_env
.get(), net_env
.get());
99 Reference
<lang::XComponent
> xComp(xContext
, UNO_QUERY
);
105 throw RuntimeException(u
"could not get mapping between C++ and .NET"_ustr
);
108 // Map the XComponentContext to a .NET proxy
109 return mapping
.mapInterface(xContext
.get(), cppu::UnoType
<decltype(xContext
)>::get());
111 catch (const Exception
& exc
)
113 SAL_WARN("net", ".NET bootstrap error: " << exc
.Message
);
114 aContext
.throwError((u
"" SAL_WHERE
""_ustr
).getStr(), exc
.Message
.getStr());
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */