LCOV - code coverage report
Current view: top level - binaryurp/source - bridgefactory.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 56 81 69.1 %
Date: 2014-11-03 Functions: 11 15 73.3 %
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/types.h"
      37             : 
      38             : #include "bridge.hxx"
      39             : #include "bridgefactory.hxx"
      40             : 
      41             : namespace binaryurp {
      42             : 
      43         168 : css::uno::Reference< css::uno::XInterface > BridgeFactory::static_create(
      44             :     css::uno::Reference< css::uno::XComponentContext > const & xContext)
      45             : {
      46         168 :     return static_cast< cppu::OWeakObject * >(new BridgeFactory(xContext));
      47             : }
      48             : 
      49         168 : OUString BridgeFactory::static_getImplementationName() {
      50         168 :     return OUString("com.sun.star.comp.bridge.BridgeFactory");
      51             : }
      52             : 
      53             : css::uno::Sequence< OUString >
      54         168 : BridgeFactory::static_getSupportedServiceNames() {
      55         168 :     OUString name("com.sun.star.bridge.BridgeFactory");
      56         168 :     return css::uno::Sequence< OUString >(&name, 1);
      57             : }
      58             : 
      59         102 : void BridgeFactory::removeBridge(
      60             :     css::uno::Reference< css::bridge::XBridge > const & bridge)
      61             : {
      62             :     assert(bridge.is());
      63         102 :     OUString n(bridge->getName());
      64         204 :     osl::MutexGuard g(m_aMutex);
      65         102 :     if (n.isEmpty()) {
      66             :         BridgeList::iterator i(
      67         102 :             std::find(unnamed_.begin(), unnamed_.end(), bridge));
      68         102 :         if (i != unnamed_.end()) {
      69         100 :             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         102 :     }
      77         102 : }
      78             : 
      79         168 : BridgeFactory::BridgeFactory(
      80             :     css::uno::Reference< css::uno::XComponentContext > const & context):
      81         168 :     BridgeFactoryBase(m_aMutex), context_(context)
      82             : {
      83             :     assert(context.is());
      84         168 : }
      85             : 
      86         320 : BridgeFactory::~BridgeFactory() {}
      87             : 
      88           0 : OUString BridgeFactory::getImplementationName()
      89             :     throw (css::uno::RuntimeException, std::exception)
      90             : {
      91           0 :     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           0 : css::uno::Sequence< OUString > BridgeFactory::getSupportedServiceNames()
     101             :     throw (css::uno::RuntimeException, std::exception)
     102             : {
     103           0 :     return static_getSupportedServiceNames();
     104             : }
     105             : 
     106         102 : 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         102 :     rtl::Reference< Bridge > b;
     116             :     {
     117         102 :         osl::MutexGuard g(m_aMutex);
     118         102 :         if (rBHelper.bDisposed) {
     119             :             throw css::lang::DisposedException(
     120             :                 "BridgeFactory disposed",
     121           0 :                 static_cast< cppu::OWeakObject * >(this));
     122             :         }
     123         102 :         if (named_.find(sName) != named_.end()) {
     124             :             throw css::bridge::BridgeExistsException(
     125           0 :                 sName, static_cast< cppu::OWeakObject * >(this));
     126             :         }
     127         102 :         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         102 :         b.set(new Bridge(this, sName, aConnection, anInstanceProvider));
     134         102 :         if (sName.isEmpty()) {
     135             :             unnamed_.push_back(
     136         102 :                 css::uno::Reference< css::bridge::XBridge >(b.get()));
     137             :         } else {
     138           0 :             named_[sName] = b.get();
     139         102 :         }
     140             :     }
     141         102 :     b->start();
     142         102 :     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           2 : BridgeFactory::getExistingBridges() throw (css::uno::RuntimeException, std::exception) {
     156           2 :     osl::MutexGuard g(m_aMutex);
     157           2 :     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           2 :     sal_Int32 n = static_cast< sal_Int32 >(unnamed_.size());
     163           2 :     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           2 :     n = static_cast< sal_Int32 >(n + named_.size());
     169           2 :     css::uno::Sequence< css::uno::Reference< css::bridge::XBridge > > s(n);
     170           2 :     sal_Int32 i = 0;
     171           2 :     for (BridgeList::iterator j(unnamed_.begin()); j != unnamed_.end(); ++j) {
     172           0 :         s[i++] = *j;
     173             :     }
     174           2 :     for (BridgeMap::iterator j(named_.begin()); j != named_.end(); ++j) {
     175           0 :         s[i++] = j->second;
     176             :     }
     177           2 :     return s;
     178             : }
     179             : 
     180         166 : void BridgeFactory::disposing() {
     181         166 :     BridgeList l1;
     182         332 :     BridgeMap l2;
     183             :     {
     184         166 :         osl::MutexGuard g(m_aMutex);
     185         166 :         l1.swap(unnamed_);
     186         166 :         l2.swap(named_);
     187             :     }
     188         168 :     for (BridgeList::iterator i(l1.begin()); i != l1.end(); ++i) {
     189             :         try {
     190             :             css::uno::Reference<css::lang::XComponent>(
     191           2 :                 *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         166 :     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         166 :     }
     204         166 : }
     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         168 : 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         168 :         pImplName, pServiceManager, pRegistryKey, services);
     225             : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10