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 <rtl/strbuf.hxx>
24 #include <sal/log.hxx>
25 #include <osl/time.h>
26 #include <osl/thread.h>
27 #include <cppuhelper/compbase.hxx>
31 #include <comphelper/logging.hxx>
32 #include <com/sun/star/deployment/DeploymentException.hpp>
33 #include <com/sun/star/logging/LogLevel.hpp>
34 #include <com/sun/star/ucb/XProgressHandler.hpp>
35 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
36 #include <com/sun/star/io/IOException.hpp>
37 #include <com/sun/star/io/XSeekable.hpp>
38 #include <stdio.h>
39 #include <o3tl/optional.hxx>
40 
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::logging;
44 
45 namespace dp_log {
46 
47 typedef ::cppu::WeakComponentImplHelper<ucb::XProgressHandler> t_log_helper;
48 
49 namespace {
50 
51 class ProgressLogImpl : public ::dp_misc::MutexHolder, public t_log_helper
52 {
53  std::unique_ptr<comphelper::EventLogger> m_logger;
54 
55 protected:
56  virtual void SAL_CALL disposing() override;
57  virtual ~ProgressLogImpl() override;
58 
59 public:
60  ProgressLogImpl( Sequence<Any> const & args,
62 
63  // XProgressHandler
64  virtual void SAL_CALL push( Any const & Status ) override;
65  virtual void SAL_CALL update( Any const & Status ) override;
66  virtual void SAL_CALL pop() override;
67 };
68 
69 }
70 
71 ProgressLogImpl::~ProgressLogImpl()
72 {
73 }
74 
75 
76 void ProgressLogImpl::disposing()
77 {
78 }
79 
80 
81 ProgressLogImpl::ProgressLogImpl(
82  Sequence<Any> const & /* args */,
84  : t_log_helper( getMutex() )
85 {
86  // Use the logger created by unopkg app
87  m_logger.reset(new comphelper::EventLogger(xContext, "unopkg"));
88 }
89 
90 // XProgressHandler
91 
92 void ProgressLogImpl::push( Any const & Status )
93 {
94  update( Status );
95 }
96 
97 void ProgressLogImpl::update( Any const & Status )
98 {
99  if (! Status.hasValue())
100  return;
101 
102  OUStringBuffer buf;
103 
104  OUString msg;
105  sal_Int32 logLevel = LogLevel::INFO;
106  if (Status >>= msg) {
107  buf.append( msg );
108  }
109  else {
110  logLevel = LogLevel::SEVERE;
111  buf.append( ::comphelper::anyToString(Status) );
112  }
113  m_logger->log(logLevel, buf.makeStringAndClear());
114 }
115 
116 
117 void ProgressLogImpl::pop()
118 {
119 }
120 
121 namespace sdecl = comphelper::service_decl;
124  servicePLI,
125  // a private one:
126  "com.sun.star.comp.deployment.ProgressLog",
127  "com.sun.star.comp.deployment.ProgressLog" );
128 
129 } // namespace dp_log
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sdecl::class_< ProgressLogImpl, sdecl::with_args< true > > const servicePLI
Definition: dp_log.cxx:122
bool update()
Definition: updater.cxx:284
::cppu::WeakComponentImplHelper< ucb::XProgressHandler > t_log_helper
Definition: dp_log.cxx:47
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:2087
std::unique_ptr< comphelper::EventLogger > m_logger
Definition: dp_log.cxx:53
OUString anyToString(uno::Any const &value)
::osl::Mutex & getMutex()