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 <sal/log.hxx>
38 #include <plugin/unx/plugcon.hxx>
43 sal_uInt32
PluginConnector::GetStreamID( NPStream
* pStream
)
45 size_t nLen
= m_aNPWrapStreams
.size();
46 for( size_t i
= 0; i
< nLen
; i
++ )
47 if( m_aNPWrapStreams
[ i
] == pStream
)
48 return static_cast<sal_uInt32
>(i
);
49 SAL_WARN("extensions.plugin", "NPStream has no ID");
50 return UnknownStreamID
;
53 sal_uInt32
PluginConnector::GetNPPID( NPP instance
)
55 size_t nLen
= m_aInstances
.size();
56 for( size_t i
=0; i
<nLen
; i
++ )
57 if( m_aInstances
[ i
]->instance
== instance
)
58 return static_cast<sal_uInt32
>(i
);
59 SAL_WARN("extensions.plugin", "NPP has no ID");
69 PtrStruct( char* i_pData
, sal_uLong i_nBytes
)
70 : pData( i_pData
), nBytes( i_nBytes
) {}
73 sal_uLong
PluginConnector::FillBuffer( char*& rpBuffer
,
74 const char* pFunction
,
75 sal_uLong nFunctionLen
,
78 std::vector
< PtrStruct
> aList
;
81 sal_uLong nDataSize
= nFunctionLen
+ sizeof( sal_uLong
);
85 pNext
= va_arg( ap
, char* );
88 aList
.push_back( PtrStruct( pNext
, va_arg( ap
, sal_uLong
) ) );
89 nDataSize
+= aList
.back().nBytes
+ sizeof(sal_uLong
);
93 rpBuffer
= new char[ nDataSize
];
94 char* pRun
= rpBuffer
;
95 memcpy( pRun
, &nFunctionLen
, sizeof( nFunctionLen
) );
96 pRun
+= sizeof( nFunctionLen
);
97 memcpy( pRun
, pFunction
, nFunctionLen
);
100 for( std::vector
<PtrStruct
>::const_iterator it
= aList
.begin(); it
!= aList
.end(); ++it
)
102 memcpy( pRun
, &it
->nBytes
, sizeof( sal_uLong
) );
103 pRun
+= sizeof( sal_uLong
);
104 memcpy( pRun
, it
->pData
, it
->nBytes
);
110 MediatorMessage
* PluginConnector::Transact( const char* pFunction
,
111 sal_uLong nFunctionLen
, ... )
116 va_start( ap
, nFunctionLen
);
117 sal_uLong nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
119 MediatorMessage
* pRet
= TransactMessage( nSize
, pBuffer
);
124 MediatorMessage
* PluginConnector::Transact( sal_uInt32 nFunction
, ... )
129 va_start( ap
, nFunction
);
130 sal_uLong nSize
= FillBuffer( pBuffer
, reinterpret_cast<char*>(&nFunction
), sizeof( nFunction
), ap
);
132 MediatorMessage
* pRet
= TransactMessage( nSize
, pBuffer
);
137 sal_uLong
PluginConnector::Send( sal_uInt32 nFunction
, ... )
142 va_start( ap
, nFunction
);
143 sal_uLong nSize
= FillBuffer( pBuffer
, reinterpret_cast<char*>(&nFunction
), sizeof( nFunction
), ap
);
145 sal_uLong nRet
= SendMessage( nSize
, pBuffer
);
150 void PluginConnector::Respond( sal_uLong nID
,
152 sal_uLong nFunctionLen
, ... )
157 va_start( ap
, nFunctionLen
);
158 sal_uLong nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
160 SendMessage( nSize
, pBuffer
, nID
| ( 1 << 24 ) );
164 MediatorMessage
* PluginConnector::WaitForAnswer( sal_uLong nMessageID
)
169 nMessageID
&= 0x00ffffff;
173 osl::MutexGuard
aGuard( m_aQueueMutex
);
174 for( size_t i
= 0; i
< m_aMessageQueue
.size(); i
++ )
176 MediatorMessage
* pMessage
= m_aMessageQueue
[ i
];
177 sal_uLong nID
= pMessage
->m_nID
;
178 if( ( nID
& 0xff000000 ) &&
179 ( ( nID
& 0x00ffffff ) == nMessageID
) )
181 m_aMessageQueue
.erase( m_aMessageQueue
.begin() + i
);
186 if( ! m_aMessageQueue
.empty() )
188 WaitForMessage( 2000 );
193 ConnectorInstance::ConnectorInstance( NPP inst
, char* type
,
194 int args
, char* pargnbuf
, sal_uLong nargnbytes
,
195 char* pargvbuf
, sal_uLong nargvbytes
,
196 char* savedata
, sal_uLong savebytes
) :
203 bShouldUseXEmbed( false ),
205 pArgnBuf( pargnbuf
),
208 memset( &window
, 0, sizeof(window
) );
209 pMimeType
= new char[ strlen( type
) + 1 ];
210 strcpy( pMimeType
, type
);
211 aData
.len
= savebytes
;
212 aData
.buf
= savedata
;
213 argn
= new char*[ nArg
];
214 argv
= new char*[ nArg
];
216 char* pRun
= pArgnBuf
;
217 for( i
= 0; i
< nArg
; i
++ )
220 while( *pRun
!= 0 && (sal_uLong
)(pRun
- pArgnBuf
) < nargnbytes
)
222 if( (sal_uLong
)(pRun
- pArgnBuf
) < nargnbytes
)
226 for( i
= 0; i
< nArg
; i
++ )
229 while( *pRun
!= 0 && (sal_uLong
)(pRun
- pArgvBuf
) < nargvbytes
)
231 if( (sal_uLong
)(pRun
- pArgvBuf
) < nargvbytes
)
236 ConnectorInstance::~ConnectorInstance()
243 delete [] static_cast<char*>(aData
.buf
);
246 const char* GetCommandName( CommandAtoms eCommand
)
250 case eNPN_GetURL
: return "NPN_GetURL";
251 case eNPN_GetURLNotify
: return "NPN_GetURLNotify";
252 case eNPN_DestroyStream
: return "NPN_DestroyStream";
253 case eNPN_NewStream
: return "NPN_NewStream";
254 case eNPN_PostURLNotify
: return "NPN_PostURLNotify";
255 case eNPN_PostURL
: return "NPN_PostURL";
256 case eNPN_RequestRead
: return "NPN_RequestRead";
257 case eNPN_Status
: return "NPN_Status";
258 case eNPN_Version
: return "NPN_Version";
259 case eNPN_Write
: return "NPN_Write";
260 case eNPN_UserAgent
: return "NPN_UserAgent";
262 case eNPP_DestroyStream
: return "NPP_DestroyStream";
263 case eNPP_Destroy
: return "NPP_Destroy";
264 case eNPP_DestroyPhase2
: return "NPP_DestroyPhase2";
265 case eNPP_NewStream
: return "NPP_NewStream";
266 case eNPP_New
: return "NPP_New";
267 case eNPP_SetWindow
: return "NPP_SetWindow";
268 case eNPP_StreamAsFile
: return "NPP_StreamAsFile";
269 case eNPP_URLNotify
: return "NPP_URLNotify";
270 case eNPP_WriteReady
: return "NPP_WriteReady";
271 case eNPP_Write
: return "NPP_Write";
272 case eNPP_GetMIMEDescription
: return "NPP_GetMIMEDescription";
273 case eNPP_Initialize
: return "NPP_Initialize";
274 case eNPP_Shutdown
: return "NPP_Shutdown";
276 case eMaxCommand
: return "eMaxCommand";
277 default: return "unknown command";
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */