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