/src/libreoffice/desktop/source/deployment/dp_log.cxx
Line | Count | Source |
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 | | |
21 | | #include <cppuhelper/basemutex.hxx> |
22 | | #include <cppuhelper/compbase.hxx> |
23 | | #include <cppuhelper/supportsservice.hxx> |
24 | | #include <comphelper/anytostring.hxx> |
25 | | #include <comphelper/logging.hxx> |
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 | | |
31 | | using namespace ::com::sun::star; |
32 | | using namespace ::com::sun::star::uno; |
33 | | using namespace ::com::sun::star::logging; |
34 | | |
35 | | namespace dp_log { |
36 | | |
37 | | typedef ::cppu::WeakComponentImplHelper<ucb::XProgressHandler, lang::XServiceInfo> t_log_helper; |
38 | | |
39 | | namespace { |
40 | | |
41 | | class ProgressLogImpl : public cppu::BaseMutex, public t_log_helper |
42 | | { |
43 | | comphelper::EventLogger m_logger; |
44 | | |
45 | | protected: |
46 | | virtual void SAL_CALL disposing() override; |
47 | | virtual ~ProgressLogImpl() override; |
48 | | |
49 | | public: |
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 | | |
66 | | ProgressLogImpl::~ProgressLogImpl() |
67 | 0 | { |
68 | 0 | } |
69 | | |
70 | | |
71 | | void ProgressLogImpl::disposing() |
72 | 0 | { |
73 | 0 | } |
74 | | |
75 | | |
76 | | ProgressLogImpl::ProgressLogImpl( |
77 | | Sequence<Any> const & /* args */, |
78 | | Reference<XComponentContext> const & xContext ) |
79 | 0 | : t_log_helper( m_aMutex ) |
80 | | // Use the logger created by unopkg app |
81 | 0 | , m_logger(xContext, "unopkg") |
82 | 0 | { |
83 | 0 | } |
84 | | |
85 | | // XServiceInfo |
86 | | OUString ProgressLogImpl::getImplementationName() |
87 | 0 | { |
88 | 0 | return u"com.sun.star.comp.deployment.ProgressLog"_ustr; |
89 | 0 | } |
90 | | |
91 | | sal_Bool ProgressLogImpl::supportsService( const OUString& ServiceName ) |
92 | 0 | { |
93 | 0 | return cppu::supportsService(this, ServiceName); |
94 | 0 | } |
95 | | |
96 | | css::uno::Sequence< OUString > ProgressLogImpl::getSupportedServiceNames() |
97 | 0 | { |
98 | | // a private one |
99 | 0 | return { u"com.sun.star.comp.deployment.ProgressLog"_ustr }; |
100 | 0 | } |
101 | | |
102 | | // XProgressHandler |
103 | | |
104 | | void ProgressLogImpl::push( Any const & Status ) |
105 | 0 | { |
106 | 0 | update( Status ); |
107 | 0 | } |
108 | | |
109 | | void ProgressLogImpl::update( Any const & Status ) |
110 | 0 | { |
111 | 0 | if (! Status.hasValue()) |
112 | 0 | return; |
113 | | |
114 | 0 | OUStringBuffer buf; |
115 | |
|
116 | 0 | OUString msg; |
117 | 0 | sal_Int32 logLevel = LogLevel::INFO; |
118 | 0 | if (Status >>= msg) { |
119 | 0 | buf.append( msg ); |
120 | 0 | } |
121 | 0 | else { |
122 | 0 | logLevel = LogLevel::SEVERE; |
123 | 0 | buf.append( ::comphelper::anyToString(Status) ); |
124 | 0 | } |
125 | 0 | m_logger.log(logLevel, buf.makeStringAndClear()); |
126 | 0 | } |
127 | | |
128 | | |
129 | | void ProgressLogImpl::pop() |
130 | 0 | { |
131 | 0 | } |
132 | | |
133 | | } // namespace dp_log |
134 | | |
135 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
136 | | com_sun_star_comp_deployment_ProgressLog_get_implementation( |
137 | | css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args) |
138 | 0 | { |
139 | 0 | return cppu::acquire(new dp_log::ProgressLogImpl(args, context)); |
140 | 0 | } |
141 | | |
142 | | |
143 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |