LCOV - code coverage report
Current view: top level - cppuhelper/source - macro_expander.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 50 84.0 %
Date: 2015-06-13 12:38:46 Functions: 16 19 84.2 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <rtl/bootstrap.hxx>
      22             : 
      23             : #include <uno/lbnames.h>
      24             : #include <uno/mapping.hxx>
      25             : 
      26             : #include <cppuhelper/factory.hxx>
      27             : #include <cppuhelper/compbase2.hxx>
      28             : #include <cppuhelper/component_context.hxx>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : 
      31             : #include <com/sun/star/lang/XServiceInfo.hpp>
      32             : #include <com/sun/star/util/XMacroExpander.hpp>
      33             : #include <com/sun/star/uno/RuntimeException.hpp>
      34             : 
      35             : #include "macro_expander.hxx"
      36             : #include "paths.hxx"
      37             : 
      38             : #define SERVICE_NAME_A "com.sun.star.lang.MacroExpander"
      39             : #define SERVICE_NAME_B "com.sun.star.lang.BootstrapMacroExpander"
      40             : #define IMPL_NAME "com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander"
      41             : 
      42             : using namespace ::osl;
      43             : using namespace ::com::sun::star;
      44             : using namespace ::com::sun::star::uno;
      45             : 
      46             : using rtl::Bootstrap;
      47             : using rtl::OUString;
      48             : 
      49             : namespace cppu
      50             : {
      51             : 
      52       79759 : Bootstrap const & get_unorc()
      53             : {
      54             :     static rtlBootstrapHandle s_bstrap = 0;
      55       79759 :     if (! s_bstrap)
      56             :     {
      57         503 :         OUString iniName(getUnoIniUri());
      58         503 :         rtlBootstrapHandle bstrap = rtl_bootstrap_args_open( iniName.pData );
      59             : 
      60        1006 :         ClearableMutexGuard guard( Mutex::getGlobalMutex() );
      61         503 :         if (s_bstrap)
      62             :         {
      63           0 :             guard.clear();
      64           0 :             rtl_bootstrap_args_close( bstrap );
      65             :         }
      66             :         else
      67             :         {
      68         503 :             s_bstrap = bstrap;
      69         503 :         }
      70             :     }
      71       79759 :     return *reinterpret_cast<Bootstrap const *>(&s_bstrap);
      72             : }
      73             : 
      74             : }
      75             : 
      76             : namespace cppuhelper { namespace detail {
      77             : 
      78       79759 : rtl::OUString expandMacros(rtl::OUString const & text) {
      79       79759 :     rtl::OUString t(text);
      80             :     rtl_bootstrap_expandMacros_from_handle(
      81       79759 :         cppu::get_unorc().getHandle(), &t.pData);
      82       79759 :     return t;
      83             : }
      84             : 
      85             : } }
      86             : 
      87             : namespace
      88             : {
      89             : 
      90         506 : class ImplNames
      91             : {
      92             : private:
      93             :     Sequence<OUString> m_aNames;
      94             : public:
      95         506 :     ImplNames() : m_aNames(2)
      96             :     {
      97         506 :         m_aNames[0] = SERVICE_NAME_A;
      98         506 :         m_aNames[1] = SERVICE_NAME_B;
      99         506 :     }
     100         519 :     const Sequence<OUString>& getNames() const { return m_aNames; }
     101             : };
     102             : 
     103             : class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
     104             : 
     105         519 : inline OUString s_impl_name()
     106             : {
     107         519 :     return OUString(IMPL_NAME);
     108             : }
     109             : 
     110         519 : inline Sequence< OUString > const & s_get_service_names()
     111             : {
     112         519 :     return theImplNames::get().getNames();
     113             : }
     114             : 
     115             : typedef ::cppu::WeakComponentImplHelper2<
     116             :     util::XMacroExpander, lang::XServiceInfo > t_uno_impl;
     117             : 
     118         418 : struct mutex_holder
     119             : {
     120             :     Mutex m_mutex;
     121             : };
     122             : 
     123             : class Bootstrap_MacroExpander : public mutex_holder, public t_uno_impl
     124             : {
     125             : protected:
     126             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     127             : 
     128             : public:
     129         211 :     inline Bootstrap_MacroExpander()
     130         211 :         : t_uno_impl( m_mutex )
     131         211 :         {}
     132             :     virtual ~Bootstrap_MacroExpander();
     133             : 
     134             :     // XMacroExpander impl
     135             :     virtual OUString SAL_CALL expandMacros( OUString const & exp )
     136             :         throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
     137             :     // XServiceInfo impl
     138             :     virtual OUString SAL_CALL getImplementationName()
     139             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     140             :     virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName )
     141             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     142             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
     143             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     144             : };
     145             : 
     146             : 
     147         209 : void Bootstrap_MacroExpander::disposing()
     148         209 : {}
     149             : 
     150         414 : Bootstrap_MacroExpander::~Bootstrap_MacroExpander()
     151         414 : {}
     152             : 
     153             : // XServiceInfo impl
     154             : 
     155           0 : OUString Bootstrap_MacroExpander::getImplementationName()
     156             :     throw (RuntimeException, std::exception)
     157             : {
     158           0 :     return s_impl_name();
     159             : }
     160             : 
     161           0 : sal_Bool Bootstrap_MacroExpander::supportsService( OUString const & serviceName )
     162             :     throw (RuntimeException, std::exception)
     163             : {
     164           0 :     return cppu::supportsService(this, serviceName);
     165             : }
     166             : 
     167           0 : Sequence< OUString > Bootstrap_MacroExpander::getSupportedServiceNames()
     168             :     throw (RuntimeException, std::exception)
     169             : {
     170           0 :     return s_get_service_names();
     171             : }
     172             : 
     173             : // XMacroExpander impl
     174             : 
     175       63199 : OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp )
     176             :     throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     177             : {
     178       63199 :     return cppuhelper::detail::expandMacros( exp );
     179             : }
     180             : 
     181             : 
     182         211 : Reference< XInterface > SAL_CALL service_create(
     183             :     SAL_UNUSED_PARAMETER Reference< XComponentContext > const & )
     184             : {
     185         211 :     return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander );
     186             : }
     187             : 
     188             : }
     189             : 
     190             : namespace cppuhelper { namespace detail {
     191             : 
     192         519 : Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory()
     193             : {
     194             :     Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory(
     195             :                                                         service_create,
     196             :                                                         s_impl_name(),
     197         519 :                                                         s_get_service_names() ));
     198             : 
     199        1038 :     uno::Environment curr_env(Environment::getCurrent());
     200        1038 :     uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
     201             : 
     202        1038 :     uno::Mapping target2curr(target_env, curr_env);
     203             : 
     204             :     return Reference<lang::XSingleComponentFactory>(
     205             :         static_cast<lang::XSingleComponentFactory *>(
     206         519 :             target2curr.mapInterface(free.get(), cppu::UnoType<decltype(free)>::get())),
     207        1038 :         SAL_NO_ACQUIRE);
     208             : }
     209             : 
     210             : } }
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11