bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / plugin / unx / sysplug.cxx
blobe8a1af9b55391539c459c8c6fb93476524f2f215
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <config_folders.h>
31 #ifdef AIX
32 #define _LINUX_SOURCE_COMPAT
33 #include <sys/timer.h>
34 #undef _LINUX_SOURCE_COMPAT
35 #endif
37 #include <sys/types.h>
38 #include <signal.h>
39 #include <sys/wait.h>
40 #include <osl/file.hxx>
41 #include <osl/thread.h>
42 #include <rtl/bootstrap.hxx>
43 #include <sal/log.hxx>
45 #include <plugin/impl.hxx>
48 ::boost::shared_ptr<SysPlugData> CreateSysPlugData()
50 return ::boost::shared_ptr<SysPlugData>();
53 UnxPluginComm::UnxPluginComm(
54 const OUString& /*mimetype*/,
55 const OUString& library,
56 Window aParent,
57 int nDescriptor1,
58 int nDescriptor2
59 ) :
60 PluginComm( OUStringToOString( library, osl_getThreadTextEncoding() ), false ),
61 PluginConnector( nDescriptor2 ),
62 m_nCommPID( 0 )
64 OString path;
65 if (!getPluginappPath(&path))
67 SAL_WARN("extensions.plugin", "cannot construct path to pluginapp.bin");
68 return;
71 char pDesc[32];
72 char pWindow[32];
73 sprintf( pWindow, "%d", (int)aParent );
74 sprintf( pDesc, "%d", nDescriptor1 );
75 OString aLib(OUStringToOString(library, osl_getThreadTextEncoding()));
77 char const* pArgs[5];
78 pArgs[0] = path.getStr();
79 pArgs[1] = pDesc;
80 pArgs[2] = aLib.getStr();
81 pArgs[3] = pWindow;
82 pArgs[4] = NULL;
84 SAL_INFO(
85 "extensions.plugin",
86 "try to launch: " << pArgs[0] << " " << pArgs[1] << " " << pArgs[2]
87 << " " << pArgs[3] << ", descriptors are " << nDescriptor1 << ", "
88 << nDescriptor2);
90 pid_t pid = fork();
91 if( pid == 0 )
93 execvp( pArgs[0], const_cast< char ** >(pArgs) );
94 SAL_WARN("extensions.plugin", "could not exec " << pArgs[0]);
95 _exit(255);
98 if( pid == -1 )
100 SAL_WARN("extensions.plugin", "fork failed");
101 return;
104 m_nCommPID = pid;
105 // wait for pluginapp.bin to start up
106 if( ! WaitForMessage( 5000 ) )
108 SAL_WARN(
109 "extensions.plugin",
110 "timeout on command: " << pArgs[0] << " " << pArgs[1] << " "
111 << pArgs[2] << " " << pArgs[3]);
112 invalidate();
114 else
116 MediatorMessage* pMessage = GetNextMessage( true );
117 Respond( pMessage->m_nID,
118 const_cast<char*>("init ack"),8,
119 NULL );
120 delete pMessage;
121 NPP_Initialize();
125 UnxPluginComm::~UnxPluginComm()
127 NPP_Shutdown();
128 if( m_nCommPID != 0 )
130 int status = 16777216;
131 pid_t nExit = waitpid( m_nCommPID, &status, WUNTRACED );
132 SAL_INFO(
133 "extensions.plugin",
134 "child " << nExit << " (plugin app child " << m_nCommPID
135 << ") exited with status " << WEXITSTATUS(status));
139 bool UnxPluginComm::getPluginappPath(OString * path) {
140 OSL_ASSERT(path != NULL);
141 OUString p("$BRAND_BASE_DIR/" LIBO_LIBEXEC_FOLDER "/pluginapp.bin");
142 rtl::Bootstrap::expandMacros(p);
143 return
144 (osl::FileBase::getSystemPathFromFileURL(p, p) ==
145 osl::FileBase::E_None) &&
146 p.convertToString(
147 path, osl_getThreadTextEncoding(),
148 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
149 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR));
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */