1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 #ifndef INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_OSUBCOMPONENT_HXX
37 #define INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_OSUBCOMPONENT_HXX
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <cppuhelper/interfacecontainer.h>
41 #include <cppuhelper/propshlp.hxx>
42 #include <cppuhelper/supportsservice.hxx>
43 #include <cppuhelper/weak.hxx>
44 #include <osl/mutex.hxx>
45 #include <osl/diagnose.h>
48 class IPropertyArrayHelper
;
65 namespace connectivity
70 void release(oslInterlockedCount
& _refCount
,
71 ::cppu::OBroadcastHelper
& rBHelper
,
72 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
73 ::com::sun::star::lang::XComponent
* _pObject
);
75 void checkDisposed(sal_Bool _bThrow
) throw ( ::com::sun::star::lang::DisposedException
);
77 template <class SELF
, class WEAK
> class OSubComponent
80 // the parent must support the tunnel implementation
81 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xParent
;
82 SELF
* m_pDerivedImplementation
;
86 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xParent
,
87 SELF
* _pDerivedImplementation
)
89 ,m_pDerivedImplementation(_pDerivedImplementation
)
94 void dispose_ChildImpl()
96 ::osl::MutexGuard
aGuard( m_pDerivedImplementation
->rBHelper
.rMutex
);
99 void release_ChildImpl()
101 release(m_pDerivedImplementation
->m_refCount
,
102 m_pDerivedImplementation
->rBHelper
,
104 m_pDerivedImplementation
);
106 m_pDerivedImplementation
->WEAK::release();
110 template <class TYPE
>
111 class OPropertyArrayUsageHelper
114 static sal_Int32 s_nRefCount
;
115 static ::cppu::IPropertyArrayHelper
* s_pProps
;
116 static ::osl::Mutex s_aMutex
;
119 OPropertyArrayUsageHelper();
120 virtual ~OPropertyArrayUsageHelper();
122 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
123 class, which is created if necessary.
125 ::cppu::IPropertyArrayHelper
* getArrayHelper();
128 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
129 This method needs to be implemented in derived classes.
131 The method gets called with s_aMutex acquired.
132 @return a pointer to the newly created array helper. Must not be NULL.
134 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const = 0;
138 sal_Int32 OPropertyArrayUsageHelper
< TYPE
>::s_nRefCount
= 0;
141 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
< TYPE
>::s_pProps
= NULL
;
144 ::osl::Mutex OPropertyArrayUsageHelper
< TYPE
>::s_aMutex
;
146 template <class TYPE
>
147 OPropertyArrayUsageHelper
<TYPE
>::OPropertyArrayUsageHelper()
149 ::osl::MutexGuard
aGuard(s_aMutex
);
153 template <class TYPE
>
154 OPropertyArrayUsageHelper
<TYPE
>::~OPropertyArrayUsageHelper()
156 ::osl::MutexGuard
aGuard(s_aMutex
);
157 OSL_ENSURE(s_nRefCount
> 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
165 template <class TYPE
>
166 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::getArrayHelper()
168 OSL_ENSURE(s_nRefCount
, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
171 ::osl::MutexGuard
aGuard(s_aMutex
);
174 s_pProps
= createArrayHelper();
175 OSL_ENSURE(s_pProps
, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
184 ::osl::Mutex m_aMutex
;
190 void implCopySequence(const T
* _pSource
, T
*& _pDest
, sal_Int32 _nSourceLen
)
192 for (sal_Int32 i
=0; i
<_nSourceLen
; ++i
, ++_pSource
, ++_pDest
)
197 /// concat two sequences
199 ::com::sun::star::uno::Sequence
<T
> concatSequences(const ::com::sun::star::uno::Sequence
<T
>& _rLeft
, const ::com::sun::star::uno::Sequence
<T
>& _rRight
)
201 sal_Int32
nLeft(_rLeft
.getLength()), nRight(_rRight
.getLength());
202 const T
* pLeft
= _rLeft
.getConstArray();
203 const T
* pRight
= _rRight
.getConstArray();
205 sal_Int32
nReturnLen(nLeft
+ nRight
);
206 ::com::sun::star::uno::Sequence
<T
> aReturn(nReturnLen
);
207 T
* pReturn
= aReturn
.getArray();
209 internal::implCopySequence(pLeft
, pReturn
, nLeft
);
210 internal::implCopySequence(pRight
, pReturn
, nRight
);
216 #define DECLARE_SERVICE_INFO() \
217 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
218 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
219 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
221 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
222 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
224 return ::rtl::OUString::createFromAscii(implasciiname); \
226 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
228 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
229 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
232 sal_Bool SAL_CALL classname::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
234 return cppu::supportsService(this, _rServiceName); \
240 #endif // INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_OSUBCOMPONENT_HXX
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */