1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppu.hxx"
31 #include "osl/mutex.hxx"
32 #include "osl/thread.h"
34 #include "cppu/helper/purpenv/Environment.hxx"
35 #include "cppu/helper/purpenv/Mapping.hxx"
39 # define LOG_LIFECYCLE_UnsafeBridge
42 #ifdef LOG_LIFECYCLE_UnsafeBridge
44 # define LOG_LIFECYCLE_UnsafeBridge_emit(x) x
47 # define LOG_LIFECYCLE_UnsafeBridge_emit(x)
52 class SAL_DLLPRIVATE UnsafeBridge
: public cppu::Enterable
56 oslThreadIdentifier m_threadId
;
58 virtual ~UnsafeBridge(void);
61 explicit UnsafeBridge(void);
63 virtual void v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
);
64 virtual void v_callOut_v (uno_EnvCallee
* pCallee
, va_list * pParam
);
66 virtual void v_enter(void);
67 virtual void v_leave(void);
69 virtual int v_isValid(rtl::OUString
* pReason
);
72 UnsafeBridge::UnsafeBridge(void)
76 LOG_LIFECYCLE_UnsafeBridge_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "UnsafeBridge::UnsafeBridge(uno_Environment * pEnv)", this));
79 UnsafeBridge::~UnsafeBridge(void)
81 LOG_LIFECYCLE_UnsafeBridge_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "UnsafeBridge::~UnsafeBridge(void)", this));
83 OSL_ASSERT(m_count
>= 0);
86 void UnsafeBridge::v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
93 void UnsafeBridge::v_callOut_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
95 OSL_ASSERT(m_count
> 0);
102 m_threadId
= osl_getThreadIdentifier(NULL
);
105 void UnsafeBridge::v_enter(void)
109 OSL_ASSERT(m_count
>= 0);
112 m_threadId
= osl_getThreadIdentifier(NULL
);
117 void UnsafeBridge::v_leave(void)
119 OSL_ASSERT(m_count
> 0);
129 int UnsafeBridge::v_isValid(rtl::OUString
* pReason
)
133 result
= m_count
> 0;
135 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered"));
139 result
= m_threadId
== osl_getThreadIdentifier(NULL
);
142 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrong thread"));
146 *pReason
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
151 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_initEnvironment(uno_Environment
* pEnv
)
154 cppu::helper::purpenv::Environment_initWithEnterable(pEnv
, new UnsafeBridge());
157 extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL
uno_ext_getMapping(uno_Mapping
** ppMapping
,
158 uno_Environment
* pFrom
,
159 uno_Environment
* pTo
)
161 cppu::helper::purpenv::createMapping(ppMapping
, pFrom
, pTo
);