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