Line data Source code
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 : #include "unxsplash.hxx"
21 : #include <stdio.h>
22 : #include <osl/process.h>
23 : #include <cppuhelper/implementationentry.hxx>
24 : #include <cppuhelper/supportsservice.hxx>
25 : #include <rtl/ustrbuf.hxx>
26 : #include <rtl/math.hxx>
27 :
28 : #define PIPE_ARG "--splash-pipe="
29 :
30 : namespace desktop
31 : {
32 0 : UnxSplashScreen::UnxSplashScreen( const Reference< uno::XComponentContext >& xCtx )
33 : : m_xCtx( xCtx ),
34 0 : m_pOutFd( NULL )
35 : {
36 0 : }
37 :
38 0 : UnxSplashScreen::~UnxSplashScreen()
39 : {
40 : #if OSL_DEBUG_LEVEL > 1
41 : fprintf( stderr, "UnxSplashScreen::~UnxSplashScreen()\n" );
42 : #endif
43 :
44 0 : if ( m_pOutFd )
45 : {
46 0 : fclose( m_pOutFd );
47 0 : m_pOutFd = NULL;
48 : }
49 0 : }
50 :
51 0 : void SAL_CALL UnxSplashScreen::start( const OUString& /*aText*/, sal_Int32 /*nRange*/ )
52 : throw ( RuntimeException, std::exception )
53 : {
54 0 : }
55 :
56 0 : void SAL_CALL UnxSplashScreen::end()
57 : throw ( RuntimeException, std::exception )
58 : {
59 : #if OSL_DEBUG_LEVEL > 1
60 : fprintf( stderr, "UnxSplashScreen::end()\n" );
61 : #endif
62 0 : if( !m_pOutFd )
63 0 : return;
64 :
65 0 : fprintf( m_pOutFd, "end\n" );
66 0 : fflush( m_pOutFd );
67 : }
68 :
69 0 : void SAL_CALL UnxSplashScreen::reset()
70 : throw ( RuntimeException, std::exception )
71 : {
72 : #if OSL_DEBUG_LEVEL > 1
73 : fprintf( stderr, "UnxSplashScreen::reset()\n" );
74 : #endif
75 0 : if( !m_pOutFd )
76 0 : return;
77 :
78 0 : fprintf( m_pOutFd, "restart\n" );
79 0 : fflush( m_pOutFd );
80 : }
81 :
82 0 : void SAL_CALL UnxSplashScreen::setText( const OUString& /*aText*/ )
83 : throw ( RuntimeException, std::exception )
84 : {
85 : // TODO?
86 0 : }
87 :
88 0 : void SAL_CALL UnxSplashScreen::setValue( sal_Int32 nValue )
89 : throw ( RuntimeException, std::exception )
90 : {
91 0 : if ( m_pOutFd )
92 : {
93 0 : fprintf( m_pOutFd, "%" SAL_PRIdINT32 "%%\n", nValue );
94 0 : fflush( m_pOutFd );
95 : }
96 0 : }
97 :
98 : // XInitialize
99 : void SAL_CALL
100 0 : UnxSplashScreen::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& )
101 : throw ( RuntimeException, std::exception )
102 : {
103 0 : for ( sal_uInt32 i = 0; i < osl_getCommandArgCount(); i++ )
104 : {
105 0 : OUString aArg;
106 0 : if ( osl_getCommandArg( i, &aArg.pData ) )
107 0 : break;
108 0 : if ( aArg.matchIgnoreAsciiCaseAsciiL( PIPE_ARG, sizeof( PIPE_ARG ) - 1, 0 ) )
109 : {
110 0 : OUString aNum = aArg.copy( sizeof( PIPE_ARG ) - 1 );
111 0 : int fd = aNum.toInt32();
112 0 : m_pOutFd = fdopen( fd, "w" );
113 : #if OSL_DEBUG_LEVEL > 1
114 : fprintf( stderr, "Got argument '--splash-pipe=%d ('%s') (%p)\n",
115 : fd, OUStringToOString( aNum, RTL_TEXTENCODING_UTF8 ).getStr(),
116 : m_pOutFd );
117 : #endif
118 : }
119 0 : }
120 0 : }
121 :
122 0 : OUString UnxSplashScreen::getImplementationName()
123 : throw (css::uno::RuntimeException, std::exception)
124 : {
125 0 : return UnxSplash_getImplementationName();
126 : }
127 :
128 0 : sal_Bool UnxSplashScreen::supportsService(OUString const & ServiceName)
129 : throw (css::uno::RuntimeException, std::exception)
130 : {
131 0 : return cppu::supportsService(this, ServiceName);
132 : }
133 :
134 0 : css::uno::Sequence<OUString> UnxSplashScreen::getSupportedServiceNames()
135 : throw (css::uno::RuntimeException, std::exception)
136 : {
137 0 : return UnxSplash_getSupportedServiceNames();
138 : }
139 :
140 : }
141 :
142 : using namespace desktop;
143 :
144 : // get service instance...
145 0 : static uno::Reference< uno::XInterface > m_xINSTANCE;
146 :
147 0 : uno::Reference< uno::XInterface > UnxSplash_createInstance(const uno::Reference< uno::XComponentContext > & xCtx ) throw( uno::Exception )
148 : {
149 0 : static osl::Mutex m_aMutex;
150 0 : if ( !m_xINSTANCE.is() )
151 : {
152 0 : osl::MutexGuard guard( m_aMutex );
153 0 : if ( !m_xINSTANCE.is() )
154 0 : m_xINSTANCE = (cppu::OWeakObject*) new UnxSplashScreen( xCtx );
155 : }
156 :
157 0 : return m_xINSTANCE;
158 : }
159 :
160 0 : OUString UnxSplash_getImplementationName()
161 : {
162 0 : return OUString( "com.sun.star.office.comp.PipeSplashScreen" );
163 : }
164 :
165 0 : uno::Sequence< OUString > UnxSplash_getSupportedServiceNames() throw()
166 : {
167 0 : const OUString aServiceName( "com.sun.star.office.PipeSplashScreen" );
168 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
169 0 : return aSeq;
170 0 : }
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|