Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * Copyright 2010, Novell Inc.
5 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
6 : : *
7 : : * OpenOffice.org - a multi-platform office productivity suite
8 : : *
9 : : * This file is part of OpenOffice.org.
10 : : *
11 : : * OpenOffice.org is free software: you can redistribute it and/or modify
12 : : * it under the terms of the GNU Lesser General Public License version 3
13 : : * only, as published by the Free Software Foundation.
14 : : *
15 : : * OpenOffice.org is distributed in the hope that it will be useful,
16 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : : * GNU Lesser General Public License version 3 for more details
19 : : * (a copy is included in the LICENSE file that accompanied this code).
20 : : *
21 : : * You should have received a copy of the GNU Lesser General Public License
22 : : * version 3 along with OpenOffice.org. If not, see
23 : : * <http://www.openoffice.org/license.html>
24 : : * for a copy of the LGPLv3 License.
25 : : *
26 : : * Contributor(s): Jan Holesovsky <kendy@novell.com>
27 : : *
28 : : ************************************************************************/
29 : : #include "unxsplash.hxx"
30 : : #include <stdio.h>
31 : : #include <unotools/bootstrap.hxx>
32 : : #include <osl/process.h>
33 : : #include <tools/stream.hxx>
34 : : #include <sfx2/sfx.hrc>
35 : : #include <com/sun/star/registry/XRegistryKey.hpp>
36 : : #include <cppuhelper/implementationentry.hxx>
37 : : #include <rtl/logfile.hxx>
38 : : #include <rtl/ustrbuf.hxx>
39 : : #include <rtl/math.hxx>
40 : :
41 : : #define PIPE_ARG "--splash-pipe="
42 : :
43 : : using namespace ::rtl;
44 : : using namespace ::com::sun::star;
45 : : using namespace ::com::sun::star::registry;
46 : :
47 : : namespace desktop
48 : : {
49 : 0 : UnxSplashScreen::UnxSplashScreen( const Reference< uno::XComponentContext >& xCtx )
50 : : : m_xCtx( xCtx ),
51 : 0 : m_pOutFd( NULL )
52 : : {
53 : 0 : }
54 : :
55 : 0 : UnxSplashScreen::~UnxSplashScreen()
56 : : {
57 : : #if OSL_DEBUG_LEVEL > 1
58 : : fprintf( stderr, "UnxSplashScreen::~UnxSplashScreen()\n" );
59 : : #endif
60 : :
61 : 0 : if ( m_pOutFd )
62 : : {
63 : 0 : fclose( m_pOutFd );
64 : 0 : m_pOutFd = NULL;
65 : : }
66 : 0 : }
67 : :
68 : 0 : void SAL_CALL UnxSplashScreen::start( const OUString& /*aText*/, sal_Int32 /*nRange*/ )
69 : : throw ( RuntimeException )
70 : : {
71 : 0 : }
72 : :
73 : 0 : void SAL_CALL UnxSplashScreen::end()
74 : : throw ( RuntimeException )
75 : : {
76 : : #if OSL_DEBUG_LEVEL > 1
77 : : fprintf( stderr, "UnxSplashScreen::end()\n" );
78 : : #endif
79 : 0 : if( !m_pOutFd )
80 : 0 : return;
81 : :
82 : 0 : fprintf( m_pOutFd, "end\n" );
83 : 0 : fflush( m_pOutFd );
84 : : }
85 : :
86 : 0 : void SAL_CALL UnxSplashScreen::reset()
87 : : throw ( RuntimeException )
88 : : {
89 : : #if OSL_DEBUG_LEVEL > 1
90 : : fprintf( stderr, "UnxSplashScreen::reset()\n" );
91 : : #endif
92 : 0 : if( !m_pOutFd )
93 : 0 : return;
94 : :
95 : 0 : fprintf( m_pOutFd, "restart\n" );
96 : 0 : fflush( m_pOutFd );
97 : : }
98 : :
99 : 0 : void SAL_CALL UnxSplashScreen::setText( const OUString& /*aText*/ )
100 : : throw ( RuntimeException )
101 : : {
102 : : // TODO?
103 : 0 : }
104 : :
105 : 0 : void SAL_CALL UnxSplashScreen::setValue( sal_Int32 nValue )
106 : : throw ( RuntimeException )
107 : : {
108 : 0 : if ( m_pOutFd )
109 : : {
110 : 0 : fprintf( m_pOutFd, "%" SAL_PRIdINT32 "%%\n", nValue );
111 : 0 : fflush( m_pOutFd );
112 : : }
113 : 0 : }
114 : :
115 : : // XInitialize
116 : : void SAL_CALL
117 : 0 : UnxSplashScreen::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& )
118 : : throw ( RuntimeException )
119 : : {
120 : 0 : for ( sal_uInt32 i = 0; i < osl_getCommandArgCount(); i++ )
121 : : {
122 : 0 : rtl::OUString aArg;
123 : 0 : if ( osl_getCommandArg( i, &aArg.pData ) )
124 : : break;
125 : 0 : if ( aArg.matchIgnoreAsciiCaseAsciiL( PIPE_ARG, sizeof( PIPE_ARG ) - 1, 0 ) )
126 : : {
127 : 0 : OUString aNum = aArg.copy( sizeof( PIPE_ARG ) - 1 );
128 : 0 : int fd = aNum.toInt32();
129 : 0 : m_pOutFd = fdopen( fd, "w" );
130 : : #if OSL_DEBUG_LEVEL > 1
131 : : fprintf( stderr, "Got argument '--splash-pipe=%d ('%s') (%p)\n",
132 : : fd, rtl::OUStringToOString( aNum, RTL_TEXTENCODING_UTF8 ).getStr(),
133 : : m_pOutFd );
134 : : #endif
135 : : }
136 : 0 : }
137 : 0 : }
138 : : }
139 : :
140 : : using namespace desktop;
141 : :
142 : : // get service instance...
143 : 0 : static uno::Reference< uno::XInterface > m_xINSTANCE;
144 : :
145 : 0 : uno::Reference< uno::XInterface > SAL_CALL UnxSplash_createInstance(const uno::Reference< uno::XComponentContext > & xCtx ) throw( uno::Exception )
146 : : {
147 : 0 : static osl::Mutex m_aMutex;
148 : 0 : if ( !m_xINSTANCE.is() )
149 : : {
150 : 0 : osl::MutexGuard guard( m_aMutex );
151 : 0 : if ( !m_xINSTANCE.is() )
152 : 0 : m_xINSTANCE = (cppu::OWeakObject*) new UnxSplashScreen( xCtx );
153 : : }
154 : :
155 : 0 : return m_xINSTANCE;
156 : : }
157 : :
158 : 0 : OUString UnxSplash_getImplementationName()
159 : : {
160 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.office.comp.PipeSplashScreen" ) );
161 : : }
162 : :
163 : 0 : uno::Sequence< OUString > SAL_CALL UnxSplash_getSupportedServiceNames() throw()
164 : : {
165 : 0 : const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.office.PipeSplashScreen" ) );
166 : 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
167 : 0 : return aSeq;
168 : : }
169 : :
170 : : ::cppu::ImplementationEntry aEntries[] =
171 : : {
172 : : {
173 : : UnxSplash_createInstance, UnxSplash_getImplementationName,
174 : : UnxSplash_getSupportedServiceNames,
175 : : ::cppu::createSingleComponentFactory,
176 : : 0, 0
177 : : },
178 : : { 0, 0, 0, 0, 0, 0 }
179 : : };
180 : :
181 : : extern "C"
182 : : {
183 : :
184 : 0 : SAL_DLLPUBLIC_EXPORT void* SAL_CALL splash_component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* pRegistryKey )
185 : : {
186 : : return ::cppu::component_getFactoryHelper( pImplName, pServiceManager,
187 : 0 : pRegistryKey, aEntries );
188 : : }
189 : :
190 : 0 : } // extern "C"
191 : :
192 : :
193 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|