146dbaceeSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 346dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 446dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file 546dbaceeSAndrew Rist * distributed with this work for additional information 646dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file 746dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the 846dbaceeSAndrew Rist * "License"); you may not use this file except in compliance 946dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at 1046dbaceeSAndrew Rist * 1146dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1246dbaceeSAndrew Rist * 1346dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing, 1446dbaceeSAndrew Rist * software distributed under the License is distributed on an 1546dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1646dbaceeSAndrew Rist * KIND, either express or implied. See the License for the 1746dbaceeSAndrew Rist * specific language governing permissions and limitations 1846dbaceeSAndrew Rist * under the License. 1946dbaceeSAndrew Rist * 2046dbaceeSAndrew Rist *************************************************************/ 2146dbaceeSAndrew Rist 2246dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef LOGHANDLER_HXX 25cdf0e10cSrcweir #define LOGHANDLER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/logging/XLogFormatter.hpp> 29cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 30cdf0e10cSrcweir #include <com/sun/star/logging/LogRecord.hpp> 31cdf0e10cSrcweir /** === end UNO includes === **/ 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 34cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 35cdf0e10cSrcweir #include <rtl/string.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir //........................................................................ 38cdf0e10cSrcweir namespace logging 39cdf0e10cSrcweir { 40cdf0e10cSrcweir //........................................................................ 41cdf0e10cSrcweir 42cdf0e10cSrcweir //==================================================================== 43cdf0e10cSrcweir //= 44cdf0e10cSrcweir //==================================================================== 45cdf0e10cSrcweir class LogHandlerHelper 46cdf0e10cSrcweir { 47cdf0e10cSrcweir private: 48cdf0e10cSrcweir // <attributes> 49cdf0e10cSrcweir rtl_TextEncoding m_eEncoding; 50cdf0e10cSrcweir sal_Int32 m_nLevel; 51cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter > 52cdf0e10cSrcweir m_xFormatter; 53cdf0e10cSrcweir // <//attributes> 54cdf0e10cSrcweir 55cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > 56cdf0e10cSrcweir m_xContext; 57cdf0e10cSrcweir ::osl::Mutex& m_rMutex; 58cdf0e10cSrcweir ::cppu::OBroadcastHelper& m_rBHelper; 59cdf0e10cSrcweir bool m_bInitialized; 60cdf0e10cSrcweir 61cdf0e10cSrcweir public: 62cdf0e10cSrcweir LogHandlerHelper( 63cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, 64cdf0e10cSrcweir ::osl::Mutex& _rMutex, 65cdf0e10cSrcweir ::cppu::OBroadcastHelper& _rBHelper 66cdf0e10cSrcweir ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir public: getIsInitialized() const69cdf0e10cSrcweir bool getIsInitialized() const { return m_bInitialized; } setIsInitialized()70cdf0e10cSrcweir void setIsInitialized() { m_bInitialized = true; } 71cdf0e10cSrcweir 72cdf0e10cSrcweir bool getEncoding( ::rtl::OUString& _out_rEncoding ) const; 73cdf0e10cSrcweir bool setEncoding( const ::rtl::OUString& _rEncoding ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir inline rtl_TextEncoding getTextEncoding() const76cdf0e10cSrcweir getTextEncoding() const { return m_eEncoding; } 77cdf0e10cSrcweir 78cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter > getFormatter() const79cdf0e10cSrcweir getFormatter() const { return m_xFormatter; } 80cdf0e10cSrcweir inline void setFormatter(const::com::sun::star::uno::Reference<::com::sun::star::logging::XLogFormatter> & _rxFormatter)81cdf0e10cSrcweir setFormatter( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >& _rxFormatter ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir m_xFormatter = _rxFormatter; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir inline sal_Int32 getLevel() const87cdf0e10cSrcweir getLevel() const { return m_nLevel; } 88cdf0e10cSrcweir inline void setLevel(const sal_Int32 _nLevel)89cdf0e10cSrcweir setLevel( const sal_Int32 _nLevel ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir m_nLevel = _nLevel; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** prepares implementation of an public accessible method of a log handler 95cdf0e10cSrcweir 96cdf0e10cSrcweir <code>enterMethod</code> does the following things: 97cdf0e10cSrcweir <ul><li>It acquires the mutex given in the constructor.</li> 98cdf0e10cSrcweir <li>It checks whether the component is already initialized, and throws an exception if not os.</li> 99cdf0e10cSrcweir <li>It checks whether the component is already disposed, and throws an exception if not os.</li> 100cdf0e10cSrcweir <li>It creates a default formatter (PlainTextFormatter), if no formatter exists at this time.</li> 101cdf0e10cSrcweir </ul> 102cdf0e10cSrcweir */ 103cdf0e10cSrcweir void enterMethod(); 104cdf0e10cSrcweir 105cdf0e10cSrcweir /** formats a record for publishing it 106cdf0e10cSrcweir 107cdf0e10cSrcweir The method first checks whether the records log level is greater or equal our own 108cdf0e10cSrcweir log level. If not, <FALSE/> is returned. 109cdf0e10cSrcweir 110cdf0e10cSrcweir Second, our formatter is used to create a unicode string from the log record. If an error occurs 111cdf0e10cSrcweir during this, e.g. if the formatter is <NULL/> or throws an exception during formatting, 112cdf0e10cSrcweir <FALSE/> is returned. 113cdf0e10cSrcweir 114cdf0e10cSrcweir Finally, the unicode string is encoded into a byte string, using our encoding setting. Then, 115cdf0e10cSrcweir <TRUE/> is returned. 116cdf0e10cSrcweir */ 117cdf0e10cSrcweir bool formatForPublishing( const ::com::sun::star::logging::LogRecord& _rRecord, ::rtl::OString& _out_rEntry ) const; 118cdf0e10cSrcweir 119cdf0e10cSrcweir /** retrieves our formatter's heading, encoded with our encoding 120cdf0e10cSrcweir 121*07a3d7f1SPedro Giffuni @return <TRUE/> in case of success, <FALSE/> if any error occurred 122cdf0e10cSrcweir */ 123cdf0e10cSrcweir bool getEncodedHead( ::rtl::OString& _out_rHead ) const; 124cdf0e10cSrcweir 125cdf0e10cSrcweir /** retrieves our formatter's tail, encoded with our encoding 126cdf0e10cSrcweir 127*07a3d7f1SPedro Giffuni @return <TRUE/> in case of success, <FALSE/> if any error occurred 128cdf0e10cSrcweir */ 129cdf0e10cSrcweir bool getEncodedTail( ::rtl::OString& _out_rTail ) const; 130cdf0e10cSrcweir 131cdf0e10cSrcweir /** initializes the instance from a collection of named settings 132cdf0e10cSrcweir 133cdf0e10cSrcweir The recognized named settings are <code>Encoding</code>, <code>Formatter</code>, and <code>Level</code>, 134cdf0e10cSrcweir which initialize the respective attributes. 135cdf0e10cSrcweir 136cdf0e10cSrcweir Settings which are recognized are remove from the given collection. This allows 137cdf0e10cSrcweir the caller to determine whether or not the collection contained any unsupported 138cdf0e10cSrcweir items, and react appropriately. 139cdf0e10cSrcweir 140cdf0e10cSrcweir @throws IllegalArgumentException 141cdf0e10cSrcweir if one of the values in the collection is of wrong type. 142cdf0e10cSrcweir */ 143cdf0e10cSrcweir void initFromSettings( const ::comphelper::NamedValueCollection& _rSettings ); 144cdf0e10cSrcweir }; 145cdf0e10cSrcweir 146cdf0e10cSrcweir //........................................................................ 147cdf0e10cSrcweir } // namespace logging 148cdf0e10cSrcweir //........................................................................ 149cdf0e10cSrcweir 150cdf0e10cSrcweir #endif // LOGHANDLER_HXX 151