2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-15 17:28:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-12-20 13:20:46 +00:00
|
|
|
|
|
|
|
|
2017-10-23 22:42:42 +02:00
|
|
|
#include <dp_misc.h>
|
|
|
|
#include <dp_services.hxx>
|
2014-06-04 10:55:43 +02:00
|
|
|
#include <rtl/strbuf.hxx>
|
|
|
|
#include <osl/time.h>
|
|
|
|
#include <osl/thread.h>
|
2015-07-22 23:48:08 +09:00
|
|
|
#include <cppuhelper/compbase.hxx>
|
2014-06-04 10:55:43 +02:00
|
|
|
#include <comphelper/anytostring.hxx>
|
|
|
|
#include <comphelper/servicedecl.hxx>
|
|
|
|
#include <comphelper/unwrapargs.hxx>
|
|
|
|
#include <com/sun/star/deployment/DeploymentException.hpp>
|
|
|
|
#include <com/sun/star/ucb/XProgressHandler.hpp>
|
|
|
|
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
|
2017-02-06 17:08:38 +01:00
|
|
|
#include <com/sun/star/io/IOException.hpp>
|
2014-06-04 10:55:43 +02:00
|
|
|
#include <com/sun/star/io/XSeekable.hpp>
|
2006-12-20 13:20:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
|
|
|
|
namespace dp_log {
|
|
|
|
|
2015-07-22 23:48:08 +09:00
|
|
|
typedef ::cppu::WeakComponentImplHelper<ucb::XProgressHandler> t_log_helper;
|
2006-12-20 13:20:46 +00:00
|
|
|
|
2014-02-25 18:19:04 +01:00
|
|
|
|
2006-12-20 13:20:46 +00:00
|
|
|
class ProgressLogImpl : public ::dp_misc::MutexHolder, public t_log_helper
|
|
|
|
{
|
|
|
|
Reference<io::XOutputStream> m_xLogFile;
|
|
|
|
sal_Int32 m_log_level;
|
|
|
|
void log_write( OString const & text );
|
|
|
|
|
|
|
|
protected:
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void SAL_CALL disposing() override;
|
2016-09-13 13:09:01 +02:00
|
|
|
virtual ~ProgressLogImpl() override;
|
2006-12-20 13:20:46 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
ProgressLogImpl( Sequence<Any> const & args,
|
|
|
|
Reference<XComponentContext> const & xContext );
|
|
|
|
|
|
|
|
// XProgressHandler
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL push( Any const & Status ) override;
|
|
|
|
virtual void SAL_CALL update( Any const & Status ) override;
|
|
|
|
virtual void SAL_CALL pop() override;
|
2006-12-20 13:20:46 +00:00
|
|
|
};
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2006-12-20 13:20:46 +00:00
|
|
|
ProgressLogImpl::~ProgressLogImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2006-12-20 13:20:46 +00:00
|
|
|
void ProgressLogImpl::disposing()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (m_xLogFile.is()) {
|
|
|
|
m_xLogFile->closeOutput();
|
|
|
|
m_xLogFile.clear();
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 00:19:44 +09:00
|
|
|
catch (const Exception & exc) {
|
2017-09-29 16:21:54 +02:00
|
|
|
SAL_WARN( "desktop", exc );
|
2006-12-20 13:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2006-12-20 13:20:46 +00:00
|
|
|
ProgressLogImpl::ProgressLogImpl(
|
|
|
|
Sequence<Any> const & args,
|
|
|
|
Reference<XComponentContext> const & xContext )
|
|
|
|
: t_log_helper( getMutex() ),
|
|
|
|
m_log_level( 0 )
|
|
|
|
{
|
|
|
|
OUString log_file;
|
|
|
|
boost::optional< Reference<task::XInteractionHandler> > interactionHandler;
|
|
|
|
comphelper::unwrapArgs( args, log_file, interactionHandler );
|
|
|
|
|
2012-11-02 17:46:30 +02:00
|
|
|
Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess( ucb::SimpleFileAccess::create(xContext) );
|
2006-12-20 13:20:46 +00:00
|
|
|
// optional ia handler:
|
|
|
|
if (interactionHandler)
|
|
|
|
xSimpleFileAccess->setInteractionHandler( *interactionHandler );
|
|
|
|
|
|
|
|
m_xLogFile.set(
|
|
|
|
xSimpleFileAccess->openFileWrite( log_file ), UNO_QUERY_THROW );
|
|
|
|
Reference<io::XSeekable> xSeekable( m_xLogFile, UNO_QUERY_THROW );
|
|
|
|
xSeekable->seek( xSeekable->getLength() );
|
|
|
|
|
|
|
|
// write log stamp
|
|
|
|
OStringBuffer buf;
|
2012-12-30 11:07:28 +01:00
|
|
|
buf.append( "###### Progress log entry " );
|
2016-04-20 10:34:01 +02:00
|
|
|
TimeValue aStartTime, tLocal;
|
2006-12-20 13:20:46 +00:00
|
|
|
oslDateTime date_time;
|
2016-04-20 10:34:01 +02:00
|
|
|
if (osl_getSystemTime( &aStartTime ) &&
|
|
|
|
osl_getLocalTimeFromSystemTime( &aStartTime, &tLocal ) &&
|
2006-12-20 13:20:46 +00:00
|
|
|
osl_getDateTimeFromTimeValue( &tLocal, &date_time ))
|
|
|
|
{
|
|
|
|
char ar[ 128 ];
|
|
|
|
snprintf(
|
|
|
|
ar, sizeof (ar),
|
|
|
|
"%04d-%02d-%02d %02d:%02d:%02d ",
|
|
|
|
date_time.Year, date_time.Month, date_time.Day,
|
|
|
|
date_time.Hours, date_time.Minutes, date_time.Seconds );
|
|
|
|
buf.append( ar );
|
|
|
|
}
|
2012-12-30 11:07:28 +01:00
|
|
|
buf.append( "######\n" );
|
2006-12-20 13:20:46 +00:00
|
|
|
log_write( buf.makeStringAndClear() );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2006-12-20 13:20:46 +00:00
|
|
|
void ProgressLogImpl::log_write( OString const & text )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (m_xLogFile.is()) {
|
|
|
|
m_xLogFile->writeBytes(
|
|
|
|
Sequence< sal_Int8 >(
|
|
|
|
reinterpret_cast< sal_Int8 const * >(text.getStr()),
|
|
|
|
text.getLength() ) );
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 00:19:44 +09:00
|
|
|
catch (const io::IOException & exc) {
|
2017-09-29 16:21:54 +02:00
|
|
|
SAL_WARN( "desktop", exc );
|
2006-12-20 13:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XProgressHandler
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2006-12-20 13:20:46 +00:00
|
|
|
void ProgressLogImpl::push( Any const & Status )
|
|
|
|
{
|
|
|
|
update( Status );
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( m_log_level >= 0 );
|
2006-12-20 13:20:46 +00:00
|
|
|
++m_log_level;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2006-12-20 13:20:46 +00:00
|
|
|
void ProgressLogImpl::update( Any const & Status )
|
|
|
|
{
|
|
|
|
if (! Status.hasValue())
|
|
|
|
return;
|
|
|
|
|
|
|
|
OUStringBuffer buf;
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( m_log_level >= 0 );
|
2006-12-20 13:20:46 +00:00
|
|
|
for ( sal_Int32 n = 0; n < m_log_level; ++n )
|
2013-12-20 14:23:33 +02:00
|
|
|
buf.append( ' ' );
|
2006-12-20 13:20:46 +00:00
|
|
|
|
|
|
|
OUString msg;
|
|
|
|
if (Status >>= msg) {
|
|
|
|
buf.append( msg );
|
|
|
|
}
|
|
|
|
else {
|
2015-08-31 08:03:47 +02:00
|
|
|
buf.append( "ERROR: " );
|
2006-12-20 13:20:46 +00:00
|
|
|
buf.append( ::comphelper::anyToString(Status) );
|
|
|
|
}
|
2015-08-31 08:03:47 +02:00
|
|
|
buf.append( "\n" );
|
2006-12-20 13:20:46 +00:00
|
|
|
log_write( OUStringToOString(
|
|
|
|
buf.makeStringAndClear(), osl_getThreadTextEncoding() ) );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void ProgressLogImpl::pop()
|
2006-12-20 13:20:46 +00:00
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( m_log_level > 0 );
|
2006-12-20 13:20:46 +00:00
|
|
|
--m_log_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace sdecl = comphelper::service_decl;
|
2017-01-09 15:43:49 +01:00
|
|
|
sdecl::class_<ProgressLogImpl, sdecl::with_args<true> > const servicePLI;
|
|
|
|
sdecl::ServiceDecl const serviceDecl(
|
2006-12-20 13:20:46 +00:00
|
|
|
servicePLI,
|
|
|
|
// a private one:
|
|
|
|
"com.sun.star.comp.deployment.ProgressLog",
|
|
|
|
"com.sun.star.comp.deployment.ProgressLog" );
|
|
|
|
|
|
|
|
} // namespace dp_log
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|