update dev300-m58
[ooovba.git] / bridges / source / remote / urp / urp_propertyobject.cxx
blobc874d97b118b2b7131dcb0496ac47e82e6978dc2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: urp_propertyobject.cxx,v $
10 * $Revision: 1.11.20.1 $
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 <stdlib.h>
34 #include <osl/diagnose.h>
36 #include <rtl/random.h>
38 #include <uno/data.h>
40 #include "com/sun/star/bridge/InvalidProtocolChangeException.hpp"
41 #include <com/sun/star/bridge/XProtocolProperties.hpp>
43 #include "urp_propertyobject.hxx"
44 #include "urp_dispatch.hxx"
45 #include "urp_bridgeimpl.hxx"
46 #include "urp_job.hxx"
48 using namespace ::rtl;
49 using namespace ::osl;
50 using namespace ::com::sun::star::bridge;
51 using namespace ::com::sun::star::uno;
53 using namespace bridges_urp;
55 extern "C" {
57 static void SAL_CALL staticAcquire( remote_Interface *pRemoteI )
59 PropertyObject *pProperties = (PropertyObject *) pRemoteI;
60 pProperties->thisAcquire();
63 static void SAL_CALL staticRelease( remote_Interface *pRemoteI )
65 PropertyObject *pProperties = (PropertyObject *) pRemoteI;
66 pProperties->thisRelease();
69 static void SAL_CALL staticDispatch(
70 remote_Interface * pRemoteI, typelib_TypeDescription const * pMemberType,
71 void * pReturn, void * pArgs[], uno_Any ** ppException )
73 PropertyObject *pProperties = (PropertyObject *) pRemoteI;
74 pProperties->thisDispatch( pMemberType, pReturn, pArgs, ppException );
79 namespace bridges_urp
81 // some nice constants ....
82 static const sal_Int32 METHOD_QUERY_INTERFACE = 0;
83 static const sal_Int32 METHOD_GET_PROPERTIES = 3;
84 static const sal_Int32 METHOD_REQUEST_CHANGE = 4;
85 static const sal_Int32 METHOD_COMMIT_CHANGE = 5;
87 static const sal_Int32 PROPERTY_BRIDGEID = 0;
88 static const sal_Int32 PROPERTY_TYPECACHESIZE = 1;
89 static const sal_Int32 PROPERTY_OIDCACHESIZE = 2;
90 static const sal_Int32 PROPERTY_TIDCACHESIZE = 3;
91 static const sal_Int32 PROPERTY_SUPPORTEDVERSIONS = 4;
92 static const sal_Int32 PROPERTY_VERSION =5;
93 static const sal_Int32 PROPERTY_FLUSHBLOCKSIZE = 6;
94 static const sal_Int32 PROPERTY_ONEWAYTIMEOUT_MUSEC = 7;
95 static const sal_Int32 PROPERTY_SUPPORTSMUSTREPLY = 8;
96 static const sal_Int32 PROPERTY_SUPPERTSSYNCHRONOUS = 9;
97 static const sal_Int32 PROPERTY_SUPPORTSMULTIPLESYNCHRONOUS = 10;
98 static const sal_Int32 PROPERTY_CLEARCACHE = 11;
99 static const sal_Int32 PROPERTY_NEGOTIATE = 12;
100 static const sal_Int32 PROPERTY_FORCESYNCHRONOUS = 13;
101 static const sal_Int32 PROPERTY_CURRENTCONTEXT = 14;
103 static const sal_Int32 MAX_PROPERTIES = PROPERTY_CURRENTCONTEXT +1;
105 const sal_Char *g_aPropertyName[] =
107 "BridgeId",
108 "TypeCacheSize",
109 "OidCacheSize",
110 "TidCacheSize",
111 "SupportedVersion",
112 "Version",
113 "FlushBlockSize",
114 "OnewayTimeoutMUSEC",
115 "SupportsMustReply",
116 "SupportsSynchronous",
117 "SupportsMultipleSynchronous",
118 "ClearCache",
119 "Negotiate",
120 "ForceSynchronous",
121 "CurrentContext"
124 // nice little helper functions for conversion
125 template< class t >
126 void assignToIdl( ProtocolProperty *pIdl, sal_Int32 nIndex, const t &value )
128 pIdl->Name = OUString::createFromAscii( g_aPropertyName[nIndex] );
129 ( *(::com::sun::star::uno::Any *)&(pIdl->Value) ) <<= value;
132 template< class t >
133 void assignFromIdl( t * p, const ProtocolProperty & property )
135 property.Value >>=*p;
138 static sal_Int32 getIndexFromIdl( const ProtocolProperty & property )
140 sal_Int32 nResult = -1;
141 for( sal_Int32 i = 0 ; i < MAX_PROPERTIES ; i ++ )
143 if( 0 == property.Name.compareToAscii( g_aPropertyName[i] ) )
145 nResult = i;
146 break;
149 return nResult;
152 static sal_Int32 getIndexFromString( const OUString & property )
154 sal_Int32 nResult = -1;
155 for( sal_Int32 i = 0 ; i < MAX_PROPERTIES ; i ++ )
157 if( 0 == property.compareToAscii( g_aPropertyName[i] ) )
159 nResult = i;
160 break;
163 return nResult;
166 static sal_Bool assignFromIdlToStruct( Properties *pProps, const ProtocolProperty &idl )
168 sal_Bool bReturn = sal_True;
170 sal_Int32 nIndex = getIndexFromIdl( idl );
171 if( nIndex >= 0 )
173 switch( nIndex )
175 case PROPERTY_SUPPORTSMULTIPLESYNCHRONOUS:
176 assignFromIdl( &(pProps->bSupportsMultipleSynchronous) , idl );
177 break;
178 case PROPERTY_SUPPERTSSYNCHRONOUS:
179 assignFromIdl( &(pProps->bSupportsMustReply) , idl );
180 break;
181 case PROPERTY_SUPPORTSMUSTREPLY:
182 assignFromIdl( &(pProps->bSupportsSynchronous) , idl );
183 break;
184 case PROPERTY_ONEWAYTIMEOUT_MUSEC:
185 assignFromIdl( &(pProps->nOnewayTimeoutMUSEC) , idl );
186 break;
187 case PROPERTY_BRIDGEID:
188 assignFromIdl( (Sequence< sal_Int8 > * )&(pProps->seqBridgeID), idl );
189 break;
190 case PROPERTY_TYPECACHESIZE:
191 assignFromIdl( &(pProps->nTypeCacheSize) , idl );
192 break;
193 case PROPERTY_OIDCACHESIZE:
194 assignFromIdl( &(pProps->nOidCacheSize) , idl );
195 break;
196 case PROPERTY_TIDCACHESIZE:
197 assignFromIdl( &(pProps->nTidCacheSize), idl );
198 break;
199 case PROPERTY_SUPPORTEDVERSIONS:
200 assignFromIdl( &(pProps->sSupportedVersions) , idl );
201 break;
202 case PROPERTY_VERSION:
203 assignFromIdl( &(pProps->sVersion) , idl );
204 break;
205 case PROPERTY_FLUSHBLOCKSIZE:
206 assignFromIdl( &(pProps->nFlushBlockSize) ,idl );
207 break;
208 case PROPERTY_CLEARCACHE:
209 assignFromIdl( &(pProps->bClearCache) ,idl );
210 break;
211 case PROPERTY_NEGOTIATE:
212 assignFromIdl( &(pProps->bNegotiate) ,idl );
213 break;
214 case PROPERTY_FORCESYNCHRONOUS:
215 assignFromIdl( &(pProps->bForceSynchronous) ,idl );
216 break;
217 case PROPERTY_CURRENTCONTEXT:
218 pProps->bCurrentContext = true;
219 break;
220 default:
221 bReturn = sal_False;
224 else
226 bReturn = sal_False;
228 return bReturn;
231 static void extractTokens(
232 const ::rtl::OUString &sProps , ::std::list< OUString > &lst )
234 sal_Int32 nNext = 0;
235 while ( sal_True )
237 sal_Int32 nStart = nNext;
238 nNext = sProps.indexOf( ',' , nNext );
239 if( -1 == nNext )
241 lst.push_back( sProps.copy( nStart, sProps.getLength() - nStart ) );
242 break;
244 lst.push_back( sProps.copy( nStart , nNext - nStart ) );
245 nNext ++;
250 static void assignFromStringToPropSeq( const OUString &sProps, uno_Sequence **ppPropertySeq)
252 ::std::list< OUString > lst;
253 extractTokens( sProps , lst );
255 typelib_TypeDescription *pSequenceType = 0;
256 getCppuType( (Sequence< ProtocolProperty > *)0).getDescription( &pSequenceType );
257 uno_Sequence *pSeq = 0;
258 uno_sequence_construct( &pSeq , pSequenceType , 0, lst.size() , 0 );
259 ProtocolProperty *pElements = (ProtocolProperty * ) pSeq->elements;
261 sal_Int32 i = 0;
262 for( ::std::list< OUString >::iterator ii = lst.begin() ; ii != lst.end() ; ++ ii, i++ )
264 sal_Int32 nAssign = (*ii).indexOf( '=' );
265 if( -1 == nAssign )
267 OString o = OUStringToOString( *ii, RTL_TEXTENCODING_ASCII_US );
268 OSL_ENSURE( !"wrong protocol propertyt format, ignored", o.getStr() );
270 OUString sPropName = (*ii).copy( 0, nAssign );
271 OUString sValue = (*ii).copy( nAssign +1, (*ii).getLength() - nAssign -1 );
273 sal_Int32 nIndex = getIndexFromString( sPropName );
274 if( -1 == nIndex )
276 OString o = OUStringToOString( sPropName , RTL_TEXTENCODING_ASCII_US);
277 OSL_ENSURE( !"unknown protocol property, ignored", o.getStr() );
279 switch( nIndex )
281 // voids
282 case PROPERTY_CURRENTCONTEXT:
283 pElements[i].Name = OUString::createFromAscii(
284 g_aPropertyName[nIndex] );
285 break;
286 // bools
287 case PROPERTY_CLEARCACHE:
288 case PROPERTY_NEGOTIATE:
289 case PROPERTY_FORCESYNCHRONOUS:
291 sal_Bool bClearCache = (sal_Bool ) sValue.toInt32();
292 assignToIdl( &(pElements[i]) , nIndex , bClearCache );
293 break;
295 // ints
296 case PROPERTY_TYPECACHESIZE:
297 case PROPERTY_OIDCACHESIZE:
298 case PROPERTY_TIDCACHESIZE:
299 case PROPERTY_FLUSHBLOCKSIZE:
300 case PROPERTY_ONEWAYTIMEOUT_MUSEC:
302 sal_Int32 nValue = sValue.toInt32();
303 assignToIdl( &(pElements[i]) , nIndex , nValue );
304 break;
307 // strings
308 case PROPERTY_VERSION:
309 assignToIdl( &(pElements[i]) , nIndex , sValue );
310 break;
311 default:
312 OString o = OUStringToOString( sPropName, RTL_TEXTENCODING_ASCII_US );
313 OSL_ENSURE( !"readonly protocol property, ignored" , o.getStr() );
316 *ppPropertySeq = pSeq;
317 typelib_typedescription_release( pSequenceType );
320 static void assignFromPropSeqToStruct( uno_Sequence *pSeq , struct Properties *pProps )
322 sal_Int32 i;
323 ProtocolProperty *pElements = (ProtocolProperty *)pSeq->elements;
324 for( i = 0 ; i < pSeq->nElements ; i ++ )
326 assignFromIdlToStruct( pProps , pElements[i] );
330 void assignFromStringToStruct( const OUString & sProps , struct Properties *pProps )
332 uno_Sequence *pSeq = 0;
333 assignFromStringToPropSeq( sProps , &pSeq );
334 assignFromPropSeqToStruct( pSeq , pProps );
335 uno_type_destructData( &pSeq, getCppuType( (Sequence< ProtocolProperty > *)0).getTypeLibType(),0);
339 //----------------------------------------------------------------------------------------------
340 // PropertyObject implementation
341 PropertyObject::PropertyObject(
342 struct Properties *pLocalSetting , uno_Environment *pEnvRemote, urp_BridgeImpl *pImpl )
343 : m_commitChangeCondition( osl_createCondition() )
344 , m_nRefCount( 0 )
345 , m_pBridgeImpl( pImpl )
346 , m_pLocalSetting( pLocalSetting )
347 , m_pEnvRemote( pEnvRemote )
348 , m_bRequestChangeHasBeenCalled( sal_False )
349 , m_bServerWaitingForCommit( sal_False )
350 , m_bApplyProperties( sal_False )
352 acquire = staticAcquire;
353 release = staticRelease;
354 pDispatcher = staticDispatch;
357 PropertyObject::~PropertyObject()
359 osl_destroyCondition( m_commitChangeCondition );
362 void SAL_CALL PropertyObject::thisDispatch(
363 typelib_TypeDescription const * pMemberType, void * pReturn, void * ppArgs[],
364 uno_Any ** ppException )
366 OSL_ASSERT( pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD );
368 typelib_InterfaceMethodTypeDescription *pMethodType =
369 ( typelib_InterfaceMethodTypeDescription * ) pMemberType;
371 switch( pMethodType->aBase.nPosition )
373 case METHOD_QUERY_INTERFACE:
374 OSL_ENSURE( 0 , "not implemented yet !" );
375 break;
376 case METHOD_GET_PROPERTIES:
378 implGetProperties( (uno_Sequence **) pReturn );
379 *ppException = 0;
380 break;
382 case METHOD_COMMIT_CHANGE:
384 implCommitChange( *(uno_Sequence ** ) ppArgs[0] , ppException );
385 break;
387 case METHOD_REQUEST_CHANGE:
389 *(sal_Int32 *) pReturn = implRequestChange( *(sal_Int32 *)ppArgs[0], ppException );
390 break;
392 default:
393 OSL_ENSURE( 0 , "unkown method !" );
397 void SAL_CALL PropertyObject::localGetPropertiesFromRemote( struct Properties *pR )
399 OUString oid = OUString::createFromAscii( g_NameOfUrpProtocolPropertiesObject );
401 typelib_TypeDescription *pInterfaceType = 0;
402 getCppuType( (Reference< XProtocolProperties > *) 0 ).getDescription( &pInterfaceType );
404 if( !pInterfaceType->bComplete )
406 typelib_typedescription_complete( &pInterfaceType );
409 typelib_TypeDescription *pMethodType = 0;
410 typelib_typedescriptionreference_getDescription(
411 &pMethodType,
412 ((typelib_InterfaceTypeDescription*) pInterfaceType)->ppAllMembers[METHOD_GET_PROPERTIES] );
415 uno_Sequence *pResult = 0;
416 uno_Any exception;
417 uno_Any *pException = &exception;
418 urp_sendRequest( m_pEnvRemote,
419 pMethodType,
420 oid.pData,
421 (typelib_InterfaceTypeDescription*) pInterfaceType,
422 &pResult,
424 &pException );
426 if( pException )
428 OSL_ENSURE( 0 , "remote urp-bridge doesn't support property-object" );
429 uno_any_destruct( pException , 0 );
430 return;
433 ProtocolProperty *pP = (ProtocolProperty * ) pResult->elements;
434 for( sal_Int32 i = 0; i < pResult->nElements ; i ++ )
436 if( ! assignFromIdlToStruct( pR , pP[i] ) )
438 OSL_ENSURE( 0 , "unknown property !!!!" );
442 typelib_typedescription_release( pInterfaceType );
443 typelib_typedescription_release( pMethodType );
447 // implementation for call from remote
448 void SAL_CALL PropertyObject::implGetProperties( uno_Sequence **ppReturnValue )
450 typelib_TypeDescription *pElementType= 0;
451 getCppuType( (Sequence< ProtocolProperty > *)0).getDescription( &pElementType );
453 OSL_ENSURE( pElementType , "Couldn't get property type" );
455 *ppReturnValue = 0;
456 uno_sequence_construct( ppReturnValue , pElementType , 0, MAX_PROPERTIES , 0 );
457 ProtocolProperty *pElements = (ProtocolProperty * ) ( *ppReturnValue )->elements;
458 Properties *pP = m_pLocalSetting;
460 assignToIdl( &(pElements[PROPERTY_BRIDGEID]),PROPERTY_BRIDGEID, *(Sequence< sal_Int8 > *)&(pP->seqBridgeID) );
461 assignToIdl( &(pElements[PROPERTY_TYPECACHESIZE]),PROPERTY_TYPECACHESIZE,pP->nTypeCacheSize );
462 assignToIdl( &(pElements[PROPERTY_OIDCACHESIZE]),PROPERTY_OIDCACHESIZE, pP->nOidCacheSize );
463 assignToIdl( &(pElements[PROPERTY_TIDCACHESIZE]),PROPERTY_TIDCACHESIZE, pP->nTidCacheSize );
464 assignToIdl( &(pElements[PROPERTY_SUPPORTEDVERSIONS]),PROPERTY_SUPPORTEDVERSIONS, pP->sSupportedVersions );
465 assignToIdl( &(pElements[PROPERTY_VERSION]),PROPERTY_VERSION, pP->sVersion );
466 assignToIdl( &(pElements[PROPERTY_FLUSHBLOCKSIZE]), PROPERTY_FLUSHBLOCKSIZE,pP->nFlushBlockSize );
467 assignToIdl( &(pElements[PROPERTY_ONEWAYTIMEOUT_MUSEC]), PROPERTY_ONEWAYTIMEOUT_MUSEC, pP->nOnewayTimeoutMUSEC );
468 assignToIdl( &(pElements[PROPERTY_SUPPORTSMUSTREPLY]), PROPERTY_SUPPORTSMUSTREPLY, pP->bSupportsMustReply );
469 assignToIdl( &(pElements[PROPERTY_SUPPERTSSYNCHRONOUS]), PROPERTY_SUPPERTSSYNCHRONOUS, pP->bSupportsSynchronous );
470 assignToIdl( &(pElements[PROPERTY_SUPPORTSMULTIPLESYNCHRONOUS]), PROPERTY_SUPPORTSMULTIPLESYNCHRONOUS, pP->bSupportsMultipleSynchronous );
471 assignToIdl( &(pElements[PROPERTY_CLEARCACHE]), PROPERTY_CLEARCACHE, pP->bClearCache );
473 typelib_typedescription_release( pElementType );
476 //----------------------------------------------------------------------------------------------
477 sal_Int32 SAL_CALL PropertyObject::localRequestChange( )
479 sal_Int32 nResult = 0;
480 sal_Bool bCall = sal_True;
482 // disallow marshaling NOW !
483 ClearableMutexGuard marshalingGuard( m_pBridgeImpl->m_marshalingMutex );
485 MutexGuard guard( m_mutex );
486 if( m_bRequestChangeHasBeenCalled || m_bServerWaitingForCommit )
488 // another transaction is already underway
489 // try again later !
490 bCall = sal_False;
492 m_bRequestChangeHasBeenCalled = sal_True;
494 if( bCall )
496 // calulate random number
497 rtlRandomPool pool = rtl_random_createPool ();
498 rtl_random_getBytes( pool , &m_nRandomNumberOfRequest, sizeof( m_nRandomNumberOfRequest ) );
499 rtl_random_destroyPool( pool );
503 if( bCall )
505 OUString oid = OUString::createFromAscii( g_NameOfUrpProtocolPropertiesObject );
507 // gather types for calling
508 typelib_TypeDescription *pInterfaceType = 0;
509 getCppuType( (Reference< XProtocolProperties > *) 0 ).getDescription( &pInterfaceType );
511 if( !pInterfaceType->bComplete )
513 typelib_typedescription_complete( &pInterfaceType );
516 typelib_TypeDescription *pMethodType = 0;
517 typelib_typedescriptionreference_getDescription(
518 &pMethodType,
519 ((typelib_InterfaceTypeDescription*) pInterfaceType)->ppAllMembers[METHOD_REQUEST_CHANGE] );
521 void *pArg1 = &m_nRandomNumberOfRequest;
522 void **ppArgs = &pArg1;
524 uno_Any exception;
525 uno_Any *pException = &exception;
527 ClientJob job( m_pEnvRemote,
529 m_pBridgeImpl,
530 oid.pData,
531 pMethodType,
532 (typelib_InterfaceTypeDescription*) pInterfaceType,
533 &nResult,
534 ppArgs,
535 &pException );
537 // put the call on the line !
538 sal_Bool bSuccess = job.pack();
540 // now allow writing on wire again.
541 // NOTE : this has been locked, because it is inevitable to set m_bRequestChangeHasBeenCalled
542 // and call requestChange in an atomar operation. Otherwise, implRequestChange may be called
543 // inbetween and reply, before the request is put on the wire. This certainly would
544 // be confusing for the remote counterpart !
545 marshalingGuard.clear();
547 // wait for the reply ...
548 if( bSuccess )
550 job.wait();
552 if( pException )
554 // the object is unknown on the other side.
555 uno_any_destruct( pException , 0 );
556 nResult = 0;
559 else
561 nResult = 0;
563 typelib_typedescription_release( pInterfaceType );
564 typelib_typedescription_release( pMethodType );
568 MutexGuard guard( m_mutex );
569 m_bRequestChangeHasBeenCalled = sal_False;
570 m_bServerWaitingForCommit = ( 0 == nResult );
572 return nResult;
575 // implementation for call from remote
576 sal_Int32 SAL_CALL PropertyObject::implRequestChange( sal_Int32 nRandomNumber, uno_Any **ppException )
578 sal_Int32 nResult = 0;
579 MutexGuard guard( m_mutex );
580 if( m_bRequestChangeHasBeenCalled )
582 // this side has also called requestChange, now negotiate, which side is allowed
583 // to commit the change !
584 if( m_nRandomNumberOfRequest > nRandomNumber )
586 // this side may commit !!!!
587 nResult = 0;
589 else if( m_nRandomNumberOfRequest == nRandomNumber )
591 // sorry, try again !
592 nResult = -1;
594 else if( m_nRandomNumberOfRequest < nRandomNumber )
596 // the other side may commit !
597 nResult = 1;
598 // m_bServerWaitingForCommit will be set by localRequestChange
601 else
603 // This side has NOT called requestChange, so the other side may commit
604 nResult = 1;
605 m_bServerWaitingForCommit = sal_True;
608 *ppException = 0;
609 return nResult;
614 void SAL_CALL PropertyObject::localCommitChange( const ::rtl::OUString &sProps , sal_Bool *pbExceptionThrown )
616 // lock the bridge NOW !
617 // NOTE: it is not allowed for other threads to call, when a commit change is underway.
618 // The remote counterpart cannot if the call following the commit already uses
619 // the new properties or not.
620 MutexGuard guard( m_pBridgeImpl->m_marshalingMutex );
622 OUString oid = OUString::createFromAscii( g_NameOfUrpProtocolPropertiesObject );
624 osl_resetCondition( m_commitChangeCondition );
626 Properties props = *m_pLocalSetting;
628 typelib_TypeDescription *pInterfaceType = 0;
629 getCppuType( (Reference< XProtocolProperties > *) 0 ).getDescription( &pInterfaceType );
631 if( !pInterfaceType->bComplete )
633 typelib_typedescription_complete( &pInterfaceType );
636 typelib_TypeDescription *pMethodType = 0;
637 typelib_typedescriptionreference_getDescription(
638 &pMethodType,
639 ((typelib_InterfaceTypeDescription*) pInterfaceType)->ppAllMembers[METHOD_COMMIT_CHANGE] );
641 // typelib_TypeDescription *pSequenceType= 0;
644 // extract name/value pairs
645 uno_Sequence *pSeq = 0;
646 assignFromStringToPropSeq( sProps, &pSeq );
647 assignFromPropSeqToStruct( pSeq , &props );
648 // ::std::list< OUString > lst;
649 // extractTokens( sProps , lst );
651 // getCppuType( (Sequence< ProtocolProperty > *)0).getDescription( &pSequenceType );
652 // uno_sequence_construct( &pSeq , pSequenceType , 0, lst.size() , 0 );
653 // ProtocolProperty *pElements = (ProtocolProperty * ) pSeq->elements;
655 // sal_Int32 i = 0;
656 // for( ::std::list< OUString >::iterator ii = lst.begin() ; ii != lst.end() ; ++ ii, i++ )
657 // {
658 // sal_Int32 nAssign = (*ii).indexOf( '=' );
659 // if( -1 == nAssign )
660 // {
661 // OString o = OUStringToOString( *ii, RTL_TEXTENCODING_ASCII_US );
662 // OSL_ENSURE( !"wrong protocol propertyt format, ignored", o.getStr() );
663 // }
664 // OUString sPropName = (*ii).copy( 0, nAssign );
665 // OUString sValue = (*ii).copy( nAssign +1, (*ii).getLength() - nAssign -1 );
667 // sal_Int32 nIndex = getIndexFromString( sPropName );
668 // if( -1 == nIndex )
669 // {
670 // OString o = OUStringToOString( sPropName , RTL_TEXTENCODING_ASCII_US);
671 // OSL_ENSURE( !"unknown protocol property, ignored", o.getStr() );
672 // }
673 // switch( nIndex )
674 // {
675 // // bools
676 // case PROPERTY_CLEARCACHE:
677 // {
678 // sal_Bool bClearCache = (sal_Bool ) sValue.toInt32();
679 // assignToIdl( &(pElements[i]) , nIndex , bClearCache );
680 // break;
681 // }
682 // // ints
683 // case PROPERTY_TYPECACHESIZE:
684 // case PROPERTY_OIDCACHESIZE:
685 // case PROPERTY_TIDCACHESIZE:
686 // case PROPERTY_FLUSHBLOCKSIZE:
687 // case PROPERTY_ONEWAYTIMEOUT_MUSEC:
688 // {
689 // sal_Int32 nValue = sValue.toInt32();
690 // assignToIdl( &(pElements[i]) , nIndex , nValue );
691 // break;
692 // }
694 // // strings
695 // case PROPERTY_VERSION:
696 // assignToIdl( &(pElements[i]) , nIndex , sValue );
697 // break;
698 // default:
699 // OString o = OUStringToOString( sPropName, RTL_TEXTENCODING_ASCII_US );
700 // OSL_ENSURE( !"readonly protocol property, ignored" , o.getStr() );
701 // }
702 // assignFromIdlToStruct( &props, pElements[i] );
703 // }
705 void *pArg1 = &pSeq;
706 uno_Any exception;
707 uno_Any *pException = &exception;
709 ClientJob job( m_pEnvRemote,
711 m_pBridgeImpl,
712 oid.pData,
713 pMethodType,
714 (typelib_InterfaceTypeDescription*) pInterfaceType,
716 &pArg1,
717 &pException );
718 job.setBridgePropertyCall();
719 if( job.pack() )
721 job.wait();
723 else
725 OSL_ASSERT( pException != NULL );
728 ::uno_type_destructData(
729 &pSeq, getCppuType( (Sequence< ProtocolProperty > *)0).getTypeLibType(), 0 );
731 *pbExceptionThrown = pException ? sal_True : sal_False;
733 if( pException )
735 OString o = OUStringToOString( ((com::sun::star::uno::Exception*)pException->pData)->Message,
736 RTL_TEXTENCODING_ASCII_US);
737 OSL_ENSURE( !"exception thrown during calling on PropertyObject",o.getStr() );
738 uno_any_destruct( pException , 0 );
740 else
742 m_pBridgeImpl->applyProtocolChanges( props );
743 m_bServerWaitingForCommit = sal_False;
744 m_bApplyProperties = sal_False;
747 // let the reader thread go ...
748 osl_setCondition( m_commitChangeCondition );
750 typelib_typedescription_release( pMethodType );
751 typelib_typedescription_release( pInterfaceType );
754 void SAL_CALL PropertyObject::implCommitChange( uno_Sequence *pSequence, uno_Any **ppException )
756 MutexGuard guard( m_mutex );
757 m_propsToBeApplied = *m_pLocalSetting;
759 ProtocolProperty *pP = (ProtocolProperty * ) pSequence->elements;
760 for( sal_Int32 i = 0; i < pSequence->nElements ; i ++ )
762 if( ! assignFromIdlToStruct( &m_propsToBeApplied , pP[i] ) )
764 InvalidProtocolChangeException exception;
765 Type type = getCppuType( &exception );
766 exception.Message = OUString::createFromAscii( "urp: unknown Property " );
767 exception.Message += pP[i].Name;
768 exception.invalidProperty = pP[i];
769 exception.reason = 1;
771 uno_type_any_construct( *ppException, &exception, type.getTypeLibType() , 0 );
773 m_bApplyProperties = sal_False;
774 m_bServerWaitingForCommit = sal_False;
775 return;
779 m_bApplyProperties = sal_True;
780 *ppException = 0;
783 Properties SAL_CALL PropertyObject::getCommitedChanges()
785 MutexGuard guard( m_mutex );
786 OSL_ASSERT( m_bApplyProperties );
787 m_bApplyProperties = sal_False;
788 m_bServerWaitingForCommit = sal_False;
789 return m_propsToBeApplied;
792 void SAL_CALL PropertyObject::waitUntilChangesAreCommitted()
794 osl_waitCondition( m_commitChangeCondition , 0 );