1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
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"
40 #include "bridgefactory.hxx"
44 css::uno::Reference
< css::uno::XInterface
> BridgeFactory::static_create(
45 css::uno::Reference
< css::uno::XComponentContext
> const & /*xContext*/)
47 return static_cast< cppu::OWeakObject
* >(new BridgeFactory
);
50 OUString
BridgeFactory::static_getImplementationName() {
51 return OUString("com.sun.star.comp.bridge.BridgeFactory");
54 css::uno::Sequence
< OUString
>
55 BridgeFactory::static_getSupportedServiceNames() {
56 return css::uno::Sequence
<OUString
>{ "com.sun.star.bridge.BridgeFactory" };
59 void BridgeFactory::removeBridge(
60 css::uno::Reference
< css::bridge::XBridge
> const & bridge
)
63 OUString
n(bridge
->getName());
64 osl::MutexGuard
g(m_aMutex
);
66 BridgeList::iterator
i(
67 std::find(unnamed_
.begin(), unnamed_
.end(), bridge
));
68 if (i
!= unnamed_
.end()) {
72 BridgeMap::iterator
i(named_
.find(n
));
73 if (i
!= named_
.end() && i
->second
== bridge
) {
79 BridgeFactory::BridgeFactory():
80 BridgeFactoryBase(m_aMutex
)
84 BridgeFactory::~BridgeFactory() {}
86 OUString
BridgeFactory::getImplementationName()
87 throw (css::uno::RuntimeException
, std::exception
)
89 return static_getImplementationName();
92 sal_Bool
BridgeFactory::supportsService(OUString
const & ServiceName
)
93 throw (css::uno::RuntimeException
, std::exception
)
95 return cppu::supportsService(this, ServiceName
);
98 css::uno::Sequence
< OUString
> BridgeFactory::getSupportedServiceNames()
99 throw (css::uno::RuntimeException
, std::exception
)
101 return static_getSupportedServiceNames();
104 css::uno::Reference
< css::bridge::XBridge
> BridgeFactory::createBridge(
105 OUString
const & sName
, OUString
const & sProtocol
,
106 css::uno::Reference
< css::connection::XConnection
> const & aConnection
,
107 css::uno::Reference
< css::bridge::XInstanceProvider
> const &
110 css::bridge::BridgeExistsException
, css::lang::IllegalArgumentException
,
111 css::uno::RuntimeException
, std::exception
)
113 rtl::Reference
< Bridge
> b
;
115 osl::MutexGuard
g(m_aMutex
);
116 if (rBHelper
.bDisposed
) {
117 throw css::lang::DisposedException(
118 "BridgeFactory disposed",
119 static_cast< cppu::OWeakObject
* >(this));
121 if (named_
.find(sName
) != named_
.end()) {
122 throw css::bridge::BridgeExistsException(
123 sName
, static_cast< cppu::OWeakObject
* >(this));
125 if (sProtocol
!= "urp" || !aConnection
.is()) {
126 throw css::lang::IllegalArgumentException(
127 ("BridgeFactory::createBridge: sProtocol != urp ||"
128 " aConnection == null"),
129 static_cast< cppu::OWeakObject
* >(this), -1);
131 b
.set(new Bridge(this, sName
, aConnection
, anInstanceProvider
));
132 if (sName
.isEmpty()) {
134 css::uno::Reference
< css::bridge::XBridge
>(b
.get()));
136 named_
[sName
] = b
.get();
140 return css::uno::Reference
< css::bridge::XBridge
>(b
.get());
143 css::uno::Reference
< css::bridge::XBridge
> BridgeFactory::getBridge(
144 OUString
const & sName
) throw (css::uno::RuntimeException
, std::exception
)
146 osl::MutexGuard
g(m_aMutex
);
147 BridgeMap::iterator
i(named_
.find(sName
));
148 return i
== named_
.end()
149 ? css::uno::Reference
< css::bridge::XBridge
>() : i
->second
;
152 css::uno::Sequence
< css::uno::Reference
< css::bridge::XBridge
> >
153 BridgeFactory::getExistingBridges() throw (css::uno::RuntimeException
, std::exception
) {
154 osl::MutexGuard
g(m_aMutex
);
155 if (unnamed_
.size() > SAL_MAX_INT32
) {
156 throw css::uno::RuntimeException(
157 "BridgeFactory::getExistingBridges: too many",
158 static_cast< cppu::OWeakObject
* >(this));
160 sal_Int32 n
= static_cast< sal_Int32
>(unnamed_
.size());
161 if (named_
.size() > static_cast< sal_uInt32
>(SAL_MAX_INT32
- n
)) {
162 throw css::uno::RuntimeException(
163 "BridgeFactory::getExistingBridges: too many",
164 static_cast< cppu::OWeakObject
* >(this));
166 n
= static_cast< sal_Int32
>(n
+ named_
.size());
167 css::uno::Sequence
< css::uno::Reference
< css::bridge::XBridge
> > s(n
);
169 for (BridgeList::iterator
j(unnamed_
.begin()); j
!= unnamed_
.end(); ++j
) {
172 for (BridgeMap::iterator
j(named_
.begin()); j
!= named_
.end(); ++j
) {
178 void BridgeFactory::disposing() {
182 osl::MutexGuard
g(m_aMutex
);
186 for (BridgeList::iterator
i(l1
.begin()); i
!= l1
.end(); ++i
) {
188 css::uno::Reference
<css::lang::XComponent
>(
189 *i
, css::uno::UNO_QUERY_THROW
)->dispose();
190 } catch (css::uno::Exception
& e
) {
191 SAL_WARN("binaryurp", "ignoring Exception " << e
.Message
);
194 for (BridgeMap::iterator
i(l2
.begin()); i
!= l2
.end(); ++i
) {
196 css::uno::Reference
<css::lang::XComponent
>(
197 i
->second
, css::uno::UNO_QUERY_THROW
)->dispose();
198 } catch (css::uno::Exception
& e
) {
199 SAL_WARN("binaryurp", "ignoring Exception " << e
.Message
);
208 static cppu::ImplementationEntry
const services
[] = {
209 { &binaryurp::BridgeFactory::static_create
,
210 &binaryurp::BridgeFactory::static_getImplementationName
,
211 &binaryurp::BridgeFactory::static_getSupportedServiceNames
,
212 &cppu::createOneInstanceComponentFactory
, nullptr, 0 },
213 { nullptr, nullptr, nullptr, nullptr, nullptr, 0 }
218 extern "C" SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
binaryurp_component_getFactory(
219 char const * pImplName
, void * pServiceManager
, void * pRegistryKey
)
221 return cppu::component_getFactoryHelper(
222 pImplName
, pServiceManager
, pRegistryKey
, services
);
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */