LCOV - code coverage report
Current view: top level - cppuhelper/source - macro_expander.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 42 50 84.0 %
Date: 2014-04-11 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       49586 : Bootstrap const & get_unorc() SAL_THROW(())
      53             : {
      54             :     static rtlBootstrapHandle s_bstrap = 0;
      55       49586 :     if (! s_bstrap)
      56             :     {
      57         456 :         OUString iniName(getUnoIniUri());
      58         456 :         rtlBootstrapHandle bstrap = rtl_bootstrap_args_open( iniName.pData );
      59             : 
      60         912 :         ClearableMutexGuard guard( Mutex::getGlobalMutex() );
      61         456 :         if (s_bstrap)
      62             :         {
      63           0 :             guard.clear();
      64           0 :             rtl_bootstrap_args_close( bstrap );
      65             :         }
      66             :         else
      67             :         {
      68         456 :             s_bstrap = bstrap;
      69         456 :         }
      70             :     }
      71       49586 :     return *(Bootstrap const *)&s_bstrap;
      72             : }
      73             : 
      74             : }
      75             : 
      76             : namespace cppuhelper { namespace detail {
      77             : 
      78       49586 : rtl::OUString expandMacros(rtl::OUString const & text) {
      79       49586 :     rtl::OUString t(text);
      80             :     rtl_bootstrap_expandMacros_from_handle(
      81       49586 :         cppu::get_unorc().getHandle(), &t.pData);
      82       49586 :     return t;
      83             : }
      84             : 
      85             : } }
      86             : 
      87             : namespace
      88             : {
      89             : 
      90         409 : class ImplNames
      91             : {
      92             : private:
      93             :     Sequence<OUString> m_aNames;
      94             : public:
      95         409 :     ImplNames() : m_aNames(2)
      96             :     {
      97         409 :         m_aNames[0] = SERVICE_NAME_A;
      98         409 :         m_aNames[1] = SERVICE_NAME_B;
      99         409 :     }
     100         419 :     const Sequence<OUString>& getNames() const { return m_aNames; }
     101             : };
     102             : 
     103             : class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
     104             : 
     105         419 : inline OUString s_impl_name()
     106             : {
     107         419 :     return OUString(IMPL_NAME);
     108             : }
     109             : 
     110         419 : inline Sequence< OUString > const & s_get_service_names()
     111             : {
     112         419 :     return theImplNames::get().getNames();
     113             : }
     114             : 
     115             : typedef ::cppu::WeakComponentImplHelper2<
     116             :     util::XMacroExpander, lang::XServiceInfo > t_uno_impl;
     117             : 
     118         283 : 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         146 :     inline Bootstrap_MacroExpander() SAL_THROW(())
     130         146 :         : t_uno_impl( m_mutex )
     131         146 :         {}
     132             :     virtual ~Bootstrap_MacroExpander()
     133             :         SAL_THROW(());
     134             : 
     135             :     // XMacroExpander impl
     136             :     virtual OUString SAL_CALL expandMacros( OUString const & exp )
     137             :         throw (lang::IllegalArgumentException, std::exception) SAL_OVERRIDE;
     138             :     // XServiceInfo impl
     139             :     virtual OUString SAL_CALL getImplementationName()
     140             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     141             :     virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName )
     142             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     143             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
     144             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
     145             : };
     146             : 
     147             : 
     148         145 : void Bootstrap_MacroExpander::disposing()
     149         145 : {}
     150             : 
     151         274 : Bootstrap_MacroExpander::~Bootstrap_MacroExpander() SAL_THROW(())
     152         274 : {}
     153             : 
     154             : // XServiceInfo impl
     155             : 
     156           0 : OUString Bootstrap_MacroExpander::getImplementationName()
     157             :     throw (RuntimeException, std::exception)
     158             : {
     159           0 :     return s_impl_name();
     160             : }
     161             : 
     162           0 : sal_Bool Bootstrap_MacroExpander::supportsService( OUString const & serviceName )
     163             :     throw (RuntimeException, std::exception)
     164             : {
     165           0 :     return cppu::supportsService(this, serviceName);
     166             : }
     167             : 
     168           0 : Sequence< OUString > Bootstrap_MacroExpander::getSupportedServiceNames()
     169             :     throw (RuntimeException, std::exception)
     170             : {
     171           0 :     return s_get_service_names();
     172             : }
     173             : 
     174             : // XMacroExpander impl
     175             : 
     176       38808 : OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp )
     177             :     throw (lang::IllegalArgumentException, std::exception)
     178             : {
     179       38808 :     return cppuhelper::detail::expandMacros( exp );
     180             : }
     181             : 
     182             : 
     183         146 : Reference< XInterface > SAL_CALL service_create(
     184             :     SAL_UNUSED_PARAMETER Reference< XComponentContext > const & )
     185             :     SAL_THROW( (RuntimeException) )
     186             : {
     187         146 :     return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander );
     188             : }
     189             : 
     190             : }
     191             : 
     192             : namespace cppuhelper { namespace detail {
     193             : 
     194         419 : Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory() SAL_THROW(())
     195             : {
     196             :     Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory(
     197             :                                                         service_create,
     198             :                                                         s_impl_name(),
     199         419 :                                                         s_get_service_names() ));
     200             : 
     201         838 :     uno::Environment curr_env(Environment::getCurrent());
     202         838 :     uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
     203             : 
     204         838 :     uno::Mapping target2curr(target_env, curr_env);
     205             : 
     206             :     return Reference<lang::XSingleComponentFactory>(
     207             :         reinterpret_cast<lang::XSingleComponentFactory *>(
     208         419 :             target2curr.mapInterface(free.get(), ::getCppuType(&free))),
     209         838 :         SAL_NO_ACQUIRE);
     210             : }
     211             : 
     212             : } }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10