diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2020-07-22 14:16:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-23 09:25:36 +0200 |
commit | c049d5336c110196886480330dba9238faee0e39 (patch) | |
tree | cb4bf90927e4076dbb607d9000b86406381010a2 /scaddins | |
parent | 7f0fb9a5e7bce720c6fd2d7ddc9fa9dbd353d8a1 (diff) |
scaddins: create instances with uno constructors
See tdf#74608 for motivation.
Change-Id: I678bc7fb73b5863b1656dc7f8b12c5b903c33b3e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99225
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'scaddins')
-rw-r--r-- | scaddins/source/analysis/analysis.component | 3 | ||||
-rw-r--r-- | scaddins/source/analysis/analysis.cxx | 53 | ||||
-rw-r--r-- | scaddins/source/analysis/analysis.hxx | 6 | ||||
-rw-r--r-- | scaddins/source/datefunc/date.component | 5 | ||||
-rw-r--r-- | scaddins/source/datefunc/datefunc.cxx | 50 | ||||
-rw-r--r-- | scaddins/source/datefunc/datefunc.hxx | 7 | ||||
-rw-r--r-- | scaddins/source/pricing/pricing.component | 5 | ||||
-rw-r--r-- | scaddins/source/pricing/pricing.cxx | 51 | ||||
-rw-r--r-- | scaddins/source/pricing/pricing.hxx | 7 |
9 files changed, 38 insertions, 149 deletions
diff --git a/scaddins/source/analysis/analysis.component b/scaddins/source/analysis/analysis.component index d20aae77d3e9..0eff15b7e9f0 100644 --- a/scaddins/source/analysis/analysis.component +++ b/scaddins/source/analysis/analysis.component @@ -19,7 +19,8 @@ <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" prefix="analysis" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.sheet.addin.AnalysisImpl"> + <implementation name="com.sun.star.sheet.addin.AnalysisImpl" + constructor="scaddins_AnalysisAddIn_get_implementation"> <service name="com.sun.star.sheet.AddIn"/> <service name="com.sun.star.sheet.addin.Analysis"/> </implementation> diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx index 36a3012c046a..b951eca29fc6 100644 --- a/scaddins/source/analysis/analysis.cxx +++ b/scaddins/source/analysis/analysis.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <o3tl/any.hxx> #include <rtl/math.hxx> +#include <rtl/ref.hxx> #include <sal/macros.h> #include <unotools/resmgr.hxx> #include <i18nlangtag/languagetag.hxx> @@ -42,29 +43,6 @@ using namespace ::com::sun::star; using namespace sca::analysis; using namespace std; -extern "C" SAL_DLLPUBLIC_EXPORT void* analysis_component_getFactory( - const char* pImplName, void* pServiceManager, void* /*pRegistryKey*/ ) -{ - void* pRet = nullptr; - - if( pServiceManager && OUString::createFromAscii( pImplName ) == AnalysisAddIn::getImplementationName_Static() ) - { - uno::Reference< lang::XSingleServiceFactory > xFactory( cppu::createOneInstanceFactory( - static_cast< lang::XMultiServiceFactory* >( pServiceManager ), - AnalysisAddIn::getImplementationName_Static(), - AnalysisAddIn_CreateInstance, - AnalysisAddIn::getSupportedServiceNames_Static() ) ); - - if( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - } - - return pRet; -} - OUString AnalysisAddIn::GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex) { return AnalysisResId(pResId[nStrIndex - 1]); @@ -141,22 +119,6 @@ double AnalysisAddIn::FactDouble( sal_Int32 nNum ) return pFactDoubles[ nNum ]; } -OUString AnalysisAddIn::getImplementationName_Static() -{ - return MY_IMPLNAME; -} - -uno::Sequence< OUString > AnalysisAddIn::getSupportedServiceNames_Static() -{ - return { ADDIN_SERVICE, MY_SERVICE }; -} - -uno::Reference< uno::XInterface > AnalysisAddIn_CreateInstance( - const uno::Reference< lang::XMultiServiceFactory >& xServiceFact ) -{ - return static_cast<cppu::OWeakObject*>(new AnalysisAddIn( comphelper::getComponentContext(xServiceFact) )); -} - // XServiceName OUString SAL_CALL AnalysisAddIn::getServiceName() { @@ -167,7 +129,7 @@ OUString SAL_CALL AnalysisAddIn::getServiceName() // XServiceInfo OUString SAL_CALL AnalysisAddIn::getImplementationName() { - return getImplementationName_Static(); + return MY_IMPLNAME; } sal_Bool SAL_CALL AnalysisAddIn::supportsService( const OUString& aName ) @@ -177,7 +139,7 @@ sal_Bool SAL_CALL AnalysisAddIn::supportsService( const OUString& aName ) uno::Sequence< OUString > SAL_CALL AnalysisAddIn::getSupportedServiceNames() { - return getSupportedServiceNames_Static(); + return { ADDIN_SERVICE, MY_SERVICE }; } // XLocalizable @@ -1090,4 +1052,13 @@ OUString AnalysisAddIn::AnalysisResId(const char* pResId) return Translate::get(pResId, aResLocale); } +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +scaddins_AnalysisAddIn_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + static rtl::Reference<AnalysisAddIn> g_Instance(new AnalysisAddIn(context)); + g_Instance->acquire(); + return static_cast<cppu::OWeakObject*>(g_Instance.get()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scaddins/source/analysis/analysis.hxx b/scaddins/source/analysis/analysis.hxx index ec82f509471c..5b9d90bdf172 100644 --- a/scaddins/source/analysis/analysis.hxx +++ b/scaddins/source/analysis/analysis.hxx @@ -36,9 +36,6 @@ namespace com::sun::star::lang { class XMultiServiceFactory; } namespace com::sun::star::sheet { struct LocalizedName; } -css::uno::Reference< css::uno::XInterface > AnalysisAddIn_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& ); - - class AnalysisAddIn : public cppu::WeakImplHelper< css::sheet::XAddIn, css::sheet::XCompatibilityNames, @@ -82,9 +79,6 @@ public: /// @throws css::lang::IllegalArgumentException double FactDouble( sal_Int32 nNum ); - static OUString getImplementationName_Static(); - static css::uno::Sequence< OUString > getSupportedServiceNames_Static(); - // XAddIn virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override; virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override; diff --git a/scaddins/source/datefunc/date.component b/scaddins/source/datefunc/date.component index 7bbf766a5895..db67781e1476 100644 --- a/scaddins/source/datefunc/date.component +++ b/scaddins/source/datefunc/date.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="date" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.sheet.addin.DateFunctionsImpl"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.sheet.addin.DateFunctionsImpl" + constructor="scaddins_ScaDateAddIn_get_implementation"> <service name="com.sun.star.sheet.AddIn"/> <service name="com.sun.star.sheet.addin.DateFunctions"/> </implementation> diff --git a/scaddins/source/datefunc/datefunc.cxx b/scaddins/source/datefunc/datefunc.cxx index 41e7437b883c..d4c1921d13f0 100644 --- a/scaddins/source/datefunc/datefunc.cxx +++ b/scaddins/source/datefunc/datefunc.cxx @@ -25,6 +25,7 @@ #include <cppuhelper/supportsservice.hxx> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <rtl/ustrbuf.hxx> +#include <rtl/ref.hxx> #include <unotools/resmgr.hxx> #include <i18nlangtag/languagetag.hxx> #include <algorithm> @@ -85,39 +86,16 @@ static void InitScaFuncDataList(ScaFuncDataList& rList) } // entry points for service registration / instantiation -static uno::Reference< uno::XInterface > ScaDateAddIn_CreateInstance( - const uno::Reference< lang::XMultiServiceFactory >& ) -{ - return static_cast<cppu::OWeakObject*>(new ScaDateAddIn()); -} - -extern "C" { -SAL_DLLPUBLIC_EXPORT void * date_component_getFactory( - const char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +scaddins_ScaDateAddIn_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - void* pRet = nullptr; - - if ( pServiceManager && - OUString::createFromAscii( pImplName ) == ScaDateAddIn::getImplementationName_Static() ) - { - uno::Reference< lang::XSingleServiceFactory > xFactory( cppu::createOneInstanceFactory( - static_cast< lang::XMultiServiceFactory* >( pServiceManager ), - ScaDateAddIn::getImplementationName_Static(), - ScaDateAddIn_CreateInstance, - ScaDateAddIn::getSupportedServiceNames_Static() ) ); - - if (xFactory.is()) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - } - - return pRet; + static rtl::Reference<ScaDateAddIn> g_Instance(new ScaDateAddIn()); + g_Instance->acquire(); + return static_cast<cppu::OWeakObject*>(g_Instance.get()); } -} // extern C // "normal" service implementation ScaDateAddIn::ScaDateAddIn() @@ -166,16 +144,6 @@ OUString ScaDateAddIn::GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex return ScaResId(pResId[nStrIndex - 1]); } -OUString ScaDateAddIn::getImplementationName_Static() -{ - return MY_IMPLNAME; -} - -uno::Sequence< OUString > ScaDateAddIn::getSupportedServiceNames_Static() -{ - return { ADDIN_SERVICE, MY_SERVICE }; -} - // XServiceName OUString SAL_CALL ScaDateAddIn::getServiceName() { @@ -186,7 +154,7 @@ OUString SAL_CALL ScaDateAddIn::getServiceName() // XServiceInfo OUString SAL_CALL ScaDateAddIn::getImplementationName() { - return getImplementationName_Static(); + return MY_IMPLNAME; } sal_Bool SAL_CALL ScaDateAddIn::supportsService( const OUString& aServiceName ) @@ -196,7 +164,7 @@ sal_Bool SAL_CALL ScaDateAddIn::supportsService( const OUString& aServiceName ) uno::Sequence< OUString > SAL_CALL ScaDateAddIn::getSupportedServiceNames() { - return getSupportedServiceNames_Static(); + return { ADDIN_SERVICE, MY_SERVICE }; } // XLocalizable diff --git a/scaddins/source/datefunc/datefunc.hxx b/scaddins/source/datefunc/datefunc.hxx index 528a6d2f0b51..590ac64ceec1 100644 --- a/scaddins/source/datefunc/datefunc.hxx +++ b/scaddins/source/datefunc/datefunc.hxx @@ -94,10 +94,6 @@ struct FindScaFuncData }; -css::uno::Reference< css::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance( - const css::uno::Reference< css::lang::XMultiServiceFactory >& ); - - // THE AddIn class for date functions class ScaDateAddIn : public ::cppu::WeakImplHelper< @@ -127,9 +123,6 @@ public: OUString ScaResId(const char* pId); - static OUString getImplementationName_Static(); - static css::uno::Sequence< OUString > getSupportedServiceNames_Static(); - // XAddIn virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override; virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override; diff --git a/scaddins/source/pricing/pricing.component b/scaddins/source/pricing/pricing.component index 6083144a4111..fcee10771c70 100644 --- a/scaddins/source/pricing/pricing.component +++ b/scaddins/source/pricing/pricing.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="pricing" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.sheet.addin.PricingFunctionsImpl"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.sheet.addin.PricingFunctionsImpl" + constructor="scaddins_ScaPricingAddIn_get_implementation"> <service name="com.sun.star.sheet.AddIn"/> <service name="com.sun.star.sheet.addin.PricingFunctions"/> </implementation> diff --git a/scaddins/source/pricing/pricing.cxx b/scaddins/source/pricing/pricing.cxx index 4781baa9babe..6cbb13256464 100644 --- a/scaddins/source/pricing/pricing.cxx +++ b/scaddins/source/pricing/pricing.cxx @@ -33,6 +33,7 @@ #include <iostream> #include <algorithm> #include <rtl/math.hxx> +#include <rtl/ref.hxx> #include <unotools/resmgr.hxx> #include <i18nlangtag/languagetag.hxx> @@ -87,40 +88,16 @@ void sca::pricing::InitScaFuncDataList(ScaFuncDataList& rList) } // entry points for service registration / instantiation -static uno::Reference< uno::XInterface > ScaPricingAddIn_CreateInstance( - const uno::Reference< lang::XMultiServiceFactory >& ) -{ - return static_cast<cppu::OWeakObject*>(new ScaPricingAddIn()); -} - -extern "C" { -SAL_DLLPUBLIC_EXPORT void * pricing_component_getFactory( - const char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +scaddins_ScaPricingAddIn_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - void* pRet = nullptr; - - if ( pServiceManager && - OUString::createFromAscii( pImplName ) == ScaPricingAddIn::getImplementationName_Static() ) - { - uno::Reference< lang::XSingleServiceFactory > xFactory( cppu::createOneInstanceFactory( - static_cast< lang::XMultiServiceFactory* >( pServiceManager ), - ScaPricingAddIn::getImplementationName_Static(), - ScaPricingAddIn_CreateInstance, - ScaPricingAddIn::getSupportedServiceNames_Static() ) ); - - if (xFactory.is()) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - } - - return pRet; + static rtl::Reference<ScaPricingAddIn> g_Instance(new ScaPricingAddIn()); + g_Instance->acquire(); + return static_cast<cppu::OWeakObject*>(g_Instance.get()); } -} // extern C - // "normal" service implementation ScaPricingAddIn::ScaPricingAddIn() { @@ -166,16 +143,6 @@ OUString ScaPricingAddIn::GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIn return ScaResId(pResId[nStrIndex - 1]); } -OUString ScaPricingAddIn::getImplementationName_Static() -{ - return MY_IMPLNAME; -} - -uno::Sequence< OUString > ScaPricingAddIn::getSupportedServiceNames_Static() -{ - return { ADDIN_SERVICE, MY_SERVICE }; -} - // XServiceName OUString SAL_CALL ScaPricingAddIn::getServiceName() { @@ -186,7 +153,7 @@ OUString SAL_CALL ScaPricingAddIn::getServiceName() // XServiceInfo OUString SAL_CALL ScaPricingAddIn::getImplementationName() { - return getImplementationName_Static(); + return MY_IMPLNAME; } sal_Bool SAL_CALL ScaPricingAddIn::supportsService( const OUString& aServiceName ) @@ -196,7 +163,7 @@ sal_Bool SAL_CALL ScaPricingAddIn::supportsService( const OUString& aServiceName uno::Sequence< OUString > SAL_CALL ScaPricingAddIn::getSupportedServiceNames() { - return getSupportedServiceNames_Static(); + return { ADDIN_SERVICE, MY_SERVICE }; } // XLocalizable diff --git a/scaddins/source/pricing/pricing.hxx b/scaddins/source/pricing/pricing.hxx index ead7296762a4..9fe391f349ef 100644 --- a/scaddins/source/pricing/pricing.hxx +++ b/scaddins/source/pricing/pricing.hxx @@ -114,10 +114,6 @@ struct FindScaFuncData } // namespace sca::pricing -css::uno::Reference< css::uno::XInterface > SAL_CALL PricingFunctionAddIn_CreateInstance( - const css::uno::Reference< css::lang::XMultiServiceFactory >& ); - - // AddIn class for pricing functions class ScaPricingAddIn : public ::cppu::WeakImplHelper< @@ -147,9 +143,6 @@ public: OUString ScaResId(const char* pResId); - static OUString getImplementationName_Static(); - static css::uno::Sequence< OUString > getSupportedServiceNames_Static(); - // XAddIn virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override; virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override; |