Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / extensions / source / logging / loghandler.hxx
blob02f4fb77376190e0b1ac30480ebbd868e5a837ff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <string_view>
26 #include <com/sun/star/logging/XLogFormatter.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/logging/LogRecord.hpp>
30 #include <comphelper/namedvaluecollection.hxx>
31 #include <cppuhelper/interfacecontainer.hxx>
32 #include <rtl/string.hxx>
35 namespace logging
38 class LogHandlerHelper
40 private:
41 // <attributes>
42 rtl_TextEncoding m_eEncoding;
43 sal_Int32 m_nLevel;
44 css::uno::Reference< css::logging::XLogFormatter >
45 m_xFormatter;
46 // <//attributes>
48 css::uno::Reference< css::uno::XComponentContext >
49 m_xContext;
50 ::osl::Mutex& m_rMutex;
51 ::cppu::OBroadcastHelper& m_rBHelper;
52 bool m_bInitialized;
54 public:
55 LogHandlerHelper(
56 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
57 ::osl::Mutex& _rMutex,
58 ::cppu::OBroadcastHelper& _rBHelper
61 public:
62 void setIsInitialized() { m_bInitialized = true; }
64 bool getEncoding( OUString& _out_rEncoding ) const;
65 bool setEncoding( std::u16string_view _rEncoding );
67 rtl_TextEncoding
68 getTextEncoding() const { return m_eEncoding; }
70 const css::uno::Reference< css::logging::XLogFormatter >&
71 getFormatter() const { return m_xFormatter; }
72 void
73 setFormatter( const css::uno::Reference< css::logging::XLogFormatter >& _rxFormatter )
75 m_xFormatter = _rxFormatter;
78 sal_Int32
79 getLevel() const { return m_nLevel; }
80 void
81 setLevel( const sal_Int32 _nLevel )
83 m_nLevel = _nLevel;
86 /** prepares implementation of a public accessible method of a log handler
88 <code>enterMethod</code> does the following things:
89 <ul><li>It acquires the mutex given in the constructor.</li>
90 <li>It checks whether the component is already initialized, and throws an exception if not os.</li>
91 <li>It checks whether the component is already disposed, and throws an exception if not os.</li>
92 <li>It creates a default formatter (PlainTextFormatter), if no formatter exists at this time.</li>
93 </ul>
95 void enterMethod();
97 /** formats a record for publishing it
99 The method first checks whether the records log level is greater or equal our own
100 log level. If not, <FALSE/> is returned.
102 Second, our formatter is used to create a unicode string from the log record. If an error occurs
103 during this, e.g. if the formatter is <NULL/> or throws an exception during formatting,
104 <FALSE/> is returned.
106 Finally, the unicode string is encoded into a byte string, using our encoding setting. Then,
107 <TRUE/> is returned.
109 bool formatForPublishing( const css::logging::LogRecord& _rRecord, OString& _out_rEntry ) const;
111 /** retrieves our formatter's heading, encoded with our encoding
113 @return <TRUE/> in case of success, <FALSE/> if any error occurred
115 bool getEncodedHead( OString& _out_rHead ) const;
117 /** retrieves our formatter's tail, encoded with our encoding
119 @return <TRUE/> in case of success, <FALSE/> if any error occurred
121 bool getEncodedTail( OString& _out_rTail ) const;
123 /** initializes the instance from a collection of named settings
125 The recognized named settings are <code>Encoding</code>, <code>Formatter</code>, and <code>Level</code>,
126 which initialize the respective attributes.
128 Settings which are recognized are remove from the given collection. This allows
129 the caller to determine whether or not the collection contained any unsupported
130 items, and react appropriately.
132 @throws IllegalArgumentException
133 if one of the values in the collection is of wrong type.
135 void initFromSettings( const ::comphelper::NamedValueCollection& _rSettings );
139 } // namespace logging
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */