1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sysplug.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
35 #include <sys/types.h>
38 #include <osl/file.hxx>
39 #include <osl/thread.h>
40 #include <rtl/bootstrap.hxx>
42 #include <plugin/impl.hxx>
44 int UnxPluginComm::nConnCounter
= 0;
46 UnxPluginComm::UnxPluginComm(
47 const String
& /*mimetype*/,
48 const String
& library
,
53 PluginComm( ::rtl::OUStringToOString( library
, osl_getThreadTextEncoding() ), false ),
54 PluginConnector( nDescriptor2
)
58 sprintf( pWindow
, "%d", (int)aParent
);
59 sprintf( pDesc
, "%d", nDescriptor1
);
60 ByteString
aLib( library
, osl_getThreadTextEncoding() );
62 if (!getPluginappPath(&path
)) {
63 fprintf( stderr
, "cannot construct path to pluginapp.bin\n" );
69 pArgs
[0] = path
.getStr();
71 pArgs
[2] = aLib
.GetBuffer();
75 #if OSL_DEBUG_LEVEL > 1
77 fprintf( stderr
, "Try to launch: %s %s %s %s, descriptors are %d, %d\n", pArgs
[0], pArgs
[1], pArgs
[2], pArgs
[3], nDescriptor1
, nDescriptor2
);
80 if( ! ( m_nCommPID
= fork() ) )
82 execvp( pArgs
[0], const_cast< char ** >(pArgs
) );
83 fprintf( stderr
, "Error: could not exec %s\n", pArgs
[0] );
87 if( m_nCommPID
!= -1 )
89 // wait for pluginapp.bin to start up
90 if( ! WaitForMessage( 5000 ) )
92 fprintf( stderr
, "Timeout on command: %s %s %s %s\n", pArgs
[0], pArgs
[1], pArgs
[2], pArgs
[3] );
97 MediatorMessage
* pMessage
= GetNextMessage( TRUE
);
98 Respond( pMessage
->m_nID
,
99 const_cast<char*>("init ack"),8,
107 UnxPluginComm::~UnxPluginComm()
110 if( m_nCommPID
!= -1 && m_nCommPID
!= 0 )
112 int status
= 16777216;
113 pid_t nExit
= waitpid( m_nCommPID
, &status
, WUNTRACED
);
114 #if OSL_DEBUG_LEVEL > 1
115 fprintf( stderr
, "child %d (plugin app child %d) exited with status %d\n", nExit
, m_nCommPID
, WEXITSTATUS(status
) );
122 bool UnxPluginComm::getPluginappPath(rtl::OString
* path
) {
123 OSL_ASSERT(path
!= NULL
);
125 RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program/pluginapp.bin"));
126 rtl::Bootstrap::expandMacros(p
);
128 (osl::FileBase::getSystemPathFromFileURL(p
, p
) ==
129 osl::FileBase::E_None
) &&
131 path
, osl_getThreadTextEncoding(),
132 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
133 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
));