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: TestProxy.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 #include "uno/mapping.hxx"
32 #include "cppu/EnvDcp.hxx"
34 #include "../mapping_tester/Mapping.tester.hxx"
36 #include "TestProxy.hxx"
40 #define LOG_LIFECYCLE_TestProxy
43 #define LOG_LIFECYCLE_TestProxy
44 #ifdef LOG_LIFECYCLE_TestProxy
46 # define LOG_LIFECYCLE_TestProxy_emit(x) x
49 # define LOG_LIFECYCLE_TestProxy_emit(x)
54 using namespace com::sun::star
;
56 extern "C" void SAL_CALL
TestProxy_free(uno_ExtEnvironment
* /*pEnv*/, void * pObject
)
59 TestProxy
* pTestProxy
= reinterpret_cast<TestProxy
*>(pObject
);
65 static void SAL_CALL
s_acquire(uno_Interface
* pUnoI
) SAL_THROW_EXTERN_C()
67 TestProxy
* pTestProxy
= static_cast<TestProxy
*>(pUnoI
);
68 pTestProxy
->acquire();
71 static void SAL_CALL
s_release(uno_Interface
* pUnoI
) SAL_THROW_EXTERN_C()
73 TestProxy
* pTestProxy
= static_cast<TestProxy
*>(pUnoI
);
74 pTestProxy
->release();
77 static void SAL_CALL
s_dispatch(uno_Interface
* pUnoI
,
78 typelib_TypeDescription
const * pMemberType
,
81 uno_Any
** ppException
)
84 TestProxy
* pThis
= static_cast<TestProxy
*>(pUnoI
);
85 pThis
->dispatch(pMemberType
, pReturn
, pArgs
, ppException
);
89 TestProxy::TestProxy(uno_Interface
* pObject
,
90 rtl::OUString
const & oid
,
91 typelib_InterfaceTypeDescription
* pTypeDescr
,
92 uno_ExtEnvironment
* pFrom_extEnv
,
93 uno_ExtEnvironment
* pTo_extEnv
)
95 m_from_envDcp(pFrom_extEnv
->aBase
.pTypeName
),
96 m_to_envDcp (pTo_extEnv
->aBase
.pTypeName
),
98 m_pTypeDescr (pTypeDescr
)
100 LOG_LIFECYCLE_TestProxy_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "TestProxy::TestProxy", this));
103 uno_Interface::acquire
= s_acquire
;
104 uno_Interface::release
= s_release
;
105 uno_Interface::pDispatcher
= s_dispatch
;
107 m_theObject
= pObject
;
108 m_theObject
->acquire(m_theObject
);
110 typelib_typedescription_acquire(&pTypeDescr
->aBase
);
112 m_pFrom_extEnv
= pFrom_extEnv
;
113 m_pFrom_extEnv
->aBase
.acquire(&m_pFrom_extEnv
->aBase
);
115 m_pTo_extEnv
= pTo_extEnv
;
116 m_pTo_extEnv
->aBase
.acquire(&m_pTo_extEnv
->aBase
);
118 m_pTo_extEnv
->registerInterface(m_pTo_extEnv
, reinterpret_cast<void **>(&pObject
), oid
.pData
, pTypeDescr
);
121 TestProxy::~TestProxy(void)
123 LOG_LIFECYCLE_TestProxy_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "TestProxy::~TestProxy", this));
125 m_pTo_extEnv
->revokeInterface(m_pTo_extEnv
, reinterpret_cast<void *>(m_theObject
));
127 typelib_typedescription_release(&m_pTypeDescr
->aBase
);
128 m_theObject
->release(m_theObject
);
129 m_pFrom_extEnv
->aBase
.release(&m_pFrom_extEnv
->aBase
);
130 m_pTo_extEnv
->aBase
.release(&m_pTo_extEnv
->aBase
);
133 void TestProxy::acquire() SAL_THROW(())
135 if (osl_incrementInterlockedCount(&m_nCount
) == 1)
137 uno_Interface
* pThis
= this;
138 m_pTo_extEnv
->registerProxyInterface(m_pTo_extEnv
,
143 OSL_ASSERT(pThis
== this);
147 void TestProxy::release() SAL_THROW(())
149 if (osl_decrementInterlockedCount(&m_nCount
) == 0)
151 m_pFrom_extEnv
->revokeInterface(m_pFrom_extEnv
, this);
155 void TestProxy::dispatch(typelib_TypeDescription
const * pMemberType
,
158 uno_Any
** ppException
)
161 rtl::OUString
arrow(RTL_CONSTASCII_USTRINGPARAM("-->"));
163 if (!g_custom
.getLength())
164 g_custom
+= m_from_envDcp
;
167 g_custom
+= m_to_envDcp
;
169 m_theObject
->pDispatcher(m_theObject
, pMemberType
, pReturn
, pArgs
, ppException
);
171 uno_Any
* any
= (uno_Any
*)pReturn
;
175 uno::Mapping
mapping(m_to_envDcp
, m_from_envDcp
);
176 mapping
.mapInterface(&pout
, any
->pReserved
, any
->pType
);
178 ((uno_Interface
*)any
->pReserved
)->release((uno_Interface
*)any
->pReserved
);
179 any
->pReserved
= pout
;