1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "IdentityMapping.hxx" 25 26 #include "uno/mapping.h" 27 #include "uno/environment.hxx" 28 29 #include "osl/interlck.h" 30 31 32 using namespace ::com::sun::star; 33 34 struct IdentityMapping : public uno_Mapping 35 { 36 sal_Int32 m_nRef; 37 uno::Environment m_env; 38 39 IdentityMapping(uno::Environment const & rEnv); 40 }; 41 42 extern "C" 43 { 44 45 static void SAL_CALL s_free(uno_Mapping * pMapping) SAL_THROW(()) 46 { 47 delete static_cast<IdentityMapping *>(pMapping); 48 } 49 50 static void SAL_CALL s_acquire(uno_Mapping * pMapping) SAL_THROW(()) 51 { 52 static rtl::OUString s_purpose; 53 54 if (1 == ::osl_incrementInterlockedCount(&static_cast<IdentityMapping *>(pMapping)->m_nRef)) 55 { 56 uno_registerMapping( 57 &pMapping, 58 s_free, 59 static_cast<IdentityMapping *>(pMapping)->m_env.get(), 60 static_cast<IdentityMapping *>(pMapping)->m_env.get(), 61 s_purpose.pData); 62 } 63 } 64 65 static void SAL_CALL s_release(uno_Mapping * pMapping) SAL_THROW(()) 66 { 67 if (!::osl_decrementInterlockedCount(&static_cast<IdentityMapping *>(pMapping )->m_nRef)) 68 uno_revokeMapping(pMapping); 69 } 70 71 static void SAL_CALL s_mapInterface(uno_Mapping * pMapping, 72 void ** ppOut, 73 void * pInterface, 74 struct _typelib_InterfaceTypeDescription * /*pInterfaceTypeDescr*/) 75 SAL_THROW(()) 76 { 77 *ppOut = pInterface; 78 79 if (pInterface) 80 { 81 IdentityMapping * that = static_cast<IdentityMapping *>(pMapping); 82 83 (that->m_env.get()->pExtEnv->acquireInterface)(that->m_env.get()->pExtEnv, pInterface); 84 } 85 } 86 } 87 88 89 IdentityMapping::IdentityMapping(uno::Environment const & rEnv) 90 : m_nRef(0), 91 m_env(rEnv) 92 { 93 uno_Mapping::acquire = s_acquire; 94 uno_Mapping::release = s_release; 95 uno_Mapping::mapInterface = s_mapInterface; 96 } 97 98 99 uno_Mapping * createIdentityMapping(uno::Environment const & rEnv) SAL_THROW(()) 100 { 101 return new IdentityMapping(rEnv); 102 } 103