1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: urp_bridgeimpl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_bridges.hxx"
33 #include <osl/thread.h>
34 #include <bridges/remote/helper.hxx>
38 #include "urp_bridgeimpl.hxx"
40 using namespace ::rtl
;
41 using namespace ::osl
;
42 using namespace ::com::sun::star::uno
;
47 inline t
mymin( const t
& val1
, const t
& val2
)
49 return val1
< val2
? val1
: val2
;
55 urp_BridgeImpl::urp_BridgeImpl( sal_Int32 nCacheSize
, sal_uInt32 nInitialMarshalerSize
) :
56 m_blockMarshaler( this , nInitialMarshalerSize
, ::bridges_remote::remote_retrieveOidFromProxy
),
57 m_nMarshaledMessages( 0 ),
58 m_oidCacheOut( (sal_uInt16
)nCacheSize
),
59 m_tidCacheOut( (sal_uInt16
)nCacheSize
),
60 m_typeCacheOut( (sal_uInt16
)nCacheSize
)
62 m_pOidIn
= new OUString
[ nCacheSize
];
63 m_pTidIn
= new ByteSequence
[ nCacheSize
];
64 m_pTypeIn
= new Type
[ nCacheSize
];
68 urp_BridgeImpl::~urp_BridgeImpl()
76 void urp_BridgeImpl::applyProtocolChanges( const Properties
&props
)
78 if( m_properties
.nTypeCacheSize
!= props
.nTypeCacheSize
)
80 if( props
.nTypeCacheSize
== 0 )
87 Type
*pNew
= new Type
[props
.nTypeCacheSize
];
89 sal_Int32 iMin
= mymin( m_properties
.nTypeCacheSize
, props
.nTypeCacheSize
);
90 for( i
= 0; i
< iMin
; i
++ )
92 pNew
[i
] = m_pTypeIn
[i
];
97 OSL_ASSERT( props
.nTypeCacheSize
<= 0xffff );
98 m_properties
.nTypeCacheSize
= props
.nTypeCacheSize
;
99 m_typeCacheOut
.resize( (sal_uInt16
)props
.nTypeCacheSize
);
102 if( m_properties
.nOidCacheSize
!= props
.nOidCacheSize
)
104 if( 0 == props
.nOidCacheSize
)
111 OUString
*pNew
= new OUString
[props
.nOidCacheSize
];
113 sal_Int32 iMin
= mymin( m_properties
.nOidCacheSize
, props
.nOidCacheSize
);
114 for( i
= 0; i
< iMin
; i
++ )
116 pNew
[i
] = m_pOidIn
[i
];
121 OSL_ASSERT( props
.nOidCacheSize
<= 0xffff );
122 m_oidCacheOut
.resize( (sal_uInt16
)props
.nOidCacheSize
);
123 m_properties
.nOidCacheSize
= props
.nOidCacheSize
;
126 if( m_properties
.nTidCacheSize
!= props
.nTidCacheSize
)
128 if( 0 == props
.nTidCacheSize
)
135 ByteSequence
*pNew
= new ByteSequence
[props
.nTidCacheSize
];
137 sal_Int32 iMin
= mymin( m_properties
.nTidCacheSize
, props
.nTidCacheSize
);
138 for( i
= 0; i
< iMin
; i
++ )
140 pNew
[i
] = m_pTidIn
[i
];
145 OSL_ASSERT( props
.nTidCacheSize
<= 0xffff );
146 m_tidCacheOut
.resize( (sal_uInt16
)props
.nTidCacheSize
);
147 m_properties
.nTidCacheSize
= props
.nTidCacheSize
;
150 if( m_properties
.sVersion
!= props
.sVersion
)
152 m_properties
.sVersion
= props
.sVersion
;
155 if( m_properties
.nFlushBlockSize
!= props
.nFlushBlockSize
)
157 m_properties
.nFlushBlockSize
= props
.nFlushBlockSize
;
160 if( m_properties
.nOnewayTimeoutMUSEC
!= props
.nOnewayTimeoutMUSEC
)
162 m_properties
.nOnewayTimeoutMUSEC
= props
.nOnewayTimeoutMUSEC
;
165 if( props
.bClearCache
)
167 if( m_properties
.nTypeCacheSize
)
170 m_pTypeIn
= new Type
[m_properties
.nTypeCacheSize
];
171 m_typeCacheOut
.clear();
173 m_lastInType
= Type();
174 m_lastOutType
= Type();
176 if( m_properties
.nOidCacheSize
)
179 m_pOidIn
= new OUString
[ m_properties
.nOidCacheSize
];
180 m_oidCacheOut
.clear();
182 m_lastOutOid
= OUString();
183 m_lastInOid
= OUString();
185 if( m_properties
.nTidCacheSize
)
188 m_pTidIn
= new ByteSequence
[m_properties
.nTidCacheSize
];
189 m_tidCacheOut
.clear();
191 m_lastInTid
= ByteSequence();
192 m_lastOutTid
= ByteSequence();
195 if( m_properties
.bNegotiate
!= props
.bNegotiate
)
197 m_properties
.bNegotiate
= props
.bNegotiate
;
200 if( m_properties
.bForceSynchronous
!= props
.bForceSynchronous
)
202 m_properties
.bForceSynchronous
= props
.bForceSynchronous
;
205 m_properties
.bCurrentContext
= props
.bCurrentContext
;
208 void urp_BridgeImpl::addError( char const *pError
)
210 OUString message
= OUString( RTL_CONSTASCII_USTRINGPARAM( "(tid=" ) );
211 message
+= OUString::valueOf( (sal_Int32
) osl_getThreadIdentifier( 0 ) );
212 message
+= OUString::createFromAscii( ") " );
213 message
+= OUString::createFromAscii( pError
);
214 MutexGuard
guard( m_errorListMutex
);
215 m_lstErrors
.push_back( message
);
218 void urp_BridgeImpl::addError( const OUString
& error
)
220 OUString message
= OUString( RTL_CONSTASCII_USTRINGPARAM( "(tid=" ) );
221 message
+= OUString::valueOf( (sal_Int32
) osl_getThreadIdentifier( 0 ) );
222 message
+= OUString::createFromAscii( ") " );
224 MutexGuard
guard( m_errorListMutex
);
225 m_lstErrors
.push_back( message
);
228 void urp_BridgeImpl::dumpErrors( FILE * f
)
230 MutexGuard
guard( m_errorListMutex
);
231 for( ::std::list
< OUString
>::iterator ii
= m_lstErrors
.begin() ;
232 ii
!= m_lstErrors
.end() ;
235 OString o
= OUStringToOString( *ii
, RTL_TEXTENCODING_UTF8
);
236 fprintf( f
, "%s\n" , o
.getStr() );
240 OUString
urp_BridgeImpl::getErrorsAsString( )
242 MutexGuard
guard( m_errorListMutex
);
244 for( ::std::list
< OUString
>::iterator ii
= m_lstErrors
.begin() ;
245 ii
!= m_lstErrors
.end() ;