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 .
21 #include "apitools.hxx"
22 #include "dbastrings.hrc"
23 #include <cppuhelper/typeprovider.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <osl/diagnose.h>
26 #include <tools/debug.hxx>
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::lang
;
33 //==================================================================================
34 //= various helper functions
35 //==================================================================================
36 //============================================================
38 //============================================================
39 DBG_NAME(OSubComponent
)
40 //--------------------------------------------------------------------------
41 OSubComponent::OSubComponent(Mutex
& _rMutex
, const Reference
< XInterface
> & xParent
)
42 :OComponentHelper(_rMutex
)
45 DBG_CTOR(OSubComponent
,NULL
);
48 // -----------------------------------------------------------------------------
49 OSubComponent::~OSubComponent()
53 DBG_DTOR(OSubComponent
,NULL
);
56 // com::sun::star::lang::XTypeProvider
57 //--------------------------------------------------------------------------
58 Sequence
< Type
> OSubComponent::getTypes() throw (RuntimeException
)
60 OTypeCollection
aTypes(::getCppuType( (const Reference
< XComponent
> *)0 ),
61 ::getCppuType( (const Reference
< XTypeProvider
> *)0 ),
62 ::getCppuType( (const Reference
< XWeak
> *)0 ));
64 return aTypes
.getTypes();
68 //--------------------------------------------------------------------------
69 void OSubComponent::acquire() throw ( )
71 OComponentHelper::acquire();
74 //--------------------------------------------------------------------------
75 void OSubComponent::release() throw ( )
77 Reference
< XInterface
> x( xDelegator
);
80 if (osl_atomic_decrement( &m_refCount
) == 0 )
82 if (! rBHelper
.bDisposed
)
84 // *before* again incrementing our ref count, ensure that our weak connection point
85 // will not create references to us anymore (via XAdapter::queryAdapted)
86 disposeWeakConnectionPoint();
88 Reference
< XInterface
> xHoldAlive( *this );
89 // remember the parent
90 Reference
< XInterface
> xParent
;
92 MutexGuard
aGuard( rBHelper
.rMutex
);
97 OSL_ENSURE( m_refCount
== 1, "OSubComponent::release: invalid ref count (before dispose)!" );
102 // only the alive ref holds the object
103 OSL_ENSURE( m_refCount
== 1, "OSubComponent::release: invalid ref count (after dispose)!" );
105 // release the parent in the ~
108 MutexGuard
aGuard( rBHelper
.rMutex
);
112 // destroy the object if xHoldAlive decrement the refcount to 0
116 // restore the reference count
117 osl_atomic_increment( &m_refCount
);
120 // as we cover the job of the componenthelper we use the ...
121 OWeakAggObject::release();
124 //--------------------------------------------------------------------------
125 Any
OSubComponent::queryInterface( const Type
& rType
) throw(RuntimeException
)
128 if (!rType
.equals(::getCppuType(static_cast< Reference
< XAggregation
>* >(NULL
))))
129 aReturn
= OComponentHelper::queryInterface(rType
);
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */