LCOV - code coverage report
Current view: top level - cppuhelper/source - macro_expander.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 42 50 84.0 %
Date: 2014-11-03 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      127562 : Bootstrap const & get_unorc()
      53             : {
      54             :     static rtlBootstrapHandle s_bstrap = 0;
      55      127562 :     if (! s_bstrap)
      56             :     {
      57         638 :         OUString iniName(getUnoIniUri());
      58         638 :         rtlBootstrapHandle bstrap = rtl_bootstrap_args_open( iniName.pData );
      59             : 
      60        1276 :         ClearableMutexGuard guard( Mutex::getGlobalMutex() );
      61         638 :         if (s_bstrap)
      62             :         {
      63           0 :             guard.clear();
      64           0 :             rtl_bootstrap_args_close( bstrap );
      65             :         }
      66             :         else
      67             :         {
      68         638 :             s_bstrap = bstrap;
      69         638 :         }
      70             :     }
      71      127562 :     return *(Bootstrap const *)&s_bstrap;
      72             : }
      73             : 
      74             : }
      75             : 
      76             : namespace cppuhelper { namespace detail {
      77             : 
      78      127562 : rtl::OUString expandMacros(rtl::OUString const & text) {
      79      127562 :     rtl::OUString t(text);
      80             :     rtl_bootstrap_expandMacros_from_handle(
      81      127562 :         cppu::get_unorc().getHandle(), &t.pData);
      82      127562 :     return t;
      83             : }
      84             : 
      85             : } }
      86             : 
      87             : namespace
      88             : {
      89             : 
      90         642 : class ImplNames
      91             : {
      92             : private:
      93             :     Sequence<OUString> m_aNames;
      94             : public:
      95         642 :     ImplNames() : m_aNames(2)
      96             :     {
      97         642 :         m_aNames[0] = SERVICE_NAME_A;
      98         642 :         m_aNames[1] = SERVICE_NAME_B;
      99         642 :     }
     100         664 :     const Sequence<OUString>& getNames() const { return m_aNames; }
     101             : };
     102             : 
     103             : class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
     104             : 
     105         664 : inline OUString s_impl_name()
     106             : {
     107         664 :     return OUString(IMPL_NAME);
     108             : }
     109             : 
     110         664 : inline Sequence< OUString > const & s_get_service_names()
     111             : {
     112         664 :     return theImplNames::get().getNames();
     113             : }
     114             : 
     115             : typedef ::cppu::WeakComponentImplHelper2<
     116             :     util::XMacroExpander, lang::XServiceInfo > t_uno_impl;
     117             : 
     118         604 : 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         309 :     inline Bootstrap_MacroExpander()
     130         309 :         : t_uno_impl( m_mutex )
     131         309 :         {}
     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         305 : void Bootstrap_MacroExpander::disposing()
     148         305 : {}
     149             : 
     150         590 : Bootstrap_MacroExpander::~Bootstrap_MacroExpander()
     151         590 : {}
     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      104222 : OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp )
     176             :     throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     177             : {
     178      104222 :     return cppuhelper::detail::expandMacros( exp );
     179             : }
     180             : 
     181             : 
     182         309 : Reference< XInterface > SAL_CALL service_create(
     183             :     SAL_UNUSED_PARAMETER Reference< XComponentContext > const & )
     184             : {
     185         309 :     return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander );
     186             : }
     187             : 
     188             : }
     189             : 
     190             : namespace cppuhelper { namespace detail {
     191             : 
     192         664 : Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory()
     193             : {
     194             :     Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory(
     195             :                                                         service_create,
     196             :                                                         s_impl_name(),
     197         664 :                                                         s_get_service_names() ));
     198             : 
     199        1328 :     uno::Environment curr_env(Environment::getCurrent());
     200        1328 :     uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
     201             : 
     202        1328 :     uno::Mapping target2curr(target_env, curr_env);
     203             : 
     204             :     return Reference<lang::XSingleComponentFactory>(
     205             :         reinterpret_cast<lang::XSingleComponentFactory *>(
     206         664 :             target2curr.mapInterface(free.get(), ::getCppuType(&free))),
     207        1328 :         SAL_NO_ACQUIRE);
     208             : }
     209             : 
     210             : } }
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10