LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/plugin/unx - sysplug.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 40 0.0 %
Date: 2012-12-27 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5             :  *
       6             :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7             :  *
       8             :  * OpenOffice.org - a multi-platform office productivity suite
       9             :  *
      10             :  * This file is part of OpenOffice.org.
      11             :  *
      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.
      15             :  *
      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).
      21             :  *
      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.
      26             :  *
      27             :  ************************************************************************/
      28             : 
      29             : 
      30             : #ifdef AIX
      31             : #define _LINUX_SOURCE_COMPAT
      32             : #include <sys/timer.h>
      33             : #undef _LINUX_SOURCE_COMPAT
      34             : #endif
      35             : 
      36             : #include <sys/types.h>
      37             : #include <signal.h>
      38             : #include <sys/wait.h>
      39             : #include <osl/file.hxx>
      40             : #include <osl/thread.h>
      41             : #include <rtl/bootstrap.hxx>
      42             : 
      43             : #include <plugin/impl.hxx>
      44             : 
      45             : 
      46           0 : ::boost::shared_ptr<SysPlugData> CreateSysPlugData()
      47             : {
      48           0 :     return ::boost::shared_ptr<SysPlugData>();
      49             : }
      50             : 
      51           0 : UnxPluginComm::UnxPluginComm(
      52             :                              const String& /*mimetype*/,
      53             :                              const String& library,
      54             :                              XLIB_Window aParent,
      55             :                              int nDescriptor1,
      56             :                              int nDescriptor2
      57             :                              ) :
      58           0 :         PluginComm( ::rtl::OUStringToOString( library, osl_getThreadTextEncoding() ), false ),
      59             :         PluginConnector( nDescriptor2 ),
      60           0 :         m_nCommPID( 0 )
      61             : {
      62           0 :     rtl::OString path;
      63           0 :     if (!getPluginappPath(&path))
      64             :     {
      65             :         SAL_WARN("extensions.plugin", "cannot construct path to pluginapp.bin");
      66             :         return;
      67             :     }
      68             : 
      69             :     char pDesc[32];
      70             :     char pWindow[32];
      71           0 :     sprintf( pWindow, "%d", (int)aParent );
      72           0 :     sprintf( pDesc, "%d", nDescriptor1 );
      73           0 :     rtl::OString aLib(rtl::OUStringToOString(library, osl_getThreadTextEncoding()));
      74             : 
      75             :     char const* pArgs[5];
      76           0 :     pArgs[0] = path.getStr();
      77           0 :     pArgs[1] = pDesc;
      78           0 :     pArgs[2] = aLib.getStr();
      79           0 :     pArgs[3] = pWindow;
      80           0 :     pArgs[4] = NULL;
      81             : 
      82             :     SAL_INFO(
      83             :         "extensions.plugin",
      84             :         "try to launch: " << pArgs[0] << " " << pArgs[1] << " " << pArgs[2]
      85             :             << " " << pArgs[3] << ", descriptors are " << nDescriptor1 << ", "
      86             :             << nDescriptor2);
      87             : 
      88           0 :     pid_t pid = fork();
      89           0 :     if( pid == 0 )
      90             :     {
      91           0 :         execvp( pArgs[0], const_cast< char ** >(pArgs) );
      92             :         SAL_WARN("extensions.plugin", "could not exec " << pArgs[0]);
      93           0 :         _exit(255);
      94             :     }
      95             : 
      96           0 :     if( pid == -1 )
      97             :     {
      98             :         SAL_WARN("extensions.plugin", "fork failed");
      99             :         return;
     100             :     }
     101             : 
     102           0 :     m_nCommPID = pid;
     103             :     // wait for pluginapp.bin to start up
     104           0 :     if( ! WaitForMessage( 5000 ) )
     105             :     {
     106             :         SAL_WARN(
     107             :             "extensions.plugin",
     108             :             "timeout on command: " << pArgs[0] << " " << pArgs[1] << " "
     109             :                 << pArgs[2] << " " << pArgs[3]);
     110           0 :         invalidate();
     111             :     }
     112             :     else
     113             :     {
     114           0 :         MediatorMessage* pMessage = GetNextMessage( sal_True );
     115             :         Respond( pMessage->m_nID,
     116             :                  const_cast<char*>("init ack"),8,
     117           0 :                  NULL );
     118           0 :         delete pMessage;
     119           0 :         NPP_Initialize();
     120           0 :     }
     121             : }
     122             : 
     123           0 : UnxPluginComm::~UnxPluginComm()
     124             : {
     125           0 :     NPP_Shutdown();
     126           0 :     if( m_nCommPID != 0 )
     127             :     {
     128           0 :         int status = 16777216;
     129           0 :         pid_t nExit = waitpid( m_nCommPID, &status, WUNTRACED );
     130             :         SAL_INFO(
     131             :             "extensions.plugin",
     132             :             "child " << nExit << " (plugin app child " << m_nCommPID
     133             :                 << ") exited with status " << WEXITSTATUS(status));
     134             :     }
     135           0 : }
     136             : 
     137           0 : bool UnxPluginComm::getPluginappPath(rtl::OString * path) {
     138             :     OSL_ASSERT(path != NULL);
     139             :     rtl::OUString p(
     140           0 :         RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR/program/pluginapp.bin"));
     141           0 :     rtl::Bootstrap::expandMacros(p);
     142             :     return
     143           0 :         (osl::FileBase::getSystemPathFromFileURL(p, p) ==
     144             :          osl::FileBase::E_None) &&
     145             :         p.convertToString(
     146           0 :             path, osl_getThreadTextEncoding(),
     147             :             (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
     148           0 :              RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR));
     149             : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10