1 /*************************************************************************
3 * $RCSfile: OSubComponent.hxx,v $
7 * last change: $Author: rt $ $Date: 2008-07-11 14:21:27 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 #ifndef _CONNECTIVITY_OSUBCOMPONENT_HXX_
42 #define _CONNECTIVITY_OSUBCOMPONENT_HXX_
44 #include <cppuhelper/weak.hxx>
45 #include <cppuhelper/interfacecontainer.h>
46 #include <com/sun/star/lang/DisposedException.hpp>
47 #include <cppuhelper/propshlp.hxx>
48 #include <osl/mutex.hxx>
49 #include <osl/diagnose.h>
52 class IPropertyArrayHelper
;
68 namespace connectivity
73 void release(oslInterlockedCount
& _refCount
,
74 ::cppu::OBroadcastHelper
& rBHelper
,
75 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
76 ::com::sun::star::lang::XComponent
* _pObject
);
78 void checkDisposed(sal_Bool _bThrow
) throw ( ::com::sun::star::lang::DisposedException
);
79 //************************************************************
81 //************************************************************
82 template <class SELF
, class WEAK
> class OSubComponent
85 // the parent must support the tunnel implementation
86 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xParent
;
87 SELF
* m_pDerivedImplementation
;
91 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xParent
,
92 SELF
* _pDerivedImplementation
)
94 ,m_pDerivedImplementation(_pDerivedImplementation
)
99 void dispose_ChildImpl()
101 ::osl::MutexGuard
aGuard( m_pDerivedImplementation
->rBHelper
.rMutex
);
104 void relase_ChildImpl()
106 release(m_pDerivedImplementation
->m_refCount
,
107 m_pDerivedImplementation
->rBHelper
,
109 m_pDerivedImplementation
);
111 m_pDerivedImplementation
->WEAK::release();
116 template <class TYPE
>
117 class OPropertyArrayUsageHelper
120 static sal_Int32 s_nRefCount
;
121 static ::cppu::IPropertyArrayHelper
* s_pProps
;
122 static ::osl::Mutex s_aMutex
;
125 OPropertyArrayUsageHelper();
126 virtual ~OPropertyArrayUsageHelper()
127 { // ARGHHHHHHH ..... would like to implement this in proparrhlp_impl.hxx (as we do with all other methods)
128 // but SUNPRO 5 compiler (linker) doesn't like this
129 ::osl::MutexGuard
aGuard(s_aMutex
);
130 OSL_ENSURE(s_nRefCount
> 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
138 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
139 class, which is created if neccessary.
141 ::cppu::IPropertyArrayHelper
* getArrayHelper();
144 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
145 This method needs to be implemented in derived classes.
147 The method gets called with s_aMutex acquired.
149 as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper
150 assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps.
151 @return an pointer to the newly created array helper. Must not be NULL.
153 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const = 0;
157 sal_Int32 OPropertyArrayUsageHelper
< TYPE
>::s_nRefCount
= 0;
160 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
< TYPE
>::s_pProps
= NULL
;
163 ::osl::Mutex OPropertyArrayUsageHelper
< TYPE
>::s_aMutex
;
165 //------------------------------------------------------------------
166 template <class TYPE
>
167 OPropertyArrayUsageHelper
<TYPE
>::OPropertyArrayUsageHelper()
169 ::osl::MutexGuard
aGuard(s_aMutex
);
173 //------------------------------------------------------------------
174 template <class TYPE
>
175 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::getArrayHelper()
177 OSL_ENSURE(s_nRefCount
, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
180 ::osl::MutexGuard
aGuard(s_aMutex
);
183 s_pProps
= createArrayHelper();
184 OSL_ENSURE(s_pProps
, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
195 ::osl::Mutex m_aMutex
;
201 void implCopySequence(const T
* _pSource
, T
*& _pDest
, sal_Int32 _nSourceLen
)
203 for (sal_Int32 i
=0; i
<_nSourceLen
; ++i
, ++_pSource
, ++_pDest
)
207 //-------------------------------------------------------------------------
208 /// concat two sequences
210 ::com::sun::star::uno::Sequence
<T
> concatSequences(const ::com::sun::star::uno::Sequence
<T
>& _rLeft
, const ::com::sun::star::uno::Sequence
<T
>& _rRight
)
212 sal_Int32
nLeft(_rLeft
.getLength()), nRight(_rRight
.getLength());
213 const T
* pLeft
= _rLeft
.getConstArray();
214 const T
* pRight
= _rRight
.getConstArray();
216 sal_Int32
nReturnLen(nLeft
+ nRight
);
217 ::com::sun::star::uno::Sequence
<T
> aReturn(nReturnLen
);
218 T
* pReturn
= aReturn
.getArray();
220 internal::implCopySequence(pLeft
, pReturn
, nLeft
);
221 internal::implCopySequence(pRight
, pReturn
, nRight
);
227 #define DECLARE_SERVICE_INFO() \
228 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
229 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
230 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
232 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
233 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
235 return ::rtl::OUString::createFromAscii(implasciiname); \
237 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
239 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
240 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
243 sal_Bool SAL_CALL classname::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
245 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); \
246 const ::rtl::OUString* pSupported = aSupported.getConstArray(); \
247 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); \
248 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) \
251 return pSupported != pEnd; \
257 #endif // _CONNECTIVITY_OSUBCOMPONENT_HXX_