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 <boost/optional.hpp>
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 
50 class ProgressLogImpl : public ::dp_misc::MutexHolder, public t_log_helper
51 {
52  std::unique_ptr<comphelper::EventLogger> m_logger;
53 
54 protected:
55  virtual void SAL_CALL disposing() override;
56  virtual ~ProgressLogImpl() override;
57 
58 public:
59  ProgressLogImpl( Sequence<Any> const & args,
61 
62  // XProgressHandler
63  virtual void SAL_CALL push( Any const & Status ) override;
64  virtual void SAL_CALL update( Any const & Status ) override;
65  virtual void SAL_CALL pop() override;
66 };
67 
68 
70 {
71 }
72 
73 
75 {
76 }
77 
78 
80  Sequence<Any> const & /* args */,
82  : t_log_helper( getMutex() )
83 {
84  // Use the logger created by unopkg app
85  m_logger.reset(new comphelper::EventLogger(xContext, "unopkg"));
86 }
87 
88 // XProgressHandler
89 
90 void ProgressLogImpl::push( Any const & Status )
91 {
92  update( Status );
93 }
94 
95 void ProgressLogImpl::update( Any const & Status )
96 {
97  if (! Status.hasValue())
98  return;
99 
100  OUStringBuffer buf;
101 
102  OUString msg;
103  sal_Int32 logLevel = LogLevel::INFO;
104  if (Status >>= msg) {
105  buf.append( msg );
106  }
107  else {
108  logLevel = LogLevel::SEVERE;
109  buf.append( ::comphelper::anyToString(Status) );
110  }
111  m_logger->log(logLevel, buf.makeStringAndClear());
112 }
113 
114 
116 {
117 }
118 
119 namespace sdecl = comphelper::service_decl;
122  servicePLI,
123  // a private one:
124  "com.sun.star.comp.deployment.ProgressLog",
125  "com.sun.star.comp.deployment.ProgressLog" );
126 
127 } // namespace dp_log
128 
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sdecl::class_< ProgressLogImpl, sdecl::with_args< true > > const servicePLI
Definition: dp_log.cxx:120
virtual void SAL_CALL pop() override
Definition: dp_log.cxx:115
::cppu::WeakComponentImplHelper< ucb::XProgressHandler > t_log_helper
Definition: dp_log.cxx:47
ProgressLogImpl(Sequence< Any > const &args, Reference< XComponentContext > const &xContext)
Definition: dp_log.cxx:79
std::unique_ptr< comphelper::EventLogger > m_logger
Definition: dp_log.cxx:52
virtual ~ProgressLogImpl() override
Definition: dp_log.cxx:69
virtual void SAL_CALL update(Any const &Status) override
Definition: dp_log.cxx:95
virtual void SAL_CALL push(Any const &Status) override
Definition: dp_log.cxx:90
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:1817
virtual void SAL_CALL disposing() override
Definition: dp_log.cxx:74
OUString anyToString(uno::Any const &value)
::osl::Mutex & getMutex()