1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2011 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef INCLUDED_BINARYURP_SOURCE_BRIDGE_HXX
30 #define INCLUDED_BINARYURP_SOURCE_BRIDGE_HXX
32 #include "sal/config.h"
39 #include "boost/noncopyable.hpp"
40 #include "com/sun/star/bridge/XBridge.hpp"
41 #include "com/sun/star/lang/XComponent.hpp"
42 #include "com/sun/star/uno/Reference.hxx"
43 #include "com/sun/star/uno/RuntimeException.hpp"
44 #include "cppuhelper/implbase2.hxx"
45 #include "osl/conditn.hxx"
46 #include "osl/mutex.hxx"
47 #include "rtl/ref.hxx"
48 #include "rtl/ustring.hxx"
49 #include "sal/types.h"
50 #include "uno/environment.hxx"
51 #include "uno/mapping.hxx"
52 #include "uno/threadpool.h"
54 #include "outgoingrequest.hxx"
55 #include "outgoingrequests.hxx"
64 namespace com
{ namespace sun
{ namespace star
{
65 namespace bridge
{ class XInstanceProvider
; }
66 namespace connection
{ class XConnection
; }
67 namespace lang
{ class XEventListener
; }
70 class TypeDescription
;
71 class UnoInterfaceReference
;
75 namespace rtl
{ class ByteSequence
; }
80 public cppu::WeakImplHelper2
<
81 com::sun::star::bridge::XBridge
, com::sun::star::lang::XComponent
>,
82 private boost::noncopyable
86 rtl::Reference
< BridgeFactory
> const & factory
,
87 rtl::OUString
const & name
,
88 com::sun::star::uno::Reference
<
89 com::sun::star::connection::XConnection
> const & connection
,
90 com::sun::star::uno::Reference
<
91 com::sun::star::bridge::XInstanceProvider
> const & provider
);
95 // Internally waits for all incoming and outgoing remote calls to terminate,
96 // so must not be called from within such a call:
99 com::sun::star::uno::Reference
< com::sun::star::connection::XConnection
>
100 getConnection() const;
102 com::sun::star::uno::Reference
< com::sun::star::bridge::XInstanceProvider
>
105 com::sun::star::uno::Mapping
& getCppToBinaryMapping();
107 BinaryAny
mapCppToBinaryAny(com::sun::star::uno::Any
const & cppAny
);
109 uno_ThreadPool
getThreadPool() const;
111 rtl::Reference
< Writer
> getWriter();
113 com::sun::star::uno::UnoInterfaceReference
registerIncomingInterface(
114 rtl::OUString
const & oid
,
115 com::sun::star::uno::TypeDescription
const & type
);
117 rtl::OUString
registerOutgoingInterface(
118 com::sun::star::uno::UnoInterfaceReference
const & object
,
119 com::sun::star::uno::TypeDescription
const & type
);
121 com::sun::star::uno::UnoInterfaceReference
findStub(
122 rtl::OUString
const & oid
,
123 com::sun::star::uno::TypeDescription
const & type
);
126 rtl::OUString
const & oid
,
127 com::sun::star::uno::TypeDescription
const & type
);
129 void resurrectProxy(Proxy
& proxy
);
131 void revokeProxy(Proxy
& proxy
);
133 void freeProxy(Proxy
& proxy
);
135 void incrementCalls(bool normalCall
) throw ();
137 void decrementCalls();
139 void incrementActiveCalls() throw ();
141 void decrementActiveCalls() throw ();
144 rtl::OUString
const & oid
,
145 com::sun::star::uno::TypeDescription
const & member
, bool setter
,
146 std::vector
< BinaryAny
> const & inArguments
, BinaryAny
* returnValue
,
147 std::vector
< BinaryAny
> * outArguments
);
149 // Only called from reader_ thread:
150 void sendRequestChangeRequest();
152 // Only called from reader_ thread:
153 void handleRequestChangeReply(
154 bool exception
, BinaryAny
const & returnValue
);
156 // Only called from reader_ thread:
157 void handleCommitChangeReply(bool exception
, BinaryAny
const & returnValue
);
159 // Only called from reader_ thread:
160 void handleRequestChangeRequest(
161 rtl::ByteSequence
const & tid
,
162 std::vector
< BinaryAny
> const & inArguments
);
164 // Only called from reader_ thread:
165 void handleCommitChangeRequest(
166 rtl::ByteSequence
const & tid
,
167 std::vector
< BinaryAny
> const & inArguments
);
169 OutgoingRequest
lastOutgoingRequest(rtl::ByteSequence
const & tid
);
171 bool isProtocolPropertiesRequest(
172 rtl::OUString
const & oid
,
173 com::sun::star::uno::TypeDescription
const & type
) const;
175 void setCurrentContextMode();
177 bool isCurrentContextMode();
182 virtual com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
183 SAL_CALL
getInstance(rtl::OUString
const & sInstanceName
)
184 throw (com::sun::star::uno::RuntimeException
);
186 virtual rtl::OUString SAL_CALL
getName()
187 throw (com::sun::star::uno::RuntimeException
);
189 virtual rtl::OUString SAL_CALL
getDescription()
190 throw (com::sun::star::uno::RuntimeException
);
192 virtual void SAL_CALL
dispose()
193 throw (com::sun::star::uno::RuntimeException
);
195 virtual void SAL_CALL
addEventListener(
196 com::sun::star::uno::Reference
< com::sun::star::lang::XEventListener
>
198 throw (com::sun::star::uno::RuntimeException
);
200 virtual void SAL_CALL
removeEventListener(
201 com::sun::star::uno::Reference
< com::sun::star::lang::XEventListener
>
203 throw (com::sun::star::uno::RuntimeException
);
205 // Only called from reader_ thread:
206 void sendCommitChangeRequest();
208 // Only called from reader_ thread:
209 void sendProtPropRequest(
210 OutgoingRequest::Kind kind
,
211 std::vector
< BinaryAny
> const & inArguments
);
213 void makeReleaseCall(
214 rtl::OUString
const & oid
,
215 com::sun::star::uno::TypeDescription
const & type
);
218 rtl::ByteSequence
const & tid
, rtl::OUString
const & oid
,
219 com::sun::star::uno::TypeDescription
const & type
,
220 com::sun::star::uno::TypeDescription
const & member
,
221 std::vector
< BinaryAny
> const & inArguments
);
223 void throwException(bool exception
, BinaryAny
const & value
);
225 com::sun::star::uno::Any
mapBinaryToCppAny(BinaryAny
const & binaryAny
);
227 bool becameUnused() const;
229 void terminateWhenUnused(bool unused
);
233 com::sun::star::uno::Reference
<
234 com::sun::star::lang::XEventListener
> >
239 typedef std::map
< com::sun::star::uno::TypeDescription
, SubStub
> Stub
;
241 typedef std::map
< rtl::OUString
, Stub
> Stubs
;
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 rtl::OUString protPropOid_
;
258 com::sun::star::uno::TypeDescription protPropType_
;
259 com::sun::star::uno::TypeDescription protPropRequest_
;
260 com::sun::star::uno::TypeDescription protPropCommit_
;
261 uno_ThreadPool threadPool_
;
262 OutgoingRequests outgoingRequests_
;
265 Listeners listeners_
;
266 rtl::Reference
< Writer
> writer_
;
267 rtl::Reference
< Reader
> reader_
;
268 bool currentContextMode_
;
270 std::size_t proxies_
;
273 std::size_t activeCalls_
;
274 osl::Condition passive_
;
275 // to guarantee that passive_ is eventually set (to avoid deadlock, see
276 // dispose), activeCalls_ only counts those calls for which it can be
277 // guaranteed that incrementActiveCalls is indeed followed by
278 // decrementActiveCalls, without an intervening exception
281 // Only accessed from reader_ thread:
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */