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 #ifndef INCLUDED_BINARYURP_SOURCE_BRIDGE_HXX
21 #define INCLUDED_BINARYURP_SOURCE_BRIDGE_HXX
23 #include "sal/config.h"
30 #include "com/sun/star/bridge/XBridge.hpp"
31 #include "com/sun/star/lang/XComponent.hpp"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "com/sun/star/uno/RuntimeException.hpp"
34 #include "cppuhelper/implbase2.hxx"
35 #include "osl/conditn.hxx"
36 #include "osl/mutex.hxx"
37 #include "rtl/ref.hxx"
38 #include "rtl/ustring.hxx"
39 #include "sal/types.h"
40 #include "uno/environment.hxx"
41 #include "uno/mapping.hxx"
42 #include "uno/threadpool.h"
44 #include "outgoingrequest.hxx"
45 #include "outgoingrequests.hxx"
54 namespace com
{ namespace sun
{ namespace star
{
55 namespace bridge
{ class XInstanceProvider
; }
56 namespace connection
{ class XConnection
; }
57 namespace lang
{ class XEventListener
; }
60 class TypeDescription
;
61 class UnoInterfaceReference
;
65 namespace rtl
{ class ByteSequence
; }
70 public cppu::WeakImplHelper2
<
71 com::sun::star::bridge::XBridge
, com::sun::star::lang::XComponent
>
75 rtl::Reference
< BridgeFactory
> const & factory
,
76 OUString
const & name
,
77 com::sun::star::uno::Reference
<
78 com::sun::star::connection::XConnection
> const & connection
,
79 com::sun::star::uno::Reference
<
80 com::sun::star::bridge::XInstanceProvider
> const & provider
);
84 // Internally waits for all incoming and outgoing remote calls to terminate,
85 // so must not be called from within such a call; when final is true, also
86 // joins all remaining threads (reader, writer, and worker threads from the
87 // thread pool), so must not be called with final set to true from such a
89 void terminate(bool final
);
91 com::sun::star::uno::Reference
< com::sun::star::connection::XConnection
>
92 getConnection() const { return connection_
;}
94 com::sun::star::uno::Reference
< com::sun::star::bridge::XInstanceProvider
>
95 getProvider() const { return provider_
;}
97 com::sun::star::uno::Mapping
& getCppToBinaryMapping() { return cppToBinaryMapping_
;}
99 BinaryAny
mapCppToBinaryAny(com::sun::star::uno::Any
const & cppAny
);
101 uno_ThreadPool
getThreadPool();
103 rtl::Reference
< Writer
> getWriter();
105 com::sun::star::uno::UnoInterfaceReference
registerIncomingInterface(
106 OUString
const & oid
,
107 com::sun::star::uno::TypeDescription
const & type
);
109 OUString
registerOutgoingInterface(
110 com::sun::star::uno::UnoInterfaceReference
const & object
,
111 com::sun::star::uno::TypeDescription
const & type
);
113 com::sun::star::uno::UnoInterfaceReference
findStub(
114 OUString
const & oid
,
115 com::sun::star::uno::TypeDescription
const & type
);
118 OUString
const & oid
,
119 com::sun::star::uno::TypeDescription
const & type
);
121 void resurrectProxy(Proxy
& proxy
);
123 void revokeProxy(Proxy
& proxy
);
125 void freeProxy(Proxy
& proxy
);
127 void incrementCalls(bool normalCall
) throw ();
129 void decrementCalls();
131 void incrementActiveCalls() throw ();
133 void decrementActiveCalls() throw ();
136 OUString
const & oid
,
137 com::sun::star::uno::TypeDescription
const & member
, bool setter
,
138 std::vector
< BinaryAny
> const & inArguments
, BinaryAny
* returnValue
,
139 std::vector
< BinaryAny
> * outArguments
);
141 // Only called from reader_ thread:
142 void sendRequestChangeRequest();
144 // Only called from reader_ thread:
145 void handleRequestChangeReply(
146 bool exception
, BinaryAny
const & returnValue
);
148 // Only called from reader_ thread:
149 void handleCommitChangeReply(bool exception
, BinaryAny
const & returnValue
);
151 // Only called from reader_ thread:
152 void handleRequestChangeRequest(
153 rtl::ByteSequence
const & tid
,
154 std::vector
< BinaryAny
> const & inArguments
);
156 // Only called from reader_ thread:
157 void handleCommitChangeRequest(
158 rtl::ByteSequence
const & tid
,
159 std::vector
< BinaryAny
> const & inArguments
);
161 OutgoingRequest
lastOutgoingRequest(rtl::ByteSequence
const & tid
);
163 bool isProtocolPropertiesRequest(
164 OUString
const & oid
,
165 com::sun::star::uno::TypeDescription
const & type
) const;
167 void setCurrentContextMode();
169 bool isCurrentContextMode();
172 Bridge(const Bridge
&) SAL_DELETED_FUNCTION
;
173 Bridge
& operator=(const Bridge
&) SAL_DELETED_FUNCTION
;
177 virtual com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
178 SAL_CALL
getInstance(OUString
const & sInstanceName
)
179 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
181 virtual OUString SAL_CALL
getName()
182 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
184 virtual OUString SAL_CALL
getDescription()
185 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
187 virtual void SAL_CALL
dispose()
188 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
190 virtual void SAL_CALL
addEventListener(
191 com::sun::star::uno::Reference
< com::sun::star::lang::XEventListener
>
193 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
195 virtual void SAL_CALL
removeEventListener(
196 com::sun::star::uno::Reference
< com::sun::star::lang::XEventListener
>
198 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
200 // Only called from reader_ thread:
201 void sendCommitChangeRequest();
203 // Only called from reader_ thread:
204 void sendProtPropRequest(
205 OutgoingRequest::Kind kind
,
206 std::vector
< BinaryAny
> const & inArguments
);
208 void makeReleaseCall(
209 OUString
const & oid
,
210 com::sun::star::uno::TypeDescription
const & type
);
213 rtl::ByteSequence
const & tid
, OUString
const & oid
,
214 com::sun::star::uno::TypeDescription
const & type
,
215 com::sun::star::uno::TypeDescription
const & member
,
216 std::vector
< BinaryAny
> const & inArguments
);
218 void throwException(bool exception
, BinaryAny
const & value
);
220 com::sun::star::uno::Any
mapBinaryToCppAny(BinaryAny
const & binaryAny
);
222 bool becameUnused() const;
224 void terminateWhenUnused(bool unused
);
226 // Must only be called with mutex_ locked:
227 void checkDisposed();
231 com::sun::star::uno::Reference
<
232 com::sun::star::lang::XEventListener
> >
237 typedef std::map
< com::sun::star::uno::TypeDescription
, SubStub
> Stub
;
239 typedef std::map
< OUString
, Stub
> Stubs
;
241 enum State
{ STATE_INITIAL
, STATE_STARTED
, STATE_TERMINATED
, STATE_FINAL
};
244 MODE_REQUESTED
, MODE_REPLY_MINUS1
, MODE_REPLY_0
, MODE_REPLY_1
,
245 MODE_WAIT
, MODE_NORMAL
, MODE_NORMAL_WAIT
};
247 rtl::Reference
< BridgeFactory
> factory_
;
249 com::sun::star::uno::Reference
< com::sun::star::connection::XConnection
>
251 com::sun::star::uno::Reference
< com::sun::star::bridge::XInstanceProvider
>
253 com::sun::star::uno::Environment binaryUno_
;
254 com::sun::star::uno::Mapping cppToBinaryMapping_
;
255 com::sun::star::uno::Mapping binaryToCppMapping_
;
256 rtl::ByteSequence protPropTid_
;
257 OUString protPropOid_
;
258 com::sun::star::uno::TypeDescription protPropType_
;
259 com::sun::star::uno::TypeDescription protPropRequest_
;
260 com::sun::star::uno::TypeDescription protPropCommit_
;
261 OutgoingRequests outgoingRequests_
;
262 osl::Condition passive_
;
263 // to guarantee that passive_ is eventually set (to avoid deadlock, see
264 // dispose), activeCalls_ only counts those calls for which it can be
265 // guaranteed that incrementActiveCalls is indeed followed by
266 // decrementActiveCalls, without an intervening exception
267 osl::Condition terminated_
;
271 Listeners listeners_
;
272 uno_ThreadPool threadPool_
;
273 rtl::Reference
< Writer
> writer_
;
274 rtl::Reference
< Reader
> reader_
;
275 bool currentContextMode_
;
277 std::size_t proxies_
;
280 std::size_t activeCalls_
;
282 // Only accessed from reader_ thread:
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */