LCOV - code coverage report
Current view: top level - cppuhelper/source - defaultbootstrap.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 28 32 87.5 %
Date: 2014-04-14 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      10             : #include "sal/config.h"
      11             : 
      12             : #include <cassert>
      13             : #include <vector>
      14             : 
      15             : #include "com/sun/star/uno/DeploymentException.hpp"
      16             : #include "com/sun/star/uno/Any.hxx"
      17             : #include "com/sun/star/uno/Reference.hxx"
      18             : #include "com/sun/star/uno/XComponentContext.hpp"
      19             : #include "cppuhelper/bootstrap.hxx"
      20             : #include "cppuhelper/component_context.hxx"
      21             : #include "rtl/bootstrap.hxx"
      22             : #include "rtl/ref.hxx"
      23             : #include "rtl/ustring.hxx"
      24             : 
      25             : using rtl::OUString;
      26             : 
      27             : #include "macro_expander.hxx"
      28             : #include "paths.hxx"
      29             : #include "servicemanager.hxx"
      30             : #include "typemanager.hxx"
      31             : 
      32             : namespace {
      33             : 
      34           2 : rtl::OUString getBootstrapVariable(
      35             :     rtl::Bootstrap const & bootstrap, rtl::OUString const & name)
      36             : {
      37           2 :     rtl::OUString v;
      38           2 :     if (!bootstrap.getFrom(name, v)) {
      39             :         throw css::uno::DeploymentException(
      40           0 :             "Cannot obtain " + name + " from uno ini",
      41           0 :             css::uno::Reference< css::uno::XInterface >());
      42             :     }
      43           2 :     return v;
      44             : }
      45             : 
      46             : }
      47             : 
      48             : css::uno::Reference< css::uno::XComponentContext >
      49           1 : cppu::defaultBootstrap_InitialComponentContext(rtl::OUString const & iniUri)
      50             :     SAL_THROW((css::uno::Exception))
      51             : {
      52           1 :     rtl::Bootstrap bs(iniUri);
      53           1 :     if (bs.getHandle() == 0) {
      54             :         throw css::uno::DeploymentException(
      55           0 :             "Cannot open uno ini " + iniUri,
      56           0 :             css::uno::Reference< css::uno::XInterface >());
      57             :     }
      58             :     rtl::Reference< cppuhelper::ServiceManager > smgr(
      59           2 :         new cppuhelper::ServiceManager);
      60           1 :     smgr->init(getBootstrapVariable(bs, "UNO_SERVICES"));
      61           2 :     rtl::Reference< cppuhelper::TypeManager > tmgr(new cppuhelper::TypeManager);
      62           1 :     tmgr->init(getBootstrapVariable(bs, "UNO_TYPES"));
      63           2 :     cppu::ContextEntry_Init entry;
      64           2 :     std::vector< cppu::ContextEntry_Init > context_values;
      65             :     context_values.push_back(
      66             :         cppu::ContextEntry_Init(
      67             :             "/singletons/com.sun.star.lang.theServiceManager",
      68             :             css::uno::makeAny(
      69             :                 css::uno::Reference< css::uno::XInterface >(
      70           1 :                     static_cast< cppu::OWeakObject * >(smgr.get()))),
      71           1 :             false));
      72             :     context_values.push_back(
      73             :         cppu::ContextEntry_Init(
      74             :             "/singletons/com.sun.star.reflection.theTypeDescriptionManager",
      75             :             css::uno::makeAny(
      76             :                 css::uno::Reference< css::uno::XInterface >(
      77           1 :                     static_cast< cppu::OWeakObject * >(tmgr.get()))),
      78           1 :             false));
      79             :     context_values.push_back( //TODO: from services.rdb?
      80             :         cppu::ContextEntry_Init(
      81             :             "/singletons/com.sun.star.util.theMacroExpander",
      82             :             css::uno::makeAny(
      83             :                 cppuhelper::detail::create_bootstrap_macro_expander_factory()),
      84           1 :             true));
      85           1 :     smgr->addSingletonContextEntries(&context_values);
      86             :     context_values.push_back(
      87             :         cppu::ContextEntry_Init(
      88             :             "/services/com.sun.star.security.AccessController/mode",
      89           1 :             css::uno::makeAny(rtl::OUString("off")), false));
      90             :     context_values.push_back(
      91             :         cppu::ContextEntry_Init(
      92             :             "/singletons/com.sun.star.security.theAccessController",
      93             :             css::uno::makeAny(
      94             :                 rtl::OUString("com.sun.star.security.AccessController")),
      95           1 :             true));
      96             :     assert(!context_values.empty());
      97             :     css::uno::Reference< css::uno::XComponentContext > context(
      98             :         createComponentContext(
      99           2 :             &context_values[0], context_values.size(),
     100           3 :             css::uno::Reference< css::uno::XComponentContext >()));
     101           1 :     smgr->setContext(context);
     102           1 :     cppu::installTypeDescriptionManager(tmgr.get());
     103           2 :     return context;
     104             : }
     105             : 
     106             : css::uno::Reference< css::uno::XComponentContext >
     107           1 : cppu::defaultBootstrap_InitialComponentContext()
     108             :     SAL_THROW((css::uno::Exception))
     109             : {
     110           1 :     return defaultBootstrap_InitialComponentContext(getUnoIniUri());
     111             : }
     112             : 
     113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10