1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
32 #include <sys/types.h>
35 #include <osl/file.hxx>
36 #include <osl/thread.h>
37 #include <rtl/bootstrap.hxx>
39 #include <plugin/impl.hxx>
41 int UnxPluginComm::nConnCounter
= 0;
43 UnxPluginComm::UnxPluginComm(
44 const String
& /*mimetype*/,
45 const String
& library
,
50 PluginComm( ::rtl::OUStringToOString( library
, osl_getThreadTextEncoding() ), false ),
51 PluginConnector( nDescriptor2
)
55 sprintf( pWindow
, "%d", (int)aParent
);
56 sprintf( pDesc
, "%d", nDescriptor1
);
57 ByteString
aLib( library
, osl_getThreadTextEncoding() );
59 if (!getPluginappPath(&path
)) {
60 fprintf( stderr
, "cannot construct path to pluginapp.bin\n" );
66 pArgs
[0] = path
.getStr();
68 pArgs
[2] = aLib
.GetBuffer();
72 #if OSL_DEBUG_LEVEL > 1
74 fprintf( stderr
, "Try to launch: %s %s %s %s, descriptors are %d, %d\n", pArgs
[0], pArgs
[1], pArgs
[2], pArgs
[3], nDescriptor1
, nDescriptor2
);
77 if( ! ( m_nCommPID
= fork() ) )
79 execvp( pArgs
[0], const_cast< char ** >(pArgs
) );
80 fprintf( stderr
, "Error: could not exec %s\n", pArgs
[0] );
84 if( m_nCommPID
!= -1 )
86 // wait for pluginapp.bin to start up
87 if( ! WaitForMessage( 5000 ) )
89 fprintf( stderr
, "Timeout on command: %s %s %s %s\n", pArgs
[0], pArgs
[1], pArgs
[2], pArgs
[3] );
94 MediatorMessage
* pMessage
= GetNextMessage( sal_True
);
95 Respond( pMessage
->m_nID
,
96 const_cast<char*>("init ack"),8,
104 UnxPluginComm::~UnxPluginComm()
107 if( m_nCommPID
!= -1 && m_nCommPID
!= 0 )
109 int status
= 16777216;
110 pid_t nExit
= waitpid( m_nCommPID
, &status
, WUNTRACED
);
111 #if OSL_DEBUG_LEVEL > 1
112 fprintf( stderr
, "child %d (plugin app child %d) exited with status %d\n", (int)nExit
, (int)m_nCommPID
, (int)WEXITSTATUS(status
) );
119 bool UnxPluginComm::getPluginappPath(rtl::OString
* path
) {
120 OSL_ASSERT(path
!= NULL
);
122 RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program/pluginapp.bin"));
123 rtl::Bootstrap::expandMacros(p
);
125 (osl::FileBase::getSystemPathFromFileURL(p
, p
) ==
126 osl::FileBase::E_None
) &&
128 path
, osl_getThreadTextEncoding(),
129 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
130 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
));