LCOV - code coverage report
Current view: top level - binaryurp/source - bridgefactory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 59 80 73.8 %
Date: 2015-06-13 12:38:46 Functions: 13 15 86.7 %
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             : #include "sal/config.h"
      21             : 
      22             : #include <algorithm>
      23             : #include <cassert>
      24             : #include <exception>
      25             : 
      26             : #include "com/sun/star/connection/XConnection.hpp"
      27             : #include "com/sun/star/uno/Exception.hpp"
      28             : #include "com/sun/star/uno/Reference.hxx"
      29             : #include "com/sun/star/uno/RuntimeException.hpp"
      30             : #include "com/sun/star/uno/XComponentContext.hpp"
      31             : #include "com/sun/star/uno/XInterface.hpp"
      32             : #include "cppuhelper/factory.hxx"
      33             : #include "cppuhelper/implementationentry.hxx"
      34             : #include <cppuhelper/supportsservice.hxx>
      35             : #include "rtl/ref.hxx"
      36             : #include "sal/log.hxx"
      37             : #include "sal/types.h"
      38             : 
      39             : #include "bridge.hxx"
      40             : #include "bridgefactory.hxx"
      41             : 
      42             : namespace binaryurp {
      43             : 
      44         119 : css::uno::Reference< css::uno::XInterface > BridgeFactory::static_create(
      45             :     css::uno::Reference< css::uno::XComponentContext > const & xContext)
      46             : {
      47         119 :     return static_cast< cppu::OWeakObject * >(new BridgeFactory(xContext));
      48             : }
      49             : 
      50         120 : OUString BridgeFactory::static_getImplementationName() {
      51         120 :     return OUString("com.sun.star.comp.bridge.BridgeFactory");
      52             : }
      53             : 
      54             : css::uno::Sequence< OUString >
      55         120 : BridgeFactory::static_getSupportedServiceNames() {
      56         120 :     return css::uno::Sequence<OUString>{ "com.sun.star.bridge.BridgeFactory" };
      57             : }
      58             : 
      59          66 : void BridgeFactory::removeBridge(
      60             :     css::uno::Reference< css::bridge::XBridge > const & bridge)
      61             : {
      62             :     assert(bridge.is());
      63          66 :     OUString n(bridge->getName());
      64         132 :     osl::MutexGuard g(m_aMutex);
      65          66 :     if (n.isEmpty()) {
      66             :         BridgeList::iterator i(
      67          66 :             std::find(unnamed_.begin(), unnamed_.end(), bridge));
      68          66 :         if (i != unnamed_.end()) {
      69          65 :             unnamed_.erase(i);
      70             :         }
      71             :     } else {
      72           0 :         BridgeMap::iterator i(named_.find(n));
      73           0 :         if (i != named_.end() && i->second == bridge) {
      74           0 :             named_.erase(i);
      75             :         }
      76          66 :     }
      77          66 : }
      78             : 
      79         119 : BridgeFactory::BridgeFactory(
      80             :     css::uno::Reference< css::uno::XComponentContext > const & context):
      81         119 :     BridgeFactoryBase(m_aMutex), context_(context)
      82             : {
      83             :     assert(context.is());
      84         119 : }
      85             : 
      86         230 : BridgeFactory::~BridgeFactory() {}
      87             : 
      88           1 : OUString BridgeFactory::getImplementationName()
      89             :     throw (css::uno::RuntimeException, std::exception)
      90             : {
      91           1 :     return static_getImplementationName();
      92             : }
      93             : 
      94           0 : sal_Bool BridgeFactory::supportsService(OUString const & ServiceName)
      95             :     throw (css::uno::RuntimeException, std::exception)
      96             : {
      97           0 :     return cppu::supportsService(this, ServiceName);
      98             : }
      99             : 
     100           1 : css::uno::Sequence< OUString > BridgeFactory::getSupportedServiceNames()
     101             :     throw (css::uno::RuntimeException, std::exception)
     102             : {
     103           1 :     return static_getSupportedServiceNames();
     104             : }
     105             : 
     106          66 : css::uno::Reference< css::bridge::XBridge > BridgeFactory::createBridge(
     107             :     OUString const & sName, OUString const & sProtocol,
     108             :     css::uno::Reference< css::connection::XConnection > const & aConnection,
     109             :     css::uno::Reference< css::bridge::XInstanceProvider > const &
     110             :         anInstanceProvider)
     111             :     throw (
     112             :         css::bridge::BridgeExistsException, css::lang::IllegalArgumentException,
     113             :         css::uno::RuntimeException, std::exception)
     114             : {
     115          66 :     rtl::Reference< Bridge > b;
     116             :     {
     117          66 :         osl::MutexGuard g(m_aMutex);
     118          66 :         if (rBHelper.bDisposed) {
     119             :             throw css::lang::DisposedException(
     120             :                 "BridgeFactory disposed",
     121           0 :                 static_cast< cppu::OWeakObject * >(this));
     122             :         }
     123          66 :         if (named_.find(sName) != named_.end()) {
     124             :             throw css::bridge::BridgeExistsException(
     125           0 :                 sName, static_cast< cppu::OWeakObject * >(this));
     126             :         }
     127          66 :         if (sProtocol != "urp" || !aConnection.is()) {
     128             :             throw css::lang::IllegalArgumentException(
     129             :                 ("BridgeFactory::createBridge: sProtocol != urp ||"
     130             :                  " aConnection == null"),
     131           0 :                 static_cast< cppu::OWeakObject * >(this), -1);
     132             :         }
     133          66 :         b.set(new Bridge(this, sName, aConnection, anInstanceProvider));
     134          66 :         if (sName.isEmpty()) {
     135             :             unnamed_.push_back(
     136          66 :                 css::uno::Reference< css::bridge::XBridge >(b.get()));
     137             :         } else {
     138           0 :             named_[sName] = b.get();
     139          66 :         }
     140             :     }
     141          66 :     b->start();
     142          66 :     return css::uno::Reference< css::bridge::XBridge >(b.get());
     143             : }
     144             : 
     145           0 : css::uno::Reference< css::bridge::XBridge > BridgeFactory::getBridge(
     146             :     OUString const & sName) throw (css::uno::RuntimeException, std::exception)
     147             : {
     148           0 :     osl::MutexGuard g(m_aMutex);
     149           0 :     BridgeMap::iterator i(named_.find(sName));
     150           0 :     return i == named_.end()
     151           0 :         ? css::uno::Reference< css::bridge::XBridge >() : i->second;
     152             : }
     153             : 
     154             : css::uno::Sequence< css::uno::Reference< css::bridge::XBridge > >
     155           1 : BridgeFactory::getExistingBridges() throw (css::uno::RuntimeException, std::exception) {
     156           1 :     osl::MutexGuard g(m_aMutex);
     157           1 :     if (unnamed_.size() > SAL_MAX_INT32) {
     158             :         throw css::uno::RuntimeException(
     159             :             "BridgeFactory::getExistingBridges: too many",
     160           0 :             static_cast< cppu::OWeakObject * >(this));
     161             :     }
     162           1 :     sal_Int32 n = static_cast< sal_Int32 >(unnamed_.size());
     163           1 :     if (named_.size() > static_cast< sal_uInt32 >(SAL_MAX_INT32 - n)) {
     164             :         throw css::uno::RuntimeException(
     165             :             "BridgeFactory::getExistingBridges: too many",
     166           0 :             static_cast< cppu::OWeakObject * >(this));
     167             :     }
     168           1 :     n = static_cast< sal_Int32 >(n + named_.size());
     169           1 :     css::uno::Sequence< css::uno::Reference< css::bridge::XBridge > > s(n);
     170           1 :     sal_Int32 i = 0;
     171           1 :     for (BridgeList::iterator j(unnamed_.begin()); j != unnamed_.end(); ++j) {
     172           0 :         s[i++] = *j;
     173             :     }
     174           1 :     for (BridgeMap::iterator j(named_.begin()); j != named_.end(); ++j) {
     175           0 :         s[i++] = j->second;
     176             :     }
     177           1 :     return s;
     178             : }
     179             : 
     180         118 : void BridgeFactory::disposing() {
     181         118 :     BridgeList l1;
     182         236 :     BridgeMap l2;
     183             :     {
     184         118 :         osl::MutexGuard g(m_aMutex);
     185         118 :         l1.swap(unnamed_);
     186         118 :         l2.swap(named_);
     187             :     }
     188         119 :     for (BridgeList::iterator i(l1.begin()); i != l1.end(); ++i) {
     189             :         try {
     190             :             css::uno::Reference<css::lang::XComponent>(
     191           1 :                 *i, css::uno::UNO_QUERY_THROW)->dispose();
     192           0 :         } catch (css::uno::Exception & e) {
     193             :             SAL_WARN("binaryurp", "ignoring Exception " << e.Message);
     194             :         }
     195             :     }
     196         118 :     for (BridgeMap::iterator i(l2.begin()); i != l2.end(); ++i) {
     197             :         try {
     198             :             css::uno::Reference<css::lang::XComponent>(
     199           0 :                 i->second, css::uno::UNO_QUERY_THROW)->dispose();
     200           0 :         } catch (css::uno::Exception & e) {
     201             :             SAL_WARN("binaryurp", "ignoring Exception " << e.Message);
     202             :         }
     203         118 :     }
     204         118 : }
     205             : 
     206             : }
     207             : 
     208             : namespace {
     209             : 
     210             : static cppu::ImplementationEntry const services[] = {
     211             :     { &binaryurp::BridgeFactory::static_create,
     212             :       &binaryurp::BridgeFactory::static_getImplementationName,
     213             :       &binaryurp::BridgeFactory::static_getSupportedServiceNames,
     214             :       &cppu::createOneInstanceComponentFactory, 0, 0 },
     215             :     { 0, 0, 0, 0, 0, 0 }
     216             : };
     217             : 
     218             : }
     219             : 
     220         119 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL binaryurp_component_getFactory(
     221             :     char const * pImplName, void * pServiceManager, void * pRegistryKey)
     222             : {
     223             :     return cppu::component_getFactoryHelper(
     224         119 :         pImplName, pServiceManager, pRegistryKey, services);
     225             : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11