update credits
[LibreOffice.git] / desktop / unx / splash / unxsplash.cxx
blob35c20b1a8c553ecb16316850e499c18d4e483080
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "unxsplash.hxx"
21 #include <stdio.h>
22 #include <osl/process.h>
23 #include <com/sun/star/registry/XRegistryKey.hpp>
24 #include <cppuhelper/implementationentry.hxx>
25 #include <rtl/logfile.hxx>
26 #include <rtl/ustrbuf.hxx>
27 #include <rtl/math.hxx>
29 #define PIPE_ARG "--splash-pipe="
31 using namespace ::rtl;
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::registry;
34 using namespace ::com::sun::star::uno;
36 namespace desktop
38 UnxSplashScreen::UnxSplashScreen( const Reference< uno::XComponentContext >& xCtx )
39 : m_xCtx( xCtx ),
40 m_pOutFd( NULL )
44 UnxSplashScreen::~UnxSplashScreen()
46 #if OSL_DEBUG_LEVEL > 1
47 fprintf( stderr, "UnxSplashScreen::~UnxSplashScreen()\n" );
48 #endif
50 if ( m_pOutFd )
52 fclose( m_pOutFd );
53 m_pOutFd = NULL;
57 void SAL_CALL UnxSplashScreen::start( const OUString& /*aText*/, sal_Int32 /*nRange*/ )
58 throw ( RuntimeException )
62 void SAL_CALL UnxSplashScreen::end()
63 throw ( RuntimeException )
65 #if OSL_DEBUG_LEVEL > 1
66 fprintf( stderr, "UnxSplashScreen::end()\n" );
67 #endif
68 if( !m_pOutFd )
69 return;
71 fprintf( m_pOutFd, "end\n" );
72 fflush( m_pOutFd );
75 void SAL_CALL UnxSplashScreen::reset()
76 throw ( RuntimeException )
78 #if OSL_DEBUG_LEVEL > 1
79 fprintf( stderr, "UnxSplashScreen::reset()\n" );
80 #endif
81 if( !m_pOutFd )
82 return;
84 fprintf( m_pOutFd, "restart\n" );
85 fflush( m_pOutFd );
88 void SAL_CALL UnxSplashScreen::setText( const OUString& /*aText*/ )
89 throw ( RuntimeException )
91 // TODO?
94 void SAL_CALL UnxSplashScreen::setValue( sal_Int32 nValue )
95 throw ( RuntimeException )
97 if ( m_pOutFd )
99 fprintf( m_pOutFd, "%" SAL_PRIdINT32 "%%\n", nValue );
100 fflush( m_pOutFd );
104 // XInitialize
105 void SAL_CALL
106 UnxSplashScreen::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& )
107 throw ( RuntimeException )
109 for ( sal_uInt32 i = 0; i < osl_getCommandArgCount(); i++ )
111 OUString aArg;
112 if ( osl_getCommandArg( i, &aArg.pData ) )
113 break;
114 if ( aArg.matchIgnoreAsciiCaseAsciiL( PIPE_ARG, sizeof( PIPE_ARG ) - 1, 0 ) )
116 OUString aNum = aArg.copy( sizeof( PIPE_ARG ) - 1 );
117 int fd = aNum.toInt32();
118 m_pOutFd = fdopen( fd, "w" );
119 #if OSL_DEBUG_LEVEL > 1
120 fprintf( stderr, "Got argument '--splash-pipe=%d ('%s') (%p)\n",
121 fd, OUStringToOString( aNum, RTL_TEXTENCODING_UTF8 ).getStr(),
122 m_pOutFd );
123 #endif
129 using namespace desktop;
131 // get service instance...
132 static uno::Reference< uno::XInterface > m_xINSTANCE;
134 uno::Reference< uno::XInterface > SAL_CALL UnxSplash_createInstance(const uno::Reference< uno::XComponentContext > & xCtx ) throw( uno::Exception )
136 static osl::Mutex m_aMutex;
137 if ( !m_xINSTANCE.is() )
139 osl::MutexGuard guard( m_aMutex );
140 if ( !m_xINSTANCE.is() )
141 m_xINSTANCE = (cppu::OWeakObject*) new UnxSplashScreen( xCtx );
144 return m_xINSTANCE;
147 OUString UnxSplash_getImplementationName()
149 return OUString( "com.sun.star.office.comp.PipeSplashScreen" );
152 uno::Sequence< OUString > SAL_CALL UnxSplash_getSupportedServiceNames() throw()
154 const OUString aServiceName( "com.sun.star.office.PipeSplashScreen" );
155 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
156 return aSeq;
159 ::cppu::ImplementationEntry aEntries[] =
162 UnxSplash_createInstance, UnxSplash_getImplementationName,
163 UnxSplash_getSupportedServiceNames,
164 ::cppu::createSingleComponentFactory,
165 0, 0
167 { 0, 0, 0, 0, 0, 0 }
170 extern "C"
173 SAL_DLLPUBLIC_EXPORT void* SAL_CALL splash_component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* pRegistryKey )
175 return ::cppu::component_getFactoryHelper( pImplName, pServiceManager,
176 pRegistryKey, aEntries );
179 } // extern "C"
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */