Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cppu / source / uno / IdentityMapping.cxx
blob32ec32c073d348b646c795b2bdaf7d161fec8223
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include "IdentityMapping.hxx"
22 #include <typelib/typedescription.h>
23 #include <uno/mapping.h>
24 #include <uno/environment.hxx>
25 #include <utility>
27 #include <osl/interlck.h>
30 using namespace ::com::sun::star;
32 namespace {
34 struct IdentityMapping : public uno_Mapping
36 sal_Int32 m_nRef;
37 uno::Environment m_env;
39 explicit IdentityMapping(uno::Environment aEnv);
44 extern "C"
47 static void s_free(uno_Mapping * pMapping)
49 delete static_cast<IdentityMapping *>(pMapping);
52 static void s_acquire(uno_Mapping * pMapping)
54 static OUString s_purpose;
56 if (1 == osl_atomic_increment(&static_cast<IdentityMapping *>(pMapping)->m_nRef))
58 uno_registerMapping(
59 &pMapping,
60 s_free,
61 static_cast<IdentityMapping *>(pMapping)->m_env.get(),
62 static_cast<IdentityMapping *>(pMapping)->m_env.get(),
63 s_purpose.pData);
67 static void s_release(uno_Mapping * pMapping)
69 if (!osl_atomic_decrement(&static_cast<IdentityMapping *>(pMapping )->m_nRef))
70 uno_revokeMapping(pMapping);
73 static void s_mapInterface(uno_Mapping * pMapping,
74 void ** ppOut,
75 void * pInterface,
76 SAL_UNUSED_PARAMETER typelib_InterfaceTypeDescription * /*pInterfaceTypeDescr*/)
78 *ppOut = pInterface;
80 if (pInterface)
82 IdentityMapping * that = static_cast<IdentityMapping *>(pMapping);
84 (that->m_env.get()->pExtEnv->acquireInterface)(that->m_env.get()->pExtEnv, pInterface);
90 IdentityMapping::IdentityMapping(uno::Environment aEnv)
91 : m_nRef(0),
92 m_env(std::move(aEnv))
94 uno_Mapping::acquire = s_acquire;
95 uno_Mapping::release = s_release;
96 uno_Mapping::mapInterface = s_mapInterface;
100 uno_Mapping * createIdentityMapping(uno::Environment const & rEnv)
102 return new IdentityMapping(rEnv);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */