LibreOffice Module desktop (master) 1
dp_log.cxx
Go to the documentation of this file.
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
26#include <rtl/ustrbuf.hxx>
27#include <com/sun/star/logging/LogLevel.hpp>
28#include <com/sun/star/ucb/XProgressHandler.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30
31using namespace ::com::sun::star;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::logging;
34
35namespace dp_log {
36
37typedef ::cppu::WeakComponentImplHelper<ucb::XProgressHandler, lang::XServiceInfo> t_log_helper;
38
39namespace {
40
41class ProgressLogImpl : public cppu::BaseMutex, public t_log_helper
42{
44
45protected:
46 virtual void SAL_CALL disposing() override;
47 virtual ~ProgressLogImpl() override;
48
49public:
50 ProgressLogImpl( Sequence<Any> const & args,
51 Reference<XComponentContext> const & xContext );
52
53 // XServiceInfo
54 virtual OUString SAL_CALL getImplementationName() override;
55 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
56 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
57
58 // XProgressHandler
59 virtual void SAL_CALL push( Any const & Status ) override;
60 virtual void SAL_CALL update( Any const & Status ) override;
61 virtual void SAL_CALL pop() override;
62};
63
64}
65
66ProgressLogImpl::~ProgressLogImpl()
67{
68}
69
70
71void ProgressLogImpl::disposing()
72{
73}
74
75
76ProgressLogImpl::ProgressLogImpl(
77 Sequence<Any> const & /* args */,
78 Reference<XComponentContext> const & xContext )
80 // Use the logger created by unopkg app
81 , m_logger(xContext, "unopkg")
82{
83}
84
85// XServiceInfo
86OUString ProgressLogImpl::getImplementationName()
87{
88 return "com.sun.star.comp.deployment.ProgressLog";
89}
90
91sal_Bool ProgressLogImpl::supportsService( const OUString& ServiceName )
92{
93 return cppu::supportsService(this, ServiceName);
94}
95
96css::uno::Sequence< OUString > ProgressLogImpl::getSupportedServiceNames()
97{
98 // a private one
99 return { "com.sun.star.comp.deployment.ProgressLog" };
100}
101
102// XProgressHandler
103
104void ProgressLogImpl::push( Any const & Status )
105{
106 update( Status );
107}
108
109void ProgressLogImpl::update( Any const & Status )
110{
111 if (! Status.hasValue())
112 return;
113
114 OUStringBuffer buf;
115
116 OUString msg;
117 sal_Int32 logLevel = LogLevel::INFO;
118 if (Status >>= msg) {
119 buf.append( msg );
120 }
121 else {
122 logLevel = LogLevel::SEVERE;
123 buf.append( ::comphelper::anyToString(Status) );
124 }
125 m_logger.log(logLevel, buf.makeStringAndClear());
126}
127
128
129void ProgressLogImpl::pop()
130{
131}
132
133} // namespace dp_log
134
135extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
137 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
138{
139 return cppu::acquire(new dp_log::ProgressLogImpl(args, context));
140}
141
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void log(const sal_Int32 _nLogLevel, const OUString &rMessage) const
comphelper::EventLogger m_logger
Definition: dp_log.cxx:43
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_deployment_ProgressLog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
Definition: dp_log.cxx:136
std::mutex m_aMutex
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2642
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
::cppu::WeakComponentImplHelper< ucb::XProgressHandler, lang::XServiceInfo > t_log_helper
Definition: dp_log.cxx:37
args
unsigned char sal_Bool
bool update()
Definition: updater.cxx:286