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