diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2015-12-28 20:15:06 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2015-12-28 20:35:40 +0100 |
commit | cc6ccaf922bc8cefec714b9110a7d36ae113817c (patch) | |
tree | 41e03ccaebe72eefbd708a7d66299d645acec872 /extensions | |
parent | 3bda8734f88b9c86fc9d5cfa83580844eeaf2221 (diff) |
tdf#74608: Ctor function for logging::ConsoleHandler
Change-Id: I4326dcb9ae2abfaddef3b68369ee08a6296e0089
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/source/logging/consolehandler.cxx | 128 | ||||
-rw-r--r-- | extensions/source/logging/log.component | 3 | ||||
-rw-r--r-- | extensions/source/logging/log_services.cxx | 1 | ||||
-rw-r--r-- | extensions/source/logging/log_services.hxx | 1 |
4 files changed, 42 insertions, 91 deletions
diff --git a/extensions/source/logging/consolehandler.cxx b/extensions/source/logging/consolehandler.cxx index e5db0639468e..be5b87c65708 100644 --- a/extensions/source/logging/consolehandler.cxx +++ b/extensions/source/logging/consolehandler.cxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> -#include "log_module.hxx" -#include "log_services.hxx" #include "methodguard.hxx" #include "loghandler.hxx" #include <com/sun/star/logging/XConsoleHandler.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/logging/LogLevel.hpp> -#include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/ucb/AlreadyInitializedException.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/beans/NamedValue.hpp> @@ -37,11 +34,8 @@ #include <stdio.h> - namespace logging { - - using ::com::sun::star::logging::XConsoleHandler; using ::com::sun::star::lang::XServiceInfo; using ::com::sun::star::uno::Reference; @@ -54,16 +48,11 @@ namespace logging using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::XInterface; - using ::com::sun::star::lang::XInitialization; - using ::com::sun::star::ucb::AlreadyInitializedException; using ::com::sun::star::lang::IllegalArgumentException; using ::com::sun::star::beans::NamedValue; - namespace LogLevel = ::com::sun::star::logging::LogLevel; - typedef ::cppu::WeakComponentImplHelper < XConsoleHandler , XServiceInfo - , XInitialization > ConsoleHandler_Base; class ConsoleHandler :public ::cppu::BaseMutex ,public ConsoleHandler_Base @@ -72,10 +61,12 @@ namespace logging LogHandlerHelper m_aHandlerHelper; sal_Int32 m_nThreshold; - protected: - explicit ConsoleHandler( const Reference< XComponentContext >& _rxContext ); + public: + ConsoleHandler(const Reference<XComponentContext> &context, + const css::uno::Sequence<css::uno::Any> &arguments); virtual ~ConsoleHandler(); + private: // XConsoleHandler virtual ::sal_Int32 SAL_CALL getThreshold() throw (RuntimeException, std::exception) override; virtual void SAL_CALL setThreshold( ::sal_Int32 _threshold ) throw (RuntimeException, std::exception) override; @@ -90,9 +81,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; @@ -102,24 +90,40 @@ namespace logging 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< ConsoleHandler > MethodGuard; void enterMethod( MethodGuard::Access ); void leaveMethod( MethodGuard::Access ); }; - ConsoleHandler::ConsoleHandler( const Reference< XComponentContext >& _rxContext ) + ConsoleHandler::ConsoleHandler(const Reference<XComponentContext> &context, + const css::uno::Sequence<css::uno::Any> &arguments) :ConsoleHandler_Base( m_aMutex ) - ,m_aHandlerHelper( _rxContext, m_aMutex, rBHelper ) - ,m_nThreshold( LogLevel::SEVERE ) + ,m_aHandlerHelper( context, m_aMutex, rBHelper ) + ,m_nThreshold( css::logging::LogLevel::SEVERE ) { - } + ::osl::MutexGuard aGuard( m_aMutex ); + if ( arguments.getLength() == 0 ) + { // create() - nothing to init + m_aHandlerHelper.setIsInitialized(); + return; + } + + if ( arguments.getLength() != 1 ) + throw IllegalArgumentException( OUString(), *this, 1 ); + + Sequence< NamedValue > aSettings; + if ( !( arguments[0] >>= aSettings ) ) + throw IllegalArgumentException( OUString(), *this, 1 ); + + // createWithSettings( [in] sequence< css::beans::NamedValue > Settings ) + ::comphelper::NamedValueCollection aTypedSettings( aSettings ); + m_aHandlerHelper.initFromSettings( aTypedSettings ); + + aTypedSettings.get_ensureType( "Threshold", m_nThreshold ); + + m_aHandlerHelper.setIsInitialized(); + } ConsoleHandler::~ConsoleHandler() { @@ -231,81 +235,29 @@ namespace logging return sal_True; } - - void SAL_CALL ConsoleHandler::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException, std::exception) - { - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_aHandlerHelper.getIsInitialized() ) - throw AlreadyInitializedException(); - - if ( _rArguments.getLength() == 0 ) - { // create() - nothing to init - m_aHandlerHelper.setIsInitialized(); - return; - } - - if ( _rArguments.getLength() != 1 ) - throw IllegalArgumentException( OUString(), *this, 1 ); - - Sequence< NamedValue > aSettings; - if ( !( _rArguments[0] >>= aSettings ) ) - throw IllegalArgumentException( OUString(), *this, 1 ); - - // createWithSettings( [in] sequence< css::beans::NamedValue > Settings ) - ::comphelper::NamedValueCollection aTypedSettings( aSettings ); - m_aHandlerHelper.initFromSettings( aTypedSettings ); - - aTypedSettings.get_ensureType( "Threshold", m_nThreshold ); - - m_aHandlerHelper.setIsInitialized(); - } - - OUString SAL_CALL ConsoleHandler::getImplementationName() throw(RuntimeException, std::exception) { - return getImplementationName_static(); + return OUString("com.sun.star.comp.extensions.ConsoleHandler"); } - sal_Bool SAL_CALL ConsoleHandler::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception) { return cppu::supportsService(this, _rServiceName); } - Sequence< OUString > SAL_CALL ConsoleHandler::getSupportedServiceNames() throw(RuntimeException, std::exception) { - return getSupportedServiceNames_static(); + return { "com.sun.star.logging.ConsoleHandler" }; } - - OUString SAL_CALL ConsoleHandler::getImplementationName_static() - { - return OUString( "com.sun.star.comp.extensions.ConsoleHandler" ); - } - - - Sequence< OUString > SAL_CALL ConsoleHandler::getSupportedServiceNames_static() - { - Sequence< OUString > aServiceNames { "com.sun.star.logging.ConsoleHandler" }; - return aServiceNames; - } - - - Reference< XInterface > ConsoleHandler::Create( const Reference< XComponentContext >& _rxContext ) - { - return *( new ConsoleHandler( _rxContext ) ); - } - - - void createRegistryInfo_ConsoleHandler() - { - static OAutoRegistration< ConsoleHandler > aAutoRegistration; - } - - } // namespace logging +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_extensions_ConsoleHandler( + css::uno::XComponentContext *context, + css::uno::Sequence<css::uno::Any> const &arguments) +{ + return cppu::acquire(new logging::ConsoleHandler(context, arguments)); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/extensions/source/logging/log.component b/extensions/source/logging/log.component index bb5f2626bc7a..4cd5a553be2d 100644 --- a/extensions/source/logging/log.component +++ b/extensions/source/logging/log.component @@ -19,7 +19,8 @@ <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" prefix="log" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.extensions.ConsoleHandler"> + <implementation name="com.sun.star.comp.extensions.ConsoleHandler" + constructor="com_sun_star_comp_extensions_ConsoleHandler"> <service name="com.sun.star.logging.ConsoleHandler"/> </implementation> <implementation name="com.sun.star.comp.extensions.CsvFormatter"> diff --git a/extensions/source/logging/log_services.cxx b/extensions/source/logging/log_services.cxx index f20c735eb4c1..d2599a0c0dad 100644 --- a/extensions/source/logging/log_services.cxx +++ b/extensions/source/logging/log_services.cxx @@ -25,7 +25,6 @@ namespace logging static void initializeModule() { ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - createRegistryInfo_ConsoleHandler(); createRegistryInfo_PlainTextFormatter(); createRegistryInfo_CsvFormatter(); } diff --git a/extensions/source/logging/log_services.hxx b/extensions/source/logging/log_services.hxx index 0aca8b5fdb61..17c5ec984722 100644 --- a/extensions/source/logging/log_services.hxx +++ b/extensions/source/logging/log_services.hxx @@ -24,7 +24,6 @@ namespace logging { -void createRegistryInfo_ConsoleHandler(); void createRegistryInfo_PlainTextFormatter(); void createRegistryInfo_CsvFormatter(); |