diff options
Diffstat (limited to 'include/uno')
-rw-r--r-- | include/uno/Enterable.h | 110 | ||||
-rw-r--r-- | include/uno/EnvDcp.h | 62 | ||||
-rw-r--r-- | include/uno/any2.h | 174 | ||||
-rw-r--r-- | include/uno/current_context.h | 67 | ||||
-rw-r--r-- | include/uno/current_context.hxx | 122 | ||||
-rw-r--r-- | include/uno/data.h | 255 | ||||
-rw-r--r-- | include/uno/dispatcher.h | 92 | ||||
-rw-r--r-- | include/uno/dispatcher.hxx | 190 | ||||
-rw-r--r-- | include/uno/environment.h | 389 | ||||
-rw-r--r-- | include/uno/environment.hxx | 290 | ||||
-rw-r--r-- | include/uno/lbnames.h | 57 | ||||
-rw-r--r-- | include/uno/mapping.h | 216 | ||||
-rw-r--r-- | include/uno/mapping.hxx | 360 | ||||
-rw-r--r-- | include/uno/sequence2.h | 199 | ||||
-rw-r--r-- | include/uno/threadpool.h | 194 |
15 files changed, 2777 insertions, 0 deletions
diff --git a/include/uno/Enterable.h b/include/uno/Enterable.h new file mode 100644 index 000000000..f0323e681 --- /dev/null +++ b/include/uno/Enterable.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_UNO_ENTERABLE_H +#define INCLUDED_UNO_ENTERABLE_H + +#include "uno/environment.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/** Generic function type declaration for entering an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_enter (void * context); + + +/** Generic function type declaration for leaving an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_leave (void * context); + + +/** Generic function type declaration for calling into an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param pCallee the function to be called + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_callInto_v(void * context, uno_EnvCallee * pCallee, va_list * pParam); + + +/** Generic function type declaration for calling out of an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param pCallee the function to be called + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_callOut_v (void * context, uno_EnvCallee * pCallee, va_list * pParam); + + +/** Generic function type declaration for checking if calling on managed object is + valid. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param ppReason the reason, in case calling is not valid + @return 0 == calling is not valid, 1 == calling is valid + @since UDK 3.2.7 +*/ +typedef int uno_Enterable_isValid_v (void * context, rtl_uString ** ppReason); + + +/** A struct pReserved needs to point to, if implementing a purpose environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @since UDK 3.2.7 +*/ +typedef struct +{ + uno_Enterable_enter * m_enter; + uno_Enterable_leave * m_leave; + uno_Enterable_callInto_v * m_callInto_v; + uno_Enterable_callOut_v * m_callOut_v; + uno_Enterable_isValid_v * m_isValid; +} +uno_Enterable; + + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/EnvDcp.h b/include/uno/EnvDcp.h new file mode 100644 index 000000000..e181b61c1 --- /dev/null +++ b/include/uno/EnvDcp.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_UNO_ENVDCP_H +#define INCLUDED_UNO_ENVDCP_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Get the OBI type part of an environment descriptor. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Descriptor) + + @param pEnvDcp the Environment Descriptor + @param ppEnvTypeName the OBI type + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void uno_EnvDcp_getTypeName(rtl_uString const * pEnvDcp, rtl_uString ** ppEnvTypeName); + + +/** Get the purpose part of an environment descriptor. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Descriptor) + + @param pEnvDcp the Environment Descriptor + @param ppEnvPurpose the purpose + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void uno_EnvDcp_getPurpose (rtl_uString const * pEnvDcp, rtl_uString ** ppEnvPurpose); + + +#ifdef __cplusplus +} +#endif + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/any2.h b/include/uno/any2.h new file mode 100644 index 000000000..e5dbfea2b --- /dev/null +++ b/include/uno/any2.h @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_ANY2_H +#define INCLUDED_UNO_ANY2_H + +#include "cppu/cppudllapi.h" +#include "uno/data.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +struct _uno_Mapping; + +/** This is the binary specification of a UNO any. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Any +{ + /** type of value + */ + struct _typelib_TypeDescriptionReference * pType; + /** pointer to value; this may point to pReserved and thus the uno_Any is not anytime + mem-copyable! You may have to correct the pData pointer to pReserved. Otherwise you need + not, because the data is stored in heap space. + */ + void * pData; + /** reserved space for storing value + */ + void * pReserved; +} uno_Any; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +/** Assign an any with a given value. Interfaces are acquired or released by the given callback + functions. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_assign( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assign an any with a given value. Interfaces are acquired or released by the given callback + functions. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_any_assign( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Constructs an any with a given value. Interfaces are acquired by the given callback function. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_construct( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Constructs an any with a given value. Interfaces are acquired by the given callback function. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_any_construct( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Constructs an any with a given value and converts/ maps interfaces. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_constructAndConvert( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); +/** Constructs an any with a given value and converts/ maps interfaces. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_any_constructAndConvert( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); + +/** Destructs an any. + + @param pValue pointer to any + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_destruct( + uno_Any * pValue, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Sets value to void. + + @param pValue pointer to any + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_clear( + uno_Any * pValue, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/current_context.h b/include/uno/current_context.h new file mode 100644 index 000000000..8e8095168 --- /dev/null +++ b/include/uno/current_context.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_CURRENT_CONTEXT_H +#define INCLUDED_UNO_CURRENT_CONTEXT_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Gets the current task's context. + @attention + Don't spread the returned interface around to other threads. Every thread has its own + current context. + + @param ppCurrentContext inout param current context of type com.sun.star.uno.XCurrentContext + @param pEnvDcp descriptor of returned interface's environment + @param pEnvContext context of returned interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_getCurrentContext( + void ** ppCurrentContext, + rtl_uString * pEnvDcp, void * pEnvContext ) + SAL_THROW_EXTERN_C(); + +/** Sets the current task's context. + + @param pCurrentContext in param current context of type com.sun.star.uno.XCurrentContext + @param pEnvDcp descriptor of interface's environment + @param pEnvContext context of interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_setCurrentContext( + void * pCurrentContext, + rtl_uString * pEnvDcp, void * pEnvContext ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/current_context.hxx b/include/uno/current_context.hxx new file mode 100644 index 000000000..dce03d9ee --- /dev/null +++ b/include/uno/current_context.hxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_CURRENT_CONTEXT_HXX +#define INCLUDED_UNO_CURRENT_CONTEXT_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "uno/current_context.h" +#include "uno/lbnames.h" + +#include "com/sun/star/uno/XCurrentContext.hpp" + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** Getting the current context. + @attention + Don't spread the returned interface around to other threads. Every thread has its own + current context. + + @return current context or null ref, if none is set +*/ +inline Reference< XCurrentContext > SAL_CALL getCurrentContext() +{ + Reference< XCurrentContext > xRet; + ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + ::uno_getCurrentContext( reinterpret_cast<void **>(&xRet), aEnvTypeName.pData, NULL ); + return xRet; +} +/** Setting the current context. + + @param xContext current context to be set + @return true, if context has been successfully set +*/ +inline bool SAL_CALL setCurrentContext( + Reference< XCurrentContext > const & xContext ) +{ + ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + return ::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, NULL ); +} + +/** Objects of this class are used for applying a current context until they are destructed, i.e. + the ctor of this class saves the previous and sets the given context while the dtor restores + the previous one upon destruction. +*/ +class ContextLayer +{ + /** this C++ environment type name. + */ + ::rtl::OUString m_aEnvTypeName; + /** previous context + */ + Reference< XCurrentContext > m_xPreviousContext; + +public: + /** Constructor: Saves the previous context and sets the new (given) one. + + @param xNewContext new context to be set + */ + inline ContextLayer( + Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() ); + /** Destructor: restores the previous context. + */ + inline ~ContextLayer(); + + /** Gets the previously set context. + + @return the previously set context + */ + Reference< XCurrentContext > SAL_CALL getPreviousContext() const + { return m_xPreviousContext; } +}; + +inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext ) + : m_aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) +{ + ::uno_getCurrentContext( reinterpret_cast<void **>(&m_xPreviousContext), m_aEnvTypeName.pData, NULL ); + ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, NULL ); +} + +inline ContextLayer::~ContextLayer() +{ + ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, NULL ); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/data.h b/include/uno/data.h new file mode 100644 index 000000000..748b30d0a --- /dev/null +++ b/include/uno/data.h @@ -0,0 +1,255 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_DATA_H +#define INCLUDED_UNO_DATA_H + +#include "cppu/cppudllapi.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +struct _typelib_InterfaceTypeDescription; +struct _uno_Mapping; + +/** Generic function pointer declaration to query for an interface. + + @param pInterface interface + @param pType demanded interface type + @return interface pointer +*/ +typedef void * (SAL_CALL * uno_QueryInterfaceFunc)( + void * pInterface, struct _typelib_TypeDescriptionReference * pType ); +/** Generic function pointer declaration to acquire an interface. + + @param pInterface interface to be acquired +*/ +typedef void (SAL_CALL * uno_AcquireFunc)( + void * pInterface ); +/** Generic function pointer declaration to release an interface. + + @param pInterface interface to be release +*/ +typedef void (SAL_CALL * uno_ReleaseFunc)( + void * pInterface ); + +/** Tests if two values are equal. May compare different types (e.g., short to long). + + @param pVal1 pointer to a value + @param pVal1TypeDescr type description of pVal1 + @param pVal2 pointer to another value + @param pVal2TypeDescr type description of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_equalData( + void * pVal1, struct _typelib_TypeDescription * pVal1TypeDescr, + void * pVal2, struct _typelib_TypeDescription * pVal2TypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Tests if two values are equal. May compare different types (e.g., short to long). + + @param pVal1 pointer to a value + @param pVal1Type type of pVal1 + @param pVal2 pointer to another value + @param pVal2Type type of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_equalData( + void * pVal1, struct _typelib_TypeDescriptionReference * pVal1Type, + void * pVal2, struct _typelib_TypeDescriptionReference * pVal2Type, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_copyData( + void * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_copyData( + void * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. Interfaces are converted/ mapped by mapping parameter. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_copyAndConvertData( + void * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. Interfaces are converted/ mapped by mapping parameter. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_copyAndConvertData( + void * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); + +/** Destructs a given value; does NOT free its memory! + + @param pValue value to be destructed + @param pTypeDescr type description of value + @param release function called each time an interface pointer needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_destructData( + void * pValue, struct _typelib_TypeDescription * pTypeDescr, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Destructs a given value; does NOT free its memory! + + @param pValue value to be destructed + @param pType type of value + @param release function called each time an interface pointer needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_destructData( + void * pValue, struct _typelib_TypeDescriptionReference * pType, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Default constructs a value. All simple types are set to 0, enums are set to their default value. + + @param pMem pointer to memory of value to be constructed + @param pTypeDescr type description of value to be constructed +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_constructData( + void * pMem, struct _typelib_TypeDescription * pTypeDescr ) + SAL_THROW_EXTERN_C(); +/** Default constructs a value. All simple types are set to 0, enums are set to their default value. + + @param pMem pointer to memory of value to be constructed + @param pType type of value to be constructed +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_constructData( + void * pMem, struct _typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C(); + +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pDest pointer to destination value + @param pDestTypeDescr type description of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned + to default value + @param pSourceTypeDescr type destination of source value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if destination has been successfully assigned +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_assignData( + void * pDest, struct _typelib_TypeDescription * pDestTypeDescr, + void * pSource, struct _typelib_TypeDescription * pSourceTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pDest pointer to destination value + @param pDestType type of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned + to default value + @param pSourceType type of source value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if destination has been successfully assigned +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_assignData( + void * pDest, struct _typelib_TypeDescriptionReference * pDestType, + void * pSource, struct _typelib_TypeDescriptionReference * pSourceType, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Tests whether a value of given type is assignable from given value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pAssignable type + @param pFrom pointer to value + @param pFromType type of value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if value is destination has been successfully assigned +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_isAssignableFromData( + struct _typelib_TypeDescriptionReference * pAssignable, + void * pFrom, struct _typelib_TypeDescriptionReference * pFromType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/dispatcher.h b/include/uno/dispatcher.h new file mode 100644 index 000000000..7de20d96f --- /dev/null +++ b/include/uno/dispatcher.h @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_DISPATCHER_H +#define INCLUDED_UNO_DISPATCHER_H + +#include "sal/types.h" +#include "uno/any2.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescription; +struct _uno_Interface; + +/** Function pointer declaration for the binary C uno dispatch function. Any pure out or return + value will be constructed by the callee, iff no exception is signalled. + If an exception is signalled, the any *ppException is properly constructed by the callee, + otherwise the pointer *ppException is set to 0. + An attribute get call is indicated by a non-null return pointer. + + @param pUnoI uno interface the call is performed on + @param pMemberType member type description of a method or attribute + @param pReturn pointer to return value memory; + pointer may be undefined if void method, null if attribute set call. + @param pArgs an array of pointers to arguments values. + (remark: the value of an interface reference stores a + uno_interface *, so you get it by *(uno_Interface **)pArgs[n]) + @param ppException pointer to pointer to unconstructed any to signal an exception. +*/ +typedef void (SAL_CALL * uno_DispatchMethod)( + struct _uno_Interface * pUnoI, + const struct _typelib_TypeDescription * pMemberType, + void * pReturn, + void * pArgs[], + uno_Any ** ppException ); + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +/** The binary C uno interface description. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Interface +{ + /** Acquires uno interface. + + @param pInterface uno interface + */ + void (SAL_CALL * acquire)( struct _uno_Interface * pInterface ); + /** Releases uno interface. + + @param pInterface uno interface + */ + void (SAL_CALL * release)( struct _uno_Interface * pInterface ); + /** dispatch function + */ + uno_DispatchMethod pDispatcher; +} uno_Interface; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/dispatcher.hxx b/include/uno/dispatcher.hxx new file mode 100644 index 000000000..1732be049 --- /dev/null +++ b/include/uno/dispatcher.hxx @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_UNO_DISPATCHER_HXX +#define INCLUDED_UNO_DISPATCHER_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "uno/dispatcher.h" + +/// @cond INTERNAL + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ holder reference for binary C uno_Interface. Not for public use, may be + subject to changes. + + @see uno_Interface + @attention + not for public use! +*/ +class UnoInterfaceReference +{ +public: + uno_Interface * m_pUnoI; + + bool is() const + { return m_pUnoI != NULL; } + + inline ~UnoInterfaceReference(); + inline UnoInterfaceReference(); + inline UnoInterfaceReference( uno_Interface * pUnoI, __sal_NoAcquire ); + inline UnoInterfaceReference( uno_Interface * pUnoI ); + inline UnoInterfaceReference( UnoInterfaceReference const & ref ); + +#if defined LIBO_INTERNAL_ONLY + UnoInterfaceReference(UnoInterfaceReference && other) noexcept : + m_pUnoI(other.m_pUnoI) + { other.m_pUnoI = nullptr; } +#endif + + uno_Interface * get() const + { return m_pUnoI; } + + inline UnoInterfaceReference & set( + uno_Interface * pUnoI ); + inline UnoInterfaceReference & set( + uno_Interface * pUnoI, __sal_NoAcquire ); + inline void clear(); + + UnoInterfaceReference & operator = ( + UnoInterfaceReference const & ref ) + { return set( ref.m_pUnoI ); } + UnoInterfaceReference & operator = ( + uno_Interface * pUnoI ) + { return set( pUnoI ); } + +#if defined LIBO_INTERNAL_ONLY + UnoInterfaceReference & operator =(UnoInterfaceReference && other) { + if (m_pUnoI != nullptr) { + (*m_pUnoI->release)(m_pUnoI); + } + m_pUnoI = other.m_pUnoI; + other.m_pUnoI = nullptr; + return *this; + } +#endif + + inline void dispatch( + struct _typelib_TypeDescription const * pMemberType, + void * pReturn, void * pArgs [], uno_Any ** ppException ) const; +}; + + +inline UnoInterfaceReference::~UnoInterfaceReference() +{ + if (m_pUnoI != NULL) + (*m_pUnoI->release)( m_pUnoI ); +} + + +inline UnoInterfaceReference::UnoInterfaceReference() + : m_pUnoI( NULL ) +{ +} + + +inline UnoInterfaceReference::UnoInterfaceReference( + uno_Interface * pUnoI, __sal_NoAcquire ) + : m_pUnoI( pUnoI ) +{ +} + + +inline UnoInterfaceReference::UnoInterfaceReference( uno_Interface * pUnoI ) + : m_pUnoI( pUnoI ) +{ + if (m_pUnoI != NULL) + (*m_pUnoI->acquire)( m_pUnoI ); +} + + +inline UnoInterfaceReference::UnoInterfaceReference( + UnoInterfaceReference const & ref ) + : m_pUnoI( ref.m_pUnoI ) +{ + if (m_pUnoI != NULL) + (*m_pUnoI->acquire)( m_pUnoI ); +} + + +inline UnoInterfaceReference & UnoInterfaceReference::set( + uno_Interface * pUnoI ) +{ + if (pUnoI != NULL) + (*pUnoI->acquire)( pUnoI ); + if (m_pUnoI != NULL) + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = pUnoI; + return *this; +} + + +inline UnoInterfaceReference & UnoInterfaceReference::set( + uno_Interface * pUnoI, __sal_NoAcquire ) +{ + if (m_pUnoI != NULL) + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = pUnoI; + return *this; +} + + +inline void UnoInterfaceReference::clear() +{ + if (m_pUnoI != NULL) + { + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = NULL; + } +} + + +inline void UnoInterfaceReference::dispatch( + struct _typelib_TypeDescription const * pMemberType, + void * pReturn, void * pArgs [], uno_Any ** ppException ) const +{ + (*m_pUnoI->pDispatcher)( + m_pUnoI, pMemberType, pReturn, pArgs, ppException ); +} + +} +} +} +} + +/// @endcond + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/environment.h b/include/uno/environment.h new file mode 100644 index 000000000..700d9c18e --- /dev/null +++ b/include/uno/environment.h @@ -0,0 +1,389 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_ENVIRONMENT_H +#define INCLUDED_UNO_ENVIRONMENT_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + +#include <stdarg.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _uno_ExtEnvironment; +struct _typelib_InterfaceTypeDescription; + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +/** The binary specification of a UNO environment. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Environment +{ + /** reserved for future use (0 if not used) + */ + void * pReserved; + + /** type name of environment + */ + rtl_uString * pTypeName; + + /** free context pointer to be used for specific classes of environments (e.g., a jvm pointer) + */ + void * pContext; + + /** pointer to extended environment (interface registration functionality), if supported + */ + struct _uno_ExtEnvironment * pExtEnv; + + /** Acquires this environment. + + @param pEnv this environment + */ + void (SAL_CALL * acquire)( struct _uno_Environment * pEnv ); + + /** Releases this environment; last release of environment will revoke the environment from + runtime. + + @param pEnv this environment + */ + void (SAL_CALL * release)( struct _uno_Environment * pEnv ); + + /** Acquires this environment weakly. You can only harden a weakly held environment if it + is still acquired hard (acquire()). + + @param pEnv this environment + */ + void (SAL_CALL * acquireWeak)( struct _uno_Environment * pEnv ); + + /** Releases this environment weakly in correspondence to acquireWeak(). + + @param pEnv this environment + */ + void (SAL_CALL * releaseWeak)( struct _uno_Environment * pEnv ); + + /** Makes hard reference out of weak referenced environment. You can only harden a weakly + held environment if it is still acquired hard (acquire()). + + @param ppHardEnv inout hard referenced environment (has to be released via release()) + @param pEnv environment (may be weak referenced) + */ + void (SAL_CALL * harden)( + struct _uno_Environment ** ppHardEnv, + struct _uno_Environment * pEnv ); + + /** Call this function to EXPLICITLY dispose this environment (e.g., release all + interfaces). You may want to call this function before shutting down due to a runtime error. + + @param pEnv this environment + */ + void (SAL_CALL * dispose)( struct _uno_Environment * pEnv ); + + /* ===== the following part will be late initialized by a matching bridge ===== * + * ===== and is NOT for public use. ===== */ + + /** CALLBACK function pointer: Disposing callback function pointer that can be set to get + signalled before the environment is destroyed. + + @param pEnv environment that is being disposed + */ + void (SAL_CALL * environmentDisposing)( struct _uno_Environment * pEnv ); +} uno_Environment; + +/** Generic function pointer declaration to free a proxy object if it is not needed by the + environment anymore. + Any proxy object must register itself on first acquire() call and revoke itself on last + release() call. This can happen several times because the environment caches proxy objects + until the environment explicitly frees the proxy object calling this function. + + @param pEnv environment + @param pProxy proxy pointer +*/ +typedef void (SAL_CALL * uno_freeProxyFunc)( struct _uno_ExtEnvironment * pEnv, void * pProxy ); + +/** Generic function pointer declaration to allocate memory. Used with getRegisteredInterfaces(). + + @param nBytes amount of memory in bytes + @return pointer to allocated memory +*/ +typedef void * (SAL_CALL * uno_memAlloc)( sal_Size nBytes ); + +/** The binary specification of a UNO environment supporting interface registration. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_ExtEnvironment +{ + /** inherits all members of a uno_Environment + */ + uno_Environment aBase; + + /** Registers an interface of this environment. + + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Registers a proxy interface of this environment that can be reanimated and is freed + explicitly by this environment. + + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param freeProxy function to free proxy object + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerProxyInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppProxy, + uno_freeProxyFunc freeProxy, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Revokes an interface from this environment. You have to revoke any interface that has + been registered via this method. + + @param pEnv this environment + @param pInterface interface to be revoked + */ + void (SAL_CALL * revokeInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + + /** Provides the object id of a given interface. + + @param ppOut inout oid + @param pInterface interface of object + */ + void (SAL_CALL * getObjectIdentifier)( + struct _uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, + void * pInterface ); + + /** Retrieves an interface identified by its object id and type from this environment. + Interfaces are retrieved in the same order as they are registered. + + @param pEnv this environment + @param ppInterface inout parameter for the registered interface; (0) if none was found + @param pOId object id of interface to be retrieved + @param pTypeDescr type description of interface to be retrieved + */ + void (SAL_CALL * getRegisteredInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Returns all currently registered interfaces of this environment. The memory block + allocated might be slightly larger than (*pnLen * sizeof(void *)). + + @param pEnv this environment + @param pppInterfaces out param; pointer to array of interface pointers + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + */ + void (SAL_CALL * getRegisteredInterfaces)( + struct _uno_ExtEnvironment * pEnv, + void *** pppInterfaces, + sal_Int32 * pnLen, + uno_memAlloc memAlloc ); + + /* ===== the following part will be late initialized by a matching bridge ===== */ + + /** Computes an object id of the given interface; is called by the environment implementation. + + @param pEnv corresponding environment + @param ppOId out param: computed id + @param pInterface an interface + */ + void (SAL_CALL * computeObjectIdentifier)( + struct _uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, void * pInterface ); + + /** Function to acquire an interface. + + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * acquireInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + + /** Function to release an interface. + + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * releaseInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + +} uno_ExtEnvironment; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +/** Function exported by some bridge library providing acquireInterface(), releaseInterface(); + may set a disposing callback. + + @param pEnv environment to be initialized +*/ +typedef void (SAL_CALL * uno_initEnvironmentFunc)( uno_Environment * pEnv ); +#define UNO_INIT_ENVIRONMENT "uno_initEnvironment" + +#ifdef DISABLE_DYNLOADING +/* We link statically and have just the C++ environment */ +void SAL_CALL CPPU_ENV_uno_initEnvironment( uno_Environment * Env ) + SAL_THROW_EXTERN_C(); + +/* We might also have the Java environment */ +void SAL_CALL java_uno_initEnvironment( uno_Environment * Env ) + SAL_THROW_EXTERN_C(); +#endif + +/** Gets a specific environment. If the specified environment does not exist, then a default one + is created and registered. The environment revokes itself on last release() call. + + @param ppEnv inout parameter of environment; given environment will be released + @param pEnvDcp descriptor of environment + @param pContext some context pointer (e.g., to distinguish java vm; set 0 if not needed) +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext ) + SAL_THROW_EXTERN_C(); + +/** Gets all specified environments. Caller has to release returned environments and free allocated + memory. + + @param pppEnvs out param; pointer to array of environments + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + @param pEnvDcp descriptor of environments; 0 defaults to all +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getRegisteredEnvironments( + uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc, + rtl_uString * pEnvDcp ) + SAL_THROW_EXTERN_C(); + +/** Creates an environment. The new environment is anonymous (NOT publicly registered/ accessible). + + @param ppEnv out parameter of environment; given environment will be released + @param pEnvDcp descriptor of environment + @param pContext context pointer (e.g., to distinguish java vm); set 0 if not needed +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_createEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext ) + SAL_THROW_EXTERN_C(); + +/** Dumps out environment information, i.e. registered interfaces. + + @param stream output stream (FILE *) + @param pEnv environment to be dumped + @param pFilter if not null, filters output +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironment( + void * stream, uno_Environment * pEnv, const char * pFilter ) + SAL_THROW_EXTERN_C(); +/** Dumps out environment information, i.e. registered interfaces. + + @param stream output stream (FILE *) + @param pEnvDcp descriptor of environment to be dumped + @param pFilter if not null, filters output +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironmentByName( + void * stream, rtl_uString * pEnvDcp, const char * pFilter ) + SAL_THROW_EXTERN_C(); + + + +/** Returns the current Environment. + In case no Environment has explicitly been entered, a purpose free + default environment gets returned (e.g. the "uno" or "gcc3" Environment). + + @param ppEnv inout parameter; a given environment will be released + @param pTypeName the optional type of the environment, falls back to "uno" + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getCurrentEnvironment(uno_Environment ** ppEnv, rtl_uString * pTypeName) + SAL_THROW_EXTERN_C(); + +/** Typedef for variable argument function. + */ +typedef void SAL_CALL uno_EnvCallee(va_list * pParam); + +/** Invoke the passed function in the given environment. + + @param pEnv the target environment + @param pCallee the function to call + @param pParam the parameter pointer passed to the function + @since UDK 3.2.7 + */ +CPPU_DLLPUBLIC void SAL_CALL uno_Environment_invoke_v(uno_Environment * pEnv, uno_EnvCallee * pCallee, va_list * pParam) + SAL_THROW_EXTERN_C(); + +/** Invoke the passed function in the given environment. + + @param pEnv the target environment + @param pCallee the function to call + @param ... the parameters passed to the function + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_Environment_invoke (uno_Environment * pEnv, uno_EnvCallee * pCallee, ...) + SAL_THROW_EXTERN_C(); + +/** Enter an environment explicitly. + + @param pEnv the environment to enter; NULL leaves all environments + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_Environment_enter(uno_Environment * pEnv) + SAL_THROW_EXTERN_C(); + +/** Check if a particular environment is currently valid, so + that objects of that environment might be called. + + @param pEnv the environment + @param pReason the reason, if it is not valid + @return 1 == valid, 0 == invalid + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC int SAL_CALL uno_Environment_isValid(uno_Environment * pEnv, rtl_uString ** pReason) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/environment.hxx b/include/uno/environment.hxx new file mode 100644 index 000000000..8a26e268d --- /dev/null +++ b/include/uno/environment.hxx @@ -0,0 +1,290 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_ENVIRONMENT_HXX +#define INCLUDED_UNO_ENVIRONMENT_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "rtl/alloc.h" +#include "rtl/ustring.hxx" +#include "uno/environment.h" + +#include "uno/lbnames.h" + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ wrapper for binary C uno_Environment. + + @see uno_Environment +*/ +class Environment +{ + /** binary C uno_Environment + */ + uno_Environment * _pEnv; + +public: + /** Returns the current Environment. + + @param typeName the optional type of the Environment, falls back to "uno" in case being empty, + respectively to current C++ Environment. + @since UDK 3.2.7 + */ + inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME)); + + /// @cond INTERNAL + // these are here to force memory de/allocation to sal lib. + static void * SAL_CALL operator new ( size_t nSize ) + { return ::rtl_allocateMemory( nSize ); } + static void SAL_CALL operator delete ( void * pMem ) + { ::rtl_freeMemory( pMem ); } + static void * SAL_CALL operator new ( size_t, void * pMem ) + { return pMem; } + static void SAL_CALL operator delete ( void *, void * ) + {} + /// @endcond + + /** Constructor: acquires given environment + + @param pEnv environment + */ + inline Environment( uno_Environment * pEnv = NULL ); + + /** Gets a specific environment. If the specified environment does not exist, then a default one + is created and registered. + + @param envDcp descriptor of the environment + @param pContext context pointer + */ + inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ); + + + /** Copy constructor: acquires given environment + + @param rEnv another environment + */ + inline Environment( const Environment & rEnv ); + +#if defined LIBO_INTERNAL_ONLY + Environment(Environment && other) noexcept : _pEnv(other._pEnv) + { other._pEnv = nullptr; } +#endif + + /** Destructor: releases a set environment. + */ + inline ~Environment(); + + /** Sets a given environment, i.e. acquires given one and releases a set one. + + @param pEnv another environment + @return this environment + */ + inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ); + /** Sets a given environment, i.e. acquires given one and releases a set one. + + @param rEnv another environment + @return this environment + */ + Environment & SAL_CALL operator = ( const Environment & rEnv ) + { return operator = ( rEnv._pEnv ); } + +#if defined LIBO_INTERNAL_ONLY + Environment & operator =(Environment && other) { + if (_pEnv != nullptr) { + (*_pEnv->release)(_pEnv); + } + _pEnv = other._pEnv; + other._pEnv = nullptr; + return *this; + } +#endif + + /** Provides UNacquired pointer to the set C environment. + + @return UNacquired pointer to the C environment struct + */ + uno_Environment * SAL_CALL get() const + { return _pEnv; } + + /** Gets type name of set environment. + + @return type name of set environment + */ + ::rtl::OUString SAL_CALL getTypeName() const + { return _pEnv->pTypeName; } + + /** Gets free context pointer of set environment. + + @return free context pointer of set environment + */ + void * SAL_CALL getContext() const + { return _pEnv->pContext; } + + /** Tests if an environment is set. + + @return true, if an environment is set, false otherwise + */ + bool SAL_CALL is() const + { return (_pEnv != NULL); } + + /** Releases a set environment. + */ + inline void SAL_CALL clear(); + + /** Invoke the passed function in this environment. + + @param pCallee the function to call + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 + */ + inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const; + + /** Invoke the passed function in this environment. + + @param pCallee the function to call + @param ... the parameters to be passed to the function + @since UDK 3.2.7 + */ + inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const; + + /** Enter this environment explicitly. + + @since UDK 3.2.7 + */ + inline void SAL_CALL enter() const; + + /** Checks, if it is valid to currently call objects + belonging to this environment. + + @since UDK 3.2.7 + */ + inline int SAL_CALL isValid(rtl::OUString * pReason) const; +}; + +inline Environment::Environment( uno_Environment * pEnv ) + : _pEnv( pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} + +inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) + : _pEnv(NULL) +{ + uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext); +} + +inline Environment::Environment( const Environment & rEnv ) + : _pEnv( rEnv._pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} + +inline Environment::~Environment() +{ + if (_pEnv) + (*_pEnv->release)( _pEnv ); +} + +inline void Environment::clear() +{ + if (_pEnv) + { + (*_pEnv->release)( _pEnv ); + _pEnv = NULL; + } +} + +inline Environment & Environment::operator = ( uno_Environment * pEnv ) +{ + if (pEnv != _pEnv) + { + if (pEnv) + (*pEnv->acquire)( pEnv ); + if (_pEnv) + (*_pEnv->release)( _pEnv ); + _pEnv = pEnv; + } + return *this; +} + +inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const +{ + if (_pEnv) + uno_Environment_invoke_v(_pEnv, pCallee, pParam); +} + +inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const +{ + if (_pEnv) + { + va_list param; + + va_start(param, pCallee); + uno_Environment_invoke_v(_pEnv, pCallee, ¶m); + va_end(param); + } + +} + +inline void SAL_CALL Environment::enter() const +{ + uno_Environment_enter(_pEnv); +} + +inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const +{ + return uno_Environment_isValid(_pEnv, &pReason->pData); +} + +inline Environment Environment::getCurrent(rtl::OUString const & typeName) +{ + Environment environment; + + uno_Environment * pEnv = NULL; + uno_getCurrentEnvironment(&pEnv, typeName.pData); + environment = pEnv; + if (pEnv) + pEnv->release(pEnv); + + return environment; +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/lbnames.h b/include/uno/lbnames.h new file mode 100644 index 000000000..56f9d9942 --- /dev/null +++ b/include/uno/lbnames.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_LBNAMES_H +#define INCLUDED_UNO_LBNAMES_H + +/* I assume "LB" means "Language Binding" */ + +#include "sal/config.h" + +#include "sal/macros.h" + +#ifdef __cplusplus + +#ifdef CPPU_ENV + +/** Name for C++ compiler/ platform, e.g. "gcc3", "msci" */ +#define CPPU_CURRENT_LANGUAGE_BINDING_NAME SAL_STRINGIFY(CPPU_ENV) + +#else + +#error "No supported C++ compiler environment." +provoking error here, because PP ignores #error + +#endif /* CPPU_ENV */ + +#endif /* __cplusplus */ + +/** Environment type name for binary C UNO. */ +#define UNO_LB_UNO "uno" +/** Environment type name for Java 1.3.1 compatible virtual machine. */ +#define UNO_LB_JAVA "java" +/** Environment type name for CLI (Common Language Infrastructure). */ +#define UNO_LB_CLI "cli" + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/mapping.h b/include/uno/mapping.h new file mode 100644 index 000000000..44ea09596 --- /dev/null +++ b/include/uno/mapping.h @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_MAPPING_H +#define INCLUDED_UNO_MAPPING_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_InterfaceTypeDescription; +struct _uno_Mapping; +struct _uno_Environment; + +/** + Function pointer declaration to acquire a UNO mapping. +*/ +typedef void (SAL_CALL * uno_AcquireMappingFunc)(struct _uno_Mapping *); + +/** + Function pointer declaration to release a UNO mapping. +*/ +typedef void (SAL_CALL * uno_ReleaseMappingFunc)(struct _uno_Mapping *); + +/** Function pointer declaration to map an interface from one environment to another. + + @param pMapping mapping + @param ppOut [inout] destination interface; existing interfaces are released + @param pInterface source interface + @param pInterfaceTypeDescr type description of the interface +*/ +typedef void (SAL_CALL * uno_MapInterfaceFunc)( + struct _uno_Mapping * pMapping, + void ** ppOut, void * pInterface, + struct _typelib_InterfaceTypeDescription * pInterfaceTypeDescr ); + + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +/** This is the binary specification of a mapping. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Mapping +{ + /** Acquires mapping + */ + uno_AcquireMappingFunc acquire; + + /** Releases mapping. The last release may unload bridges. + */ + uno_ReleaseMappingFunc release; + + /** mapping function + */ + uno_MapInterfaceFunc mapInterface; +} uno_Mapping; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +/** Gets an interface mapping from one environment to another. + + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment + @param pTo destination environment + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getMapping( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo, + rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/** Callback function pointer declaration to get a mapping. + + @param ppMapping inout mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose +*/ +typedef void (SAL_CALL * uno_getMappingFunc)( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo, + rtl_uString * pAddPurpose ); + +/** Registers a callback being called each time a mapping is demanded. + + @param pCallback callback function +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_registerMappingCallback( + uno_getMappingFunc pCallback ) + SAL_THROW_EXTERN_C(); + +/** Revokes a mapping callback registration. + + @param pCallback callback function +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_revokeMappingCallback( + uno_getMappingFunc pCallback ) + SAL_THROW_EXTERN_C(); + +/** Function pointer declaration to free a mapping. + + @param pMapping mapping to be freed +*/ +typedef void (SAL_CALL * uno_freeMappingFunc)( struct _uno_Mapping * pMapping ); + +/** Registers a mapping. A mapping registers itself on first acquire and revokes itself on last + release. The given freeMapping function is called by the runtime to cleanup any resources. + + @param ppMapping inout mapping to be registered + @param freeMapping called by runtime to delete mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose string; defaults to 0 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_registerMapping( + struct _uno_Mapping ** ppMapping, uno_freeMappingFunc freeMapping, + struct _uno_Environment * pFrom, struct _uno_Environment * pTo, rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/** Revokes a mapping. A mapping registers itself on first acquire and revokes itself on last + release. + + @param pMapping mapping to be revoked +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_revokeMapping( + struct _uno_Mapping * pMapping ) + SAL_THROW_EXTERN_C(); + +/** Gets an interface mapping from one language environment to another by corresponding environment + type names. + + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment type name + @param pTo destination environment type name + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getMappingByName( + struct _uno_Mapping ** ppMapping, + rtl_uString * pFrom, + rtl_uString * pTo, + rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/* symbol exported by each language binding library */ +#define UNO_EXT_GETMAPPING "uno_ext_getMapping" + +/** Function pointer declaration to get a mapping from a loaded bridge. Bridges export a function + called uno_ext_getMapping() of this signature. + + @param[in,out] ppMapping mapping; existing mapping will be released + @param[in] pFrom source environment + @param[in] pTo destination environment +*/ +typedef void (SAL_CALL * uno_ext_getMappingFunc)( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo ); + +#ifdef DISABLE_DYNLOADING +/* Static linking, this is the uno_ext_getMapping function in the C++/UNO bridge */ +void SAL_CALL CPPU_ENV_uno_ext_getMapping( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo ) + SAL_THROW_EXTERN_C(); + +/* This is the uno_ext_getMapping function in the Java/UNO bridge */ +void SAL_CALL java_uno_ext_getMapping( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo ) + SAL_THROW_EXTERN_C(); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/mapping.hxx b/include/uno/mapping.hxx new file mode 100644 index 000000000..5b8cf41be --- /dev/null +++ b/include/uno/mapping.hxx @@ -0,0 +1,360 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_MAPPING_HXX +#define INCLUDED_UNO_MAPPING_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "uno/lbnames.h" +#include "rtl/alloc.h" +#include "rtl/ustring.hxx" +#include "osl/diagnose.h" +#include "uno/mapping.h" +#include "com/sun/star/uno/Type.hxx" +#include "com/sun/star/uno/Reference.hxx" +#include "cppu/unotype.hxx" +#include "uno/environment.hxx" + +typedef struct _typelib_TypeDescription typelib_TypeDescription; +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; +typedef struct _uno_Interface uno_Interface; + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ wrapper for C uno_Mapping. + + @see uno_Mapping +*/ +class Mapping +{ + uno_Mapping * _pMapping; + +public: + // these are here to force memory de/allocation to sal lib. + /// @cond INTERNAL + static void * SAL_CALL operator new ( size_t nSize ) + { return ::rtl_allocateMemory( nSize ); } + static void SAL_CALL operator delete ( void * pMem ) + { ::rtl_freeMemory( pMem ); } + static void * SAL_CALL operator new ( size_t, void * pMem ) + { return pMem; } + static void SAL_CALL operator delete ( void *, void * ) + {} + /// @endcond + + /** Holds a mapping from the specified source to the specified destination by environment + type names. + + @param rFrom type name of source environment + @param rTo type name of destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( + const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Holds a mapping from the specified source to the specified destination. + + @param pFrom source environment + @param pTo destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( + uno_Environment * pFrom, uno_Environment * pTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Holds a mapping from the specified source to the specified destination + environment. + + @param rFrom source environment + @param rTo destination environment + @param rAddPurpose additional purpose + */ + inline Mapping(const Environment & rFrom, const Environment & rTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Constructor. + + @param pMapping another mapping + */ + inline Mapping( uno_Mapping * pMapping = NULL ); + + /** Copy constructor. + + @param rMapping another mapping + */ + inline Mapping( const Mapping & rMapping ); + +#if defined LIBO_INTERNAL_ONLY + Mapping(Mapping && other) noexcept : _pMapping(other._pMapping) + { other._pMapping = nullptr; } +#endif + + /** Destructor. + */ + inline ~Mapping(); + + /** Sets a given mapping. + + @param pMapping another mapping + @return this mapping + */ + inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ); + /** Sets a given mapping. + + @param rMapping another mapping + @return this mapping + */ + Mapping & SAL_CALL operator = ( const Mapping & rMapping ) + { return operator = ( rMapping._pMapping ); } + +#if defined LIBO_INTERNAL_ONLY + Mapping & operator =(Mapping && other) noexcept { + if (_pMapping != nullptr) { + (*_pMapping->release)(_pMapping); + } + _pMapping = other._pMapping; + other._pMapping = nullptr; + return *this; + } +#endif + + /** Provides a pointer to the C mapping. The returned mapping is NOT acquired! + + @return UNacquired C mapping + */ + uno_Mapping * SAL_CALL get() const + { return _pMapping; } + + /** Tests if a mapping is set. + + @return true if a mapping is set + */ + bool SAL_CALL is() const + { return (_pMapping != NULL); } + + /** Releases a set mapping. + */ + inline void SAL_CALL clear(); + + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const; + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const + { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); } + + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param rType type of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( + void * pInterface, const css::uno::Type & rType ) const; + + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); } + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); } + + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param rType type of interface to be mapped + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const css::uno::Type & rType ) const; +}; + +inline Mapping::Mapping( + const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose ) + : _pMapping( NULL ) +{ + uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData ); +} + +inline Mapping::Mapping( + uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose ) + : _pMapping( NULL ) +{ + uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData ); +} + +inline Mapping::Mapping( + const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose ) + : _pMapping(NULL) +{ + uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData ); +} + +inline Mapping::Mapping( uno_Mapping * pMapping ) + : _pMapping( pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} + +inline Mapping::Mapping( const Mapping & rMapping ) + : _pMapping( rMapping._pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} + +inline Mapping::~Mapping() +{ + if (_pMapping) + (*_pMapping->release)( _pMapping ); +} + +inline void Mapping::clear() +{ + if (_pMapping) + { + (*_pMapping->release)( _pMapping ); + _pMapping = NULL; + } +} + +inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) +{ + if (pMapping) + (*pMapping->acquire)( pMapping ); + if (_pMapping) + (*_pMapping->release)( _pMapping ); + _pMapping = pMapping; + return *this; +} + +inline void Mapping::mapInterface( + void ** ppOut, void * pInterface, const css::uno::Type & rType ) const +{ + typelib_TypeDescription * pTD = NULL; + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + if (pTD) + { + (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) ); + TYPELIB_DANGER_RELEASE( pTD ); + } +} + +inline void * Mapping::mapInterface( + void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const +{ + void * pOut = NULL; + (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr ); + return pOut; +} + +inline void * Mapping::mapInterface( + void * pInterface, const css::uno::Type & rType ) const +{ + void * pOut = NULL; + mapInterface( &pOut, pInterface, rType ); + return pOut; +} + +/** Deprecated. This function DOES NOT WORK with Purpose Environments + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) + + Maps a binary C UNO interface to be used in the currently used compiler environment. + + @tparam C interface type + @param ppRet inout returned interface pointer + @param pUnoI binary C UNO interface + @return true if successful, false otherwise + + @deprecated +*/ +template< class C > +SAL_DEPRECATED("use uno_Mapping") +inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) +{ + Mapping aMapping( UNO_LB_UNO, CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( + reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) ); + return (0 != *ppRet); +} +/** Deprecated. This function DOES NOT WORK with Purpose Environments + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) + + Maps a UNO interface of the currently used compiler environment to binary C UNO. + + @tparam C interface type + @param ppRet inout returned interface pointer + @param x interface reference + @return true if successful, false otherwise + + @deprecated +*/ +template< class C > +SAL_DEPRECATED("use uno_Mapping") +inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) +{ + Mapping aMapping( CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_UNO ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( + reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) ); + return (NULL != *ppRet); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/sequence2.h b/include/uno/sequence2.h new file mode 100644 index 000000000..bf74a6170 --- /dev/null +++ b/include/uno/sequence2.h @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_UNO_SEQUENCE2_H +#define INCLUDED_UNO_SEQUENCE2_H + +#include "cppu/cppudllapi.h" +#include "uno/data.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +typedef sal_Sequence uno_Sequence; + +/** Assigns a sequence. + + @param ppDest destination sequence + @param pSource source sequence + @param pTypeDescr type description of the sequence and NOT of an element + @param release function called each time an interface needs to + be released; defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assigns a sequence. + + @param ppDest destination sequence + @param pSource source sequence + @param pType type of the sequence and NOT of an element + @param release function called each time an interface needs to + be released; defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Constructs a new sequence with given elements. + + @param ppSequence out parameter sequence; + 0 if memory allocation has failed + @param pTypeDescr type description of the sequence and NOT of an + element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_sequence_construct( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Constructs a new sequence with given elements. + + @param ppSequence out parameter sequence; + 0 if memory allocation has failed + @param pType type of the sequence and NOT of an element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_sequence_construct( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count + of one. + + @param ppSequence inout sequence + @param pTypeDescr type description of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_sequence_reference2One( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count + of one. + + @param ppSequence inout sequence + @param pType type of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_sequence_reference2One( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Reallocates length of a sequence. This truncates a sequence or enlarges + it default constructing appended elements. + + @param ppSequence inout sequence + @param pTypeDescr type description of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_sequence_realloc( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Reallocates length of a sequence. This truncates a sequence or enlarges + it default constructing appended elements. + + @param ppSequence inout sequence + @param pType type of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_sequence_realloc( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Destroy a sequence whose reference count has dropped to zero. + + @param sequence must be non-null, sequence->nRefCount must be zero + @param type the type of the sequence, must be non-null + @param release function called each time an interface needs to be release, + must be non-null + + @since LibreOffice 4.4 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_sequence_destroy( + uno_Sequence * sequence, struct _typelib_TypeDescriptionReference * type, + uno_ReleaseFunc release) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/threadpool.h b/include/uno/threadpool.h new file mode 100644 index 000000000..11264bd5a --- /dev/null +++ b/include/uno/threadpool.h @@ -0,0 +1,194 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_UNO_THREADPOOL_H +#define INCLUDED_UNO_THREADPOOL_H + +#include "cppu/cppudllapi.h" +#include "sal/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*** + * Thread identifier administration. + ***/ +/** + Establishes an association between the current thread and the given thread identifier. + There can be only one association at a time. The association must be broken by + uno_releaseIdFromCurrentThread(). + This method is in general called by a bridge, that wants to bind a remote threadId + to a new thread. + + @param pThreadId a byte sequence, that contains the identifier of the current thread. + @return true, when the identifier was registered. + false, when the thread has already an identifier. The identifier was not + altered. ( This is in general a bug ). + + @see uno_releaseIdFromCurrentThread() + */ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ) + SAL_THROW_EXTERN_C(); + + +/** + Get the identifier of the current thread. + If no id has been bound for the thread before, a new one is generated and bound + to the thread. + For each call to uno_getIdOfCurrentThread(), a call to uno_releaseIdFromCurrentThread() + must be done. + + @param ppThreadId [out] Contains the (acquired) ThreadId. + @see uno_releaseIdFromCurrentThread() + */ +CPPU_DLLPUBLIC void SAL_CALL uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ) + SAL_THROW_EXTERN_C(); + + +/** + If the internal refcount drops to zero, the association between threadId and + thread is broken. + */ +CPPU_DLLPUBLIC void SAL_CALL uno_releaseIdFromCurrentThread() + SAL_THROW_EXTERN_C(); + + +struct _uno_ThreadPool; +typedef struct _uno_ThreadPool * uno_ThreadPool; + +/** + Creates a threadpool handle. Typically each remote bridge instances creates one + handle. + */ +CPPU_DLLPUBLIC uno_ThreadPool SAL_CALL +uno_threadpool_create() SAL_THROW_EXTERN_C(); + + +/** + Makes the current thread known to the threadpool. This function must be + called, BEFORE uno_threadpool_enter() is called and BEFORE a job for this + thread is put into the threadpool (avoid a race between this thread and + an incoming request/reply). + For every call to uno_threadpool_attach, a corresponding call to + uno_threadpool_detach must be done. + + @param hPool The bridge threadpool handle previously created by uno_threadpool_create. + +*/ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_attach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +/** + This method is called to wait for a reply of a previously sent request. This is a + blocking method. uno_threadpool_attach() must have been called before. + + @param hPool the handle that was previously created by uno_threadpool_create(). + @param ppJob [out] the pointer, that was given by uno_threadpool_putJob + 0, when uno_threadpool_dispose() was the reason to fall off from threadpool. + @see uno_threadpool_dispose() + **/ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob ) + SAL_THROW_EXTERN_C(); + +/** + Detaches the current thread from the threadpool. Must be called for + every call to uno_threadpool_attach. + @param hPool the handle that was previously created by uno_threadpool_create(). +*/ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_detach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +/** + Puts a job into the pool. A job may either be a request or a reply + (replies have a 0 in the doRequest parameter). This function is non-blocking. + + A request may either be synchronous or asynchronous. + If the request is synchronous, it is first looked up, + if there exists a handle with the given + identifier. If this is the case, the thread is woken up and the doRequest + function is called with the given pJob. If no handle exists, + a new thread is created and the given threadId is bound to the new thread. + + If the request is asynchronous, it is put into the queue of asynchronous + requests for the current threadid. The requests are always executed in a new + thread, even if the thread with the given id is waiting in the pool. No id is bound + to the newly created thread. The responsibility is left to the bridge (if it + wishes to bind a name). + + If pJob is a reply, there MUST be a thread with the given threadId waiting + for this reply. + + @param hPool the handle that was previously created by uno_threadpool_create(). + @param pThreadId The Id of the thread, that initialized this request. (In general a + remote threadid). + @param pJob The argument, that doRequest will get or that will be returned by + uno_threadpool_enter(). + @param doRequest The function, that shall be called to execute the request. + 0 if pJob is a reply. + @param bIsOneway True, if the request is asynchronous. False, if it is synchronous. + Set to sal_False, if pJob is a reply. + */ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_putJob( + uno_ThreadPool hPool, + sal_Sequence *pThreadId, + void *pJob, + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), + sal_Bool bIsOneway ) SAL_THROW_EXTERN_C(); + +/** + All threads, that are waiting on the hPool handle, are forced out of the pool. + The threads waiting with uno_threadpool_enter() will return with *ppJob == 0 + + Later calls to uno_threadpool_enter() using the hPool handle will also + return immediately with *ppJob == 0. + + @param hPool The handle to be disposed. + + This function is called i.e. by a bridge, that is forced to dispose itself. + */ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + + +/** Releases the previously with uno_threadpool_create() created handle. + The handle thus becomes invalid. It is an error to use the handle after + uno_threadpool_destroy(). + + A call to uno_threadpool_destroy can synchronously join on spawned worker + threads, so this function must never be called from such a worker thread. + + @see uno_threadpool_create() + */ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDED_UNO_THREADPOOL_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |