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 _CONNECTIVITY_OSUBCOMPONENT_HXX_
21 #define _CONNECTIVITY_OSUBCOMPONENT_HXX_
23 #include <cppuhelper/weak.hxx>
24 #include <cppuhelper/interfacecontainer.h>
25 #include <com/sun/star/lang/DisposedException.hpp>
26 #include <cppuhelper/propshlp.hxx>
27 #include <osl/mutex.hxx>
28 #include <osl/diagnose.h>
31 class IPropertyArrayHelper
;
47 namespace connectivity
52 void release(oslInterlockedCount
& _refCount
,
53 ::cppu::OBroadcastHelper
& rBHelper
,
54 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
55 ::com::sun::star::lang::XComponent
* _pObject
);
57 void checkDisposed(sal_Bool _bThrow
) throw (::com::sun::star::lang::DisposedException
);
58 //************************************************************
60 //************************************************************
61 template <class SELF
, class WEAK
> class OSubComponent
64 // the parent must support the tunnel implementation
65 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xParent
;
66 SELF
* m_pDerivedImplementation
;
70 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xParent
,
71 SELF
* _pDerivedImplementation
)
73 ,m_pDerivedImplementation(_pDerivedImplementation
)
78 void dispose_ChildImpl()
80 ::osl::MutexGuard
aGuard(m_pDerivedImplementation
->rBHelper
.rMutex
);
83 void relase_ChildImpl()
85 release(m_pDerivedImplementation
->m_refCount
,
86 m_pDerivedImplementation
->rBHelper
,
88 m_pDerivedImplementation
);
90 m_pDerivedImplementation
->WEAK::release();
96 class OPropertyArrayUsageHelper
99 static sal_Int32 s_nRefCount
;
100 static ::cppu::IPropertyArrayHelper
* s_pProps
;
101 static ::osl::Mutex s_aMutex
;
104 OPropertyArrayUsageHelper();
105 virtual ~OPropertyArrayUsageHelper()
106 { // ARGHHHHHHH ..... would like to implement this in proparrhlp_impl.hxx (as we do with all other methods)
107 // but SUNPRO 5 compiler (linker) doesn't like this
108 ::osl::MutexGuard
aGuard(s_aMutex
);
109 OSL_ENSURE(s_nRefCount
> 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
117 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
118 class, which is created if neccessary.
120 ::cppu::IPropertyArrayHelper
* getArrayHelper();
123 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
124 This method needs to be implemented in derived classes.
126 The method gets called with s_aMutex acquired.
128 as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper
129 assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps.
130 @return an pointer to the newly created array helper. Must not be NULL.
132 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper() const = 0;
136 sal_Int32 OPropertyArrayUsageHelper
< TYPE
>::s_nRefCount
= 0;
139 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
< TYPE
>::s_pProps
= NULL
;
142 ::osl::Mutex OPropertyArrayUsageHelper
< TYPE
>::s_aMutex
;
144 //------------------------------------------------------------------
145 template <class TYPE
>
146 OPropertyArrayUsageHelper
<TYPE
>::OPropertyArrayUsageHelper()
148 ::osl::MutexGuard
aGuard(s_aMutex
);
152 //------------------------------------------------------------------
153 template <class TYPE
>
154 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::getArrayHelper()
156 OSL_ENSURE(s_nRefCount
, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
158 ::osl::MutexGuard
aGuard(s_aMutex
);
160 s_pProps
= createArrayHelper();
161 OSL_ENSURE(s_pProps
, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
171 ::osl::Mutex m_aMutex
;
177 void implCopySequence(const T
* _pSource
, T
*& _pDest
, sal_Int32 _nSourceLen
)
179 for (sal_Int32 i
=0; i
<_nSourceLen
; ++i
, ++_pSource
, ++_pDest
)
183 //-------------------------------------------------------------------------
184 /// concat two sequences
186 ::com::sun::star::uno::Sequence
<T
> concatSequences(const ::com::sun::star::uno::Sequence
<T
>& _rLeft
, const ::com::sun::star::uno::Sequence
<T
>& _rRight
)
188 sal_Int32
nLeft(_rLeft
.getLength()), nRight(_rRight
.getLength());
189 const T
* pLeft
= _rLeft
.getConstArray();
190 const T
* pRight
= _rRight
.getConstArray();
192 sal_Int32
nReturnLen(nLeft
+ nRight
);
193 ::com::sun::star::uno::Sequence
<T
> aReturn(nReturnLen
);
194 T
* pReturn
= aReturn
.getArray();
196 internal::implCopySequence(pLeft
, pReturn
, nLeft
);
197 internal::implCopySequence(pRight
, pReturn
, nRight
);
203 #define DECLARE_SERVICE_INFO() \
204 virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException); \
205 virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw(::com::sun::star::uno::RuntimeException); \
206 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) \
208 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
209 ::rtl::OUString SAL_CALL classname::getImplementationName() throw (::com::sun::star::uno::RuntimeException) \
211 return ::rtl::OUString::createFromAscii(implasciiname); \
213 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) \
215 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
216 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
219 sal_Bool SAL_CALL classname::supportsService(const ::rtl::OUString& _rServiceName) throw(::com::sun::star::uno::RuntimeException) \
221 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); \
222 const ::rtl::OUString* pSupported = aSupported.getConstArray(); \
223 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); \
224 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) \
226 return pSupported != pEnd; \
232 #endif // _CONNECTIVITY_OSUBCOMPONENT_HXX_
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */