Line data Source code
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 : #ifndef INCLUDED_DBACCESS_SOURCE_INC_APITOOLS_HXX
21 : #define INCLUDED_DBACCESS_SOURCE_INC_APITOOLS_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 : #include <cppuhelper/component.hxx>
27 : #include <osl/mutex.hxx>
28 : #include <cppuhelper/interfacecontainer.hxx>
29 : #include <osl/diagnose.h>
30 : #include <cppuhelper/typeprovider.hxx>
31 : #include <comphelper/sequence.hxx>
32 : #include <connectivity/CommonTools.hxx>
33 :
34 : // OSubComponent - a component which holds a hard ref to its parent
35 : // and is been hold itself (by the parent) with a weak ref
36 : class OSubComponent : public ::cppu::OComponentHelper
37 : {
38 : protected:
39 : // the parent must support the tunnel implementation
40 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xParent;
41 : virtual ~OSubComponent();
42 :
43 : public:
44 : OSubComponent(::osl::Mutex& _rMutex,
45 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xParent);
46 :
47 : // ::com::sun::star::lang::XTypeProvider
48 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
49 :
50 : // ::com::sun::star::uno::XInterface
51 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType )
52 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
53 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
54 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
55 :
56 14353 : inline operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > () const
57 14353 : { return static_cast<com::sun::star::uno::XWeak *>(const_cast<OSubComponent *>(this)); }
58 :
59 : };
60 :
61 : // helper for implementing the XServiceInfo interface
62 :
63 : // (internal - not to be used outside - usually)
64 : #define IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
65 : OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
66 : { \
67 : return OUString(implasciiname); \
68 : } \
69 :
70 : #define IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
71 : OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
72 : { \
73 : return getImplementationName_Static(); \
74 : } \
75 : OUString SAL_CALL classname::getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException) \
76 : { \
77 : return OUString(implasciiname); \
78 : } \
79 :
80 : #define IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
81 : sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
82 : { \
83 : ::com::sun::star::uno::Sequence< OUString > aSupported(getSupportedServiceNames()); \
84 : const OUString* pSupported = aSupported.getConstArray(); \
85 : for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) \
86 : if (pSupported->equals(_rServiceName)) \
87 : return sal_True; \
88 : \
89 : return sal_False; \
90 : } \
91 :
92 : #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
93 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
94 : { \
95 : ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
96 : aSupported[0] = serviceasciiname; \
97 : return aSupported; \
98 : } \
99 :
100 : #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
101 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
102 : { \
103 : return getSupportedServiceNames_Static(); \
104 : } \
105 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
106 : { \
107 : ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
108 : aSupported[0] = serviceasciiname; \
109 : return aSupported; \
110 : } \
111 :
112 : #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1, serviceasciiname2) \
113 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
114 : { \
115 : return getSupportedServiceNames_Static(); \
116 : } \
117 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
118 : { \
119 : ::com::sun::star::uno::Sequence< OUString > aSupported(2); \
120 : aSupported[0] = serviceasciiname1; \
121 : aSupported[1] = serviceasciiname2; \
122 : return aSupported; \
123 : } \
124 :
125 : #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
126 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
127 : { \
128 : ::com::sun::star::uno::Sequence< OUString > aSupported(2); \
129 : aSupported[0] = serviceasciiname1; \
130 : aSupported[1] = serviceasciiname2; \
131 : return aSupported; \
132 : } \
133 :
134 : #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
135 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
136 : { \
137 : ::com::sun::star::uno::Sequence< OUString > aSupported(3); \
138 : aSupported[0] = serviceasciiname1; \
139 : aSupported[1] = serviceasciiname2; \
140 : aSupported[2] = serviceasciiname3; \
141 : return aSupported; \
142 : } \
143 :
144 : #define IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
145 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
146 : SAL_CALL classname::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB) \
147 : { \
148 : return static_cast< XServiceInfo* >(new classname(_rxORB)); \
149 : } \
150 :
151 : #define DECLARE_SERVICE_INFO_STATIC() \
152 : DECLARE_SERVICE_INFO(); \
153 : static OUString SAL_CALL getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); \
154 : static ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); \
155 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
156 : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&) \
157 :
158 : #define IMPLEMENT_SERVICE_INFO1(classname, implasciiname, serviceasciiname) \
159 : IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
160 : IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
161 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
162 :
163 : #define IMPLEMENT_SERVICE_INFO1_STATIC(classname, implasciiname, serviceasciiname) \
164 : IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
165 : IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
166 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
167 : IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
168 :
169 : #define IMPLEMENT_SERVICE_INFO2(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
170 : IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
171 : IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
172 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2)
173 :
174 : #define IMPLEMENT_SERVICE_INFO2_STATIC(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
175 : IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
176 : IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
177 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1,serviceasciiname2) \
178 : IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
179 :
180 : #define IMPLEMENT_SERVICE_INFO3(classname, implasciiname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
181 : IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
182 : IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
183 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
184 :
185 : #define IMPLEMENT_SERVICE_INFO1_ABSTRACT(classname, serviceasciiname) \
186 : IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
187 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
188 :
189 : #define IMPLEMENT_SERVICE_INFO2_ABSTRACT(classname, serviceasciiname1, serviceasciiname2) \
190 : IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
191 : IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
192 :
193 : // XTypeProvider helpers
194 :
195 : #define DECLARE_IMPLEMENTATION_ID( ) \
196 : virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
197 : static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId() \
198 :
199 : #define DECLARE_GETTYPES( ) \
200 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception);
201 :
202 : #define DECLARE_TYPEPROVIDER( ) \
203 : DECLARE_GETTYPES( ) \
204 : DECLARE_IMPLEMENTATION_ID( )
205 :
206 : #define IMPLEMENT_IMPLEMENTATION_ID( classname ) \
207 : ::com::sun::star::uno::Sequence< sal_Int8 > classname::getUnoTunnelImplementationId() \
208 : { \
209 : static ::cppu::OImplementationId* pId = 0; \
210 : if ( !pId ) \
211 : { \
212 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); \
213 : if ( !pId ) \
214 : { \
215 : static ::cppu::OImplementationId aId; \
216 : pId = &aId; \
217 : } \
218 : } \
219 : return pId->getImplementationId(); \
220 : } \
221 : ::com::sun::star::uno::Sequence< sal_Int8 > classname::getImplementationId() throw (::com::sun::star::uno::RuntimeException, std::exception) \
222 : { \
223 : return css::uno::Sequence<sal_Int8>(); \
224 : }
225 :
226 : #define IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 ) \
227 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) \
228 : { \
229 : return ::comphelper::concatSequences( \
230 : baseclass1::getTypes( ), \
231 : baseclass2::getTypes( ) \
232 : ); \
233 : }
234 :
235 : #define IMPLEMENT_GETTYPES3( classname, baseclass1, baseclass2, baseclass3 ) \
236 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) \
237 : { \
238 : return ::comphelper::concatSequences( \
239 : baseclass1::getTypes( ), \
240 : baseclass2::getTypes( ), \
241 : baseclass3::getTypes( ) \
242 : ); \
243 : }
244 :
245 : #define IMPLEMENT_TYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
246 : IMPLEMENT_IMPLEMENTATION_ID( classname) \
247 : IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 )
248 :
249 : #define IMPLEMENT_TYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \
250 : IMPLEMENT_IMPLEMENTATION_ID( classname) \
251 : IMPLEMENT_GETTYPES3(classname, baseclass1, baseclass2, baseclass3 )
252 :
253 : // helper for declaring/implementing classes based on the OPropertyContainer and an OPropertyArrayUsageHelper
254 : #define DECLARE_PROPERTYCONTAINER_DEFAULTS( ) \
255 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
256 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE; \
257 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE
258 :
259 : #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname , baseclass1) \
260 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL classname::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException, std::exception) \
261 : { \
262 : Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); \
263 : return xInfo; \
264 : } \
265 : ::cppu::IPropertyArrayHelper& classname::getInfoHelper() \
266 : { \
267 : return *baseclass1::getArrayHelper(); \
268 : } \
269 : ::cppu::IPropertyArrayHelper* classname::createArrayHelper( ) const \
270 : { \
271 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps; \
272 : describeProperties(aProps); \
273 : return new ::cppu::OPropertyArrayHelper(aProps); \
274 : }
275 : #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( classname ) \
276 : IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname, classname )
277 :
278 : // helper for implementing the createArrayHelper
279 : #define BEGIN_PROPERTY_SEQUENCE(count) \
280 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aDescriptor(count); \
281 : ::com::sun::star::beans::Property* pDesc = aDescriptor.getArray(); \
282 : sal_Int32 nPos = 0; \
283 :
284 : #define BEGIN_PROPERTY_HELPER(count) \
285 : BEGIN_PROPERTY_SEQUENCE(count)
286 :
287 : #define DECL_PROP_IMPL(varname, cpputype) \
288 : pDesc[nPos++] = ::com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, cpputype,
289 :
290 : #define DECL_PROP0(varname, type) \
291 : DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) 0)
292 :
293 : #define DECL_PROP0_BOOL(varname) \
294 : DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) 0)
295 :
296 : #define DECL_PROP0_IFACE(varname, iface) \
297 : DECL_PROP_IMPL(varname, cppu::UnoType<iface>::get()) 0)
298 :
299 : #define DECL_PROP1(varname, type, attrib1) \
300 : DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1)
301 :
302 : #define DECL_PROP1_BOOL(varname, attrib1) \
303 : DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1)
304 :
305 : #define DECL_PROP1_IFACE(varname, iface, attrib1) \
306 : DECL_PROP_IMPL(varname, cppu::UnoType<iface>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1)
307 :
308 : #define DECL_PROP2_IFACE(varname, iface, attrib1, attrib2) \
309 : DECL_PROP_IMPL(varname, cppu::UnoType<iface>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
310 :
311 : #define DECL_PROP2(varname, type, attrib1, attrib2) \
312 : DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
313 :
314 : #define DECL_PROP2_BOOL(varname, attrib1, attrib2) \
315 : DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
316 :
317 : #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3) \
318 : DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3)
319 :
320 : #define DECL_PROP3_BOOL(varname, attrib1, attrib2, attrib3) \
321 : DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3)
322 :
323 : #define END_PROPERTY_SEQUENCE() \
324 : OSL_ENSURE(nPos == aDescriptor.getLength(), "forgot to adjust the count ?"); \
325 :
326 : #define END_PROPERTY_HELPER() \
327 : END_PROPERTY_SEQUENCE() \
328 : return new ::cppu::OPropertyArrayHelper(aDescriptor);
329 :
330 : #define NOTIFY_LISTERNERS(_rListeners,T,method) \
331 : Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
332 : \
333 : const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
334 : const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
335 : \
336 : _rGuard.clear(); \
337 : while( pxInt > pxIntBegin ) \
338 : { \
339 : try \
340 : { \
341 : while( pxInt > pxIntBegin ) \
342 : { \
343 : --pxInt; \
344 : static_cast< T* >( pxInt->get() )->method(aEvt); \
345 : } \
346 : } \
347 : catch( RuntimeException& ) \
348 : { \
349 : } \
350 : } \
351 : _rGuard.reset();
352 :
353 : #endif // INCLUDED_DBACCESS_SOURCE_INC_APITOOLS_HXX
354 :
355 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|