summaryrefslogtreecommitdiffstats
path: root/cppuhelper/source/defaultbootstrap.cxx
blob: ca70a91d3f57611a1c236101218e4e5f306b21b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <sal/config.h>

#include <vector>

#include <com/sun/star/uno/DeploymentException.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <cppuhelper/bootstrap.hxx>
#include <cppuhelper/component_context.hxx>
#include <cppuhelper/weak.hxx>
#include <rtl/bootstrap.hxx>
#include <rtl/ref.hxx>
#include <rtl/ustring.hxx>

#include "macro_expander.hxx"
#include "paths.hxx"
#include "servicemanager.hxx"
#include "typemanager.hxx"

namespace com :: sun :: star :: uno { class XComponentContext; }

namespace {

OUString getBootstrapVariable(
    rtl::Bootstrap const & bootstrap, OUString const & name)
{
    OUString v;
    if (!bootstrap.getFrom(name, v)) {
        throw css::uno::DeploymentException(
            "Cannot obtain " + name + " from uno ini");
    }
    return v;
}

}

css::uno::Reference< css::uno::XComponentContext >
cppu::defaultBootstrap_InitialComponentContext(OUString const & iniUri)
{
    rtl::Bootstrap bs(iniUri);
    if (bs.getHandle() == nullptr) {
        throw css::uno::DeploymentException(
            "Cannot open uno ini " + iniUri);
    }
    rtl::Reference smgr(
        new cppuhelper::ServiceManager);
    smgr->init(getBootstrapVariable(bs, u"UNO_SERVICES"_ustr));
    rtl::Reference tmgr(new cppuhelper::TypeManager);
    tmgr->init(getBootstrapVariable(bs, u"UNO_TYPES"_ustr));
    std::vector< cppu::ContextEntry_Init > context_values
    {
        cppu::ContextEntry_Init(
            u"/singletons/com.sun.star.lang.theServiceManager"_ustr,
            css::uno::Any(
                css::uno::Reference< css::uno::XInterface >(
                    static_cast< cppu::OWeakObject * >(smgr.get()))),
            false),
        cppu::ContextEntry_Init(
            u"/singletons/com.sun.star.reflection.theTypeDescriptionManager"_ustr,
            css::uno::Any(
                css::uno::Reference< css::uno::XInterface >(
                    static_cast< cppu::OWeakObject * >(tmgr.get()))),
            false),
        cppu::ContextEntry_Init( //TODO: from services.rdb?
            u"/singletons/com.sun.star.util.theMacroExpander"_ustr,
            css::uno::Any(
                cppuhelper::detail::create_bootstrap_macro_expander_factory()),
            true)
    };
    smgr->addSingletonContextEntries(&context_values);
    context_values.push_back(
        cppu::ContextEntry_Init(
            u"/services/com.sun.star.security.AccessController/mode"_ustr,
            css::uno::Any(u"off"_ustr), false));
    context_values.push_back(
        cppu::ContextEntry_Init(
            u"/singletons/com.sun.star.security.theAccessController"_ustr,
            css::uno::Any(
                u"com.sun.star.security.AccessController"_ustr),
            true));
    css::uno::Reference< css::uno::XComponentContext > context(
        createComponentContext(context_values.data(), context_values.size()));
    smgr->setContext(context);
    cppu::installTypeDescriptionManager(tmgr);
    return context;
}

css::uno::Reference< css::uno::XComponentContext >
cppu::defaultBootstrap_InitialComponentContext()
{
    return defaultBootstrap_InitialComponentContext(getUnoIniUri());
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */