update dev300-m58
[ooovba.git] / extensions / source / logging / loghandler.hxx
blobae3e9739edd8c6be00bf505f41d7ed459767c863
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loghandler.hxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef LOGHANDLER_HXX
32 #define LOGHANDLER_HXX
34 /** === begin UNO includes === **/
35 #include <com/sun/star/logging/XLogFormatter.hpp>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <com/sun/star/logging/LogRecord.hpp>
38 /** === end UNO includes === **/
40 #include <comphelper/namedvaluecollection.hxx>
41 #include <cppuhelper/interfacecontainer.hxx>
42 #include <rtl/string.hxx>
44 //........................................................................
45 namespace logging
47 //........................................................................
49 //====================================================================
50 //=
51 //====================================================================
52 class LogHandlerHelper
54 private:
55 // <attributes>
56 rtl_TextEncoding m_eEncoding;
57 sal_Int32 m_nLevel;
58 ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >
59 m_xFormatter;
60 // <//attributes>
62 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
63 m_xContext;
64 ::osl::Mutex& m_rMutex;
65 ::cppu::OBroadcastHelper& m_rBHelper;
66 bool m_bInitialized;
68 public:
69 LogHandlerHelper(
70 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
71 ::osl::Mutex& _rMutex,
72 ::cppu::OBroadcastHelper& _rBHelper
75 public:
76 bool getIsInitialized() const { return m_bInitialized; }
77 void setIsInitialized() { m_bInitialized = true; }
79 bool getEncoding( ::rtl::OUString& _out_rEncoding ) const;
80 bool setEncoding( const ::rtl::OUString& _rEncoding );
82 inline rtl_TextEncoding
83 getTextEncoding() const { return m_eEncoding; }
85 inline ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >
86 getFormatter() const { return m_xFormatter; }
87 inline void
88 setFormatter( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >& _rxFormatter )
90 m_xFormatter = _rxFormatter;
93 inline sal_Int32
94 getLevel() const { return m_nLevel; }
95 inline void
96 setLevel( const sal_Int32 _nLevel )
98 m_nLevel = _nLevel;
101 /** prepares implementation of an public accessible method of a log handler
103 <code>enterMethod</code> does the following things:
104 <ul><li>It acquires the mutex given in the constructor.</li>
105 <li>It checks whether the component is already initialized, and throws an exception if not os.</li>
106 <li>It checks whether the component is already disposed, and throws an exception if not os.</li>
107 <li>It creates a default formatter (PlainTextFormatter), if no formatter exists at this time.</li>
108 </ul>
110 void enterMethod();
112 /** formats a record for publishing it
114 The method first checks whether the records log level is greater or equal our own
115 log level. If not, <FALSE/> is returned.
117 Second, our formatter is used to create a unicode string from the log record. If an error occurs
118 during this, e.g. if the formatter is <NULL/> or throws an exception during formatting,
119 <FALSE/> is returned.
121 Finally, the unicode string is encoded into a byte string, using our encoding setting. Then,
122 <TRUE/> is returned.
124 bool formatForPublishing( const ::com::sun::star::logging::LogRecord& _rRecord, ::rtl::OString& _out_rEntry ) const;
126 /** retrieves our formatter's heading, encoded with our encoding
128 @return <TRUE/> in case of success, <FALSE/> if any error occured
130 bool getEncodedHead( ::rtl::OString& _out_rHead ) const;
132 /** retrieves our formatter's tail, encoded with our encoding
134 @return <TRUE/> in case of success, <FALSE/> if any error occured
136 bool getEncodedTail( ::rtl::OString& _out_rTail ) const;
138 /** initializes the instance from a collection of named settings
140 The recognized named settings are <code>Encoding</code>, <code>Formatter</code>, and <code>Level</code>,
141 which initialize the respective attributes.
143 Settings which are recognized are remove from the given collection. This allows
144 the caller to determine whether or not the collection contained any unsupported
145 items, and react appropriately.
147 @throws IllegalArgumentException
148 if one of the values in the collection is of wrong type.
150 void initFromSettings( const ::comphelper::NamedValueCollection& _rSettings );
153 //........................................................................
154 } // namespace logging
155 //........................................................................
157 #endif // LOGHANDLER_HXX