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

Generated by: LCOV version 1.10