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 
21 #include <dp_misc.h>
22 #include <dp_services.hxx>
23 #include <cppuhelper/compbase.hxx>
26 #include <comphelper/logging.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <com/sun/star/logging/LogLevel.hpp>
29 #include <com/sun/star/ucb/XProgressHandler.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> t_log_helper;
38 
39 namespace {
40 
41 class ProgressLogImpl : public ::dp_misc::MutexHolder, public t_log_helper
42 {
43  std::unique_ptr<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,
52 
53  // XProgressHandler
54  virtual void SAL_CALL push( Any const & Status ) override;
55  virtual void SAL_CALL update( Any const & Status ) override;
56  virtual void SAL_CALL pop() override;
57 };
58 
59 }
60 
61 ProgressLogImpl::~ProgressLogImpl()
62 {
63 }
64 
65 
66 void ProgressLogImpl::disposing()
67 {
68 }
69 
70 
71 ProgressLogImpl::ProgressLogImpl(
72  Sequence<Any> const & /* args */,
74  : t_log_helper( getMutex() )
75 {
76  // Use the logger created by unopkg app
77  m_logger.reset(new comphelper::EventLogger(xContext, "unopkg"));
78 }
79 
80 // XProgressHandler
81 
82 void ProgressLogImpl::push( Any const & Status )
83 {
84  update( Status );
85 }
86 
87 void ProgressLogImpl::update( Any const & Status )
88 {
89  if (! Status.hasValue())
90  return;
91 
92  OUStringBuffer buf;
93 
94  OUString msg;
95  sal_Int32 logLevel = LogLevel::INFO;
96  if (Status >>= msg) {
97  buf.append( msg );
98  }
99  else {
100  logLevel = LogLevel::SEVERE;
101  buf.append( ::comphelper::anyToString(Status) );
102  }
103  m_logger->log(logLevel, buf.makeStringAndClear());
104 }
105 
106 
107 void ProgressLogImpl::pop()
108 {
109 }
110 
111 namespace sdecl = comphelper::service_decl;
114  servicePLI,
115  // a private one:
116  "com.sun.star.comp.deployment.ProgressLog",
117  "com.sun.star.comp.deployment.ProgressLog" );
118 
119 } // namespace dp_log
120 
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sdecl::class_< ProgressLogImpl, sdecl::with_args< true > > const servicePLI
Definition: dp_log.cxx:112
bool update()
Definition: updater.cxx:284
::cppu::WeakComponentImplHelper< ucb::XProgressHandler > t_log_helper
Definition: dp_log.cxx:37
sdecl::ServiceDecl const serviceDecl(servicePLI,"com.sun.star.comp.deployment.ProgressLog","com.sun.star.comp.deployment.ProgressLog")
Definition: dp_services.hxx:22
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2105
std::unique_ptr< comphelper::EventLogger > m_logger
Definition: dp_log.cxx:43
OUString anyToString(uno::Any const &value)
::osl::Mutex & getMutex()