LibreOffice Module binaryurp (master) 1
bridge.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/config.h>
23
24#include <cstddef>
25#include <map>
26#include <mutex>
27#include <vector>
28
29#include <com/sun/star/bridge/XBridge.hpp>
30#include <com/sun/star/lang/XComponent.hpp>
31#include <com/sun/star/uno/Reference.hxx>
33#include <osl/conditn.hxx>
34#include <osl/mutex.hxx>
35#include <rtl/ref.hxx>
36#include <rtl/ustring.hxx>
37#include <sal/types.h>
38#include <uno/environment.hxx>
39#include <uno/mapping.hxx>
40#include <uno/threadpool.h>
41
42#include "outgoingrequest.hxx"
43#include "outgoingrequests.hxx"
44#include "writer.hxx"
45
46namespace binaryurp {
47 class BinaryAny;
48 class BridgeFactory;
49 class Proxy;
50 class Reader;
51}
52namespace com::sun::star {
53 namespace bridge { class XInstanceProvider; }
54 namespace connection { class XConnection; }
55 namespace lang { class XEventListener; }
56 namespace uno {
57 class Any;
58 class TypeDescription;
59 class UnoInterfaceReference;
60 class XInterface;
61 }
62}
63namespace rtl { class ByteSequence; }
64
65namespace binaryurp {
66
67class Bridge:
68 public cppu::WeakImplHelper<
69 com::sun::star::bridge::XBridge, com::sun::star::lang::XComponent >
70{
71public:
73 rtl::Reference< BridgeFactory > const & factory,
74 OUString name,
76 com::sun::star::connection::XConnection > const & connection,
78 com::sun::star::bridge::XInstanceProvider > provider);
79
80 void start();
81
82 // Internally waits for all incoming and outgoing remote calls to terminate,
83 // so must not be called from within such a call; when final is true, also
84 // joins all remaining threads (reader, writer, and worker threads from the
85 // thread pool), so must not be called with final set to true from such a
86 // thread:
87 void terminate(bool final);
88
90 getConnection() const { return connection_;}
91
93 getProvider() const { return provider_;}
94
95 com::sun::star::uno::Mapping & getCppToBinaryMapping() { return cppToBinaryMapping_;}
96
97 BinaryAny mapCppToBinaryAny(com::sun::star::uno::Any const & cppAny);
98
99 uno_ThreadPool getThreadPool();
100
102
103 com::sun::star::uno::UnoInterfaceReference registerIncomingInterface(
104 OUString const & oid,
105 com::sun::star::uno::TypeDescription const & type);
106
108 com::sun::star::uno::UnoInterfaceReference const & object,
109 com::sun::star::uno::TypeDescription const & type);
110
111 com::sun::star::uno::UnoInterfaceReference findStub(
112 OUString const & oid,
113 com::sun::star::uno::TypeDescription const & type);
114
115 void releaseStub(
116 OUString const & oid,
117 com::sun::star::uno::TypeDescription const & type);
118
119 void resurrectProxy(Proxy & proxy);
120
121 void revokeProxy(Proxy & proxy);
122
123 void freeProxy(Proxy & proxy);
124
125 void incrementCalls(bool normalCall) noexcept;
126
127 void decrementCalls();
128
129 void incrementActiveCalls() noexcept;
130
131 void decrementActiveCalls() noexcept;
132
133 bool makeCall(
134 OUString const & oid,
135 com::sun::star::uno::TypeDescription const & member, bool setter,
136 std::vector< BinaryAny >&& inArguments, BinaryAny * returnValue,
137 std::vector< BinaryAny > * outArguments);
138
139 // Only called from reader_ thread:
141
142 // Only called from reader_ thread:
144 bool exception, BinaryAny const & returnValue);
145
146 // Only called from reader_ thread:
147 void handleCommitChangeReply(bool exception, BinaryAny const & returnValue);
148
149 // Only called from reader_ thread:
151 rtl::ByteSequence const & tid,
152 std::vector< BinaryAny > const & inArguments);
153
154 // Only called from reader_ thread:
156 rtl::ByteSequence const & tid,
157 std::vector< BinaryAny > const & inArguments);
158
159 OutgoingRequest lastOutgoingRequest(rtl::ByteSequence const & tid);
160
162 std::u16string_view oid,
163 com::sun::star::uno::TypeDescription const & type) const;
164
166
168
169private:
170 Bridge(const Bridge&) = delete;
171 Bridge& operator=(const Bridge&) = delete;
172
173 virtual ~Bridge() override;
174
175 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
176 SAL_CALL getInstance(OUString const & sInstanceName) override;
177
178 virtual OUString SAL_CALL getName() override;
179
180 virtual OUString SAL_CALL getDescription() override;
181
182 virtual void SAL_CALL dispose() override;
183
184 virtual void SAL_CALL addEventListener(
185 com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
186 const & xListener) override;
187
188 virtual void SAL_CALL removeEventListener(
189 com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
190 const & aListener) override;
191
192 // Only called from reader_ thread:
194
195 // Only called from reader_ thread:
197 OutgoingRequest::Kind kind,
198 std::vector< BinaryAny > const & inArguments);
199
200 void makeReleaseCall(
201 OUString const & oid,
202 com::sun::star::uno::TypeDescription const & type);
203
204 void sendRequest(
205 rtl::ByteSequence const & tid, OUString const & oid,
206 com::sun::star::uno::TypeDescription const & type,
207 com::sun::star::uno::TypeDescription const & member,
208 std::vector< BinaryAny >&& inArguments);
209
210 void throwException(bool exception, BinaryAny const & value);
211
212 com::sun::star::uno::Any mapBinaryToCppAny(BinaryAny const & binaryAny);
213
214 bool becameUnused() const;
215
216 void terminateWhenUnused(bool unused);
217
218 // Must only be called with mutex_ locked:
219 void checkDisposed();
220
221 typedef
222 std::vector<
223 com::sun::star::uno::Reference<
224 com::sun::star::lang::XEventListener > >
226
227 struct SubStub;
228
229 typedef std::map< com::sun::star::uno::TypeDescription, SubStub > Stub;
230
231 typedef std::map< OUString, Stub > Stubs;
232
234
235 enum Mode {
238
240 OUString name_;
245 com::sun::star::uno::Environment binaryUno_;
246 com::sun::star::uno::Mapping cppToBinaryMapping_;
247 com::sun::star::uno::Mapping binaryToCppMapping_;
248 rtl::ByteSequence protPropTid_;
249 OUString protPropOid_;
250 com::sun::star::uno::TypeDescription protPropType_;
251 com::sun::star::uno::TypeDescription protPropRequest_;
252 com::sun::star::uno::TypeDescription protPropCommit_;
254 osl::Condition passive_;
255 // to guarantee that passive_ is eventually set (to avoid deadlock, see
256 // dispose), activeCalls_ only counts those calls for which it can be
257 // guaranteed that incrementActiveCalls is indeed followed by
258 // decrementActiveCalls, without an intervening exception
259 osl::Condition terminated_;
260
261 std::mutex mutex_;
264 uno_ThreadPool threadPool_;
269 std::size_t proxies_;
270 std::size_t calls_;
272 std::size_t activeCalls_;
273
274 // Only accessed from reader_ thread:
276 sal_Int32 random_;
277};
278
279}
280
281/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::Mapping binaryToCppMapping_
Definition: bridge.hxx:247
void sendRequest(rtl::ByteSequence const &tid, OUString const &oid, com::sun::star::uno::TypeDescription const &type, com::sun::star::uno::TypeDescription const &member, std::vector< BinaryAny > &&inArguments)
Definition: bridge.cxx:1004
void incrementActiveCalls() noexcept
Definition: bridge.cxx:569
void sendCommitChangeRequest()
Definition: bridge.cxx:952
virtual void SAL_CALL removeEventListener(com::sun::star::uno::Reference< com::sun::star::lang::XEventListener > const &aListener) override
Definition: bridge.cxx:941
osl::Condition terminated_
Definition: bridge.hxx:259
void handleRequestChangeRequest(rtl::ByteSequence const &tid, std::vector< BinaryAny > const &inArguments)
Definition: bridge.cxx:714
rtl::Reference< Writer > writer_
Definition: bridge.hxx:265
const com::sun::star::uno::Reference< com::sun::star::connection::XConnection > & getConnection() const
Definition: bridge.hxx:90
std::vector< com::sun::star::uno::Reference< com::sun::star::lang::XEventListener > > Listeners
Definition: bridge.hxx:225
void throwException(bool exception, BinaryAny const &value)
Definition: bridge.cxx:1013
uno_ThreadPool getThreadPool()
Definition: bridge.cxx:365
rtl::ByteSequence protPropTid_
Definition: bridge.hxx:248
com::sun::star::uno::Any mapBinaryToCppAny(BinaryAny const &binaryAny)
Definition: bridge.cxx:1019
void decrementActiveCalls() noexcept
Definition: bridge.cxx:578
void sendProtPropRequest(OutgoingRequest::Kind kind, std::vector< BinaryAny > const &inArguments)
Definition: bridge.cxx:960
void sendRequestChangeRequest()
Definition: bridge.cxx:624
com::sun::star::uno::Mapping cppToBinaryMapping_
Definition: bridge.hxx:246
com::sun::star::uno::TypeDescription protPropType_
Definition: bridge.hxx:250
bool currentContextMode_
Definition: bridge.hxx:267
virtual OUString SAL_CALL getDescription() override
Definition: bridge.cxx:907
void terminate(bool final)
Definition: bridge.cxx:232
uno_ThreadPool threadPool_
Definition: bridge.hxx:264
com::sun::star::uno::UnoInterfaceReference registerIncomingInterface(OUString const &oid, com::sun::star::uno::TypeDescription const &type)
Definition: bridge.cxx:379
void resurrectProxy(Proxy &proxy)
Definition: bridge.cxx:516
void decrementCalls()
Definition: bridge.cxx:558
virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL getInstance(OUString const &sInstanceName) override
Definition: bridge.cxx:851
com::sun::star::uno::UnoInterfaceReference findStub(OUString const &oid, com::sun::star::uno::TypeDescription const &type)
Definition: bridge.cxx:459
std::map< com::sun::star::uno::TypeDescription, SubStub > Stub
Definition: bridge.hxx:227
std::map< OUString, Stub > Stubs
Definition: bridge.hxx:231
void terminateWhenUnused(bool unused)
Definition: bridge.cxx:1034
rtl::Reference< Reader > reader_
Definition: bridge.hxx:266
sal_Int32 random_
Definition: bridge.hxx:276
void freeProxy(Proxy &proxy)
Definition: bridge.cxx:532
OUString name_
Definition: bridge.hxx:240
void handleRequestChangeReply(bool exception, BinaryAny const &returnValue)
Definition: bridge.cxx:634
virtual void SAL_CALL dispose() override
Definition: bridge.cxx:912
Bridge(rtl::Reference< BridgeFactory > const &factory, OUString name, com::sun::star::uno::Reference< com::sun::star::connection::XConnection > const &connection, com::sun::star::uno::Reference< com::sun::star::bridge::XInstanceProvider > provider)
com::sun::star::uno::Mapping & getCppToBinaryMapping()
Definition: bridge.hxx:95
com::sun::star::uno::Reference< com::sun::star::bridge::XInstanceProvider > provider_
Definition: bridge.hxx:244
std::size_t calls_
Definition: bridge.hxx:270
com::sun::star::uno::TypeDescription protPropCommit_
Definition: bridge.hxx:252
void setCurrentContextMode()
Definition: bridge.cxx:828
BinaryAny mapCppToBinaryAny(com::sun::star::uno::Any const &cppAny)
Definition: bridge.cxx:354
virtual void SAL_CALL addEventListener(com::sun::star::uno::Reference< com::sun::star::lang::XEventListener > const &xListener) override
Definition: bridge.cxx:925
bool makeCall(OUString const &oid, com::sun::star::uno::TypeDescription const &member, bool setter, std::vector< BinaryAny > &&inArguments, BinaryAny *returnValue, std::vector< BinaryAny > *outArguments)
Definition: bridge.cxx:587
OutgoingRequest lastOutgoingRequest(rtl::ByteSequence const &tid)
Definition: bridge.cxx:816
std::mutex mutex_
Definition: bridge.hxx:261
OUString protPropOid_
Definition: bridge.hxx:249
com::sun::star::uno::TypeDescription protPropRequest_
Definition: bridge.hxx:251
void incrementCalls(bool normalCall) noexcept
Definition: bridge.cxx:551
Listeners listeners_
Definition: bridge.hxx:263
com::sun::star::uno::Reference< com::sun::star::connection::XConnection > connection_
Definition: bridge.hxx:242
const com::sun::star::uno::Reference< com::sun::star::bridge::XInstanceProvider > & getProvider() const
Definition: bridge.hxx:93
void handleCommitChangeRequest(rtl::ByteSequence const &tid, std::vector< BinaryAny > const &inArguments)
Definition: bridge.cxx:765
void handleCommitChangeReply(bool exception, BinaryAny const &returnValue)
Definition: bridge.cxx:696
void releaseStub(OUString const &oid, com::sun::star::uno::TypeDescription const &type)
Definition: bridge.cxx:482
void checkDisposed()
Definition: bridge.cxx:1043
com::sun::star::uno::Environment binaryUno_
Definition: bridge.hxx:245
bool becameUnused() const
Definition: bridge.cxx:1030
rtl::Reference< BridgeFactory > factory_
Definition: bridge.hxx:239
bool isCurrentContextMode()
Definition: bridge.cxx:833
bool isProtocolPropertiesRequest(std::u16string_view oid, com::sun::star::uno::TypeDescription const &type) const
Definition: bridge.cxx:822
OUString registerOutgoingInterface(com::sun::star::uno::UnoInterfaceReference const &object, com::sun::star::uno::TypeDescription const &type)
Definition: bridge.cxx:412
osl::Condition passive_
Definition: bridge.hxx:254
OutgoingRequests outgoingRequests_
Definition: bridge.hxx:253
virtual OUString SAL_CALL getName() override
Definition: bridge.cxx:903
std::size_t activeCalls_
Definition: bridge.hxx:272
void makeReleaseCall(OUString const &oid, com::sun::star::uno::TypeDescription const &type)
Definition: bridge.cxx:977
void revokeProxy(Proxy &proxy)
Definition: bridge.cxx:527
std::size_t proxies_
Definition: bridge.hxx:269
rtl::Reference< Writer > getWriter()
Definition: bridge.cxx:372