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/types.h"
39 #include "bridgefactory.hxx"
43 css::uno::Reference
< css::uno::XInterface
> BridgeFactory::static_create(
44 css::uno::Reference
< css::uno::XComponentContext
> const & xContext
)
45 SAL_THROW((css::uno::Exception
))
47 return static_cast< cppu::OWeakObject
* >(new BridgeFactory(xContext
));
50 OUString
BridgeFactory::static_getImplementationName() {
51 return OUString("com.sun.star.comp.bridge.BridgeFactory");
54 css::uno::Sequence
< OUString
>
55 BridgeFactory::static_getSupportedServiceNames() {
56 OUString
name("com.sun.star.bridge.BridgeFactory");
57 return css::uno::Sequence
< OUString
>(&name
, 1);
60 void BridgeFactory::removeBridge(
61 css::uno::Reference
< css::bridge::XBridge
> const & bridge
)
64 OUString
n(bridge
->getName());
65 osl::MutexGuard
g(m_aMutex
);
67 BridgeList::iterator
i(
68 std::find(unnamed_
.begin(), unnamed_
.end(), bridge
));
69 if (i
!= unnamed_
.end()) {
73 BridgeMap::iterator
i(named_
.find(n
));
74 if (i
!= named_
.end() && i
->second
== bridge
) {
80 BridgeFactory::BridgeFactory(
81 css::uno::Reference
< css::uno::XComponentContext
> const & context
):
82 BridgeFactoryBase(m_aMutex
), context_(context
)
87 BridgeFactory::~BridgeFactory() {}
89 OUString
BridgeFactory::getImplementationName()
90 throw (css::uno::RuntimeException
, std::exception
)
92 return static_getImplementationName();
95 sal_Bool
BridgeFactory::supportsService(OUString
const & ServiceName
)
96 throw (css::uno::RuntimeException
, std::exception
)
98 return cppu::supportsService(this, ServiceName
);
101 css::uno::Sequence
< OUString
> BridgeFactory::getSupportedServiceNames()
102 throw (css::uno::RuntimeException
, std::exception
)
104 return static_getSupportedServiceNames();
107 css::uno::Reference
< css::bridge::XBridge
> BridgeFactory::createBridge(
108 OUString
const & sName
, OUString
const & sProtocol
,
109 css::uno::Reference
< css::connection::XConnection
> const & aConnection
,
110 css::uno::Reference
< css::bridge::XInstanceProvider
> const &
113 css::bridge::BridgeExistsException
, css::lang::IllegalArgumentException
,
114 css::uno::RuntimeException
, std::exception
)
116 rtl::Reference
< Bridge
> b
;
118 osl::MutexGuard
g(m_aMutex
);
119 if (rBHelper
.bDisposed
) {
120 throw css::lang::DisposedException(
121 "BridgeFactory disposed",
122 static_cast< cppu::OWeakObject
* >(this));
124 if (named_
.find(sName
) != named_
.end()) {
125 throw css::bridge::BridgeExistsException(
126 sName
, static_cast< cppu::OWeakObject
* >(this));
128 if (sProtocol
!= "urp" || !aConnection
.is()) {
129 throw css::lang::IllegalArgumentException(
130 ("BridgeFactory::createBridge: sProtocol != urp ||"
131 " aConnection == null"),
132 static_cast< cppu::OWeakObject
* >(this), -1);
134 b
.set(new Bridge(this, sName
, aConnection
, anInstanceProvider
));
135 if (sName
.isEmpty()) {
137 css::uno::Reference
< css::bridge::XBridge
>(b
.get()));
139 named_
[sName
] = b
.get();
143 return css::uno::Reference
< css::bridge::XBridge
>(b
.get());
146 css::uno::Reference
< css::bridge::XBridge
> BridgeFactory::getBridge(
147 OUString
const & sName
) throw (css::uno::RuntimeException
, std::exception
)
149 osl::MutexGuard
g(m_aMutex
);
150 BridgeMap::iterator
i(named_
.find(sName
));
151 return i
== named_
.end()
152 ? css::uno::Reference
< css::bridge::XBridge
>() : i
->second
;
155 css::uno::Sequence
< css::uno::Reference
< css::bridge::XBridge
> >
156 BridgeFactory::getExistingBridges() throw (css::uno::RuntimeException
, std::exception
) {
157 osl::MutexGuard
g(m_aMutex
);
158 if (unnamed_
.size() > SAL_MAX_INT32
) {
159 throw css::uno::RuntimeException(
160 "BridgeFactory::getExistingBridges: too many",
161 static_cast< cppu::OWeakObject
* >(this));
163 sal_Int32 n
= static_cast< sal_Int32
>(unnamed_
.size());
164 if (named_
.size() > static_cast< sal_uInt32
>(SAL_MAX_INT32
- n
)) {
165 throw css::uno::RuntimeException(
166 "BridgeFactory::getExistingBridges: too many",
167 static_cast< cppu::OWeakObject
* >(this));
169 n
= static_cast< sal_Int32
>(n
+ named_
.size());
170 css::uno::Sequence
< css::uno::Reference
< css::bridge::XBridge
> > s(n
);
172 for (BridgeList::iterator
j(unnamed_
.begin()); j
!= unnamed_
.end(); ++j
) {
175 for (BridgeMap::iterator
j(named_
.begin()); j
!= named_
.end(); ++j
) {
181 void BridgeFactory::disposing() {
185 osl::MutexGuard
g(m_aMutex
);
189 for (BridgeList::iterator
i(l1
.begin()); i
!= l1
.end(); ++i
) {
191 css::uno::Reference
<css::lang::XComponent
>(
192 *i
, css::uno::UNO_QUERY_THROW
)->dispose();
193 } catch (css::uno::Exception
& e
) {
194 SAL_WARN("binaryurp", "ignoring Exception " << e
.Message
);
197 for (BridgeMap::iterator
i(l2
.begin()); i
!= l2
.end(); ++i
) {
199 css::uno::Reference
<css::lang::XComponent
>(
200 i
->second
, css::uno::UNO_QUERY_THROW
)->dispose();
201 } catch (css::uno::Exception
& e
) {
202 SAL_WARN("binaryurp", "ignoring Exception " << e
.Message
);
211 static cppu::ImplementationEntry
const services
[] = {
212 { &binaryurp::BridgeFactory::static_create
,
213 &binaryurp::BridgeFactory::static_getImplementationName
,
214 &binaryurp::BridgeFactory::static_getSupportedServiceNames
,
215 &cppu::createOneInstanceComponentFactory
, 0, 0 },
221 extern "C" SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
binaryurp_component_getFactory(
222 char const * pImplName
, void * pServiceManager
, void * pRegistryKey
)
224 return cppu::component_getFactoryHelper(
225 pImplName
, pServiceManager
, pRegistryKey
, services
);
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */