update dev300-m58
[ooovba.git] / cppu / source / uno / IdentityMapping.cxx
blob81b583c03f2e1314009ff1a751dd385c047ea558
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: IdentityMapping.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "IdentityMapping.hxx"
33 #include "uno/mapping.h"
34 #include "uno/environment.hxx"
36 #include "osl/interlck.h"
39 using namespace ::com::sun::star;
41 struct IdentityMapping : public uno_Mapping
43 sal_Int32 m_nRef;
44 uno::Environment m_env;
46 IdentityMapping(uno::Environment const & rEnv);
49 extern "C"
52 static void SAL_CALL s_free(uno_Mapping * pMapping) SAL_THROW(())
54 delete static_cast<IdentityMapping *>(pMapping);
57 static void SAL_CALL s_acquire(uno_Mapping * pMapping) SAL_THROW(())
59 static rtl::OUString s_purpose;
61 if (1 == ::osl_incrementInterlockedCount(&static_cast<IdentityMapping *>(pMapping)->m_nRef))
63 uno_registerMapping(
64 &pMapping,
65 s_free,
66 static_cast<IdentityMapping *>(pMapping)->m_env.get(),
67 static_cast<IdentityMapping *>(pMapping)->m_env.get(),
68 s_purpose.pData);
72 static void SAL_CALL s_release(uno_Mapping * pMapping) SAL_THROW(())
74 if (!::osl_decrementInterlockedCount(&static_cast<IdentityMapping *>(pMapping )->m_nRef))
75 uno_revokeMapping(pMapping);
78 static void SAL_CALL s_mapInterface(uno_Mapping * pMapping,
79 void ** ppOut,
80 void * pInterface,
81 struct _typelib_InterfaceTypeDescription * /*pInterfaceTypeDescr*/)
82 SAL_THROW(())
84 *ppOut = pInterface;
86 if (pInterface)
88 IdentityMapping * that = static_cast<IdentityMapping *>(pMapping);
90 (that->m_env.get()->pExtEnv->acquireInterface)(that->m_env.get()->pExtEnv, pInterface);
96 IdentityMapping::IdentityMapping(uno::Environment const & rEnv)
97 : m_nRef(0),
98 m_env(rEnv)
100 uno_Mapping::acquire = s_acquire;
101 uno_Mapping::release = s_release;
102 uno_Mapping::mapInterface = s_mapInterface;
106 uno_Mapping * createIdentityMapping(uno::Environment const & rEnv) SAL_THROW(())
108 return new IdentityMapping(rEnv);