Update ooo320-m1
[ooovba.git] / bridges / source / remote / static / remote.cxx
blob51fc67a0d7cefb9d6ed9e08a56ae4b5449b94069
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: remote.cxx,v $
10 * $Revision: 1.10 $
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 #if OSL_DEBUG_LEVEL == 0
34 # ifndef NDEBUG
35 # define NDEBUG
36 # endif
37 #endif
38 #include <assert.h>
39 #include <bridges/remote/remote.hxx>
40 #include <bridges/remote/counter.hxx>
42 #if OSL_DEBUG_LEVEL > 1
43 static MyCounter thisCounter( "DEBUG : Remote2RemoteStub");
44 #endif
46 using namespace bridges_remote;
48 extern "C" {
50 static void SAL_CALL thisRelease( remote_Interface *pThis )
52 Remote2RemoteStub *p = ( Remote2RemoteStub * ) pThis;
53 if (! osl_decrementInterlockedCount( &(p->m_nRef) ))
55 p->m_pEnvRemote->pExtEnv->revokeInterface( p->m_pEnvRemote->pExtEnv, pThis );
60 static void SAL_CALL thisDispatch(
61 remote_Interface * pRemoteI,
62 typelib_TypeDescription const * pMemberType,
63 void * pReturn,
64 void * pArgs[],
65 uno_Any ** ppException )
67 Remote2RemoteStub *pThis = ( Remote2RemoteStub * ) pRemoteI;
69 pThis->m_dispatch( pThis->m_pEnvRemote,
70 pMemberType,
71 pThis->m_sOid.pData,
72 pThis->m_pType,
73 pReturn,
74 pArgs,
75 ppException );
80 namespace bridges_remote {
82 void acquireRemote2RemoteStub( remote_Interface *pThis )
84 Remote2RemoteStub *p = ( Remote2RemoteStub * ) pThis;
85 if( 1 == osl_incrementInterlockedCount( &(p->m_nRef) ) )
87 p->m_pEnvRemote->pExtEnv->registerProxyInterface(
88 p->m_pEnvRemote->pExtEnv,
89 (void**)&pThis,
90 freeRemote2RemoteStub,
91 p->m_sOid.pData,
92 p->m_pType );
93 assert( (remote_Interface *)p == pThis );
97 void freeRemote2RemoteStub(uno_ExtEnvironment *, void * stub) {
98 delete static_cast< Remote2RemoteStub * >(stub);
101 Remote2RemoteStub::Remote2RemoteStub( rtl_uString *pOid,
102 typelib_InterfaceTypeDescription *pType,
103 uno_Environment *pEnvRemote,
104 requestClientSideDispatcher dispatch ) :
105 m_sOid( pOid ),
106 m_pType( (typelib_InterfaceTypeDescription * ) pType ),
107 m_nRef( 1 ),
108 m_pEnvRemote( pEnvRemote ),
109 m_dispatch( dispatch ),
110 m_nReleaseRemote( 1 )
112 typelib_typedescription_acquire( ( typelib_TypeDescription * ) m_pType );
113 m_pEnvRemote->acquire( m_pEnvRemote );
115 acquire = acquireRemote2RemoteStub;
116 release = thisRelease;
117 pDispatcher = thisDispatch;
118 #if OSL_DEBUG_LEVEL > 1
119 thisCounter.acquire();
120 #endif
123 Remote2RemoteStub::~Remote2RemoteStub()
126 // send a release via the connection !
127 sal_Bool bNeedsRelease = sal_False;
128 if( ! m_pType->aBase.bComplete )
130 // m_pType may be exchanged during complete, so it needs to be acquired
131 // (MT : Another thread may use m_pType during e.g. dispatch ! ).
132 typelib_typedescription_acquire( (typelib_TypeDescription*)m_pType );
133 bNeedsRelease = sal_True;
134 typelib_typedescription_complete( (typelib_TypeDescription **) &m_pType );
137 uno_Any any;
138 uno_Any *pAny = &any;
140 typelib_TypeDescription *pReleaseMethod = 0;
141 typelib_typedescriptionreference_getDescription(
142 &pReleaseMethod ,
143 m_pType->ppAllMembers[REMOTE_RELEASE_METHOD_INDEX] );
144 for( int i = 0 ; i < m_nReleaseRemote ; i ++ )
146 thisDispatch( this,
147 pReleaseMethod,
150 &pAny );
152 typelib_typedescription_release( pReleaseMethod );
153 if( bNeedsRelease )
155 typelib_typedescription_release( (typelib_TypeDescription * ) m_pType );
158 typelib_typedescription_release( (typelib_TypeDescription * ) m_pType );
159 m_pEnvRemote->release( m_pEnvRemote );
160 #if OSL_DEBUG_LEVEL > 1
161 thisCounter.release();
162 #endif
165 void Remote2RemoteStub::releaseRemote()
167 osl_incrementInterlockedCount( &m_nReleaseRemote );
170 } // end namespace bridges_remote