xref: /trunk/main/connectivity/source/inc/OSubComponent.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CONNECTIVITY_OSUBCOMPONENT_HXX_
28 #define _CONNECTIVITY_OSUBCOMPONENT_HXX_
29 
30 #include <cppuhelper/weak.hxx>
31 #include <cppuhelper/interfacecontainer.h>
32 #include "connectivity/dbtoolsdllapi.hxx"
33 
34 namespace com
35 {
36     namespace sun
37     {
38         namespace star
39         {
40             namespace lang
41             {
42                 class XComponent;
43             }
44         }
45     }
46 }
47 namespace connectivity
48 {
49     OOO_DLLPUBLIC_DBTOOLS
50     void release(oslInterlockedCount& _refCount,
51                  ::cppu::OBroadcastHelper& rBHelper,
52                  ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
53                  ::com::sun::star::lang::XComponent* _pObject);
54     //************************************************************
55     // OSubComponent
56     //************************************************************
57     template <class SELF, class WEAK> class OSubComponent
58     {
59     protected:
60         // the parent must support the tunnel implementation
61         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xParent;
62         SELF*   m_pDerivedImplementation;
63 
64     public:
65         OSubComponent(
66                 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xParent,
67                 SELF* _pDerivedImplementation)
68             :m_xParent(_xParent)
69             ,m_pDerivedImplementation(_pDerivedImplementation)
70         {
71         }
72 
73     protected:
74         void dispose_ChildImpl()
75         {
76             // avoid ambiguity
77             ::osl::MutexGuard aGuard( m_pDerivedImplementation->WEAK::rBHelper.rMutex );
78         m_xParent.clear();
79         }
80         void relase_ChildImpl()
81         {
82             ::connectivity::release(m_pDerivedImplementation->m_refCount,
83                                     m_pDerivedImplementation->WEAK::rBHelper,
84                                     m_xParent,
85                                     m_pDerivedImplementation);
86 
87             m_pDerivedImplementation->WEAK::release();
88         }
89     };
90 }
91 #endif // _CONNECTIVITY_OSUBCOMPONENT_HXX_
92 
93