LCOV - code coverage report
Current view: top level - cppuhelper/source - defaultbootstrap.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 28 32 87.5 %
Date: 2014-04-11 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         838 : rtl::OUString getBootstrapVariable(
      35             :     rtl::Bootstrap const & bootstrap, rtl::OUString const & name)
      36             : {
      37         838 :     rtl::OUString v;
      38         838 :     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         838 :     return v;
      44             : }
      45             : 
      46             : }
      47             : 
      48             : css::uno::Reference< css::uno::XComponentContext >
      49         419 : cppu::defaultBootstrap_InitialComponentContext(rtl::OUString const & iniUri)
      50             :     SAL_THROW((css::uno::Exception))
      51             : {
      52         419 :     rtl::Bootstrap bs(iniUri);
      53         419 :     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         838 :         new cppuhelper::ServiceManager);
      60         419 :     smgr->init(getBootstrapVariable(bs, "UNO_SERVICES"));
      61         838 :     rtl::Reference< cppuhelper::TypeManager > tmgr(new cppuhelper::TypeManager);
      62         419 :     tmgr->init(getBootstrapVariable(bs, "UNO_TYPES"));
      63         838 :     cppu::ContextEntry_Init entry;
      64         838 :     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         419 :                     static_cast< cppu::OWeakObject * >(smgr.get()))),
      71         419 :             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         419 :                     static_cast< cppu::OWeakObject * >(tmgr.get()))),
      78         419 :             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         419 :             true));
      85         419 :     smgr->addSingletonContextEntries(&context_values);
      86             :     context_values.push_back(
      87             :         cppu::ContextEntry_Init(
      88             :             "/services/com.sun.star.security.AccessController/mode",
      89         419 :             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         419 :             true));
      96             :     assert(!context_values.empty());
      97             :     css::uno::Reference< css::uno::XComponentContext > context(
      98             :         createComponentContext(
      99         838 :             &context_values[0], context_values.size(),
     100        1257 :             css::uno::Reference< css::uno::XComponentContext >()));
     101         419 :     smgr->setContext(context);
     102         419 :     cppu::installTypeDescriptionManager(tmgr.get());
     103         838 :     return context;
     104             : }
     105             : 
     106             : css::uno::Reference< css::uno::XComponentContext >
     107         419 : cppu::defaultBootstrap_InitialComponentContext()
     108             :     SAL_THROW((css::uno::Exception))
     109             : {
     110         419 :     return defaultBootstrap_InitialComponentContext(getUnoIniUri());
     111             : }
     112             : 
     113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10