LCOV - code coverage report
Current view: top level - extensions/source/logging - loghandler.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 10 12 83.3 %
Date: 2015-06-13 12:38:46 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGHANDLER_HXX
      21             : #define INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGHANDLER_HXX
      22             : 
      23             : #include <com/sun/star/logging/XLogFormatter.hpp>
      24             : #include <com/sun/star/uno/XComponentContext.hpp>
      25             : #include <com/sun/star/logging/LogRecord.hpp>
      26             : 
      27             : #include <comphelper/namedvaluecollection.hxx>
      28             : #include <cppuhelper/interfacecontainer.hxx>
      29             : #include <rtl/string.hxx>
      30             : 
      31             : 
      32             : namespace logging
      33             : {
      34             : 
      35           2 :     class LogHandlerHelper
      36             :     {
      37             :     private:
      38             :         // <attributes>
      39             :         rtl_TextEncoding    m_eEncoding;
      40             :         sal_Int32           m_nLevel;
      41             :         ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >
      42             :                             m_xFormatter;
      43             :         // <//attributes>
      44             : 
      45             :         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
      46             :                                     m_xContext;
      47             :         ::osl::Mutex&               m_rMutex;
      48             :         ::cppu::OBroadcastHelper&   m_rBHelper;
      49             :         bool                        m_bInitialized;
      50             : 
      51             :     public:
      52             :         LogHandlerHelper(
      53             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
      54             :             ::osl::Mutex& _rMutex,
      55             :             ::cppu::OBroadcastHelper& _rBHelper
      56             :         );
      57             : 
      58             :     public:
      59          49 :         bool    getIsInitialized() const { return m_bInitialized; }
      60          17 :         void    setIsInitialized() { m_bInitialized = true; }
      61             : 
      62             :         bool    getEncoding(        OUString& _out_rEncoding ) const;
      63             :         bool    setEncoding( const  OUString& _rEncoding     );
      64             : 
      65             :         inline  rtl_TextEncoding
      66           0 :                 getTextEncoding() const { return m_eEncoding; }
      67             : 
      68             :         inline  ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >
      69          32 :                 getFormatter() const { return m_xFormatter; }
      70             :         inline  void
      71          34 :                 setFormatter( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >& _rxFormatter )
      72             :                 {
      73          34 :                     m_xFormatter = _rxFormatter;
      74          34 :                 }
      75             : 
      76             :         inline  sal_Int32
      77           0 :                 getLevel() const { return m_nLevel; }
      78             :         inline  void
      79          16 :                 setLevel( const sal_Int32 _nLevel )
      80             :                 {
      81          16 :                     m_nLevel = _nLevel;
      82          16 :                 }
      83             : 
      84             :         /** prepares implementation of an public accessible method of a log handler
      85             : 
      86             :             <code>enterMethod</code> does the following things:
      87             :             <ul><li>It acquires the mutex given in the constructor.</li>
      88             :                 <li>It checks whether the component is already initialized, and throws an exception if not os.</li>
      89             :                 <li>It checks whether the component is already disposed, and throws an exception if not os.</li>
      90             :                 <li>It creates a default formatter (PlainTextFormatter), if no formatter exists at this time.</li>
      91             :             </ul>
      92             :         */
      93             :         void enterMethod();
      94             : 
      95             :         /** formats a record for publishing it
      96             : 
      97             :             The method first checks whether the records log level is greater or equal our own
      98             :             log level. If not, <FALSE/> is returned.
      99             : 
     100             :             Second, our formatter is used to create a unicode string from the log record. If an error occurs
     101             :             during this, e.g. if the formatter is <NULL/> or throws an exception during formatting,
     102             :             <FALSE/> is returned.
     103             : 
     104             :             Finally, the unicode string is encoded into a byte string, using our encoding setting. Then,
     105             :             <TRUE/> is returned.
     106             :         */
     107             :         bool    formatForPublishing( const ::com::sun::star::logging::LogRecord& _rRecord, OString& _out_rEntry ) const;
     108             : 
     109             :         /** retrieves our formatter's heading, encoded with our encoding
     110             : 
     111             :             @return <TRUE/> in case of success, <FALSE/> if any error occurred
     112             :         */
     113             :         bool    getEncodedHead( OString& _out_rHead ) const;
     114             : 
     115             :         /** retrieves our formatter's tail, encoded with our encoding
     116             : 
     117             :             @return <TRUE/> in case of success, <FALSE/> if any error occurred
     118             :         */
     119             :         bool    getEncodedTail( OString& _out_rTail ) const;
     120             : 
     121             :         /** initializes the instance from a collection of named settings
     122             : 
     123             :             The recognized named settings are <code>Encoding</code>, <code>Formatter</code>, and <code>Level</code>,
     124             :             which initialize the respective attributes.
     125             : 
     126             :             Settings which are recognized are remove from the given collection. This allows
     127             :             the caller to determine whether or not the collection contained any unsupported
     128             :             items, and react appropriately.
     129             : 
     130             :             @throws IllegalArgumentException
     131             :                 if one of the values in the collection is of wrong type.
     132             :         */
     133             :         void    initFromSettings( const ::comphelper::NamedValueCollection& _rSettings );
     134             :     };
     135             : 
     136             : 
     137             : } // namespace logging
     138             : 
     139             : 
     140             : #endif // INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGHANDLER_HXX
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11