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 "boost/noncopyable.hpp"
31 #include "com/sun/star/bridge/XBridge.hpp"
32 #include "com/sun/star/lang/XComponent.hpp"
33 #include "com/sun/star/uno/Reference.hxx"
34 #include "com/sun/star/uno/RuntimeException.hpp"
35 #include "cppuhelper/implbase2.hxx"
36 #include "osl/conditn.hxx"
37 #include "osl/mutex.hxx"
38 #include "rtl/ref.hxx"
39 #include "rtl/ustring.hxx"
40 #include "sal/types.h"
41 #include "uno/environment.hxx"
42 #include "uno/mapping.hxx"
43 #include "uno/threadpool.h"
45 #include "outgoingrequest.hxx"
46 #include "outgoingrequests.hxx"
55 namespace com
{ namespace sun
{ namespace star
{
56 namespace bridge
{ class XInstanceProvider
; }
57 namespace connection
{ class XConnection
; }
58 namespace lang
{ class XEventListener
; }
61 class TypeDescription
;
62 class UnoInterfaceReference
;
66 namespace rtl
{ class ByteSequence
; }
71 public cppu::WeakImplHelper2
<
72 com::sun::star::bridge::XBridge
, com::sun::star::lang::XComponent
>,
73 private boost::noncopyable
77 rtl::Reference
< BridgeFactory
> const & factory
,
78 OUString
const & name
,
79 com::sun::star::uno::Reference
<
80 com::sun::star::connection::XConnection
> const & connection
,
81 com::sun::star::uno::Reference
<
82 com::sun::star::bridge::XInstanceProvider
> const & provider
);
86 // Internally waits for all incoming and outgoing remote calls to terminate,
87 // so must not be called from within such a call; when final is true, also
88 // joins all remaining threads (reader, writer, and worker threads from the
89 // thread pool), so must not be called with final set to true from such a
91 void terminate(bool final
);
93 com::sun::star::uno::Reference
< com::sun::star::connection::XConnection
>
94 getConnection() const;
96 com::sun::star::uno::Reference
< com::sun::star::bridge::XInstanceProvider
>
99 com::sun::star::uno::Mapping
& getCppToBinaryMapping();
101 BinaryAny
mapCppToBinaryAny(com::sun::star::uno::Any
const & cppAny
);
103 uno_ThreadPool
getThreadPool();
105 rtl::Reference
< Writer
> getWriter();
107 com::sun::star::uno::UnoInterfaceReference
registerIncomingInterface(
108 OUString
const & oid
,
109 com::sun::star::uno::TypeDescription
const & type
);
111 OUString
registerOutgoingInterface(
112 com::sun::star::uno::UnoInterfaceReference
const & object
,
113 com::sun::star::uno::TypeDescription
const & type
);
115 com::sun::star::uno::UnoInterfaceReference
findStub(
116 OUString
const & oid
,
117 com::sun::star::uno::TypeDescription
const & type
);
120 OUString
const & oid
,
121 com::sun::star::uno::TypeDescription
const & type
);
123 void resurrectProxy(Proxy
& proxy
);
125 void revokeProxy(Proxy
& proxy
);
127 void freeProxy(Proxy
& proxy
);
129 void incrementCalls(bool normalCall
) throw ();
131 void decrementCalls();
133 void incrementActiveCalls() throw ();
135 void decrementActiveCalls() throw ();
138 OUString
const & oid
,
139 com::sun::star::uno::TypeDescription
const & member
, bool setter
,
140 std::vector
< BinaryAny
> const & inArguments
, BinaryAny
* returnValue
,
141 std::vector
< BinaryAny
> * outArguments
);
143 // Only called from reader_ thread:
144 void sendRequestChangeRequest();
146 // Only called from reader_ thread:
147 void handleRequestChangeReply(
148 bool exception
, BinaryAny
const & returnValue
);
150 // Only called from reader_ thread:
151 void handleCommitChangeReply(bool exception
, BinaryAny
const & returnValue
);
153 // Only called from reader_ thread:
154 void handleRequestChangeRequest(
155 rtl::ByteSequence
const & tid
,
156 std::vector
< BinaryAny
> const & inArguments
);
158 // Only called from reader_ thread:
159 void handleCommitChangeRequest(
160 rtl::ByteSequence
const & tid
,
161 std::vector
< BinaryAny
> const & inArguments
);
163 OutgoingRequest
lastOutgoingRequest(rtl::ByteSequence
const & tid
);
165 bool isProtocolPropertiesRequest(
166 OUString
const & oid
,
167 com::sun::star::uno::TypeDescription
const & type
) const;
169 void setCurrentContextMode();
171 bool isCurrentContextMode();
176 virtual com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
177 SAL_CALL
getInstance(OUString
const & sInstanceName
)
178 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
180 virtual OUString SAL_CALL
getName()
181 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
183 virtual OUString SAL_CALL
getDescription()
184 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
186 virtual void SAL_CALL
dispose()
187 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
189 virtual void SAL_CALL
addEventListener(
190 com::sun::star::uno::Reference
< com::sun::star::lang::XEventListener
>
192 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
194 virtual void SAL_CALL
removeEventListener(
195 com::sun::star::uno::Reference
< com::sun::star::lang::XEventListener
>
197 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
199 // Only called from reader_ thread:
200 void sendCommitChangeRequest();
202 // Only called from reader_ thread:
203 void sendProtPropRequest(
204 OutgoingRequest::Kind kind
,
205 std::vector
< BinaryAny
> const & inArguments
);
207 void makeReleaseCall(
208 OUString
const & oid
,
209 com::sun::star::uno::TypeDescription
const & type
);
212 rtl::ByteSequence
const & tid
, OUString
const & oid
,
213 com::sun::star::uno::TypeDescription
const & type
,
214 com::sun::star::uno::TypeDescription
const & member
,
215 std::vector
< BinaryAny
> const & inArguments
);
217 void throwException(bool exception
, BinaryAny
const & value
);
219 com::sun::star::uno::Any
mapBinaryToCppAny(BinaryAny
const & binaryAny
);
221 bool becameUnused() const;
223 void terminateWhenUnused(bool unused
);
225 // Must only be called with mutex_ locked:
226 void checkDisposed();
230 com::sun::star::uno::Reference
<
231 com::sun::star::lang::XEventListener
> >
236 typedef std::map
< com::sun::star::uno::TypeDescription
, SubStub
> Stub
;
238 typedef std::map
< OUString
, Stub
> Stubs
;
240 enum State
{ STATE_INITIAL
, STATE_STARTED
, STATE_TERMINATED
, STATE_FINAL
};
243 MODE_REQUESTED
, MODE_REPLY_MINUS1
, MODE_REPLY_0
, MODE_REPLY_1
,
244 MODE_WAIT
, MODE_NORMAL
, MODE_NORMAL_WAIT
};
246 rtl::Reference
< BridgeFactory
> factory_
;
248 com::sun::star::uno::Reference
< com::sun::star::connection::XConnection
>
250 com::sun::star::uno::Reference
< com::sun::star::bridge::XInstanceProvider
>
252 com::sun::star::uno::Environment binaryUno_
;
253 com::sun::star::uno::Mapping cppToBinaryMapping_
;
254 com::sun::star::uno::Mapping binaryToCppMapping_
;
255 rtl::ByteSequence protPropTid_
;
256 OUString protPropOid_
;
257 com::sun::star::uno::TypeDescription protPropType_
;
258 com::sun::star::uno::TypeDescription protPropRequest_
;
259 com::sun::star::uno::TypeDescription protPropCommit_
;
260 OutgoingRequests outgoingRequests_
;
261 osl::Condition passive_
;
262 // to guarantee that passive_ is eventually set (to avoid deadlock, see
263 // dispose), activeCalls_ only counts those calls for which it can be
264 // guaranteed that incrementActiveCalls is indeed followed by
265 // decrementActiveCalls, without an intervening exception
266 osl::Condition terminated_
;
270 Listeners listeners_
;
271 uno_ThreadPool threadPool_
;
272 rtl::Reference
< Writer
> writer_
;
273 rtl::Reference
< Reader
> reader_
;
274 bool currentContextMode_
;
276 std::size_t proxies_
;
279 std::size_t activeCalls_
;
281 // Only accessed from reader_ thread:
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */