From: Yurii R. <yr...@us...> - 2003-02-08 03:26:23
|
Update of /cvsroot/eas-dev/eas-dev/components/logger/src In directory sc8-pr-cvs1:/tmp/cvs-serv8584/src Modified Files: Makefile.am consolelogger.cxx consolelogger.hxx logger.cxx Added Files: sysloglogger.cxx sysloglogger.hxx Log Message: adding syslog logger (not finished yet) --- NEW FILE: sysloglogger.cxx --- /* $Id: sysloglogger.cxx,v 1.1 2003/02/08 03:26:20 yrashk Exp $ */ #include <config.h> #include <stdio.h> #include <iostream.h> #ifndef _OSL_MUTEX_HXX_ #include <osl/mutex.hxx> #endif #ifndef _RTL_USTRING_HXX_ #include <rtl/ustring> #endif #ifndef _UNO_DISPATCHER_H_ #include <uno/dispatcher.h> #endif #ifndef _UNO_MAPPING_HXX_ #include <uno/mapping.hxx> #endif #ifndef _CPPUHELPER_QUIRYINTERFACE_HXX_ #include <cppuhelper/queryinterface.hxx> #endif #ifndef _CPPUHELPER_FACTORY_HXX_ #include <cppuhelper/factory.hxx> #endif // generated c++ interfaces // #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ #include <com/sun/star/lang/XSingleServiceFactory.hpp> #endif #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #endif #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ #include <com/sun/star/lang/XServiceInfo.hpp> #endif #ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ #include <com/sun/star/registry/XRegistryKey.hpp> #endif #ifndef _ORG_OPENEAS_UTIL_XCONSOLELOGGER_HPP #include <org/openeas/util/XSyslogLogger.hpp> #endif using namespace ::rtl; using namespace ::osl; using namespace ::cppu; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::registry; using namespace ::org::openeas::util; #define CONSOLELOGGERIMPLNAME "org.openeas.util.SyslogLogger" #define SERVICENAME "org.openeas.util.Logger" class XSyslogLoggerImpl: public XSyslogLogger, public XServiceInfo { Reference<XMultiServiceFactory> m_xServiceManager; Mutex m_mutex; sal_Int32 m_nRefCount; public: XSyslogLoggerImpl(const Reference<XMultiServiceFactory> & xServiceManager) : m_xServiceManager(xServiceManager), m_nRefCount(0) { } ~XSyslogLoggerImpl() { } // XInterface virtual void SAL_CALL acquire() throw () { ++m_nRefCount; } virtual void SAL_CALL release() throw () { if (! --m_nRefCount) delete this; } virtual Any SAL_CALL queryInterface(const Type & rType) throw(RuntimeException) { return cppu::queryInterface(rType, static_cast<XInterface *> (static_cast<XServiceInfo *>(this)), static_cast<XSyslogLogger *>(this), static_cast<XServiceInfo *>(this)); } // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw(RuntimeException); virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(RuntimeException); virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(RuntimeException); static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static(); // XSyslogLogger virtual void SAL_CALL log(const OUString& message) throw (RuntimeException) { // utf-8 is temporary, need to make it better cout << OUStringToOString(message,RTL_TEXTENCODING_UTF8).getStr() << endl; cout.flush(); } virtual bool SAL_CALL isSupported() throw (RuntimeException) { #ifdef HAVE_SYSLOG return true; #else return false; #endif } }; OUString SAL_CALL XSyslogLoggerImpl::getImplementationName() throw(RuntimeException) { Guard<Mutex> aGuard(m_mutex); return OUString(RTL_CONSTASCII_USTRINGPARAM(CONSOLELOGGERIMPLNAME)); } sal_Bool SAL_CALL XSyslogLoggerImpl::supportsService(const OUString& ServiceName) throw(RuntimeException) { Guard< Mutex > aGuard( m_mutex ); Sequence< OUString > aSNL = getSupportedServiceNames(); const OUString * pArray = aSNL.getArray(); for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) if( pArray[i] == ServiceName ) return sal_True; return sal_False; } Sequence<OUString> SAL_CALL XSyslogLoggerImpl::getSupportedServiceNames() throw(RuntimeException) { Guard<Mutex> aGuard(m_mutex); return getSupportedServiceNames_Static(); } Sequence<OUString> SAL_CALL XSyslogLoggerImpl::getSupportedServiceNames_Static() { OUString aName(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); return Sequence<OUString>( &aName, 1 ); } Reference<XInterface> SAL_CALL XSyslogLoggerImpl_create( const Reference<XMultiServiceFactory> & xMgr) { return Reference<XSyslogLogger>(new XSyslogLoggerImpl(xMgr)); } --- NEW FILE: sysloglogger.hxx --- /* $Id: sysloglogger.hxx,v 1.1 2003/02/08 03:26:20 yrashk Exp $ */ #ifndef _LOGGER_SYSLOGLOGGER_HXX_ #define _LOGGER_SYSLOGLOGGER_HXX_ #ifndef _ORG_OPENEAS_UTIL_XCONSOLELOGGER_HPP #include <org/openeas/util/XSyslogLogger.hpp> #endif using namespace ::rtl; using namespace ::osl; using namespace ::cppu; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::registry; using namespace ::org::openeas::util; #define SYSLOGLOGGERIMPLNAME "org.openeas.util.XSyslogLogger" class XSyslogLoggerImpl: public XSyslogLogger, public XServiceInfo { Reference<XMultiServiceFactory> m_xServiceManager; Mutex m_mutex; sal_Int32 m_nRefCount; public: XSyslogLoggerImpl(const Reference<XMultiServiceFactory> & xServiceManager) : m_xServiceManager(xServiceManager), m_nRefCount(0) { } ~XSyslogLoggerImpl() { } // XInterface virtual void SAL_CALL acquire() throw (); virtual void SAL_CALL release() throw (); virtual Any SAL_CALL queryInterface(const Type & rType) throw(RuntimeException); // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw(RuntimeException); virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(RuntimeException); virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(RuntimeException); static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static(); // XSyslogLogger virtual void SAL_CALL ignoreLogLevel (logLevel aLL, sal_Bool bOnOff) throw (RuntimeException); virtual void SAL_CALL log(const OUString& message) throw (RuntimeException); virtual bool SAL_CALL isSupported(); throw (RuntimeException); Sequence<OUString> SAL_CALL getImplementations() throw (RuntimeException); }; Reference<XInterface> SAL_CALL XSyslogLoggerImpl_create( const Reference<XMultiServiceFactory> & xMgr); #endif /* _LOGGER_SYSLOGGER_HXX_ */ Index: Makefile.am =================================================================== RCS file: /cvsroot/eas-dev/eas-dev/components/logger/src/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 3 Feb 2003 06:30:45 -0000 1.3 +++ Makefile.am 8 Feb 2003 03:26:20 -0000 1.4 @@ -11,7 +11,7 @@ @INCLUDE@ @ODK_PATH@/settings/std.mk lib_LTLIBRARIES = liblogger.la -liblogger_la_SOURCES = logger.cxx consolelogger.cxx +liblogger_la_SOURCES = logger.cxx consolelogger.cxx sysloglogger.cxx INCLUDES = -I../../.include -I@top_include@ -I@ODK_PATH@/include liblogger_la_LIBADD = $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB) -lstdc++ liblogger_la_LDFLAGS = -L/opt/openoffice/program/ -L@ODK_PATH@/linux/lib Index: consolelogger.cxx =================================================================== RCS file: /cvsroot/eas-dev/eas-dev/components/logger/src/consolelogger.cxx,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- consolelogger.cxx 7 Feb 2003 11:03:52 -0000 1.4 +++ consolelogger.cxx 8 Feb 2003 03:26:20 -0000 1.5 @@ -53,9 +53,6 @@ using namespace com::sun::star::registry; using namespace ::org::openeas::util; -#define CONSOLELOGGERIMPLNAME "org.openeas.util.ConsoleLogger" -#define SERVICENAME "org.openeas.util.Logger" - class XConsoleLoggerImpl: public XConsoleLogger, public XServiceInfo { Reference<XMultiServiceFactory> m_xServiceManager; @@ -101,6 +98,13 @@ // utf-8 is temporary, need to make it better cout << OUStringToOString(message,RTL_TEXTENCODING_UTF8).getStr() << endl; cout.flush(); + } + + virtual bool SAL_CALL isSupported() + throw (RuntimeException) + { + return true; // we assume that console is available everywhere. + // however, it is an issue to check (FIXME) } }; Index: consolelogger.hxx =================================================================== RCS file: /cvsroot/eas-dev/eas-dev/components/logger/src/consolelogger.hxx,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- consolelogger.hxx 7 Feb 2003 11:03:52 -0000 1.4 +++ consolelogger.hxx 8 Feb 2003 03:26:20 -0000 1.5 @@ -48,11 +48,13 @@ throw(RuntimeException); static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static(); - // XXConsoleLogger + // XConsoleLogger virtual void SAL_CALL ignoreLogLevel (logLevel aLL, sal_Bool bOnOff) throw (RuntimeException); virtual void SAL_CALL log(const OUString& message) throw (RuntimeException); + virtual bool SAL_CALL isSupported(); + throw (RuntimeException); Sequence<OUString> SAL_CALL getImplementations() throw (RuntimeException); }; Index: logger.cxx =================================================================== RCS file: /cvsroot/eas-dev/eas-dev/components/logger/src/logger.cxx,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- logger.cxx 7 Feb 2003 11:03:52 -0000 1.5 +++ logger.cxx 8 Feb 2003 03:26:20 -0000 1.6 @@ -47,6 +47,7 @@ #endif #include "consolelogger.hxx" +#include "sysloglogger.hxx" using namespace ::rtl; using namespace ::osl; @@ -112,14 +113,15 @@ throw (RuntimeException) { if (!m_ignore[aLL]) - m_handler->log(message); + m_handler->log(message); // what we shall do if m_handler isn't set? FIXME } virtual void SAL_CALL setHandler(const Reference<XLoggerHandler>& xHandler) throw (RuntimeException) { - m_handler = xHandler; + if (xHandler->isSupported()) + m_handler = xHandler; } }; @@ -221,7 +223,28 @@ { // TODO: handle exception } - + try + { + Reference< XRegistryKey > xSyslogKey( + reinterpret_cast<XRegistryKey *> + (pRegistryKey)->createKey( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "/" SYSLOGLOGGERIMPLNAME "/UNO/SERVICES") ) ) ); + // FIXME: /UNO/ or /EAS/ ? + const Sequence< OUString > & rSNL = + XLoggerImpl::getSupportedServiceNames_Static(); + const OUString *pArray = rSNL.getConstArray(); + for (sal_Int32 nPos = rSNL.getLength(); nPos--;) + xSyslogKey->createKey(pArray[nPos]); + + + return sal_True; + } + catch (InvalidRegistryException &) + { + // TODO: handle exception + } } return result; } @@ -259,6 +282,24 @@ CONSOLELOGGERIMPLNAME)), XConsoleLoggerImpl_create, XConsoleLoggerImpl::getSupportedServiceNames_Static())); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + if (rtl_str_compare(pImplName, SYSLOGLOGGERIMPLNAME) == 0) + { + Reference<XSingleServiceFactory> xFactory( + createSingleFactory( + reinterpret_cast<XMultiServiceFactory *> + (pServiceManager), + OUString(RTL_CONSTASCII_USTRINGPARAM( + SYSLOGLOGGERIMPLNAME)), + XSyslogLoggerImpl_create, + XSyslogLoggerImpl::getSupportedServiceNames_Static())); if (xFactory.is()) { |