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_DBACCESS_SOURCE_INC_APITOOLS_HXX
21 #define INCLUDED_DBACCESS_SOURCE_INC_APITOOLS_HXX
23 #include <sal/config.h>
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>
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
39 // the parent must support the tunnel implementation
40 css::uno::Reference
< css::uno::XInterface
> m_xParent
;
41 virtual ~OSubComponent();
44 OSubComponent(::osl::Mutex
& _rMutex
,
45 const css::uno::Reference
< css::uno::XInterface
>& _xParent
);
47 // css::lang::XTypeProvider
48 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() throw (css::uno::RuntimeException
, std::exception
) override
;
50 // css::uno::XInterface
51 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
)
52 throw(css::uno::RuntimeException
, std::exception
) override
;
53 virtual void SAL_CALL
acquire() throw() override
;
54 virtual void SAL_CALL
release() throw() override
;
56 inline operator css::uno::Reference
< css::uno::XInterface
> () const
57 { return static_cast<css::uno::XWeak
*>(const_cast<OSubComponent
*>(this)); }
61 // helper for implementing the XServiceInfo interface
63 // (internal - not to be used outside - usually)
64 #define IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
65 OUString SAL_CALL classname::getImplementationName( ) throw (css::uno::RuntimeException, std::exception) \
67 return OUString(implasciiname); \
70 #define IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
71 OUString SAL_CALL classname::getImplementationName( ) throw (css::uno::RuntimeException, std::exception) \
73 return getImplementationName_Static(); \
75 OUString SAL_CALL classname::getImplementationName_Static( ) throw (css::uno::RuntimeException) \
77 return OUString(implasciiname); \
80 #define IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
81 sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(css::uno::RuntimeException, std::exception) \
83 css::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)) \
92 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
93 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) \
95 return getSupportedServiceNames_Static(); \
97 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(css::uno::RuntimeException) \
99 css::uno::Sequence< OUString > aSupported { serviceasciiname }; \
103 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1, serviceasciiname2) \
104 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) \
106 return getSupportedServiceNames_Static(); \
108 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(css::uno::RuntimeException) \
110 css::uno::Sequence< OUString > aSupported(2); \
111 aSupported[0] = serviceasciiname1; \
112 aSupported[1] = serviceasciiname2; \
116 #define DECLARE_SERVICE_INFO_STATIC() \
117 DECLARE_SERVICE_INFO(); \
118 static OUString SAL_CALL getImplementationName_Static( ) throw (css::uno::RuntimeException); \
119 static css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(css::uno::RuntimeException); \
120 static css::uno::Reference< css::uno::XInterface > \
121 SAL_CALL Create(const css::uno::Reference< css::lang::XMultiServiceFactory >&) \
123 #define IMPLEMENT_SERVICE_INFO1(classname, implasciiname, serviceasciiname) \
124 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
125 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
126 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) \
128 return css::uno::Sequence< OUString > { serviceasciiname }; \
132 #define IMPLEMENT_SERVICE_INFO2(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
133 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
134 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
135 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) \
137 return css::uno::Sequence< OUString > { serviceasciiname1, serviceasciiname2 }; \
141 #define IMPLEMENT_SERVICE_INFO2_STATIC(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
142 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
143 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
144 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1,serviceasciiname2) \
145 css::uno::Reference< css::uno::XInterface > \
146 SAL_CALL classname::Create(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxORB) \
148 return static_cast< XServiceInfo* >(new classname(_rxORB)); \
152 #define IMPLEMENT_SERVICE_INFO3(classname, implasciiname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
153 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
154 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
155 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) \
157 return css::uno::Sequence< OUString > { serviceasciiname1, serviceasciiname2, serviceasciiname3 }; \
161 // XTypeProvider helpers
163 #define IMPLEMENT_IMPLEMENTATION_ID( classname ) \
164 css::uno::Sequence< sal_Int8 > classname::getUnoTunnelImplementationId() \
166 static ::cppu::OImplementationId* pId = nullptr; \
169 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); \
172 static ::cppu::OImplementationId aId; \
176 return pId->getImplementationId(); \
178 css::uno::Sequence< sal_Int8 > classname::getImplementationId() throw (css::uno::RuntimeException, std::exception) \
180 return css::uno::Sequence<sal_Int8>(); \
183 #define IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 ) \
184 css::uno::Sequence< css::uno::Type > classname::getTypes() throw (css::uno::RuntimeException, std::exception) \
186 return ::comphelper::concatSequences( \
187 baseclass1::getTypes( ), \
188 baseclass2::getTypes( ) \
192 #define IMPLEMENT_GETTYPES3( classname, baseclass1, baseclass2, baseclass3 ) \
193 css::uno::Sequence< css::uno::Type > classname::getTypes() throw (css::uno::RuntimeException, std::exception) \
195 return ::comphelper::concatSequences( \
196 baseclass1::getTypes( ), \
197 baseclass2::getTypes( ), \
198 baseclass3::getTypes( ) \
202 // helper for declaring/implementing classes based on the OPropertyContainer and an OPropertyArrayUsageHelper
203 #define DECLARE_PROPERTYCONTAINER_DEFAULTS( ) \
204 virtual css::uno::Reference< css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(css::uno::RuntimeException, std::exception) override; \
205 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; \
206 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override
208 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname , baseclass1) \
209 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL classname::getPropertySetInfo() throw(css::uno::RuntimeException, std::exception) \
211 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); \
214 ::cppu::IPropertyArrayHelper& classname::getInfoHelper() \
216 return *baseclass1::getArrayHelper(); \
218 ::cppu::IPropertyArrayHelper* classname::createArrayHelper( ) const \
220 css::uno::Sequence< css::beans::Property > aProps; \
221 describeProperties(aProps); \
222 return new ::cppu::OPropertyArrayHelper(aProps); \
224 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( classname ) \
225 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname, classname )
227 // helper for implementing the createArrayHelper
228 #define BEGIN_PROPERTY_SEQUENCE(count) \
229 css::uno::Sequence< css::beans::Property> aDescriptor(count); \
230 css::beans::Property* pDesc = aDescriptor.getArray(); \
231 sal_Int32 nPos = 0; \
233 #define BEGIN_PROPERTY_HELPER(count) \
234 BEGIN_PROPERTY_SEQUENCE(count)
236 #define DECL_PROP_IMPL(varname, cpputype) \
237 pDesc[nPos++] = css::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, cpputype,
239 #define DECL_PROP0(varname, type) \
240 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) 0)
242 #define DECL_PROP0_BOOL(varname) \
243 DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) 0)
245 #define DECL_PROP1(varname, type, attrib1) \
246 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) css::beans::PropertyAttribute::attrib1)
248 #define DECL_PROP1_BOOL(varname, attrib1) \
249 DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) css::beans::PropertyAttribute::attrib1)
251 #define DECL_PROP2_IFACE(varname, iface, attrib1, attrib2) \
252 DECL_PROP_IMPL(varname, cppu::UnoType<iface>::get()) css::beans::PropertyAttribute::attrib1 | css::beans::PropertyAttribute::attrib2)
254 #define DECL_PROP2(varname, type, attrib1, attrib2) \
255 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) css::beans::PropertyAttribute::attrib1 | css::beans::PropertyAttribute::attrib2)
257 #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3) \
258 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) css::beans::PropertyAttribute::attrib1 | css::beans::PropertyAttribute::attrib2 | css::beans::PropertyAttribute::attrib3)
260 #define END_PROPERTY_SEQUENCE() \
261 OSL_ENSURE(nPos == aDescriptor.getLength(), "forgot to adjust the count ?"); \
263 #define END_PROPERTY_HELPER() \
264 END_PROPERTY_SEQUENCE() \
265 return new ::cppu::OPropertyArrayHelper(aDescriptor);
267 #endif // INCLUDED_DBACCESS_SOURCE_INC_APITOOLS_HXX
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */