28#include <Foundation/Foundation.h>
32#include <com/sun/star/loader/CannotActivateFactoryException.hpp>
33#include <com/sun/star/registry/CannotRegisterImplementationException.hpp>
34#include <com/sun/star/registry/XRegistryKey.hpp>
38#include <osl/module.hxx>
40#include <uno/environment.hxx>
41#include <uno/mapping.hxx>
45#if defined DISABLE_DYNLOADING
46#include <osl/detail/component-mapping.h>
50 OUString
const & name, std::u16string_view implementation)
53 if (!implementation.empty()) {
54 static char const *
log = std::getenv(
"UNO_ENV_LOG");
55 if (
log !=
nullptr && *
log != 0) {
57 for (sal_Int32
i = 0;
i != -1;) {
68 return css::uno::Environment(
n);
73#if !defined DISABLE_DYNLOADING
75css::uno::Environment getEnvironmentFromModule(
76 osl::Module
const & module, css::uno::Environment
const & target,
77 std::u16string_view implementation, OUString
const & prefix)
79 char const *
name =
nullptr;
80 css::uno::Environment
env;
81 OUString fullPrefix(prefix);
82 if (!fullPrefix.isEmpty()) {
101 name = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
104 if (!
env.is() && name !=
nullptr) {
106 OUString::createFromAscii(name), implementation);
113extern "C" void getFactory(va_list * args) {
115 OString
const * implementation = va_arg(*args, OString
const *);
116 void * smgr = va_arg(*args,
void *);
117 void ** factory = va_arg(*args,
void **);
118 *factory = (*fn)(implementation->getStr(), smgr,
nullptr);
121css::uno::Reference<css::uno::XInterface> invokeComponentFactory(
122 css::uno::Environment
const & source, css::uno::Environment
const & target,
124 std::u16string_view implementation,
125 css::uno::Reference<css::lang::XMultiServiceFactory>
const & serviceManager)
127 if (!(source.is() && target.is())) {
128 throw css::loader::CannotActivateFactoryException(
129 "cannot get environments",
130 css::uno::Reference<css::uno::XInterface>());
134 if (source.get() == target.get()) {
135 return css::uno::Reference<css::uno::XInterface>(
136 static_cast<css::uno::XInterface *
>(
137 (*function)(
impl.getStr(), serviceManager.get(),
nullptr)),
140 css::uno::Mapping mapTo(source, target);
141 css::uno::Mapping mapFrom(target, source);
142 if (!(mapTo.is() && mapFrom.is())) {
143 throw css::loader::CannotActivateFactoryException(
144 "cannot get mappings",
145 css::uno::Reference<css::uno::XInterface>());
147 void * smgr = mapTo.mapInterface(
148 serviceManager.get(),
150 void * factory =
nullptr;
151 target.invoke(getFactory, function, &
impl, smgr, &factory);
152 if (smgr !=
nullptr) {
153 (*target.get()->pExtEnv->releaseInterface)(
154 target.get()->pExtEnv, smgr);
156 if (factory ==
nullptr) {
157 throw css::loader::CannotActivateFactoryException(
158 (OUString::Concat(
"calling factory function for \"") + implementation +
"\" in <"
159 + uri +
"> returned null"),
160 css::uno::Reference<css::uno::XInterface>());
162 css::uno::Reference<css::uno::XInterface> res;
163 mapFrom.mapInterface(
164 reinterpret_cast<void **
>(&res), factory,
166 (*target.get()->pExtEnv->releaseInterface)(
167 target.get()->pExtEnv, factory);
171#if !defined DISABLE_DYNLOADING
173extern "C" void getInstance(va_list * args) {
175 void * ctxt = va_arg(*args,
void *);
177 void * argseq = va_arg(*args,
void *);
179 void ** instance = va_arg(*args,
void **);
181 assert(*instance ==
nullptr);
182 *instance = (*fn)(
static_cast<css::uno::XComponentContext*
>(ctxt),
183 *
static_cast<css::uno::Sequence<css::uno::Any> const*
>(argseq));
187 css::uno::Environment
const & source, css::uno::Environment
const & target,
190 if (!(source.is() && target.is())) {
191 throw css::loader::CannotActivateFactoryException(
192 "cannot get environments",
193 css::uno::Reference<css::uno::XInterface>());
195 if (source.get() == target.get()) {
201 css::uno::Mapping mapTo(source, target);
202 css::uno::Mapping mapFrom(target, source);
203 if (!(mapTo.is() && mapFrom.is())) {
204 throw css::loader::CannotActivateFactoryException(
205 "cannot get mappings",
206 css::uno::Reference<css::uno::XInterface>());
208 return [mapFrom, mapTo, target, constructorFunction]
209 (css::uno::XComponentContext *
const context, css::uno::Sequence<css::uno::Any>
const&
args)
211 void *
const ctxt = mapTo.mapInterface(
214 if (
args.hasElements()) {
217 void * instance =
nullptr;
218 target.invoke(getInstance, constructorFunction, ctxt, &args, &instance);
219 if (ctxt !=
nullptr) {
220 (*target.get()->pExtEnv->releaseInterface)(
221 target.get()->pExtEnv, ctxt);
223 css::uno::XInterface * res =
nullptr;
224 if (instance ==
nullptr) {
227 mapFrom.mapInterface(
228 reinterpret_cast<void **
>(&res), instance,
230 (*target.get()->pExtEnv->releaseInterface)(
231 target.get()->pExtEnv, instance);
241 OUString
const & uri, OUString
const & environment,
242 OUString
const & prefix, OUString
const & implementation,
243 OUString
const & constructor,
244 css::uno::Reference<css::lang::XMultiServiceFactory>
const & serviceManager,
246 css::uno::Reference<css::uno::XInterface> * factory)
248 assert(constructor.isEmpty() || !environment.isEmpty());
250 (constructorFunction ==
nullptr && constructor.isEmpty())
251 || !*constructorFunction);
252 assert(factory !=
nullptr && !factory->is());
253#if defined DISABLE_DYNLOADING
254 assert(!environment.isEmpty());
255 if (constructor.isEmpty()) {
256 css::uno::Environment curEnv(css::uno::Environment::getCurrent());
258 if (!(curEnv.is() &&
env.is())) {
259 throw css::loader::CannotActivateFactoryException(
260 "cannot get environments",
261 css::uno::Reference<css::uno::XInterface>());
263 if (curEnv.get() !=
env.get()) {
266 SAL_INFO(
"cppuhelper.shlib",
"prefix=" <<
prefix <<
" implementation=" << implementation <<
" uri=" << uri);
267 lib_to_factory_mapping
const *
map = lo_get_factory_map();
269 for (
int i = 0;
map[
i].name != 0; ++
i) {
270 if (uri.equalsAscii(
map[
i].name)) {
271 fp =
map[
i].component_getFactory_function;
276 SAL_WARN(
"cppuhelper",
"unknown factory name \"" << uri <<
"\"");
278 NSLog(
@"Unknown factory %s", uri.toUtf8().getStr());
280 throw css::loader::CannotActivateFactoryException(
281 "unknown factory name \"" + uri +
"\"",
282 css::uno::Reference<css::uno::XInterface>());
284 *factory = invokeComponentFactory(
285 css::uno::Environment::getCurrent(),
287 implementation, serviceManager);
289 SAL_INFO(
"cppuhelper.shlib",
"constructor=" << constructor);
290 lib_to_constructor_mapping
const *
map = lo_get_constructor_map();
291 for (
int i = 0;
map[
i].name != 0; ++
i) {
292 if (constructor.equalsAscii(
map[
i].name)) {
295 map[
i].constructor_function);
299 SAL_WARN(
"cppuhelper",
"unknown constructor name \"" << constructor <<
"\"");
301 NSLog(
@"Unknown constructor %s", constructor.toUtf8().getStr());
303 throw css::loader::CannotActivateFactoryException(
304 "unknown constructor name \"" + constructor +
"\"",
305 css::uno::Reference<css::uno::XInterface>());
308 osl::Module mod(uri, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
310 throw css::loader::CannotActivateFactoryException(
311 "loading component library <" + uri +
"> failed",
312 css::uno::Reference<css::uno::XInterface>());
314 if (constructor.isEmpty()) {
316 SAL_INFO(
"cppuhelper.shlib",
"prefix=" <<
prefix <<
" implementation=" << implementation <<
" uri=" << uri);
322 oslGenericFunction fp = mod.getFunctionSymbol(sym);
324 throw css::loader::CannotActivateFactoryException(
325 (
"no factory symbol \"" + sym +
"\" in component library <"
327 css::uno::Reference<css::uno::XInterface>());
329 css::uno::Environment curEnv(css::uno::Environment::getCurrent());
330 *factory = invokeComponentFactory(
332 (environment.isEmpty()
333 ? getEnvironmentFromModule(mod, curEnv, implementation,
prefix)
338 SAL_INFO(
"cppuhelper.shlib",
"constructor=" << constructor);
339 oslGenericFunction fp = mod.getFunctionSymbol(constructor);
341 throw css::loader::CannotActivateFactoryException(
342 (
"no constructor symbol \"" + constructor
343 +
"\" in component library <" + uri +
">"),
344 css::uno::Reference<css::uno::XInterface>());
346 css::uno::Environment curEnv(css::uno::Environment::getCurrent());
347 *constructorFunction = mapConstructorFn(
349 (environment.isEmpty()
350 ? getEnvironmentFromModule(mod, curEnv, implementation,
prefix)
359 OUString
const & uri, OUString
const & rPath,
360 OUString
const & rImplName,
361 css::uno::Reference<css::lang::XMultiServiceFactory>
const & xMgr,
362 css::uno::Reference<css::registry::XRegistryKey>
const & xKey)
364 assert(rPath.isEmpty()); (void) rPath;
365 assert(!xKey.is()); (void) xKey;
366 css::uno::Reference<css::uno::XInterface>
fac;
368 uri,
"",
"", rImplName,
"", xMgr,
nullptr, &fac);
372#if !defined DISABLE_DYNLOADING
376extern "C" void writeInfo(va_list * args) {
378 void * smgr = va_arg(*args,
void *);
379 void * key = va_arg(*args,
void *);
381 *ok = (*fn)(smgr, key);
387 OUString
const & uri, OUString
const & rPath,
388 css::uno::Reference<css::lang::XMultiServiceFactory>
const & xMgr,
389 css::uno::Reference<css::registry::XRegistryKey>
const & xKey)
391 assert(rPath.isEmpty()); (void) rPath;
392 osl::Module mod(uri, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
394 throw css::registry::CannotRegisterImplementationException(
395 "loading component library <" + uri +
"> failed",
396 css::uno::Reference<css::uno::XInterface>());
400 throw css::registry::CannotRegisterImplementationException(
403 css::uno::Reference<css::uno::XInterface>());
405 css::uno::Environment curEnv(css::uno::Environment::getCurrent());
406 css::uno::Environment
env(getEnvironmentFromModule(mod, curEnv, u
"",
""));
407 if (!(curEnv.is() &&
env.is())) {
408 throw css::registry::CannotRegisterImplementationException(
409 "cannot get environments",
410 css::uno::Reference<css::uno::XInterface>());
412 css::uno::Mapping
map(curEnv, env);
414 throw css::registry::CannotRegisterImplementationException(
415 "cannot get mapping", css::uno::Reference<css::uno::XInterface>());
417 void * smgr =
map.mapInterface(
419 void * key =
map.mapInterface(
422 env.invoke(writeInfo, fp, smgr, key, &ok);
423 (*
env.get()->pExtEnv->releaseInterface)(
env.get()->pExtEnv, key);
424 if (smgr !=
nullptr) {
425 (*
env.get()->pExtEnv->releaseInterface)(
env.get()->pExtEnv, smgr);
428 throw css::registry::CannotRegisterImplementationException(
430 +
"> returned false"),
431 css::uno::Reference<css::uno::XInterface>());
css::uno::Type const & get()
void(SAL_CALL * component_getImplementationEnvironmentExtFunc)(char const **ppEnvTypeName, uno_Environment **ppEnv, char const *pImplName, uno_Environment *pTargetEnv)
Function pointer declaration.
void(SAL_CALL * component_getImplementationEnvironmentFunc)(const char **ppEnvTypeName, uno_Environment **ppEnv)
Function pointer declaration.
struct _uno_Environment uno_Environment
#define COMPONENT_WRITEINFO
sal_Bool(SAL_CALL * component_writeInfoFunc)(void *pServiceManager, void *pRegistryKey)
Function pointer declaration.
#define COMPONENT_GETFACTORY
void *(SAL_CALL * component_getFactoryFunc)(const char *pImplName, void *pServiceManager, void *pRegistryKey)
Function pointer declaration.
#define COMPONENT_GETENVEXT
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
SAL_DLLPUBLIC_EXPORT css::uno::Reference< css::uno::XInterface > SAL_CALL loadSharedLibComponentFactory(OUString const &, OUString const &, OUString const &, css::uno::Reference< css::lang::XMultiServiceFactory > const &, css::uno::Reference< css::registry::XRegistryKey > const &, OUString const &)
CPPUHELPER_DLLPUBLIC void SAL_CALL writeSharedLibComponentInfo(::rtl::OUString const &uri, ::rtl::OUString const &rPath, css::uno::Reference< css::lang::XMultiServiceFactory > const &xMgr, css::uno::Reference< css::registry::XRegistryKey > const &xKey)
Invokes component_writeInfo() function of specified component library.
css::uno::Environment getEnvironment(OUString const &name, std::u16string_view implementation)
void loadSharedLibComponentFactory(OUString const &uri, OUString const &environment, OUString const &prefix, OUString const &implementation, OUString const &constructor, css::uno::Reference< css::lang::XMultiServiceFactory > const &serviceManager, WrapperConstructorFn *constructorFunction, css::uno::Reference< css::uno::XInterface > *factory)
css::uno::XInterface * ImplementationConstructorFn(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
std::function< css::uno::XInterface *(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)> WrapperConstructorFn
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
bool equalsAscii(std::u16string_view s1, std::string_view s2)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::map< OUString, rtl::Reference< Entity > > map