From 3bda8734f88b9c86fc9d5cfa83580844eeaf2221 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Mon, 28 Dec 2015 20:06:38 +0100 Subject: tdf#74608: Ctor function for logging::FileHandler Change-Id: I3c9e0c33f63a82f9dc172adde6351abbc822fb9e --- extensions/source/logging/filehandler.cxx | 133 +++++++++-------------------- extensions/source/logging/log.component | 3 +- extensions/source/logging/log_services.cxx | 1 - extensions/source/logging/log_services.hxx | 1 - 4 files changed, 44 insertions(+), 94 deletions(-) (limited to 'extensions/source') diff --git a/extensions/source/logging/filehandler.cxx b/extensions/source/logging/filehandler.cxx index 52c4c368aa50..686ccb63692e 100644 --- a/extensions/source/logging/filehandler.cxx +++ b/extensions/source/logging/filehandler.cxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include -#include "log_module.hxx" -#include "log_services.hxx" #include "methodguard.hxx" #include "loghandler.hxx" #include #include -#include -#include #include #include #include @@ -39,16 +36,12 @@ #include #include - #include #include - namespace logging { - - using ::com::sun::star::uno::Reference; using ::com::sun::star::logging::LogRecord; using ::com::sun::star::uno::RuntimeException; @@ -58,19 +51,14 @@ namespace logging using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::logging::XLogHandler; using ::com::sun::star::lang::XServiceInfo; - using ::com::sun::star::ucb::AlreadyInitializedException; - using ::com::sun::star::lang::XInitialization; - using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Exception; using ::com::sun::star::lang::IllegalArgumentException; - using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::util::PathSubstitution; using ::com::sun::star::util::XStringSubstitution; using ::com::sun::star::beans::NamedValue; typedef ::cppu::WeakComponentImplHelper < XLogHandler , XServiceInfo - , XInitialization > FileHandler_Base; class FileHandler :public ::cppu::BaseMutex ,public FileHandler_Base @@ -86,17 +74,18 @@ namespace logging eInvalid }; - private: Reference m_xContext; LogHandlerHelper m_aHandlerHelper; OUString m_sFileURL; ::std::unique_ptr< ::osl::File > m_pFile; FileValidity m_eFileValidity; - protected: - explicit FileHandler( const Reference< XComponentContext >& _rxContext ); + public: + FileHandler(const css::uno::Reference &context, + const css::uno::Sequence &arguments); virtual ~FileHandler(); + private: // XLogHandler virtual OUString SAL_CALL getEncoding() throw (RuntimeException, std::exception) override; virtual void SAL_CALL setEncoding( const OUString& _encoding ) throw (RuntimeException, std::exception) override; @@ -107,9 +96,6 @@ namespace logging virtual void SAL_CALL flush( ) throw (RuntimeException, std::exception) override; virtual sal_Bool SAL_CALL publish( const LogRecord& Record ) throw (RuntimeException, std::exception) override; - // XInitialization - virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override; - // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw(RuntimeException, std::exception) override; virtual sal_Bool SAL_CALL supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception) override; @@ -118,12 +104,6 @@ namespace logging // OComponentHelper virtual void SAL_CALL disposing() override; - public: - // XServiceInfo - static version - static OUString SAL_CALL getImplementationName_static(); - static Sequence< OUString > SAL_CALL getSupportedServiceNames_static(); - static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext ); - public: typedef ComponentMethodGuard< FileHandler > MethodGuard; void enterMethod( MethodGuard::Access ); @@ -142,16 +122,40 @@ namespace logging void impl_doStringsubstitution_nothrow( OUString& _inout_rURL ); }; - FileHandler::FileHandler( const Reference< XComponentContext >& _rxContext ) + FileHandler::FileHandler(const css::uno::Reference &context, + const css::uno::Sequence &arguments) :FileHandler_Base( m_aMutex ) - ,m_xContext( _rxContext ) - ,m_aHandlerHelper( _rxContext, m_aMutex, rBHelper ) + ,m_xContext( context ) + ,m_aHandlerHelper( context, m_aMutex, rBHelper ) ,m_sFileURL( ) ,m_pFile( ) ,m_eFileValidity( eUnknown ) { - } + ::osl::MutexGuard aGuard( m_aMutex ); + if ( arguments.getLength() != 1 ) + throw IllegalArgumentException( OUString(), *this, 1 ); + + Sequence< NamedValue > aSettings; + if ( arguments[0] >>= m_sFileURL ) + { + // create( [in] string URL ); + impl_doStringsubstitution_nothrow( m_sFileURL ); + } + else if ( arguments[0] >>= aSettings ) + { + // createWithSettings( [in] sequence< css::beans::NamedValue > Settings ) + ::comphelper::NamedValueCollection aTypedSettings( aSettings ); + m_aHandlerHelper.initFromSettings( aTypedSettings ); + + if ( aTypedSettings.get_ensureType( "FileURL", m_sFileURL ) ) + impl_doStringsubstitution_nothrow( m_sFileURL ); + } + else + throw IllegalArgumentException( OUString(), *this, 1 ); + + m_aHandlerHelper.setIsInitialized(); + } FileHandler::~FileHandler() { @@ -328,42 +332,9 @@ namespace logging return sal_True; } - - void SAL_CALL FileHandler::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException, std::exception) - { - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_aHandlerHelper.getIsInitialized() ) - throw AlreadyInitializedException(); - - if ( _rArguments.getLength() != 1 ) - throw IllegalArgumentException( OUString(), *this, 1 ); - - Sequence< NamedValue > aSettings; - if ( _rArguments[0] >>= m_sFileURL ) - { - // create( [in] string URL ); - impl_doStringsubstitution_nothrow( m_sFileURL ); - } - else if ( _rArguments[0] >>= aSettings ) - { - // createWithSettings( [in] sequence< css::beans::NamedValue > Settings ) - ::comphelper::NamedValueCollection aTypedSettings( aSettings ); - m_aHandlerHelper.initFromSettings( aTypedSettings ); - - if ( aTypedSettings.get_ensureType( "FileURL", m_sFileURL ) ) - impl_doStringsubstitution_nothrow( m_sFileURL ); - } - else - throw IllegalArgumentException( OUString(), *this, 1 ); - - m_aHandlerHelper.setIsInitialized(); - } - - OUString SAL_CALL FileHandler::getImplementationName() throw(RuntimeException, std::exception) { - return getImplementationName_static(); + return OUString("com.sun.star.comp.extensions.FileHandler"); } sal_Bool SAL_CALL FileHandler::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception) @@ -371,39 +342,19 @@ namespace logging return cppu::supportsService(this, _rServiceName); } - Sequence< OUString > SAL_CALL FileHandler::getSupportedServiceNames() throw(RuntimeException, std::exception) { - return getSupportedServiceNames_static(); - } - - - OUString SAL_CALL FileHandler::getImplementationName_static() - { - return OUString( "com.sun.star.comp.extensions.FileHandler" ); + return { "com.sun.star.logging.FileHandler" }; } - - Sequence< OUString > SAL_CALL FileHandler::getSupportedServiceNames_static() - { - Sequence< OUString > aServiceNames { "com.sun.star.logging.FileHandler" }; - return aServiceNames; - } - - - Reference< XInterface > FileHandler::Create( const Reference< XComponentContext >& _rxContext ) - { - return *( new FileHandler( _rxContext ) ); - } - - - void createRegistryInfo_FileHandler() - { - static OAutoRegistration< FileHandler > aAutoRegistration; - } - - } // namespace logging +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_extensions_FileHandler( + css::uno::XComponentContext *context, + css::uno::Sequence const &arguments) +{ + return cppu::acquire(new logging::FileHandler(context, arguments)); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/extensions/source/logging/log.component b/extensions/source/logging/log.component index 38f4a739f2f7..bb5f2626bc7a 100644 --- a/extensions/source/logging/log.component +++ b/extensions/source/logging/log.component @@ -25,7 +25,8 @@ - +