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 ************************************************************************/
31 #define _LINUX_SOURCE_COMPAT
32 #include <sys/timer.h>
33 #undef _LINUX_SOURCE_COMPAT
36 #include <plugin/unx/plugcon.hxx>
41 sal_uInt32
PluginConnector::GetStreamID( NPStream
* pStream
)
43 size_t nLen
= m_aNPWrapStreams
.size();
44 for( size_t i
= 0; i
< nLen
; i
++ )
45 if( m_aNPWrapStreams
[ i
] == pStream
)
46 return static_cast<sal_uInt32
>(i
);
47 SAL_WARN("extensions.plugin", "NPStream has no ID");
48 return UnknownStreamID
;
51 sal_uInt32
PluginConnector::GetNPPID( NPP instance
)
53 size_t nLen
= m_aInstances
.size();
54 for( size_t i
=0; i
<nLen
; i
++ )
55 if( m_aInstances
[ i
]->instance
== instance
)
56 return static_cast<sal_uInt32
>(i
);
57 SAL_WARN("extensions.plugin", "NPP has no ID");
67 PtrStruct( char* i_pData
, sal_uLong i_nBytes
)
68 : pData( i_pData
), nBytes( i_nBytes
) {}
71 sal_uLong
PluginConnector::FillBuffer( char*& rpBuffer
,
72 const char* pFunction
,
73 sal_uLong nFunctionLen
,
76 std::vector
< PtrStruct
> aList
;
79 sal_uLong nDataSize
= nFunctionLen
+ sizeof( sal_uLong
);
83 pNext
= va_arg( ap
, char* );
86 aList
.push_back( PtrStruct( pNext
, va_arg( ap
, sal_uLong
) ) );
87 nDataSize
+= aList
.back().nBytes
+ sizeof(sal_uLong
);
91 rpBuffer
= new char[ nDataSize
];
92 char* pRun
= rpBuffer
;
93 memcpy( pRun
, &nFunctionLen
, sizeof( nFunctionLen
) );
94 pRun
+= sizeof( nFunctionLen
);
95 memcpy( pRun
, pFunction
, nFunctionLen
);
98 for( std::vector
<PtrStruct
>::const_iterator it
= aList
.begin(); it
!= aList
.end(); ++it
)
100 memcpy( pRun
, &it
->nBytes
, sizeof( sal_uLong
) );
101 pRun
+= sizeof( sal_uLong
);
102 memcpy( pRun
, it
->pData
, it
->nBytes
);
108 MediatorMessage
* PluginConnector::Transact( const char* pFunction
,
109 sal_uLong nFunctionLen
, ... )
114 va_start( ap
, nFunctionLen
);
115 sal_uLong nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
117 MediatorMessage
* pRet
= TransactMessage( nSize
, pBuffer
);
122 MediatorMessage
* PluginConnector::Transact( sal_uInt32 nFunction
, ... )
127 va_start( ap
, nFunction
);
128 sal_uLong nSize
= FillBuffer( pBuffer
, (char*)&nFunction
, sizeof( nFunction
), ap
);
130 MediatorMessage
* pRet
= TransactMessage( nSize
, pBuffer
);
135 sal_uLong
PluginConnector::Send( sal_uInt32 nFunction
, ... )
140 va_start( ap
, nFunction
);
141 sal_uLong nSize
= FillBuffer( pBuffer
, (char*)&nFunction
, sizeof( nFunction
), ap
);
143 sal_uLong nRet
= SendMessage( nSize
, pBuffer
);
148 void PluginConnector::Respond( sal_uLong nID
,
150 sal_uLong nFunctionLen
, ... )
155 va_start( ap
, nFunctionLen
);
156 sal_uLong nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
158 SendMessage( nSize
, pBuffer
, nID
| ( 1 << 24 ) );
162 MediatorMessage
* PluginConnector::WaitForAnswer( sal_uLong nMessageID
)
167 nMessageID
&= 0x00ffffff;
171 osl::MutexGuard
aGuard( m_aQueueMutex
);
172 for( size_t i
= 0; i
< m_aMessageQueue
.size(); i
++ )
174 MediatorMessage
* pMessage
= m_aMessageQueue
[ i
];
175 sal_uLong nID
= pMessage
->m_nID
;
176 if( ( nID
& 0xff000000 ) &&
177 ( ( nID
& 0x00ffffff ) == nMessageID
) )
179 m_aMessageQueue
.erase( m_aMessageQueue
.begin() + i
);
184 if( ! m_aMessageQueue
.empty() )
186 WaitForMessage( 2000 );
191 ConnectorInstance::ConnectorInstance( NPP inst
, char* type
,
192 int args
, char* pargnbuf
, sal_uLong nargnbytes
,
193 char* pargvbuf
, sal_uLong nargvbytes
,
194 char* savedata
, sal_uLong savebytes
) :
201 bShouldUseXEmbed( false ),
203 pArgnBuf( pargnbuf
),
206 memset( &window
, 0, sizeof(window
) );
207 pMimeType
= new char[ strlen( type
) + 1 ];
208 strcpy( pMimeType
, type
);
209 aData
.len
= savebytes
;
210 aData
.buf
= savedata
;
211 argn
= new char*[ nArg
];
212 argv
= new char*[ nArg
];
214 char* pRun
= pArgnBuf
;
215 for( i
= 0; i
< nArg
; i
++ )
218 while( *pRun
!= 0 && (sal_uLong
)(pRun
- pArgnBuf
) < nargnbytes
)
220 if( (sal_uLong
)(pRun
- pArgnBuf
) < nargnbytes
)
224 for( i
= 0; i
< nArg
; i
++ )
227 while( *pRun
!= 0 && (sal_uLong
)(pRun
- pArgvBuf
) < nargvbytes
)
229 if( (sal_uLong
)(pRun
- pArgvBuf
) < nargvbytes
)
234 ConnectorInstance::~ConnectorInstance()
241 delete [] (char*)aData
.buf
;
244 const char* GetCommandName( CommandAtoms eCommand
)
248 case eNPN_GetURL
: return "NPN_GetURL";
249 case eNPN_GetURLNotify
: return "NPN_GetURLNotify";
250 case eNPN_DestroyStream
: return "NPN_DestroyStream";
251 case eNPN_NewStream
: return "NPN_NewStream";
252 case eNPN_PostURLNotify
: return "NPN_PostURLNotify";
253 case eNPN_PostURL
: return "NPN_PostURL";
254 case eNPN_RequestRead
: return "NPN_RequestRead";
255 case eNPN_Status
: return "NPN_Status";
256 case eNPN_Version
: return "NPN_Version";
257 case eNPN_Write
: return "NPN_Write";
258 case eNPN_UserAgent
: return "NPN_UserAgent";
260 case eNPP_DestroyStream
: return "NPP_DestroyStream";
261 case eNPP_Destroy
: return "NPP_Destroy";
262 case eNPP_DestroyPhase2
: return "NPP_DestroyPhase2";
263 case eNPP_NewStream
: return "NPP_NewStream";
264 case eNPP_New
: return "NPP_New";
265 case eNPP_SetWindow
: return "NPP_SetWindow";
266 case eNPP_StreamAsFile
: return "NPP_StreamAsFile";
267 case eNPP_URLNotify
: return "NPP_URLNotify";
268 case eNPP_WriteReady
: return "NPP_WriteReady";
269 case eNPP_Write
: return "NPP_Write";
270 case eNPP_GetMIMEDescription
: return "NPP_GetMIMEDescription";
271 case eNPP_Initialize
: return "NPP_Initialize";
272 case eNPP_Shutdown
: return "NPP_Shutdown";
274 case eMaxCommand
: return "eMaxCommand";
275 default: return "unknown command";
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */