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: remote.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 #if OSL_DEBUG_LEVEL == 0
39 #include <bridges/remote/remote.hxx>
40 #include <bridges/remote/counter.hxx>
42 #if OSL_DEBUG_LEVEL > 1
43 static MyCounter
thisCounter( "DEBUG : Remote2RemoteStub");
46 using namespace bridges_remote
;
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
,
65 uno_Any
** ppException
)
67 Remote2RemoteStub
*pThis
= ( Remote2RemoteStub
* ) pRemoteI
;
69 pThis
->m_dispatch( pThis
->m_pEnvRemote
,
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
,
90 freeRemote2RemoteStub
,
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
) :
106 m_pType( (typelib_InterfaceTypeDescription
* ) pType
),
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();
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
);
138 uno_Any
*pAny
= &any
;
140 typelib_TypeDescription
*pReleaseMethod
= 0;
141 typelib_typedescriptionreference_getDescription(
143 m_pType
->ppAllMembers
[REMOTE_RELEASE_METHOD_INDEX
] );
144 for( int i
= 0 ; i
< m_nReleaseRemote
; i
++ )
152 typelib_typedescription_release( pReleaseMethod
);
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();
165 void Remote2RemoteStub::releaseRemote()
167 osl_incrementInterlockedCount( &m_nReleaseRemote
);
170 } // end namespace bridges_remote