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 <cppuhelper/compbase.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 ::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  // 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 {
68 }
69 
70 
71 void ProgressLogImpl::disposing()
72 {
73 }
74 
75 
76 ProgressLogImpl::ProgressLogImpl(
77  Sequence<Any> const & /* args */,
79  : t_log_helper( getMutex() )
80 {
81  // Use the logger created by unopkg app
82  m_logger.reset(new comphelper::EventLogger(xContext, "unopkg"));
83 }
84 
85 // XServiceInfo
86 OUString ProgressLogImpl::getImplementationName()
87 {
88  return "com.sun.star.comp.deployment.ProgressLog";
89 }
90 
91 sal_Bool ProgressLogImpl::supportsService( const OUString& ServiceName )
92 {
93  return cppu::supportsService(this, ServiceName);
94 }
95 
96 css::uno::Sequence< OUString > ProgressLogImpl::getSupportedServiceNames()
97 {
98  // a private one
99  return { "com.sun.star.comp.deployment.ProgressLog" };
100 }
101 
102 // XProgressHandler
103 
104 void ProgressLogImpl::push( Any const & Status )
105 {
106  update( Status );
107 }
108 
109 void 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 
129 void ProgressLogImpl::pop()
130 {
131 }
132 
133 } // namespace dp_log
134 
135 extern "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: */
bool update()
Definition: updater.cxx:286
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
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
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2245
::cppu::WeakComponentImplHelper< ucb::XProgressHandler, lang::XServiceInfo > t_log_helper
Definition: dp_log.cxx:37
std::unique_ptr< comphelper::EventLogger > m_logger
Definition: dp_log.cxx:43
OUString anyToString(uno::Any const &value)
::osl::Mutex & getMutex()