LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/plugin/unx - plugcon.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 133 0.0 %
Date: 2012-12-27 Functions: 0 12 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 <plugin/unx/plugcon.hxx>
      37             : 
      38             : #include <cstdarg>
      39             : #include <vector>
      40             : 
      41           0 : sal_uInt32 PluginConnector::GetStreamID( NPStream* pStream )
      42             : {
      43           0 :     size_t nLen = m_aNPWrapStreams.size();
      44           0 :     for( size_t i = 0; i < nLen; i++ )
      45           0 :         if( m_aNPWrapStreams[ i ] == pStream )
      46           0 :             return static_cast<sal_uInt32>(i);
      47             :     SAL_WARN("extensions.plugin", "NPStream has no ID");
      48           0 :     return UnknownStreamID;
      49             : }
      50             : 
      51           0 : sal_uInt32 PluginConnector::GetNPPID( NPP instance )
      52             : {
      53           0 :     size_t nLen = m_aInstances.size();
      54           0 :     for( size_t i=0; i <nLen; i++ )
      55           0 :         if( m_aInstances[ i ]->instance == instance )
      56           0 :             return static_cast<sal_uInt32>(i);
      57             :     SAL_WARN("extensions.plugin", "NPP has no ID");
      58             : 
      59           0 :     return UnknownNPPID;
      60             : }
      61             : 
      62             : struct PtrStruct
      63             : {
      64             :     char* pData;
      65             :     sal_uLong nBytes;
      66             : 
      67           0 :     PtrStruct( char* i_pData, sal_uLong i_nBytes )
      68           0 :     : pData( i_pData ), nBytes( i_nBytes ) {}
      69             : };
      70             : 
      71           0 : sal_uLong PluginConnector::FillBuffer( char*& rpBuffer,
      72             :                                    const char* pFunction,
      73             :                                    sal_uLong nFunctionLen,
      74             :                                    va_list ap )
      75             : {
      76           0 :     std::vector< PtrStruct > aList;
      77           0 :     aList.reserve( 5 );
      78             : 
      79           0 :     sal_uLong nDataSize = nFunctionLen + sizeof( sal_uLong );
      80             :     char* pNext;
      81             : 
      82           0 :     do {
      83           0 :         pNext = va_arg( ap, char* );
      84           0 :         if( pNext )
      85             :         {
      86           0 :             aList.push_back( PtrStruct( pNext, va_arg( ap, sal_uLong ) ) );
      87           0 :             nDataSize += aList.back().nBytes + sizeof(sal_uLong);
      88             :         }
      89             :     } while( pNext );
      90             : 
      91           0 :     rpBuffer = new char[ nDataSize ];
      92           0 :     char* pRun = rpBuffer;
      93           0 :     memcpy( pRun, &nFunctionLen, sizeof( nFunctionLen ) );
      94           0 :     pRun += sizeof( nFunctionLen );
      95           0 :     memcpy( pRun, pFunction, nFunctionLen );
      96           0 :     pRun += nFunctionLen;
      97             : 
      98           0 :     for( std::vector<PtrStruct>::const_iterator it = aList.begin(); it != aList.end(); ++it )
      99             :     {
     100           0 :         memcpy( pRun, &it->nBytes, sizeof( sal_uLong ) );
     101           0 :         pRun += sizeof( sal_uLong );
     102           0 :         memcpy( pRun, it->pData, it->nBytes );
     103           0 :         pRun += it->nBytes;
     104             :     }
     105           0 :     return nDataSize;
     106             : }
     107             : 
     108           0 : MediatorMessage* PluginConnector::Transact( const char* pFunction,
     109             :                                             sal_uLong nFunctionLen, ... )
     110             : {
     111             :     va_list ap;
     112             :     char* pBuffer;
     113             : 
     114           0 :     va_start( ap, nFunctionLen );
     115           0 :     sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
     116           0 :     va_end( ap );
     117           0 :     return TransactMessage( nSize, pBuffer );
     118             : }
     119             : 
     120           0 : MediatorMessage* PluginConnector::Transact( sal_uInt32 nFunction, ... )
     121             : {
     122             :     va_list ap;
     123             :     char* pBuffer;
     124             : 
     125           0 :     va_start( ap, nFunction );
     126           0 :     sal_uLong nSize = FillBuffer( pBuffer, (char*)&nFunction, sizeof( nFunction ), ap );
     127           0 :     va_end( ap );
     128           0 :     return TransactMessage( nSize, pBuffer );
     129             : }
     130             : 
     131           0 : sal_uLong PluginConnector::Send( sal_uInt32 nFunction, ... )
     132             : {
     133             :     va_list ap;
     134             :     char* pBuffer;
     135             : 
     136           0 :     va_start( ap, nFunction );
     137           0 :     sal_uLong nSize = FillBuffer( pBuffer, (char*)&nFunction, sizeof( nFunction ), ap );
     138           0 :     va_end( ap );
     139           0 :     return SendMessage( nSize, pBuffer );
     140             : }
     141             : 
     142           0 : void PluginConnector::Respond( sal_uLong nID,
     143             :                                char* pFunction,
     144             :                                sal_uLong nFunctionLen, ... )
     145             : {
     146             :     va_list ap;
     147             :     char* pBuffer;
     148             : 
     149           0 :     va_start( ap, nFunctionLen );
     150           0 :     sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
     151           0 :     va_end( ap );
     152           0 :     SendMessage( nSize, pBuffer, nID | ( 1 << 24 ) );
     153           0 : }
     154             : 
     155           0 : MediatorMessage* PluginConnector::WaitForAnswer( sal_uLong nMessageID )
     156             : {
     157           0 :     if( ! m_bValid )
     158           0 :         return NULL;
     159             : 
     160           0 :     nMessageID &= 0x00ffffff;
     161           0 :     while( m_pListener )
     162             :     {
     163             :         {
     164           0 :             osl::MutexGuard aGuard( m_aQueueMutex );
     165           0 :             for( size_t i = 0; i < m_aMessageQueue.size(); i++ )
     166             :             {
     167           0 :                 MediatorMessage* pMessage = m_aMessageQueue[ i ];
     168           0 :                 sal_uLong nID = pMessage->m_nID;
     169           0 :                 if(  ( nID & 0xff000000 ) &&
     170             :                      ( ( nID & 0x00ffffff ) == nMessageID ) )
     171             :                 {
     172           0 :                     m_aMessageQueue.erase( m_aMessageQueue.begin() + i );
     173           0 :                     return pMessage;
     174             :                 }
     175           0 :             }
     176             :         }
     177           0 :         if( ! m_aMessageQueue.empty() )
     178           0 :             CallWorkHandler();
     179           0 :         WaitForMessage( 2000 );
     180             :     }
     181           0 :     return NULL;
     182             : }
     183             : 
     184           0 : ConnectorInstance::ConnectorInstance( NPP inst, char* type,
     185             :                                       int args, char* pargnbuf, sal_uLong nargnbytes,
     186             :                                       char* pargvbuf, sal_uLong nargvbytes,
     187             :                                       char* savedata, sal_uLong savebytes ) :
     188             :         instance( inst ),
     189             :         pShell( NULL ),
     190             :         pWidget( NULL ),
     191             :         pForm( NULL ),
     192             :         pGtkWindow( NULL ),
     193             :         pGtkWidget( NULL ),
     194             :         bShouldUseXEmbed( false ),
     195             :         nArg( args ),
     196             :         pArgnBuf( pargnbuf ),
     197           0 :         pArgvBuf( pargvbuf )
     198             : {
     199           0 :     memset( &window, 0, sizeof(window) );
     200           0 :     pMimeType = new char[ strlen( type ) + 1 ];
     201           0 :     strcpy( pMimeType, type );
     202           0 :     aData.len = savebytes;
     203           0 :     aData.buf = savedata;
     204           0 :     argn = new char*[ nArg ];
     205           0 :     argv = new char*[ nArg ];
     206             :     int i;
     207           0 :     char* pRun = pArgnBuf;
     208           0 :     for( i = 0; i < nArg; i++ )
     209             :     {
     210           0 :         argn[i] = pRun;
     211           0 :         while( *pRun != 0 && (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
     212           0 :             pRun++;
     213           0 :         if( (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
     214           0 :             pRun++;
     215             :     }
     216           0 :     pRun = pArgvBuf;
     217           0 :     for( i = 0; i < nArg; i++ )
     218             :     {
     219           0 :         argv[i] = pRun;
     220           0 :         while( *pRun != 0 && (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
     221           0 :             pRun++;
     222           0 :         if( (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
     223           0 :             pRun++;
     224             :     }
     225           0 : }
     226             : 
     227           0 : ConnectorInstance::~ConnectorInstance()
     228             : {
     229           0 :     delete [] pMimeType;
     230           0 :     delete [] argn;
     231           0 :     delete [] argv;
     232           0 :     delete [] pArgnBuf;
     233           0 :     delete [] pArgvBuf;
     234           0 :     delete [] (char*)aData.buf;
     235           0 : }
     236             : 
     237           0 : const char* GetCommandName( CommandAtoms eCommand )
     238             : {
     239           0 :     switch( eCommand )
     240             :     {
     241           0 :         case eNPN_GetURL:               return "NPN_GetURL";
     242           0 :         case eNPN_GetURLNotify:         return "NPN_GetURLNotify";
     243           0 :         case eNPN_DestroyStream:        return "NPN_DestroyStream";
     244           0 :         case eNPN_NewStream:            return "NPN_NewStream";
     245           0 :         case eNPN_PostURLNotify:        return "NPN_PostURLNotify";
     246           0 :         case eNPN_PostURL:              return "NPN_PostURL";
     247           0 :         case eNPN_RequestRead:          return "NPN_RequestRead";
     248           0 :         case eNPN_Status:               return "NPN_Status";
     249           0 :         case eNPN_Version:              return "NPN_Version";
     250           0 :         case eNPN_Write:                return "NPN_Write";
     251           0 :         case eNPN_UserAgent:            return "NPN_UserAgent";
     252             : 
     253           0 :         case eNPP_DestroyStream:        return "NPP_DestroyStream";
     254           0 :         case eNPP_Destroy:              return "NPP_Destroy";
     255           0 :         case eNPP_DestroyPhase2:        return "NPP_DestroyPhase2";
     256           0 :         case eNPP_NewStream:            return "NPP_NewStream";
     257           0 :         case eNPP_New:                  return "NPP_New";
     258           0 :         case eNPP_SetWindow:            return "NPP_SetWindow";
     259           0 :         case eNPP_StreamAsFile:         return "NPP_StreamAsFile";
     260           0 :         case eNPP_URLNotify:            return "NPP_URLNotify";
     261           0 :         case eNPP_WriteReady:           return "NPP_WriteReady";
     262           0 :         case eNPP_Write:                return "NPP_Write";
     263           0 :         case eNPP_GetMIMEDescription:   return "NPP_GetMIMEDescription";
     264           0 :         case eNPP_Initialize:           return "NPP_Initialize";
     265           0 :         case eNPP_Shutdown:             return "NPP_Shutdown";
     266             : 
     267           0 :         case eMaxCommand:               return "eMaxCommand";
     268           0 :         default:                        return "unknown command";
     269             :     }
     270             :     return NULL;
     271             : }
     272             : 
     273             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10