LCOV - code coverage report
Current view: top level - scripting/source/provider - ProviderCache.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 7 57.1 %
Date: 2015-06-13 12:38:46 Functions: 4 4 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             :  * 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             : #ifndef INCLUDED_SCRIPTING_SOURCE_PROVIDER_PROVIDERCACHE_HXX
      21             : #define INCLUDED_SCRIPTING_SOURCE_PROVIDER_PROVIDERCACHE_HXX
      22             : 
      23             : #include <osl/mutex.hxx>
      24             : #include <rtl/ustring.hxx>
      25             : #include <cppuhelper/implbase1.hxx>
      26             : #include <com/sun/star/uno/RuntimeException.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      29             : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
      30             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      31             : 
      32             : #include <com/sun/star/frame/XModel.hpp>
      33             : #include <com/sun/star/script/provider/XScriptProvider.hpp>
      34             : 
      35             : #include <unordered_map>
      36             : 
      37             : namespace func_provider
      38             : {
      39             : 
      40             : //Typedefs
      41             : 
      42             : 
      43         185 : struct ProviderDetails
      44             : {
      45             :     //css::uno::Reference< css::lang::XSingleServiceFactory > factory;
      46             :     css::uno::Reference< css::lang::XSingleComponentFactory > factory;
      47             :     css::uno::Reference< css::script::provider::XScriptProvider > provider;
      48             : };
      49             : typedef std::unordered_map < OUString, ProviderDetails , OUStringHash,
      50             :             ::std::equal_to< OUString > > ProviderDetails_hash;
      51             : 
      52             : 
      53             : class ProviderCache
      54             : {
      55             : 
      56             : public:
      57             :      ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext )
      58             :         throw ( css::uno::RuntimeException );
      59             :      ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext,
      60             :         const css::uno::Sequence< OUString >& blackList )
      61             :         throw ( css::uno::RuntimeException );
      62             :     ~ProviderCache();
      63             :      css::uno::Reference< css::script::provider::XScriptProvider >
      64             :          getProvider( const OUString& providerName );
      65             :      css::uno::Sequence < css::uno::Reference< css::script::provider::XScriptProvider > >
      66             :          getAllProviders() throw ( css::uno::RuntimeException );
      67             : private:
      68             :     void populateCache()
      69             :         throw ( css::uno::RuntimeException );
      70             : 
      71             :    css::uno::Reference< css::script::provider::XScriptProvider >
      72             :         createProvider( ProviderDetails& details ) throw ( css::uno::RuntimeException );
      73          37 :     bool isInBlackList( const OUString& serviceName )
      74             :     {
      75          37 :         if ( m_sBlackList.getLength() > 0 )
      76             :         {
      77           0 :             for ( sal_Int32 index = 0; index < m_sBlackList.getLength(); index++ )
      78             :             {
      79           0 :                 if ( m_sBlackList[ index ].equals( serviceName ) )
      80             :                 {
      81           0 :                     return true;
      82             :                 }
      83             :             }
      84             :         }
      85          37 :         return false;
      86             :     }
      87             :     css::uno::Sequence< OUString >  m_sBlackList;
      88             :     ProviderDetails_hash  m_hProviderDetailsCache;
      89             :     osl::Mutex m_mutex;
      90             :     css::uno::Sequence< css::uno::Any >  m_Sctx;
      91             :     css::uno::Reference< css::uno::XComponentContext > m_xContext;
      92             :     css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
      93             : 
      94             : 
      95             : };
      96             : } // func_provider
      97             : #endif
      98             : 
      99             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11