diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-14 10:16:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-14 12:04:06 +0200 |
commit | 3fbadfa1ad41a3477804c592e06caec708c05218 (patch) | |
tree | e070ddf4fb572c16d07a0afcebffd28b8987c2e6 /lingucomponent | |
parent | c6642e6c2366741eba893f2e91a6bc2761df7c35 (diff) |
lingucomponent: create instances with uno constructors
See tdf#74608 for motivation.
Change-Id: I11770c8873d14cfd0e438fb580d8d0ea9e99f594
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98709
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'lingucomponent')
13 files changed, 53 insertions, 227 deletions
diff --git a/lingucomponent/source/hyphenator/hyphen/hyphen.component b/lingucomponent/source/hyphenator/hyphen/hyphen.component index ea9298e464a0..0d775423dd5c 100644 --- a/lingucomponent/source/hyphenator/hyphen/hyphen.component +++ b/lingucomponent/source/hyphenator/hyphen/hyphen.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="hyphen" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="org.openoffice.lingu.LibHnjHyphenator"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="org.openoffice.lingu.LibHnjHyphenator" + constructor="lingucomponent_Hyphenator_get_implementation"> <service name="com.sun.star.linguistic2.Hyphenator"/> </implementation> </component> diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx index d03aaf1df0ea..b50e0048689e 100644 --- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx +++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx @@ -692,14 +692,6 @@ OUString Hyphenator::makeInitCap(const OUString& aTerm, CharClass const * pCC) return aTerm; } -/// @throws Exception -static Reference< XInterface > Hyphenator_CreateInstance( - const Reference< XMultiServiceFactory > & /*rSMgr*/ ) -{ - Reference< XInterface > xService = static_cast<cppu::OWeakObject*>(new Hyphenator); - return xService; -} - sal_Bool SAL_CALL Hyphenator::addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) { @@ -794,7 +786,7 @@ void SAL_CALL Hyphenator::removeEventListener( const Reference< XEventListener > // Service specific part OUString SAL_CALL Hyphenator::getImplementationName() { - return getImplementationName_Static(); + return "org.openoffice.lingu.LibHnjHyphenator"; } sal_Bool SAL_CALL Hyphenator::supportsService( const OUString& ServiceName ) @@ -804,37 +796,15 @@ sal_Bool SAL_CALL Hyphenator::supportsService( const OUString& ServiceName ) Sequence< OUString > SAL_CALL Hyphenator::getSupportedServiceNames() { - return getSupportedServiceNames_Static(); + return { SN_HYPHENATOR }; } -Sequence< OUString > Hyphenator::getSupportedServiceNames_Static() - throw() +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +lingucomponent_Hyphenator_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - Sequence< OUString > aSNS { SN_HYPHENATOR }; - return aSNS; + return cppu::acquire(new Hyphenator()); } -extern "C" -{ - -SAL_DLLPUBLIC_EXPORT void * hyphen_component_getFactory( - const char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) -{ - void * pRet = nullptr; - if ( Hyphenator::getImplementationName_Static().equalsAscii( pImplName ) ) - { - Reference< XSingleServiceFactory > xFactory = - cppu::createOneInstanceFactory( - static_cast< XMultiServiceFactory * >( pServiceManager ), - Hyphenator::getImplementationName_Static(), - Hyphenator_CreateInstance, - Hyphenator::getSupportedServiceNames_Static()); - // acquire, because we return an interface pointer instead of a reference - xFactory->acquire(); - pRet = xFactory.get(); - } - return pRet; -} -} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx index d5103b8e7aa5..9ab7df50879b 100644 --- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx +++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx @@ -114,20 +114,12 @@ public: virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; - static inline OUString getImplementationName_Static() throw(); - static Sequence< OUString > getSupportedServiceNames_Static() throw(); - private: static OUString makeLowerCase(const OUString&, CharClass const *); static OUString makeUpperCase(const OUString&, CharClass const *); static OUString makeInitCap(const OUString&, CharClass const *); }; -inline OUString Hyphenator::getImplementationName_Static() throw() -{ - return "org.openoffice.lingu.LibHnjHyphenator"; -} - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lingucomponent/source/languageguessing/guesslang.component b/lingucomponent/source/languageguessing/guesslang.component index 8e2f2c001dca..75f6e7ce2daa 100644 --- a/lingucomponent/source/languageguessing/guesslang.component +++ b/lingucomponent/source/languageguessing/guesslang.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="guesslang" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.lingu2.LanguageGuessing"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.lingu2.LanguageGuessing" + constructor="lingucomponent_LangGuess_get_implementation"> <service name="com.sun.star.linguistic2.LanguageGuessing"/> </implementation> </component> diff --git a/lingucomponent/source/languageguessing/guesslang.cxx b/lingucomponent/source/languageguessing/guesslang.cxx index 4f73e5e008a2..560f883e1c55 100644 --- a/lingucomponent/source/languageguessing/guesslang.cxx +++ b/lingucomponent/source/languageguessing/guesslang.cxx @@ -52,20 +52,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::linguistic2; -#define SERVICENAME "com.sun.star.linguistic2.LanguageGuessing" -#define IMPLNAME "com.sun.star.lingu2.LanguageGuessing" - -static Sequence< OUString > getSupportedServiceNames_LangGuess_Impl() -{ - Sequence<OUString> names { SERVICENAME }; - return names; -} - -static OUString getImplementationName_LangGuess_Impl() -{ - return IMPLNAME; -} - static osl::Mutex & GetLangGuessMutex() { static osl::Mutex aMutex; @@ -309,7 +295,7 @@ void SAL_CALL LangGuess_Impl::enableLanguages( OUString SAL_CALL LangGuess_Impl::getImplementationName( ) { - return IMPLNAME; + return "com.sun.star.lingu2.LanguageGuessing"; } sal_Bool SAL_CALL LangGuess_Impl::supportsService( const OUString& ServiceName ) @@ -319,42 +305,15 @@ sal_Bool SAL_CALL LangGuess_Impl::supportsService( const OUString& ServiceName ) Sequence<OUString> SAL_CALL LangGuess_Impl::getSupportedServiceNames( ) { - return { SERVICENAME }; -} - -/** - * Function to create a new component instance; is needed by factory helper implementation. - * @param xMgr service manager to if the components needs other component instances - */ -static Reference< XInterface > LangGuess_Impl_create( - Reference< XComponentContext > const & ) -{ - return static_cast< ::cppu::OWeakObject * >( new LangGuess_Impl ); + return { "com.sun.star.linguistic2.LanguageGuessing" }; } -//#### EXPORTED ### functions to allow for registration and creation of the UNO component -const struct ::cppu::ImplementationEntry s_component_entries [] = +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +lingucomponent_LangGuess_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - { - LangGuess_Impl_create, getImplementationName_LangGuess_Impl, - getSupportedServiceNames_LangGuess_Impl, - ::cppu::createSingleComponentFactory, - nullptr, 0 - }, - { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } -}; - -extern "C" -{ - -SAL_DLLPUBLIC_EXPORT void * guesslang_component_getFactory( - char const * implName, void * xMgr, - void * xRegistry ) -{ - return ::cppu::component_getFactoryHelper( - implName, xMgr, xRegistry, s_component_entries ); + return cppu::acquire(new LangGuess_Impl()); } -} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lingucomponent/source/numbertext/numbertext.component b/lingucomponent/source/numbertext/numbertext.component index b17cc31e0840..c3277533b55c 100644 --- a/lingucomponent/source/numbertext/numbertext.component +++ b/lingucomponent/source/numbertext/numbertext.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="numbertext" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.lingu2.NumberText"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.lingu2.NumberText" + constructor="lingucomponent_NumberText_get_implementation"> <service name="com.sun.star.linguistic2.NumberText"/> </implementation> </component> diff --git a/lingucomponent/source/numbertext/numbertext.cxx b/lingucomponent/source/numbertext/numbertext.cxx index 71927a7ac9c7..dfc11a1fbb85 100644 --- a/lingucomponent/source/numbertext/numbertext.cxx +++ b/lingucomponent/source/numbertext/numbertext.cxx @@ -47,17 +47,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::linguistic2; -#define SERVICENAME "com.sun.star.linguistic2.NumberText" -#define IMPLNAME "com.sun.star.lingu2.NumberText" - -static Sequence<OUString> getSupportedServiceNames_NumberText_Impl() -{ - Sequence<OUString> names{ SERVICENAME }; - return names; -} - -static OUString getImplementationName_NumberText_Impl() { return IMPLNAME; } - static osl::Mutex& GetNumberTextMutex() { static osl::Mutex aMutex; @@ -156,38 +145,26 @@ uno::Sequence<Locale> SAL_CALL NumberText_Impl::getAvailableLanguages() return aRes; } -OUString SAL_CALL NumberText_Impl::getImplementationName() { return IMPLNAME; } +OUString SAL_CALL NumberText_Impl::getImplementationName() +{ + return "com.sun.star.lingu2.NumberText"; +} sal_Bool SAL_CALL NumberText_Impl::supportsService(const OUString& ServiceName) { return cppu::supportsService(this, ServiceName); } -Sequence<OUString> SAL_CALL NumberText_Impl::getSupportedServiceNames() { return { SERVICENAME }; } - -/** - * Function to create a new component instance; is needed by factory helper implementation. - * @param xMgr service manager to if the components needs other component instances - */ -static Reference<XInterface> NumberText_Impl_create(Reference<XComponentContext> const&) +Sequence<OUString> SAL_CALL NumberText_Impl::getSupportedServiceNames() { - return static_cast<::cppu::OWeakObject*>(new NumberText_Impl); + return { "com.sun.star.linguistic2.NumberText" }; } -//#### EXPORTED ### functions to allow for registration and creation of the UNO component -const struct ::cppu::ImplementationEntry s_component_entries[] - = { { NumberText_Impl_create, getImplementationName_NumberText_Impl, - getSupportedServiceNames_NumberText_Impl, ::cppu::createSingleComponentFactory, nullptr, - 0 }, - { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } }; - -extern "C" { - -SAL_DLLPUBLIC_EXPORT void* numbertext_component_getFactory(char const* implName, void* xMgr, - void* xRegistry) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +lingucomponent_NumberText_get_implementation(css::uno::XComponentContext*, + css::uno::Sequence<css::uno::Any> const&) { - return ::cppu::component_getFactoryHelper(implName, xMgr, xRegistry, s_component_entries); -} + return cppu::acquire(new NumberText_Impl()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lingucomponent/source/spellcheck/spell/spell.component b/lingucomponent/source/spellcheck/spell/spell.component index c11b7a7c3b4b..59f634eab02a 100644 --- a/lingucomponent/source/spellcheck/spell/spell.component +++ b/lingucomponent/source/spellcheck/spell/spell.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="spell" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="org.openoffice.lingu.MySpellSpellChecker"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="org.openoffice.lingu.MySpellSpellChecker" + constructor="lingucomponent_SpellChecker_get_implementation"> <service name="com.sun.star.linguistic2.SpellChecker"/> </implementation> </component> diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.cxx b/lingucomponent/source/spellcheck/spell/sspellimp.cxx index 3a6a39e92a12..23bd9e014c29 100644 --- a/lingucomponent/source/spellcheck/spell/sspellimp.cxx +++ b/lingucomponent/source/spellcheck/spell/sspellimp.cxx @@ -524,15 +524,6 @@ Reference< XSpellAlternatives > SAL_CALL SpellChecker::spell( return xAlt; } -/// @throws Exception -static Reference< XInterface > SpellChecker_CreateInstance( - const Reference< XMultiServiceFactory > & /*rSMgr*/ ) -{ - - Reference< XInterface > xService = static_cast<cppu::OWeakObject*>(new SpellChecker); - return xService; -} - sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) { @@ -627,7 +618,7 @@ void SAL_CALL SpellChecker::removeEventListener( const Reference< XEventListener // Service specific part OUString SAL_CALL SpellChecker::getImplementationName() { - return getImplementationName_Static(); + return "org.openoffice.lingu.MySpellSpellChecker"; } sal_Bool SAL_CALL SpellChecker::supportsService( const OUString& ServiceName ) @@ -637,38 +628,17 @@ sal_Bool SAL_CALL SpellChecker::supportsService( const OUString& ServiceName ) Sequence< OUString > SAL_CALL SpellChecker::getSupportedServiceNames() { - return getSupportedServiceNames_Static(); -} - -Sequence< OUString > SpellChecker::getSupportedServiceNames_Static() - throw() -{ - Sequence< OUString > aSNS { SN_SPELLCHECKER }; - return aSNS; + return { SN_SPELLCHECKER }; } -extern "C" -{ - -SAL_DLLPUBLIC_EXPORT void * spell_component_getFactory( - const char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +lingucomponent_SpellChecker_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - void * pRet = nullptr; - if ( SpellChecker::getImplementationName_Static().equalsAscii( pImplName ) ) - { - Reference< XSingleServiceFactory > xFactory = - cppu::createOneInstanceFactory( - static_cast< XMultiServiceFactory * >( pServiceManager ), - SpellChecker::getImplementationName_Static(), - SpellChecker_CreateInstance, - SpellChecker::getSupportedServiceNames_Static()); - // acquire, because we return an interface pointer instead of a reference - xFactory->acquire(); - pRet = xFactory.get(); - } - return pRet; + static rtl::Reference<SpellChecker> g_Instance(new SpellChecker()); + g_Instance->acquire(); + return static_cast<cppu::OWeakObject*>(g_Instance.get()); } -} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.hxx b/lingucomponent/source/spellcheck/spell/sspellimp.hxx index 3c55d3c9fcf7..7adf0ab17b5f 100644 --- a/lingucomponent/source/spellcheck/spell/sspellimp.hxx +++ b/lingucomponent/source/spellcheck/spell/sspellimp.hxx @@ -115,16 +115,8 @@ public: virtual OUString SAL_CALL getImplementationName() override; virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; - - static inline OUString getImplementationName_Static() throw(); - static Sequence< OUString > getSupportedServiceNames_Static() throw(); }; -inline OUString SpellChecker::getImplementationName_Static() throw() -{ - return "org.openoffice.lingu.MySpellSpellChecker"; -} - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lingucomponent/source/thesaurus/libnth/lnth.component b/lingucomponent/source/thesaurus/libnth/lnth.component index 50aa23c87b52..dfe3d3300cbc 100644 --- a/lingucomponent/source/thesaurus/libnth/lnth.component +++ b/lingucomponent/source/thesaurus/libnth/lnth.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="lnth" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="org.openoffice.lingu.new.Thesaurus"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="org.openoffice.lingu.new.Thesaurus" + constructor="lingucomponent_Thesaurus_get_implementation"> <service name="com.sun.star.linguistic2.Thesaurus"/> </implementation> </component> diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx index b24b8beb51f4..11f557cd1d54 100644 --- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx +++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx @@ -452,14 +452,6 @@ Sequence < Reference < css::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryM return noMeanings; } -/// @throws Exception -static Reference< XInterface > Thesaurus_CreateInstance( - const Reference< XMultiServiceFactory > & /*rSMgr*/ ) -{ - Reference< XInterface > xService = static_cast<cppu::OWeakObject*>(new Thesaurus); - return xService; -} - OUString SAL_CALL Thesaurus::getServiceDisplayName(const Locale& rLocale) { std::locale loc(Translate::Create("svt", LanguageTag(rLocale))); @@ -558,7 +550,7 @@ void SAL_CALL Thesaurus::removeEventListener( const Reference< XEventListener >& // Service specific part OUString SAL_CALL Thesaurus::getImplementationName() { - return getImplementationName_Static(); + return "org.openoffice.lingu.new.Thesaurus"; } sal_Bool SAL_CALL Thesaurus::supportsService( const OUString& ServiceName ) @@ -568,37 +560,16 @@ sal_Bool SAL_CALL Thesaurus::supportsService( const OUString& ServiceName ) Sequence< OUString > SAL_CALL Thesaurus::getSupportedServiceNames() { - return getSupportedServiceNames_Static(); -} - -Sequence< OUString > Thesaurus::getSupportedServiceNames_Static() - throw() -{ - Sequence< OUString > aSNS { SN_THESAURUS }; - return aSNS; + return { SN_THESAURUS }; } -extern "C" +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +lingucomponent_Thesaurus_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { -SAL_DLLPUBLIC_EXPORT void * lnth_component_getFactory( - const char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) -{ - void * pRet = nullptr; - if ( Thesaurus::getImplementationName_Static().equalsAscii( pImplName ) ) - { - - Reference< XSingleServiceFactory > xFactory = - cppu::createOneInstanceFactory( - static_cast< XMultiServiceFactory * >( pServiceManager ), - Thesaurus::getImplementationName_Static(), - Thesaurus_CreateInstance, - Thesaurus::getSupportedServiceNames_Static()); - // acquire, because we return an interface pointer instead of a reference - xFactory->acquire(); - pRet = xFactory.get(); - } - return pRet; -} + static rtl::Reference<Thesaurus> g_Instance(new Thesaurus()); + g_Instance->acquire(); + return static_cast<cppu::OWeakObject*>(g_Instance.get()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.hxx b/lingucomponent/source/thesaurus/libnth/nthesimp.hxx index cef9016b123e..69a67a224002 100644 --- a/lingucomponent/source/thesaurus/libnth/nthesimp.hxx +++ b/lingucomponent/source/thesaurus/libnth/nthesimp.hxx @@ -117,22 +117,12 @@ public: virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; - static inline OUString - getImplementationName_Static() throw(); - static Sequence< OUString > - getSupportedServiceNames_Static() throw(); - private: static OUString makeLowerCase(const OUString&, CharClass const *); static OUString makeUpperCase(const OUString&, CharClass const *); static OUString makeInitCap(const OUString&, CharClass const *); }; -inline OUString Thesaurus::getImplementationName_Static() throw() -{ - return "org.openoffice.lingu.new.Thesaurus"; -} - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |