LibreOffice Module dbaccess (master) 1
apitools.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <apitools.hxx>
22#include <sal/log.hxx>
23
24using namespace ::com::sun::star::uno;
25using namespace ::com::sun::star::lang;
26using namespace cppu;
27using namespace osl;
28
29// various helper functions
30// OSubComponent
31OSubComponent::OSubComponent(Mutex& _rMutex, const Reference< XInterface > & xParent)
32 :WeakComponentImplHelper(_rMutex)
33 ,m_xParent(xParent)
34{
35
36}
37
39{
40 m_xParent = nullptr;
41
42}
43
44// XInterface
45
47{
48 if (osl_atomic_decrement( &m_refCount ) == 0 )
49 {
50 if (! rBHelper.bDisposed)
51 {
52 // *before* again incrementing our ref count, ensure that our weak connection point
53 // will not create references to us anymore (via XAdapter::queryAdapted)
54 disposeWeakConnectionPoint();
55
56 Reference< XInterface > xHoldAlive( *this );
57 // remember the parent
58 Reference< XInterface > xParent;
59 {
60 MutexGuard aGuard( rBHelper.rMutex );
61 xParent = m_xParent;
62 m_xParent = nullptr;
63 }
64
65 SAL_WARN_IF( m_refCount != 1, "dbaccess.core", "OSubComponent::release: invalid ref count (before dispose)!" );
66
67 // First dispose
68 dispose();
69
70 // only the alive ref holds the object
71 SAL_WARN_IF( m_refCount != 1, "dbaccess.core", "OSubComponent::release: invalid ref count (after dispose)!" );
72
73 // release the parent in the ~
74 if (xParent.is())
75 {
76 MutexGuard aGuard( rBHelper.rMutex );
77 m_xParent = xParent;
78 }
79
80 // destroy the object if xHoldAlive decrement the refcount to 0
81 return;
82 }
83 }
84 // restore the reference count
85 osl_atomic_increment( &m_refCount );
86
87 // as we cover the job of the WeakComponentImplHelper we use the ...
88 OWeakObject::release();
89}
90
91/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XInterface > m_xParent
Definition: apitools.hxx:33
virtual void SAL_CALL release() noexcept override
Definition: apitools.cxx:46
virtual ~OSubComponent() override
Definition: apitools.cxx:38
OSubComponent(::osl::Mutex &_rMutex, const css::uno::Reference< css::uno::XInterface > &_xParent)
Definition: apitools.cxx:31
ULONG m_refCount
#define SAL_WARN_IF(condition, area, stream)
void dispose()