20#include <osl/interlck.h>
21#include <rtl/ustring.hxx>
22#include <uno/environment.hxx>
23#include <uno/lbnames.h>
24#include <uno/mapping.hxx>
25#include <uno/dispatcher.h>
40 uno::Mapping m_from2uno;
41 uno::Mapping m_uno2to;
43 uno::Environment m_from;
44 uno::Environment m_interm;
45 uno::Environment m_to;
51 void mapInterface(
void ** ppOut,
53 typelib_InterfaceTypeDescription * pInterfaceTypeDescr);
64 MediatorMapping * pMediatorMapping =
static_cast<MediatorMapping *
>(mapping);
65 pMediatorMapping->acquire();
70 MediatorMapping * pMediatorMapping =
static_cast<MediatorMapping *
>(mapping);
71 pMediatorMapping->release();
78 typelib_InterfaceTypeDescription * pInterfaceTypeDescr)
80 MediatorMapping * pMediatorMapping =
static_cast<MediatorMapping *
>(mapping);
81 pMediatorMapping->mapInterface(ppOut, pInterface, pInterfaceTypeDescr);
89 m_from2uno(pFrom, pInterm),
90 m_uno2to (pInterm, pTo),
95 if (!m_from2uno.get() || !m_uno2to.get())
103void MediatorMapping::acquire()
105 osl_atomic_increment(&m_refCount);
108void MediatorMapping::release()
110 if (osl_atomic_decrement(&m_refCount) == 0)
118 void ** ppOut = va_arg(*pParam,
void **);
119 void * pInterface = va_arg(*pParam,
void *);
120 typelib_InterfaceTypeDescription * pInterfaceTypeDescr = va_arg(*pParam, typelib_InterfaceTypeDescription *);
126void MediatorMapping::mapInterface(
129 typelib_InterfaceTypeDescription * pInterfaceTypeDescr)
131 if (*ppOut !=
nullptr)
133 uno_ExtEnvironment *
env = m_to.get()->pExtEnv;
134 OSL_ASSERT( env !=
nullptr );
135 env->releaseInterface( env, *ppOut );
139 void * ret =
nullptr;
140 uno_Interface * pUnoI =
nullptr;
142 m_from.invoke(
s_mapInterface_v, &pUnoI, pInterface, pInterfaceTypeDescr, m_from2uno.get());
144 m_uno2to.mapInterface(&ret, pUnoI, pInterfaceTypeDescr);
147 m_interm.get()->pExtEnv->releaseInterface(m_interm.get()->pExtEnv, pUnoI);
155 delete static_cast<MediatorMapping *
>(
pMapping);
159static OUString
getPrefix(std::u16string_view str1, std::u16string_view str2)
161 sal_Int32 nIndex1 = 0;
162 sal_Int32 nIndex2 = 0;
165 std::u16string_view token1;
166 std::u16string_view token2;
173 if (token1 == token2)
174 sim += token1.size() + 1;
176 while(nIndex1 == nIndex2 && nIndex1 >= 0 && token1 == token2);
181 result = str1.substr(0, sim - 1);
206 rtl_uString * pAddPurpose)
208 if (pAddPurpose && pAddPurpose->length)
211 OUString uno_envType(UNO_LB_UNO);
218#ifdef LOG_CALLING_named_purpose_getMapping
219 OString s_from_name =
OUStringToOString(pFrom->pTypeName, RTL_TEXTENCODING_ASCII_US);
220 OString s_to_name =
OUStringToOString(pTo->pTypeName, RTL_TEXTENCODING_ASCII_US);
222 std::cerr << __FUNCTION__ <<
" - creating mediation ";
223 std::cerr <<
"pFrom: " << s_from_name.getStr();
224 std::cerr <<
" pTo: " << s_to_name.getStr() << std::endl;
227 if (from_envPurpose == to_envPurpose)
235 if (from_envType == uno_envType && to_envType == uno_envType)
237 OUString purpose =
getPrefix(from_envPurpose, to_envPurpose);
239 OUString uno_envDcp = uno_envType + purpose;
243 if (from_envPurpose == purpose)
245 OUString rest = to_envPurpose.copy(purpose.getLength());
247 sal_Int32
index = rest.indexOf(
':', 1);
254 uno_envDcp += rest.subView(0,
index);
256 else if (to_envPurpose == purpose)
258 OUString rest = from_envPurpose.copy(purpose.getLength());
260 sal_Int32
index = rest.indexOf(
':', 1);
267 uno_envDcp += rest.subView(0,
index);
272 else if (from_envType != uno_envType && to_envType == uno_envType)
275 OUString envDcp = uno_envType + from_envPurpose;
278 else if (from_envType == uno_envType && to_envType != uno_envType)
281 OUString envDcp = uno_envType + to_envPurpose;
287 OUString purpose =
getPrefix(from_envPurpose, to_envPurpose);
289 OUString uno_envDcp = uno_envType + purpose;
295 pInterm->release(pInterm);
303 (*ppMapping)->release(*ppMapping);
static void s_mapInterface_v(va_list *pParam)
static void s_MediatorMapping_free(uno_Mapping *pMapping) SAL_THROW_EXTERN_C()
static void s_acquire(uno_Mapping *mapping)
static void s_release(uno_Mapping *mapping)
static void s_mapInterface(uno_Mapping *mapping, void **ppOut, void *pInterface, typelib_InterfaceTypeDescription *pInterfaceTypeDescr)
static OUString getPrefix(std::u16string_view str1, std::u16string_view str2)
void getCascadeMapping(uno_Mapping **ppMapping, uno_Environment *pFrom, uno_Environment *pTo, rtl_uString *pAddPurpose)
struct _uno_Environment uno_Environment
void SAL_CALL uno_getEnvironment(uno_Environment **ppEnv, rtl_uString *pEnvDcp, void *pContext) SAL_THROW_EXTERN_C()
void SAL_CALL uno_getMapping(uno_Mapping **ppMapping, uno_Environment *pFrom, uno_Environment *pTo, rtl_uString *pAddPurpose) SAL_THROW_EXTERN_C()
void SAL_CALL uno_registerMapping(uno_Mapping **ppMapping, uno_freeMappingFunc freeMapping, uno_Environment *pFrom, uno_Environment *pTo, rtl_uString *pAddPurpose) SAL_THROW_EXTERN_C()
void SAL_CALL uno_revokeMapping(uno_Mapping *pMapping) SAL_THROW_EXTERN_C()
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
struct _uno_Mapping uno_Mapping
rtl::OUString getPurpose(rtl::OUString const &rEnvDcp)
Get the purpose part of an environment descriptor.
rtl::OUString getTypeName(rtl::OUString const &rEnvDcp)
Get the OBI type part of an environment descriptor.
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
#define SAL_THROW_EXTERN_C()